From 451d061141a14021ff95a093967827cd548720ba Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 25 Jul 2017 00:49:16 -0700 Subject: Fix cycle dependency for repeated field not collected by gc (#3399) --- php/ext/google/protobuf/protobuf.h | 57 +++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 10 deletions(-) (limited to 'php/ext/google/protobuf/protobuf.h') diff --git a/php/ext/google/protobuf/protobuf.h b/php/ext/google/protobuf/protobuf.h index 33787e86..c00cd917 100644 --- a/php/ext/google/protobuf/protobuf.h +++ b/php/ext/google/protobuf/protobuf.h @@ -74,13 +74,22 @@ #define PHP_PROTO_HASH_OF(array) Z_ARRVAL_P(array) -#define php_proto_zend_hash_index_update(ht, h, pData, nDataSize, pDest) \ +#define php_proto_zend_hash_index_update_zval(ht, h, pData) \ + zend_hash_index_update(ht, h, &(pData), sizeof(void*), NULL) + +#define php_proto_zend_hash_index_update_mem(ht, h, pData, nDataSize, pDest) \ zend_hash_index_update(ht, h, pData, nDataSize, pDest) -#define php_proto_zend_hash_index_find(ht, h, pDest) \ +#define php_proto_zend_hash_index_find_zval(ht, h, pDest) \ + zend_hash_index_find(ht, h, pDest) + +#define php_proto_zend_hash_index_find_mem(ht, h, pDest) \ zend_hash_index_find(ht, h, pDest) -#define php_proto_zend_hash_next_index_insert(ht, pData, nDataSize, pDest) \ +#define php_proto_zend_hash_next_index_insert_zval(ht, pData) \ + zend_hash_next_index_insert(ht, pData, sizeof(void*), NULL) + +#define php_proto_zend_hash_next_index_insert_mem(ht, pData, nDataSize, pDest) \ zend_hash_next_index_insert(ht, pData, nDataSize, pDest) #define php_proto_zend_hash_get_current_data_ex(ht, pDest, pos) \ @@ -217,7 +226,14 @@ #define PHP_PROTO_HASH_OF(array) Z_ARRVAL_P(&array) -static inline int php_proto_zend_hash_index_update(HashTable* ht, ulong h, +static inline int php_proto_zend_hash_index_update_zval(HashTable* ht, ulong h, + zval* pData) { + void* result = NULL; + result = zend_hash_index_update(ht, h, pData); + return result != NULL ? SUCCESS : FAILURE; +} + +static inline int php_proto_zend_hash_index_update_mem(HashTable* ht, ulong h, void* pData, uint nDataSize, void** pDest) { void* result = NULL; @@ -226,18 +242,33 @@ static inline int php_proto_zend_hash_index_update(HashTable* ht, ulong h, return result != NULL ? SUCCESS : FAILURE; } -static inline int php_proto_zend_hash_index_find(const HashTable* ht, ulong h, - void** pDest) { +static inline int php_proto_zend_hash_index_find_zval(const HashTable* ht, + ulong h, void** pDest) { + zval* result = zend_hash_index_find(ht, h); + if (pDest != NULL) *pDest = result; + return result != NULL ? SUCCESS : FAILURE; +} + +static inline int php_proto_zend_hash_index_find_mem(const HashTable* ht, + ulong h, void** pDest) { void* result = NULL; result = zend_hash_index_find_ptr(ht, h); if (pDest != NULL) *pDest = result; return result != NULL ? SUCCESS : FAILURE; } -static inline int php_proto_zend_hash_next_index_insert(HashTable* ht, - void* pData, - uint nDataSize, - void** pDest) { +static inline int php_proto_zend_hash_next_index_insert_zval(HashTable* ht, + void* pData) { + zval tmp; + ZVAL_OBJ(&tmp, *(zend_object**)pData); + zval* result = zend_hash_next_index_insert(ht, &tmp); + return result != NULL ? SUCCESS : FAILURE; +} + +static inline int php_proto_zend_hash_next_index_insert_mem(HashTable* ht, + void* pData, + uint nDataSize, + void** pDest) { void* result = NULL; result = zend_hash_next_index_insert_mem(ht, pData, nDataSize); if (pDest != NULL) *pDest = result; @@ -640,6 +671,8 @@ bool native_slot_set(upb_fieldtype_t type, const zend_class_entry* klass, bool native_slot_set_by_array(upb_fieldtype_t type, const zend_class_entry* klass, void* memory, zval* value TSRMLS_DC); +bool native_slot_set_by_map(upb_fieldtype_t type, const zend_class_entry* klass, + void* memory, zval* value TSRMLS_DC); void native_slot_init(upb_fieldtype_t type, void* memory, CACHED_VALUE* cache); // For each property, in order to avoid conversion between the zval object and // the actual data type during parsing/serialization, the containing message @@ -654,6 +687,10 @@ void native_slot_get(upb_fieldtype_t type, const void* memory, // So we need to make a special method to handle that. void native_slot_get_by_array(upb_fieldtype_t type, const void* memory, CACHED_VALUE* cache TSRMLS_DC); +void native_slot_get_by_map_key(upb_fieldtype_t type, const void* memory, + int length, CACHED_VALUE* cache TSRMLS_DC); +void native_slot_get_by_map_value(upb_fieldtype_t type, const void* memory, + CACHED_VALUE* cache TSRMLS_DC); void native_slot_get_default(upb_fieldtype_t type, CACHED_VALUE* cache TSRMLS_DC); -- cgit v1.2.3