From 75b69887aa446aeb7f1b6325ec826f2b5ddfa972 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Wed, 5 Oct 2016 10:54:39 -0700 Subject: Fix segmentation fault when ZTS is defined. --- php/ext/google/protobuf/array.c | 3 +-- php/ext/google/protobuf/encode_decode.c | 28 +++++++++++++++++----------- php/ext/google/protobuf/type_check.c | 1 - 3 files changed, 18 insertions(+), 14 deletions(-) (limited to 'php/ext/google') diff --git a/php/ext/google/protobuf/array.c b/php/ext/google/protobuf/array.c index f96e95ec..c24ede81 100644 --- a/php/ext/google/protobuf/array.c +++ b/php/ext/google/protobuf/array.c @@ -160,8 +160,7 @@ static void repeated_field_write_dimension(zval *object, zval *offset, unsigned char memory[NATIVE_SLOT_MAX_SIZE]; memset(memory, 0, NATIVE_SLOT_MAX_SIZE); - if (!native_slot_set(intern->type, intern->msg_ce, memory, value - TSRMLS_CC)) { + if (!native_slot_set(intern->type, intern->msg_ce, memory, value TSRMLS_CC)) { return; } diff --git a/php/ext/google/protobuf/encode_decode.c b/php/ext/google/protobuf/encode_decode.c index af90ff33..b45d1b2a 100644 --- a/php/ext/google/protobuf/encode_decode.c +++ b/php/ext/google/protobuf/encode_decode.c @@ -199,8 +199,9 @@ static void *startseq_handler(void* closure, const void* hd) { // Handlers that append primitive values to a repeated field. #define DEFINE_APPEND_HANDLER(type, ctype) \ static bool append##type##_handler(void* closure, const void* hd, \ - ctype val TSRMLS_DC) { \ + ctype val) { \ zval* array = (zval*)closure; \ + TSRMLS_FETCH(); \ RepeatedField* intern = \ (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); \ repeated_field_push_native(intern, &val TSRMLS_CC); \ @@ -218,8 +219,9 @@ DEFINE_APPEND_HANDLER(double, double) // Appends a string to a repeated field. static void* appendstr_handler(void *closure, const void *hd, - size_t size_hint TSRMLS_DC) { + size_t size_hint) { zval* array = (zval*)closure; + TSRMLS_FETCH(); RepeatedField* intern = (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); @@ -234,8 +236,9 @@ static void* appendstr_handler(void *closure, // Appends a 'bytes' string to a repeated field. static void* appendbytes_handler(void *closure, const void *hd, - size_t size_hint TSRMLS_DC) { + size_t size_hint) { zval* array = (zval*)closure; + TSRMLS_FETCH(); RepeatedField* intern = (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); @@ -296,8 +299,9 @@ static size_t stringdata_handler(void* closure, const void* hd, } // Appends a submessage to a repeated field. -static void *appendsubmsg_handler(void *closure, const void *hd TSRMLS_DC) { +static void *appendsubmsg_handler(void *closure, const void *hd) { zval* array = (zval*)closure; + TSRMLS_FETCH(); RepeatedField* intern = (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); @@ -319,10 +323,11 @@ static void *appendsubmsg_handler(void *closure, const void *hd TSRMLS_DC) { } // Sets a non-repeated submessage field in a message. -static void *submsg_handler(void *closure, const void *hd TSRMLS_DC) { +static void *submsg_handler(void *closure, const void *hd) { MessageHeader* msg = closure; const submsg_handlerdata_t* submsgdata = hd; zval* subdesc_php = get_def_obj((void*)submsgdata->md); + TSRMLS_FETCH(); Descriptor* subdesc = zend_object_store_get_object(subdesc_php TSRMLS_CC); zend_class_entry* subklass = subdesc->klass; zval* submsg_php; @@ -465,11 +470,11 @@ static void *startmapentry_handler(void *closure, const void *hd) { // Handler to end a map entry: inserts the value defined during the message into // the map. This is the 'endmsg' handler on the map entry msgdef. -static bool endmap_handler(void *closure, const void *hd, upb_status* s - TSRMLS_DC) { +static bool endmap_handler(void* closure, const void* hd, upb_status* s) { map_parse_frame_t* frame = closure; const map_handlerdata_t* mapdata = hd; + TSRMLS_FETCH(); Map *map = (Map *)zend_object_store_get_object(frame->map TSRMLS_CC); const char* keyval = NULL; @@ -575,12 +580,12 @@ static void *oneofbytes_handler(void *closure, } // Handler for a submessage field in a oneof. -static void *oneofsubmsg_handler(void *closure, - const void *hd TSRMLS_DC) { +static void* oneofsubmsg_handler(void* closure, const void* hd) { MessageHeader* msg = closure; const oneof_handlerdata_t *oneofdata = hd; uint32_t oldcase = DEREF(msg, oneofdata->case_ofs, uint32_t); zval* subdesc_php = get_def_obj((void*)oneofdata->md); + TSRMLS_FETCH(); Descriptor* subdesc = zend_object_store_get_object(subdesc_php TSRMLS_CC); zend_class_entry* subklass = subdesc->klass; zval* submsg_php; @@ -773,9 +778,10 @@ static void add_handlers_for_oneof_field(upb_handlers *h, upb_handlerattr_uninit(&attr); } -static void add_handlers_for_message(const void *closure, upb_handlers *h - TSRMLS_DC) { +static void add_handlers_for_message(const void* closure, + upb_handlers* h) { const upb_msgdef* msgdef = upb_handlers_msgdef(h); + TSRMLS_FETCH(); Descriptor* desc = (Descriptor*)zend_object_store_get_object( get_def_obj((void*)msgdef) TSRMLS_CC); upb_msg_field_iter i; diff --git a/php/ext/google/protobuf/type_check.c b/php/ext/google/protobuf/type_check.c index fe9359fc..c215d72e 100644 --- a/php/ext/google/protobuf/type_check.c +++ b/php/ext/google/protobuf/type_check.c @@ -214,7 +214,6 @@ bool protobuf_convert_to_bool(zval* from, int8_t* to) { } else { *to = 1; } - STR_FREE(strval); } break; default: { zend_error(E_USER_ERROR, "Given value cannot be converted to bool."); -- cgit v1.2.3