aboutsummaryrefslogtreecommitdiff
path: root/php/ext/google/protobuf/message.c
diff options
context:
space:
mode:
authorPaul Yang <TeBoring@users.noreply.github.com>2017-08-04 16:35:49 -0700
committerGitHub <noreply@github.com>2017-08-04 16:35:49 -0700
commit49b44bff2b6257a119f9c6a342d6151c736586b8 (patch)
tree75fbf8e5e5b9645c1108b321cd803b697fda0b34 /php/ext/google/protobuf/message.c
parent21b0e5587c01948927ede9be789671ff116b7ad4 (diff)
downloadprotobuf-49b44bff2b6257a119f9c6a342d6151c736586b8.tar.gz
protobuf-49b44bff2b6257a119f9c6a342d6151c736586b8.tar.bz2
protobuf-49b44bff2b6257a119f9c6a342d6151c736586b8.zip
Fix the bug in php c extension that setting one field can change anotherĀ field's value. (#3455)
* Fix the bug in php c extension that setting one field can change another field's value. The reason is that previously, in c extension, it was assumed that the order that fields were declared in php is the same as the order of fields in upb. This is not true. Now, for every field in upb, we will look up the actual property that is corresponding to the upb field. * Cleanup pull request * Fix indentation * Port to php5 * Port with php7.1 * Port to zts
Diffstat (limited to 'php/ext/google/protobuf/message.c')
-rw-r--r--php/ext/google/protobuf/message.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c
index 254640c7..519786dd 100644
--- a/php/ext/google/protobuf/message.c
+++ b/php/ext/google/protobuf/message.c
@@ -172,7 +172,7 @@ static zval* message_get_property(zval* object, zval* member, int type,
zend_get_property_info(Z_OBJCE_P(object), member, true TSRMLS_CC);
return layout_get(
self->descriptor->layout, message_data(self), field,
- &Z_OBJ_P(object)->properties_table[property_info->offset] TSRMLS_CC);
+ OBJ_PROP(Z_OBJ_P(object), property_info->offset) TSRMLS_CC);
#else
property_info =
zend_get_property_info(Z_OBJCE_P(object), Z_STR_P(member), true);
@@ -222,7 +222,7 @@ void custom_data_init(const zend_class_entry* ce,
// case a collection happens during object creation in layout_init().
intern->descriptor = desc;
layout_init(desc->layout, message_data(intern),
- intern->std.properties_table PHP_PROTO_TSRMLS_CC);
+ &intern->std PHP_PROTO_TSRMLS_CC);
}
void build_class_from_descriptor(
@@ -265,8 +265,7 @@ PHP_METHOD(Message, clear) {
zend_class_entry* ce = desc->klass;
object_properties_init(&msg->std, ce);
- layout_init(desc->layout, message_data(msg),
- msg->std.properties_table TSRMLS_CC);
+ layout_init(desc->layout, message_data(msg), &msg->std TSRMLS_CC);
}
PHP_METHOD(Message, mergeFrom) {
@@ -301,7 +300,8 @@ PHP_METHOD(Message, readOneof) {
int property_cache_index =
msg->descriptor->layout->fields[upb_fielddef_index(field)].cache_index;
- zval* property_ptr = OBJ_PROP(Z_OBJ_P(getThis()), property_cache_index);
+ zval* property_ptr = CACHED_PTR_TO_ZVAL_PTR(
+ OBJ_PROP(Z_OBJ_P(getThis()), property_cache_index));
// Unlike singular fields, oneof fields share cached property. So we cannot
// let lay_get modify the cached property. Instead, we pass in the return