Skip to content

Commit

Permalink
Fix segmentation fault when ZTS is defined.
Browse files Browse the repository at this point in the history
  • Loading branch information
TeBoring committed Oct 10, 2016
1 parent 1e5d4ba commit 4f3d20a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 34 deletions.
3 changes: 1 addition & 2 deletions php/ext/google/protobuf/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
28 changes: 17 additions & 11 deletions php/ext/google/protobuf/encode_decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -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); \
Expand All @@ -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);

Expand All @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion php/ext/google/protobuf/type_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
Expand Down
40 changes: 20 additions & 20 deletions php/tests/array_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -789,26 +789,26 @@ public function testOffset()
$this->assertSame(1, count($arr));
}

public function testInsertRemoval()
{
$arr = new RepeatedField(GPBType::INT32);

$arr []= 0;
$arr []= 1;
$arr []= 2;
$this->assertSame(3, count($arr));

unset($arr[2]);
$this->assertSame(2, count($arr));
$this->assertSame(0, $arr[0]);
$this->assertSame(1, $arr[1]);

$arr [] = 3;
$this->assertSame(3, count($arr));
$this->assertSame(0, $arr[0]);
$this->assertSame(1, $arr[1]);
$this->assertSame(3, $arr[2]);
}
public function testInsertRemoval()
{
$arr = new RepeatedField(GPBType::INT32);

$arr []= 0;
$arr []= 1;
$arr []= 2;
$this->assertSame(3, count($arr));

unset($arr[2]);
$this->assertSame(2, count($arr));
$this->assertSame(0, $arr[0]);
$this->assertSame(1, $arr[1]);

$arr [] = 3;
$this->assertSame(3, count($arr));
$this->assertSame(0, $arr[0]);
$this->assertSame(1, $arr[1]);
$this->assertSame(3, $arr[2]);
}

/**
* @expectedException PHPUnit_Framework_Error
Expand Down
1 change: 1 addition & 0 deletions tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ build_php5.5_mac() {

build_php5.5_zts_c() {
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 ../..
}

Expand Down

0 comments on commit 4f3d20a

Please sign in to comment.