Fix segmentation fault when ZTS is defined.

pull/2232/head
Bo Yang 8 years ago
parent 52ab3b07ac
commit 75b69887aa
  1. 3
      php/ext/google/protobuf/array.c
  2. 28
      php/ext/google/protobuf/encode_decode.c
  3. 1
      php/ext/google/protobuf/type_check.c
  4. 40
      php/tests/array_test.php
  5. 1
      tests.sh

@ -160,8 +160,7 @@ static void repeated_field_write_dimension(zval *object, zval *offset,
unsigned char memory[NATIVE_SLOT_MAX_SIZE]; unsigned char memory[NATIVE_SLOT_MAX_SIZE];
memset(memory, 0, NATIVE_SLOT_MAX_SIZE); memset(memory, 0, NATIVE_SLOT_MAX_SIZE);
if (!native_slot_set(intern->type, intern->msg_ce, memory, value if (!native_slot_set(intern->type, intern->msg_ce, memory, value TSRMLS_CC)) {
TSRMLS_CC)) {
return; return;
} }

@ -199,8 +199,9 @@ static void *startseq_handler(void* closure, const void* hd) {
// Handlers that append primitive values to a repeated field. // Handlers that append primitive values to a repeated field.
#define DEFINE_APPEND_HANDLER(type, ctype) \ #define DEFINE_APPEND_HANDLER(type, ctype) \
static bool append##type##_handler(void* closure, const void* hd, \ static bool append##type##_handler(void* closure, const void* hd, \
ctype val TSRMLS_DC) { \ ctype val) { \
zval* array = (zval*)closure; \ zval* array = (zval*)closure; \
TSRMLS_FETCH(); \
RepeatedField* intern = \ RepeatedField* intern = \
(RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); \ (RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); \
repeated_field_push_native(intern, &val 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. // Appends a string to a repeated field.
static void* appendstr_handler(void *closure, static void* appendstr_handler(void *closure,
const void *hd, const void *hd,
size_t size_hint TSRMLS_DC) { size_t size_hint) {
zval* array = (zval*)closure; zval* array = (zval*)closure;
TSRMLS_FETCH();
RepeatedField* intern = RepeatedField* intern =
(RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); (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. // Appends a 'bytes' string to a repeated field.
static void* appendbytes_handler(void *closure, static void* appendbytes_handler(void *closure,
const void *hd, const void *hd,
size_t size_hint TSRMLS_DC) { size_t size_hint) {
zval* array = (zval*)closure; zval* array = (zval*)closure;
TSRMLS_FETCH();
RepeatedField* intern = RepeatedField* intern =
(RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); (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. // 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; zval* array = (zval*)closure;
TSRMLS_FETCH();
RepeatedField* intern = RepeatedField* intern =
(RepeatedField*)zend_object_store_get_object(array TSRMLS_CC); (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. // 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; MessageHeader* msg = closure;
const submsg_handlerdata_t* submsgdata = hd; const submsg_handlerdata_t* submsgdata = hd;
zval* subdesc_php = get_def_obj((void*)submsgdata->md); zval* subdesc_php = get_def_obj((void*)submsgdata->md);
TSRMLS_FETCH();
Descriptor* subdesc = zend_object_store_get_object(subdesc_php TSRMLS_CC); Descriptor* subdesc = zend_object_store_get_object(subdesc_php TSRMLS_CC);
zend_class_entry* subklass = subdesc->klass; zend_class_entry* subklass = subdesc->klass;
zval* submsg_php; 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 // 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. // the map. This is the 'endmsg' handler on the map entry msgdef.
static bool endmap_handler(void *closure, const void *hd, upb_status* s static bool endmap_handler(void* closure, const void* hd, upb_status* s) {
TSRMLS_DC) {
map_parse_frame_t* frame = closure; map_parse_frame_t* frame = closure;
const map_handlerdata_t* mapdata = hd; const map_handlerdata_t* mapdata = hd;
TSRMLS_FETCH();
Map *map = (Map *)zend_object_store_get_object(frame->map TSRMLS_CC); Map *map = (Map *)zend_object_store_get_object(frame->map TSRMLS_CC);
const char* keyval = NULL; const char* keyval = NULL;
@ -575,12 +580,12 @@ static void *oneofbytes_handler(void *closure,
} }
// Handler for a submessage field in a oneof. // Handler for a submessage field in a oneof.
static void *oneofsubmsg_handler(void *closure, static void* oneofsubmsg_handler(void* closure, const void* hd) {
const void *hd TSRMLS_DC) {
MessageHeader* msg = closure; MessageHeader* msg = closure;
const oneof_handlerdata_t *oneofdata = hd; const oneof_handlerdata_t *oneofdata = hd;
uint32_t oldcase = DEREF(msg, oneofdata->case_ofs, uint32_t); uint32_t oldcase = DEREF(msg, oneofdata->case_ofs, uint32_t);
zval* subdesc_php = get_def_obj((void*)oneofdata->md); zval* subdesc_php = get_def_obj((void*)oneofdata->md);
TSRMLS_FETCH();
Descriptor* subdesc = zend_object_store_get_object(subdesc_php TSRMLS_CC); Descriptor* subdesc = zend_object_store_get_object(subdesc_php TSRMLS_CC);
zend_class_entry* subklass = subdesc->klass; zend_class_entry* subklass = subdesc->klass;
zval* submsg_php; zval* submsg_php;
@ -773,9 +778,10 @@ static void add_handlers_for_oneof_field(upb_handlers *h,
upb_handlerattr_uninit(&attr); upb_handlerattr_uninit(&attr);
} }
static void add_handlers_for_message(const void *closure, upb_handlers *h static void add_handlers_for_message(const void* closure,
TSRMLS_DC) { upb_handlers* h) {
const upb_msgdef* msgdef = upb_handlers_msgdef(h); const upb_msgdef* msgdef = upb_handlers_msgdef(h);
TSRMLS_FETCH();
Descriptor* desc = (Descriptor*)zend_object_store_get_object( Descriptor* desc = (Descriptor*)zend_object_store_get_object(
get_def_obj((void*)msgdef) TSRMLS_CC); get_def_obj((void*)msgdef) TSRMLS_CC);
upb_msg_field_iter i; upb_msg_field_iter i;

@ -214,7 +214,6 @@ bool protobuf_convert_to_bool(zval* from, int8_t* to) {
} else { } else {
*to = 1; *to = 1;
} }
STR_FREE(strval);
} break; } break;
default: { default: {
zend_error(E_USER_ERROR, "Given value cannot be converted to bool."); zend_error(E_USER_ERROR, "Given value cannot be converted to bool.");

@ -789,26 +789,26 @@ class RepeatedFieldTest extends PHPUnit_Framework_TestCase
$this->assertSame(1, count($arr)); $this->assertSame(1, count($arr));
} }
public function testInsertRemoval() public function testInsertRemoval()
{ {
$arr = new RepeatedField(GPBType::INT32); $arr = new RepeatedField(GPBType::INT32);
$arr []= 0; $arr []= 0;
$arr []= 1; $arr []= 1;
$arr []= 2; $arr []= 2;
$this->assertSame(3, count($arr)); $this->assertSame(3, count($arr));
unset($arr[2]); unset($arr[2]);
$this->assertSame(2, count($arr)); $this->assertSame(2, count($arr));
$this->assertSame(0, $arr[0]); $this->assertSame(0, $arr[0]);
$this->assertSame(1, $arr[1]); $this->assertSame(1, $arr[1]);
$arr [] = 3; $arr [] = 3;
$this->assertSame(3, count($arr)); $this->assertSame(3, count($arr));
$this->assertSame(0, $arr[0]); $this->assertSame(0, $arr[0]);
$this->assertSame(1, $arr[1]); $this->assertSame(1, $arr[1]);
$this->assertSame(3, $arr[2]); $this->assertSame(3, $arr[2]);
} }
/** /**
* @expectedException PHPUnit_Framework_Error * @expectedException PHPUnit_Framework_Error

@ -377,6 +377,7 @@ build_php5.5_mac() {
build_php5.5_zts_c() { build_php5.5_zts_c() {
use_php_zts 5.5 use_php_zts 5.5
wget https://phar.phpunit.de/phpunit-old.phar -O /usr/bin/phpunit
cd php/tests && /bin/bash ./test.sh && cd ../.. cd php/tests && /bin/bash ./test.sh && cd ../..
} }

Loading…
Cancel
Save