From 84c61b09e41c169755320a44c0e27a3ce95db932 Mon Sep 17 00:00:00 2001 From: Michael Maclean Date: Mon, 23 Sep 2013 02:39:06 +0200 Subject: [PATCH] Contain the mosquitto_message within the struct --- test.php => examples/test.php | 0 mosquitto.c | 8 ++++---- mosquitto_message.c | 19 +++++++++---------- php_mosquitto.h | 6 +++--- 4 files changed, 16 insertions(+), 17 deletions(-) rename test.php => examples/test.php (100%) diff --git a/test.php b/examples/test.php similarity index 100% rename from test.php rename to examples/test.php diff --git a/mosquitto.c b/mosquitto.c index 8ed43bd..e9b6d6b 100644 --- a/mosquitto.c +++ b/mosquitto.c @@ -395,7 +395,7 @@ PHP_MOSQUITTO_API void php_mosquitto_message_callback(struct mosquitto *mosq, vo ALLOC_INIT_ZVAL(message_zval); object_init_ex(message_zval, mosquitto_ce_message); message_object = (mosquitto_message_object *) zend_object_store_get_object(message_zval TSRMLS_CC); - mosquitto_message_copy(message_object->message, message); + mosquitto_message_copy(&message_object->message, message); params[0] = &message_zval; object->message_callback.params = params; @@ -420,15 +420,15 @@ PHP_MOSQUITTO_API void php_mosquitto_subscribe_callback(struct mosquitto *mosq, { mosquitto_client_object *object = (mosquitto_client_object *) client_obj; zval *retval_ptr = NULL; - zval *mid_zval = NULL, *qos_count_zval = NULL; + zval *mid_zval, *qos_count_zval; zval **params[2]; if (!ZEND_FCI_INITIALIZED(object->subscribe_callback)) { return; } - ALLOC_INIT_ZVAL(mid_zval); - ALLOC_INIT_ZVAL(qos_count_zval); + MAKE_STD_ZVAL(mid_zval); + MAKE_STD_ZVAL(qos_count_zval); ZVAL_LONG(mid_zval, mid); ZVAL_LONG(qos_count_zval, qos_count); /* TODO: handle granted_qos */ diff --git a/mosquitto_message.c b/mosquitto_message.c index 4d3faac..c672fa8 100644 --- a/mosquitto_message.c +++ b/mosquitto_message.c @@ -34,21 +34,21 @@ PHP_MOSQUITTO_MESSAGE_LONG_PROPERTY_READER_FUNCTION(qos); static int php_mosquitto_message_read_retain(mosquitto_message_object *mosquitto_object, zval **retval TSRMLS_DC) { MAKE_STD_ZVAL(*retval); - ZVAL_BOOL(*retval, mosquitto_object->message->retain); + ZVAL_BOOL(*retval, mosquitto_object->message.retain); return SUCCESS; } static int php_mosquitto_message_read_topic(mosquitto_message_object *mosquitto_object, zval **retval TSRMLS_DC) { MAKE_STD_ZVAL(*retval); - ZVAL_STRINGL(*retval, mosquitto_object->message->topic, strlen(mosquitto_object->message->topic), 1); + ZVAL_STRINGL(*retval, mosquitto_object->message.topic, strlen(mosquitto_object->message.topic), 1); return SUCCESS; } static int php_mosquitto_message_read_payload(mosquitto_message_object *mosquitto_object, zval **retval TSRMLS_DC) { MAKE_STD_ZVAL(*retval); - ZVAL_STRINGL(*retval, mosquitto_object->message->payload, mosquitto_object->message->payloadlen, 1); + ZVAL_STRINGL(*retval, mosquitto_object->message.payload, mosquitto_object->message.payloadlen, 1); return SUCCESS; } @@ -65,7 +65,7 @@ static int php_mosquitto_message_write_retain(mosquitto_message_object *mosquitt newval = &ztmp; } - mosquitto_object->message->retain = Z_LVAL_P(newval); + mosquitto_object->message.retain = Z_LVAL_P(newval); if (newval == &ztmp) { zval_dtor(newval); @@ -84,7 +84,7 @@ static int php_mosquitto_message_write_topic(mosquitto_message_object *mosquitto newval = &ztmp; } - mosquitto_object->message->topic = estrdup(Z_STRVAL_P(newval)); + mosquitto_object->message.topic = estrdup(Z_STRVAL_P(newval)); mosquitto_object->owned_topic = 1; if (newval == &ztmp) { @@ -104,8 +104,8 @@ static int php_mosquitto_message_write_payload(mosquitto_message_object *mosquit newval = &ztmp; } - mosquitto_object->message->payload = estrdup(Z_STRVAL_P(newval)); - mosquitto_object->message->payloadlen = Z_STRLEN_P(newval); + mosquitto_object->message.payload = estrdup(Z_STRVAL_P(newval)); + mosquitto_object->message.payloadlen = Z_STRLEN_P(newval); mosquitto_object->owned_payload = 1; if (newval == &ztmp) { @@ -284,11 +284,11 @@ static void mosquitto_message_object_destroy(void *object TSRMLS_DC) FREE_HASHTABLE(message->std.properties); if (message->owned_topic == 1) { - efree(message->message->topic); + efree(message->message.topic); } if (message->owned_payload == 1) { - efree(message->message->payload); + efree(message->message.payload); } efree(object); @@ -302,7 +302,6 @@ static zend_object_value mosquitto_message_object_new() { message_obj = ecalloc(1, sizeof(mosquitto_message_object)); message_obj->std.ce = mosquitto_ce_message; - message_obj->message = NULL; ALLOC_HASHTABLE(message_obj->std.properties); zend_hash_init(message_obj->std.properties, 0, NULL, ZVAL_PTR_DTOR, 0); diff --git a/php_mosquitto.h b/php_mosquitto.h index 953c4e4..5a7e552 100644 --- a/php_mosquitto.h +++ b/php_mosquitto.h @@ -39,7 +39,7 @@ typedef struct _mosquitto_client_object { typedef struct _mosquitto_message_object { zend_object std; - struct mosquitto_message *message; + struct mosquitto_message message; zend_bool owned_topic; zend_bool owned_payload; } mosquitto_message_object; @@ -81,7 +81,7 @@ typedef struct _php_mosquitto_prop_handler { static int php_mosquitto_message_read_##name(mosquitto_message_object *mosquitto_object, zval **retval TSRMLS_DC) \ { \ MAKE_STD_ZVAL(*retval); \ - ZVAL_LONG(*retval, mosquitto_object->message->name); \ + ZVAL_LONG(*retval, mosquitto_object->message.name); \ return SUCCESS; \ } @@ -96,7 +96,7 @@ static int php_mosquitto_message_write_##name(mosquitto_message_object *mosquitt newval = &ztmp; \ } \ \ - mosquitto_object->message->name = Z_LVAL_P(newval); \ + mosquitto_object->message.name = Z_LVAL_P(newval); \ \ if (newval == &ztmp) { \ zval_dtor(newval); \