Skip to content

Commit

Permalink
Merge pull request #5 from mgdm/fixGlobals
Browse files Browse the repository at this point in the history
Add error handling to a thread global
  • Loading branch information
mgdm committed Dec 4, 2013
2 parents f772714 + 7552312 commit 7d0eac7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
9 changes: 7 additions & 2 deletions mosquitto.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
zend_class_entry *mosquitto_ce_client;
zend_class_entry *mosquitto_ce_exception;
zend_object_handlers mosquitto_std_object_handlers;
zend_error_handling mosquitto_original_error_handling;

ZEND_DECLARE_MODULE_GLOBALS(mosquitto)

static inline mosquitto_client_object *mosquitto_client_object_get(zval *zobj TSRMLS_DC);

Expand Down Expand Up @@ -996,7 +997,11 @@ zend_module_entry mosquitto_module_entry = {
#if ZEND_MODULE_API_NO >= 20010901
"0.1", /* Replace with version number for your extension */
#endif
STANDARD_MODULE_PROPERTIES
PHP_MODULE_GLOBALS(mosquitto),
NULL,
NULL,
NULL,
STANDARD_MODULE_PROPERTIES_EX
};
/* }}} */

Expand Down
18 changes: 14 additions & 4 deletions php_mosquitto.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ typedef struct _php_mosquitto_prop_handler {


#define PHP_MOSQUITTO_ERROR_HANDLING() \
zend_replace_error_handling(EH_THROW, mosquitto_ce_exception, &mosquitto_original_error_handling TSRMLS_CC)
zend_replace_error_handling(EH_THROW, mosquitto_ce_exception, &MQTTG(mosquitto_original_error_handling) TSRMLS_CC)

#define PHP_MOSQUITTO_RESTORE_ERRORS() \
zend_restore_error_handling(&mosquitto_original_error_handling TSRMLS_CC)
zend_restore_error_handling(&MQTTG(mosquitto_original_error_handling) TSRMLS_CC)



Expand Down Expand Up @@ -126,9 +126,19 @@ static int php_mosquitto_message_write_##name(mosquitto_message_object *mosquitt
return SUCCESS; \
}

ZEND_BEGIN_MODULE_GLOBALS(mosquitto)
char *client_key;
zend_object_handlers mosquitto_std_object_handlers;
zend_error_handling mosquitto_original_error_handling;
ZEND_END_MODULE_GLOBALS(mosquitto)

extern zend_object_handlers mosquitto_std_object_handlers;
extern zend_error_handling mosquitto_original_error_handling;
#ifdef ZTS
# define MQTTG(v) TSRMG(mosquitto_globals_id, zend_mosquitto_globals *, v)
#else
# define MQTTG(v) (mosquitto_globals.v)
#endif

ZEND_EXTERN_MODULE_GLOBALS(mosquitto)

extern zend_class_entry *mosquitto_ce_exception;
extern zend_class_entry *mosquitto_ce_client;
Expand Down

0 comments on commit 7d0eac7

Please sign in to comment.