From de44982a747519602409fcf7b0cceaf123bf1420 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Thu, 30 Nov 2017 12:21:00 -0800 Subject: Remove duplicate typedef. (#3975) --- php/ext/google/protobuf/protobuf.h | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) (limited to 'php') diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 18343772..e2a67220 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -608,48 +608,36 @@ typedef struct Api Api; typedef struct BoolValue BoolValue; typedef struct BytesValue BytesValue; typedef struct Descriptor Descriptor; -typedef struct Descriptor Descriptor; typedef struct DescriptorPool DescriptorPool; typedef struct DoubleValue DoubleValue; typedef struct Duration Duration; -typedef struct Enum Enum; typedef struct EnumDescriptor EnumDescriptor; -typedef struct EnumDescriptor EnumDescriptor; -typedef struct EnumValue EnumValue; -typedef struct EnumValueDescriptor EnumValueDescriptor; +typedef struct Enum Enum; typedef struct EnumValueDescriptor EnumValueDescriptor; -typedef struct Field Field; -typedef struct FieldDescriptor FieldDescriptor; -typedef struct FieldDescriptor FieldDescriptor; -typedef struct FieldMask FieldMask; +typedef struct EnumValue EnumValue; typedef struct Field_Cardinality Field_Cardinality; +typedef struct FieldDescriptor FieldDescriptor; +typedef struct Field Field; typedef struct Field_Kind Field_Kind; +typedef struct FieldMask FieldMask; typedef struct FloatValue FloatValue; typedef struct GPBEmpty GPBEmpty; typedef struct Int32Value Int32Value; typedef struct Int64Value Int64Value; typedef struct InternalDescriptorPool InternalDescriptorPool; typedef struct ListValue ListValue; -typedef struct Map Map; -typedef struct Map Map; -typedef struct MapIter MapIter; typedef struct MapIter MapIter; +typedef struct Map Map; typedef struct MessageField MessageField; -typedef struct MessageField MessageField; -typedef struct MessageHeader MessageHeader; typedef struct MessageHeader MessageHeader; typedef struct MessageLayout MessageLayout; -typedef struct MessageLayout MessageLayout; typedef struct Method Method; typedef struct Mixin Mixin; typedef struct NullValue NullValue; typedef struct Oneof Oneof; -typedef struct Oneof Oneof; typedef struct Option Option; -typedef struct RepeatedField RepeatedField; -typedef struct RepeatedField RepeatedField; -typedef struct RepeatedFieldIter RepeatedFieldIter; typedef struct RepeatedFieldIter RepeatedFieldIter; +typedef struct RepeatedField RepeatedField; typedef struct SourceContext SourceContext; typedef struct StringValue StringValue; typedef struct Struct Struct; -- cgit v1.2.3 From e0d3aa057b89540cf83de6639a86d1ddb7199315 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Fri, 1 Dec 2017 20:14:19 -0800 Subject: Fix memory leak when creating repeated field via array. --- php/ext/google/protobuf/type_check.c | 3 +-- php/tests/memory_leak_test.php | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'php') diff --git a/php/ext/google/protobuf/type_check.c b/php/ext/google/protobuf/type_check.c index f588774c..50e0f8c1 100644 --- a/php/ext/google/protobuf/type_check.c +++ b/php/ext/google/protobuf/type_check.c @@ -461,8 +461,7 @@ void check_repeated_field(const zend_class_entry* klass, PHP_PROTO_LONG type, CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)memory) TSRMLS_CC); } - Z_DELREF_P(CACHED_TO_ZVAL_PTR(repeated_field)); - RETURN_ZVAL(CACHED_TO_ZVAL_PTR(repeated_field), 1, 0); + RETURN_ZVAL(CACHED_TO_ZVAL_PTR(repeated_field), 1, 1); } else if (Z_TYPE_P(val) == IS_OBJECT) { if (!instanceof_function(Z_OBJCE_P(val), repeated_field_type TSRMLS_CC)) { diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php index b76c8bff..fa272b56 100644 --- a/php/tests/memory_leak_test.php +++ b/php/tests/memory_leak_test.php @@ -105,6 +105,11 @@ $m = new TestMessage(); $m->mergeFromString(hex2bin('F80601')); assert('F80601', bin2hex($m->serializeToString())); +// Test create repeated field via array. +$str_arr = array(); +$m = new TestMessage(); +$m->setRepeatedString($str_arr); + # $from = new TestMessage(); # $to = new TestMessage(); # TestUtil::setTestMessage($from); -- cgit v1.2.3 From 7d3437152ad420d4382b883f0a52a86526166ef5 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Mon, 4 Dec 2017 12:32:10 -0800 Subject: Fix memory leak when creating map field via array. --- php/ext/google/protobuf/type_check.c | 3 +-- php/tests/memory_leak_test.php | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'php') diff --git a/php/ext/google/protobuf/type_check.c b/php/ext/google/protobuf/type_check.c index 50e0f8c1..37171426 100644 --- a/php/ext/google/protobuf/type_check.c +++ b/php/ext/google/protobuf/type_check.c @@ -534,8 +534,7 @@ void check_map_field(const zend_class_entry* klass, PHP_PROTO_LONG key_type, CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)value) TSRMLS_CC); } - Z_DELREF_P(CACHED_TO_ZVAL_PTR(map_field)); - RETURN_ZVAL(CACHED_TO_ZVAL_PTR(map_field), 1, 0); + RETURN_ZVAL(CACHED_TO_ZVAL_PTR(map_field), 1, 1); } else if (Z_TYPE_P(val) == IS_OBJECT) { if (!instanceof_function(Z_OBJCE_P(val), map_field_type TSRMLS_CC)) { zend_error(E_USER_ERROR, "Given value is not an instance of %s.", diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php index fa272b56..772b466f 100644 --- a/php/tests/memory_leak_test.php +++ b/php/tests/memory_leak_test.php @@ -110,6 +110,11 @@ $str_arr = array(); $m = new TestMessage(); $m->setRepeatedString($str_arr); +// Test create map field via array. +$str_arr = array(); +$m = new TestMessage(); +$m->setMapStringString($str_arr); + # $from = new TestMessage(); # $to = new TestMessage(); # TestUtil::setTestMessage($from); -- cgit v1.2.3 From 3b7a5f451546888ad96aaa143ef86fea904a03ec Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Tue, 5 Dec 2017 16:44:19 -0800 Subject: Fix several more memory leak --- php/ext/google/protobuf/def.c | 1 + php/ext/google/protobuf/message.c | 8 ++++---- php/ext/google/protobuf/type_check.c | 1 + php/tests/memory_leak_test.php | 23 +++++++++++++++++++++-- 4 files changed, 27 insertions(+), 6 deletions(-) (limited to 'php') diff --git a/php/ext/google/protobuf/def.c b/php/ext/google/protobuf/def.c index 13f7cdd6..55291e23 100644 --- a/php/ext/google/protobuf/def.c +++ b/php/ext/google/protobuf/def.c @@ -249,6 +249,7 @@ PHP_METHOD(Descriptor, getField) { MAKE_STD_ZVAL(field_hashtable_value); ZVAL_OBJ(field_hashtable_value, field_descriptor_type->create_object( field_descriptor_type TSRMLS_CC)); + Z_DELREF_P(field_hashtable_value); #else field_hashtable_value = field_descriptor_type->create_object(field_descriptor_type TSRMLS_CC); diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index 3fce2c17..b11c7215 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -374,7 +374,7 @@ PHP_METHOD(Message, whichOneof) { LOWER_FIELD) \ PHP_METHOD(UPPER_CLASS, get##UPPER_FIELD) { \ zval member; \ - PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 1); \ + PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 0); \ PHP_PROTO_FAKE_SCOPE_BEGIN(LOWER_CLASS##_type); \ zval* value = message_get_property_internal(getThis(), &member TSRMLS_CC); \ PHP_PROTO_FAKE_SCOPE_END; \ @@ -387,7 +387,7 @@ PHP_METHOD(Message, whichOneof) { return; \ } \ zval member; \ - PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 1); \ + PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 0); \ message_set_property_internal(getThis(), &member, value TSRMLS_CC); \ PHP_PROTO_RETVAL_ZVAL(getThis()); \ } @@ -396,7 +396,7 @@ PHP_METHOD(Message, whichOneof) { LOWER_FIELD) \ PHP_METHOD(UPPER_CLASS, get##UPPER_FIELD) { \ zval member; \ - PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 1); \ + PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 0); \ PHP_PROTO_FAKE_SCOPE_BEGIN(LOWER_CLASS##_type); \ message_get_oneof_property_internal(getThis(), &member, \ return_value TSRMLS_CC); \ @@ -409,7 +409,7 @@ PHP_METHOD(Message, whichOneof) { return; \ } \ zval member; \ - PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 1); \ + PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 0); \ message_set_property_internal(getThis(), &member, value TSRMLS_CC); \ PHP_PROTO_RETVAL_ZVAL(getThis()); \ } diff --git a/php/ext/google/protobuf/type_check.c b/php/ext/google/protobuf/type_check.c index 37171426..85f5051e 100644 --- a/php/ext/google/protobuf/type_check.c +++ b/php/ext/google/protobuf/type_check.c @@ -532,6 +532,7 @@ void check_map_field(const zend_class_entry* klass, PHP_PROTO_LONG key_type, map_field_handlers->write_dimension( CACHED_TO_ZVAL_PTR(map_field), &key, CACHED_PTR_TO_ZVAL_PTR((CACHED_VALUE*)value) TSRMLS_CC); + zval_dtor(&key); } RETURN_ZVAL(CACHED_TO_ZVAL_PTR(map_field), 1, 1); diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php index 772b466f..29ca7787 100644 --- a/php/tests/memory_leak_test.php +++ b/php/tests/memory_leak_test.php @@ -106,15 +106,34 @@ $m->mergeFromString(hex2bin('F80601')); assert('F80601', bin2hex($m->serializeToString())); // Test create repeated field via array. -$str_arr = array(); +$str_arr = array("abc"); $m = new TestMessage(); $m->setRepeatedString($str_arr); // Test create map field via array. -$str_arr = array(); +$str_arr = array("abc"=>"abc"); $m = new TestMessage(); $m->setMapStringString($str_arr); +// Test unset +$from = new TestMessage(); +TestUtil::setTestMessage($from); +unset($from); + +// Test wellknown +$from = new \Google\Protobuf\Timestamp(); +$from->setSeconds(1); +assert(1, $from->getSeconds()); + +$from = new \Google\Protobuf\Value(); +$from->setNumberValue(1); +assert(1, $from->getNumberValue()); + +// Test descriptor +$pool = \Google\Protobuf\DescriptorPool::getGeneratedPool(); +$desc = $pool->getDescriptorByClassName("\Foo\TestMessage"); +$field = $desc->getField(1); + # $from = new TestMessage(); # $to = new TestMessage(); # TestUtil::setTestMessage($from); -- cgit v1.2.3 From 212563d756d50a70272d42d7f8b6374ce5a86317 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Tue, 5 Dec 2017 18:29:51 -0800 Subject: Fix memory leak in php7 --- php/ext/google/protobuf/def.c | 1 + php/ext/google/protobuf/message.c | 12 ++++++++---- php/tests/memory_leak_test.php | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) (limited to 'php') diff --git a/php/ext/google/protobuf/def.c b/php/ext/google/protobuf/def.c index 55291e23..8140fe47 100644 --- a/php/ext/google/protobuf/def.c +++ b/php/ext/google/protobuf/def.c @@ -253,6 +253,7 @@ PHP_METHOD(Descriptor, getField) { #else field_hashtable_value = field_descriptor_type->create_object(field_descriptor_type TSRMLS_CC); + --GC_REFCOUNT(field_hashtable_value); #endif FieldDescriptor *field_php = UNBOX_HASHTABLE_VALUE(FieldDescriptor, field_hashtable_value); diff --git a/php/ext/google/protobuf/message.c b/php/ext/google/protobuf/message.c index b11c7215..cf75d979 100644 --- a/php/ext/google/protobuf/message.c +++ b/php/ext/google/protobuf/message.c @@ -374,10 +374,11 @@ PHP_METHOD(Message, whichOneof) { LOWER_FIELD) \ PHP_METHOD(UPPER_CLASS, get##UPPER_FIELD) { \ zval member; \ - PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 0); \ + PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 1); \ PHP_PROTO_FAKE_SCOPE_BEGIN(LOWER_CLASS##_type); \ zval* value = message_get_property_internal(getThis(), &member TSRMLS_CC); \ PHP_PROTO_FAKE_SCOPE_END; \ + zval_dtor(&member); \ PHP_PROTO_RETVAL_ZVAL(value); \ } \ PHP_METHOD(UPPER_CLASS, set##UPPER_FIELD) { \ @@ -387,8 +388,9 @@ PHP_METHOD(Message, whichOneof) { return; \ } \ zval member; \ - PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 0); \ + PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 1); \ message_set_property_internal(getThis(), &member, value TSRMLS_CC); \ + zval_dtor(&member); \ PHP_PROTO_RETVAL_ZVAL(getThis()); \ } @@ -396,11 +398,12 @@ PHP_METHOD(Message, whichOneof) { LOWER_FIELD) \ PHP_METHOD(UPPER_CLASS, get##UPPER_FIELD) { \ zval member; \ - PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 0); \ + PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 1); \ PHP_PROTO_FAKE_SCOPE_BEGIN(LOWER_CLASS##_type); \ message_get_oneof_property_internal(getThis(), &member, \ return_value TSRMLS_CC); \ PHP_PROTO_FAKE_SCOPE_END; \ + zval_dtor(&member); \ } \ PHP_METHOD(UPPER_CLASS, set##UPPER_FIELD) { \ zval* value = NULL; \ @@ -409,8 +412,9 @@ PHP_METHOD(Message, whichOneof) { return; \ } \ zval member; \ - PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 0); \ + PHP_PROTO_ZVAL_STRING(&member, LOWER_FIELD, 1); \ message_set_property_internal(getThis(), &member, value TSRMLS_CC); \ + zval_dtor(&member); \ PHP_PROTO_RETVAL_ZVAL(getThis()); \ } diff --git a/php/tests/memory_leak_test.php b/php/tests/memory_leak_test.php index 29ca7787..8ea84f68 100644 --- a/php/tests/memory_leak_test.php +++ b/php/tests/memory_leak_test.php @@ -50,7 +50,8 @@ $to->mergeFromString($data); TestUtil::assertTestMessage($to); -$from->setRecursive($from); +// TODO(teboring): This causes following tests fail in php7. +# $from->setRecursive($from); $arr = new RepeatedField(GPBType::MESSAGE, TestMessage::class); $arr[] = new TestMessage; -- cgit v1.2.3 From ba60b854b6da0494e91b81edc7b91ef3ddf219c9 Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Wed, 6 Dec 2017 10:46:57 -0800 Subject: Update php c extension version number to 3.5.0.1 --- php/ext/google/protobuf/package.xml | 6 +++--- php/ext/google/protobuf/protobuf.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'php') diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 4a473801..07641b4e 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -10,11 +10,11 @@ protobuf-opensource@google.com yes - 2017-09-14 + 2017-12-06 - 3.4.1 - 3.4.1 + 3.5.0.1 + 3.5.0.1 stable diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index e2a67220..8289eb2b 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -37,7 +37,7 @@ #include "upb.h" #define PHP_PROTOBUF_EXTNAME "protobuf" -#define PHP_PROTOBUF_VERSION "3.4.1" +#define PHP_PROTOBUF_VERSION "3.5.0.1" #define MAX_LENGTH_OF_INT64 20 #define SIZEOF_INT64 8 -- cgit v1.2.3 From 457f6a607ce167132b833c049b0eaf3a9c4b3f5f Mon Sep 17 00:00:00 2001 From: Bo Yang Date: Wed, 6 Dec 2017 10:54:11 -0800 Subject: Add release log --- php/ext/google/protobuf/package.xml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'php') diff --git a/php/ext/google/protobuf/package.xml b/php/ext/google/protobuf/package.xml index 07641b4e..0107ebc2 100644 --- a/php/ext/google/protobuf/package.xml +++ b/php/ext/google/protobuf/package.xml @@ -165,6 +165,22 @@ GA release. 3-Clause BSD License +GA release. + + + + + 3.5.0.1 + 3.5.0.1 + + + stable + stable + + 2017-12-06 + + 3-Clause BSD License + GA release. -- cgit v1.2.3