diff options
author | Paul Yang <TeBoring@users.noreply.github.com> | 2017-10-05 21:03:57 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-05 21:03:57 -0700 |
commit | 77f64bb7779ec2195f9bc4dc82497d12c18fc6b7 (patch) | |
tree | 0c1b7683a15ecd6fb597a05aaaae08cf4420107e /php/ext/google/protobuf/storage.c | |
parent | cd5f49d0942e19a5854a325941918fca02fdb409 (diff) | |
download | protobuf-77f64bb7779ec2195f9bc4dc82497d12c18fc6b7.tar.gz protobuf-77f64bb7779ec2195f9bc4dc82497d12c18fc6b7.tar.bz2 protobuf-77f64bb7779ec2195f9bc4dc82497d12c18fc6b7.zip |
Add well known types to php runtime. (#3697)
* Add well known types to php runtime.
* Fix php7.0 tests
* No longer generate empty.proto in test as it has been included in
runtime.
* Fix zts build
* Clean code
* Rename g_p_b_empty to empty.
* Don't generate code for empty.proto in compatibility test
* Fix 32-bit
* Fix mac build
* Fix Makefile.am to add new files
Diffstat (limited to 'php/ext/google/protobuf/storage.c')
-rw-r--r-- | php/ext/google/protobuf/storage.c | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/php/ext/google/protobuf/storage.c b/php/ext/google/protobuf/storage.c index cc34dcf6..a0488ecb 100644 --- a/php/ext/google/protobuf/storage.c +++ b/php/ext/google/protobuf/storage.c @@ -856,12 +856,41 @@ void layout_set(MessageLayout* layout, MessageHeader* header, zval* property_ptr = CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory); if (EXPECTED(property_ptr != val)) { + zend_class_entry *subce = NULL; + zval converted_value; + + if (upb_fielddef_ismap(field)) { + const upb_msgdef* mapmsg = upb_fielddef_msgsubdef(field); + const upb_fielddef* keyfield = upb_msgdef_ntof(mapmsg, "key", 3); + const upb_fielddef* valuefield = upb_msgdef_ntof(mapmsg, "value", 5); + if (upb_fielddef_descriptortype(valuefield) == + UPB_DESCRIPTOR_TYPE_MESSAGE) { + const upb_msgdef* submsg = upb_fielddef_msgsubdef(valuefield); + Descriptor* subdesc = + UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj(submsg)); + subce = subdesc->klass; + } + check_map_field(subce, upb_fielddef_descriptortype(keyfield), + upb_fielddef_descriptortype(valuefield), val, + &converted_value); + } else { + if (upb_fielddef_type(field) == UPB_TYPE_MESSAGE) { + const upb_msgdef* submsg = upb_fielddef_msgsubdef(field); + Descriptor* subdesc = + UNBOX_HASHTABLE_VALUE(Descriptor, get_def_obj(submsg)); + subce = subdesc->klass; + } + + check_repeated_field(subce, upb_fielddef_descriptortype(field), val, + &converted_value); + } #if PHP_MAJOR_VERSION < 7 - REPLACE_ZVAL_VALUE((zval**)memory, val, 1); + REPLACE_ZVAL_VALUE((zval**)memory, &converted_value, 1); #else - php_proto_zval_ptr_dtor(property_ptr); - ZVAL_ZVAL(property_ptr, val, 1, 0); + php_proto_zval_ptr_dtor(property_ptr); + ZVAL_ZVAL(property_ptr, &converted_value, 1, 0); #endif + zval_dtor(&converted_value); } } else { upb_fieldtype_t type = upb_fielddef_type(field); |