From 5324acff699b2654c3be5f83bf2ff5f7a57a7a97 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 17 Jul 2025 14:27:12 +0200 Subject: [PATCH 01/44] Refactor --- php_phongo.c | 2 +- php_phongo.h | 22 ---------------------- src/BSON/Binary.c | 2 +- src/BSON/DBPointer.c | 2 +- src/BSON/Decimal128.c | 2 +- src/BSON/Document.c | 8 ++------ src/BSON/Int64.c | 2 +- src/BSON/Iterator.c | 2 +- src/BSON/Javascript.c | 8 ++------ src/BSON/ObjectId.c | 2 +- src/BSON/PackedArray.c | 8 ++------ src/BSON/Regex.c | 2 +- src/BSON/Symbol.c | 2 +- src/BSON/Timestamp.c | 2 +- src/BSON/UTCDateTime.c | 2 +- src/MongoDB/ReadConcern.c | 2 +- src/MongoDB/ReadPreference.c | 2 +- src/MongoDB/ServerApi.c | 2 +- src/MongoDB/ServerDescription.c | 2 +- src/MongoDB/TopologyDescription.c | 2 +- src/MongoDB/WriteConcern.c | 2 +- tests/bson/bug1598-002.phpt | 3 --- tests/readConcern/bug1598-002.phpt | 3 --- tests/readPreference/bug1598-002.phpt | 3 --- tests/writeConcern/bug1598-002.phpt | 3 --- 25 files changed, 23 insertions(+), 69 deletions(-) diff --git a/php_phongo.c b/php_phongo.c index 6c9bd29fc..948ce6c69 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -159,7 +159,7 @@ static HashTable* php_phongo_std_get_gc(zend_object* object, zval** table, int* { *table = NULL; *n = 0; - return zend_std_get_properties(object); + return object->handlers->get_properties(object); } PHP_MINIT_FUNCTION(mongodb) /* {{{ */ diff --git a/php_phongo.h b/php_phongo.h index d0655f911..bf2fec501 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -60,28 +60,6 @@ ZEND_TSRMLS_CACHE_EXTERN() zend_object_handlers* phongo_get_std_object_handlers(void); -#define PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size) \ - do { \ - if (is_temp) { \ - ALLOC_HASHTABLE(props); \ - zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \ - } else if ((intern)->properties) { \ - (props) = (intern)->properties; \ - } else { \ - ALLOC_HASHTABLE(props); \ - zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \ - (intern)->properties = (props); \ - } \ - } while (0) - -#define PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props) \ - do { \ - if (is_temp) { \ - zend_hash_destroy((props)); \ - FREE_HASHTABLE(props); \ - } \ - } while (0) - #define PHONGO_ZVAL_EXCEPTION_NAME(e) (ZSTR_VAL(e->ce->name)) #define PHONGO_SET_CREATED_BY_PID(intern) \ diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index 4583ac8ab..adf1fa5de 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -70,7 +70,7 @@ static HashTable* php_phongo_binary_get_properties_hash(zend_object* object, boo intern = Z_OBJ_BINARY(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); + props = zend_std_get_properties(object); if (!intern->data) { return props; diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index b0285732e..1f7db9f11 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -71,7 +71,7 @@ HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object, bool is intern = Z_OBJ_DBPOINTER(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); + props = zend_std_get_properties(object); if (!intern->ref) { return props; diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 970ee00e7..6c6ad5822 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -61,7 +61,7 @@ static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object, intern = Z_OBJ_DECIMAL128(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); + props = zend_std_get_properties(object); if (!intern->initialized) { return props; diff --git a/src/BSON/Document.c b/src/BSON/Document.c index b0886b369..5bc3b712c 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -62,7 +62,7 @@ static HashTable* php_phongo_document_get_properties_hash(zend_object* object, b intern = Z_OBJ_DOCUMENT(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size); + props = zend_std_get_properties(object); if (!intern->bson) { return props; @@ -514,17 +514,13 @@ static HashTable* php_phongo_document_get_debug_info(zend_object* object, int* i state.map.document.type = PHONGO_TYPEMAP_BSON; if (!php_phongo_bson_to_zval_ex(intern->bson, &state)) { zval_ptr_dtor(&state.zchild); - goto failure; + return NULL; } zend_hash_str_update(props, "value", sizeof("value") - 1, &state.zchild); } return props; - -failure: - PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); - return NULL; } static HashTable* php_phongo_document_get_properties(zend_object* object) diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index d350f2b7b..c1a4074d7 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -69,7 +69,7 @@ HashTable* php_phongo_int64_get_properties_hash(zend_object* object, bool is_tem intern = Z_OBJ_INT64(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); + props = zend_std_get_properties(object); if (!intern->initialized) { return props; diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index 1306dbc7d..1e11538b0 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -160,7 +160,7 @@ static HashTable* php_phongo_iterator_get_properties_hash(zend_object* object, b intern = Z_OBJ_ITERATOR(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); + props = zend_std_get_properties(object); zend_hash_str_update(props, "bson", sizeof("bson") - 1, &intern->bson); Z_TRY_ADDREF(intern->bson); diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index 38312dc2d..7dd0eab26 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -76,7 +76,7 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object, bool i intern = Z_OBJ_JAVASCRIPT(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); + props = zend_std_get_properties(object); if (!intern->code) { return props; @@ -94,7 +94,7 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object, bool i PHONGO_BSON_INIT_STATE(state); if (!php_phongo_bson_to_zval_ex(intern->scope, &state)) { zval_ptr_dtor(&state.zchild); - goto failure; + return NULL; } zend_hash_str_update(props, "scope", sizeof("scope") - 1, &state.zchild); @@ -107,10 +107,6 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object, bool i } return props; - -failure: - PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); - return NULL; } /* Construct a new BSON Javascript type. The scope is a document mapping diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 240441ac4..8f3291abf 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -84,7 +84,7 @@ static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object, b intern = Z_OBJ_OBJECTID(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); + props = zend_std_get_properties(object); if (!intern->initialized) { return props; diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index 6fdbcf575..210fbd246 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -63,7 +63,7 @@ static HashTable* php_phongo_packedarray_get_properties_hash(zend_object* object intern = Z_OBJ_PACKEDARRAY(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size); + props = zend_std_get_properties(object); if (!intern->bson) { return props; @@ -499,17 +499,13 @@ static HashTable* php_phongo_packedarray_get_debug_info(zend_object* object, int state.map.document.type = PHONGO_TYPEMAP_BSON; if (!php_phongo_bson_to_zval_ex(intern->bson, &state)) { zval_ptr_dtor(&state.zchild); - goto failure; + return NULL; } zend_hash_str_update(props, "value", sizeof("value") - 1, &state.zchild); } return props; - -failure: - PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); - return NULL; } static HashTable* php_phongo_packedarray_get_properties(zend_object* object) diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index a75b75e39..a698470ec 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -85,7 +85,7 @@ static HashTable* php_phongo_regex_get_properties_hash(zend_object* object, bool intern = Z_OBJ_REGEX(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); + props = zend_std_get_properties(object); if (!intern->pattern) { return props; diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index a47b6c2fe..bb3820321 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -59,7 +59,7 @@ HashTable* php_phongo_symbol_get_properties_hash(zend_object* object, bool is_te intern = Z_OBJ_SYMBOL(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); + props = zend_std_get_properties(object); if (!intern->symbol) { return props; diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 82cd6f537..9bbfccd5b 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -96,7 +96,7 @@ static HashTable* php_phongo_timestamp_get_properties_hash(zend_object* object, intern = Z_OBJ_TIMESTAMP(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); + props = zend_std_get_properties(object); if (!intern->initialized) { return props; diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index d0f169858..c75412dbb 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -128,7 +128,7 @@ static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object intern = Z_OBJ_UTCDATETIME(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); + props = zend_std_get_properties(object); if (!intern->initialized) { return props; diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index 54ed384db..bcb5411a0 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -130,7 +130,7 @@ static HashTable* php_phongo_readconcern_get_properties_hash(zend_object* object intern = Z_OBJ_READCONCERN(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); + props = zend_std_get_properties(object); if (!intern->read_concern) { return props; diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index cd7fed69b..6e27715e5 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -389,7 +389,7 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zend_object* obj intern = Z_OBJ_READPREFERENCE(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 4); + props = zend_std_get_properties(object); if (!intern->read_preference) { return props; diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index 3dd6f6264..30ce583dc 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -146,7 +146,7 @@ static HashTable* php_phongo_serverapi_get_properties_hash(zend_object* object, intern = Z_OBJ_SERVERAPI(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); + props = zend_std_get_properties(object); ZVAL_STRING(&version, mongoc_server_api_version_to_string(mongoc_server_api_get_version(intern->server_api))); zend_hash_str_add(props, "version", sizeof("version") - 1, &version); diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index 7a21e9e07..a8235ad46 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -187,7 +187,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object, intern = Z_OBJ_SERVERDESCRIPTION(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 6); + props = zend_std_get_properties(object); if (!intern->server_description) { return props; diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index ab625dff0..2e6513f47 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -136,7 +136,7 @@ HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* objec intern = Z_OBJ_TOPOLOGYDESCRIPTION(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 2); + props = zend_std_get_properties(object); if (!intern->topology_description) { return props; diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index c0edb5a05..cd2b8d213 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -272,7 +272,7 @@ static HashTable* php_phongo_writeconcern_get_properties_hash(zend_object* objec intern = Z_OBJ_WRITECONCERN(object); - PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 4); + props = zend_std_get_properties(object); if (!intern->write_concern) { return props; diff --git a/tests/bson/bug1598-002.phpt b/tests/bson/bug1598-002.phpt index de32da9a8..0b675f37a 100644 --- a/tests/bson/bug1598-002.phpt +++ b/tests/bson/bug1598-002.phpt @@ -1,8 +1,5 @@ --TEST-- PHPC-1598: BSON type get_gc should delegate to zend_std_get_properties ---SKIPIF-- - -=', '8.1.99'); ?> --FILE-- -=', '8.1.99'); ?> --FILE-- -=', '8.1.99'); ?> --FILE-- -=', '8.1.99'); ?> --FILE-- Date: Thu, 17 Jul 2025 14:28:16 +0200 Subject: [PATCH 02/44] Fix --- src/BSON/Binary.c | 2 +- src/BSON/DBPointer.c | 2 +- src/BSON/Decimal128.c | 2 +- src/BSON/Document.c | 2 +- src/BSON/Int64.c | 2 +- src/BSON/Iterator.c | 2 +- src/BSON/Javascript.c | 2 +- src/BSON/ObjectId.c | 2 +- src/BSON/PackedArray.c | 2 +- src/BSON/Regex.c | 2 +- src/BSON/Symbol.c | 2 +- src/BSON/Timestamp.c | 2 +- src/BSON/UTCDateTime.c | 2 +- src/MongoDB/BulkWrite.c | 2 +- src/MongoDB/BulkWriteCommand.c | 2 +- src/MongoDB/BulkWriteCommandResult.c | 2 +- src/MongoDB/ClientEncryption.c | 2 +- src/MongoDB/Command.c | 2 +- src/MongoDB/Cursor.c | 2 +- src/MongoDB/Manager.c | 2 +- src/MongoDB/Monitoring/CommandFailedEvent.c | 2 +- src/MongoDB/Monitoring/CommandStartedEvent.c | 2 +- src/MongoDB/Monitoring/CommandSucceededEvent.c | 2 +- src/MongoDB/Monitoring/ServerChangedEvent.c | 2 +- src/MongoDB/Monitoring/ServerClosedEvent.c | 2 +- src/MongoDB/Monitoring/ServerHeartbeatFailedEvent.c | 2 +- src/MongoDB/Monitoring/ServerHeartbeatStartedEvent.c | 2 +- src/MongoDB/Monitoring/ServerHeartbeatSucceededEvent.c | 2 +- src/MongoDB/Monitoring/ServerOpeningEvent.c | 2 +- src/MongoDB/Monitoring/TopologyChangedEvent.c | 2 +- src/MongoDB/Monitoring/TopologyClosedEvent.c | 2 +- src/MongoDB/Monitoring/TopologyOpeningEvent.c | 2 +- src/MongoDB/Query.c | 2 +- src/MongoDB/ReadConcern.c | 2 +- src/MongoDB/ReadPreference.c | 2 +- src/MongoDB/Server.c | 2 +- src/MongoDB/ServerApi.c | 2 +- src/MongoDB/ServerDescription.c | 2 +- src/MongoDB/Session.c | 2 +- src/MongoDB/TopologyDescription.c | 2 +- src/MongoDB/WriteConcern.c | 2 +- src/MongoDB/WriteConcernError.c | 2 +- src/MongoDB/WriteError.c | 2 +- src/MongoDB/WriteResult.c | 2 +- 44 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index adf1fa5de..fad2319f8 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -272,7 +272,7 @@ static int php_phongo_binary_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_binary_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_binary_get_properties_hash(object, true); } diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index 1f7db9f11..fa4e94538 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -232,7 +232,7 @@ static int php_phongo_dbpointer_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_dbpointer_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_dbpointer_get_properties_hash(object, true); } diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 6c6ad5822..0e31e5773 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -207,7 +207,7 @@ static zend_object* php_phongo_decimal128_clone_object(zend_object* object) static HashTable* php_phongo_decimal128_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_decimal128_get_properties_hash(object, true); } diff --git a/src/BSON/Document.c b/src/BSON/Document.c index 5bc3b712c..2a5c685d8 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -498,7 +498,7 @@ static HashTable* php_phongo_document_get_debug_info(zend_object* object, int* i php_phongo_document_t* intern; HashTable* props; - *is_temp = 1; + *is_temp = 0; intern = Z_OBJ_DOCUMENT(object); /* This get_debug_info handler reports an additional property. This does not diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index c1a4074d7..e243c9222 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -545,7 +545,7 @@ static zend_result php_phongo_int64_do_operation(zend_uchar opcode, zval* result static HashTable* php_phongo_int64_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_int64_get_properties_hash(object, true); } diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index 1e11538b0..7e93058ba 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -288,7 +288,7 @@ static zend_object* php_phongo_iterator_clone_object(zend_object* object) static HashTable* php_phongo_iterator_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_iterator_get_properties_hash(object, true); } diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index 7dd0eab26..04bc2e44d 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -309,7 +309,7 @@ static int php_phongo_javascript_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_javascript_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_javascript_get_properties_hash(object, true); } diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 8f3291abf..034c94440 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -254,7 +254,7 @@ static int php_phongo_objectid_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_objectid_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_objectid_get_properties_hash(object, true); } diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index 210fbd246..d2c528088 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -482,7 +482,7 @@ static HashTable* php_phongo_packedarray_get_debug_info(zend_object* object, int php_phongo_packedarray_t* intern; HashTable* props; - *is_temp = 1; + *is_temp = 0; intern = Z_OBJ_PACKEDARRAY(object); /* This get_debug_info handler reports an additional property. This does not diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index a698470ec..90a0ef6e2 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -285,7 +285,7 @@ static int php_phongo_regex_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_regex_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_regex_get_properties_hash(object, true); } diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index bb3820321..728ada960 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -199,7 +199,7 @@ static int php_phongo_symbol_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_symbol_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_symbol_get_properties_hash(object, true); } diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 9bbfccd5b..f23b55684 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -319,7 +319,7 @@ static int php_phongo_timestamp_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_timestamp_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_timestamp_get_properties_hash(object, true); } diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index c75412dbb..324db0cce 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -354,7 +354,7 @@ static int php_phongo_utcdatetime_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_utcdatetime_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_utcdatetime_get_properties_hash(object, true); } diff --git a/src/MongoDB/BulkWrite.c b/src/MongoDB/BulkWrite.c index d72c4c79a..9ebdec6ef 100644 --- a/src/MongoDB/BulkWrite.c +++ b/src/MongoDB/BulkWrite.c @@ -592,7 +592,7 @@ static HashTable* php_phongo_bulkwrite_get_debug_info(zend_object* object, int* zval retval = ZVAL_STATIC_INIT; php_phongo_bulkwrite_t* intern = NULL; - *is_temp = 1; + *is_temp = 0; intern = Z_OBJ_BULKWRITE(object); array_init(&retval); diff --git a/src/MongoDB/BulkWriteCommand.c b/src/MongoDB/BulkWriteCommand.c index 22fc35778..a818b5da3 100644 --- a/src/MongoDB/BulkWriteCommand.c +++ b/src/MongoDB/BulkWriteCommand.c @@ -788,7 +788,7 @@ static HashTable* php_phongo_bulkwritecommand_get_debug_info(zend_object* object zval retval = ZVAL_STATIC_INIT; php_phongo_bulkwritecommand_t* intern = NULL; - *is_temp = 1; + *is_temp = 0; intern = Z_OBJ_BULKWRITECOMMAND(object); array_init(&retval); diff --git a/src/MongoDB/BulkWriteCommandResult.c b/src/MongoDB/BulkWriteCommandResult.c index 5b1f7813e..54fb61396 100644 --- a/src/MongoDB/BulkWriteCommandResult.c +++ b/src/MongoDB/BulkWriteCommandResult.c @@ -201,7 +201,7 @@ static HashTable* php_phongo_bulkwritecommandresult_get_debug_info(zend_object* zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_BULKWRITECOMMANDRESULT(object); - *is_temp = 1; + *is_temp = 0; array_init_size(&retval, 12); ADD_ASSOC_BOOL_EX(&retval, "isAcknowledged", intern->is_acknowledged); diff --git a/src/MongoDB/ClientEncryption.c b/src/MongoDB/ClientEncryption.c index c8950d551..7325a6f44 100644 --- a/src/MongoDB/ClientEncryption.c +++ b/src/MongoDB/ClientEncryption.c @@ -514,7 +514,7 @@ static HashTable* php_phongo_clientencryption_get_debug_info(zend_object* object php_phongo_clientencryption_t* intern = NULL; zval retval = ZVAL_STATIC_INIT; - *is_temp = 1; + *is_temp = 0; intern = Z_OBJ_CLIENTENCRYPTION(object); array_init(&retval); diff --git a/src/MongoDB/Command.c b/src/MongoDB/Command.c index 93f35e56d..cbcbb0fad 100644 --- a/src/MongoDB/Command.c +++ b/src/MongoDB/Command.c @@ -146,7 +146,7 @@ static HashTable* php_phongo_command_get_debug_info(zend_object* object, int* is php_phongo_command_t* intern; zval retval = ZVAL_STATIC_INIT; - *is_temp = 1; + *is_temp = 0; intern = Z_OBJ_COMMAND(object); array_init_size(&retval, 1); diff --git a/src/MongoDB/Cursor.c b/src/MongoDB/Cursor.c index 491706c9c..2e8a8695e 100644 --- a/src/MongoDB/Cursor.c +++ b/src/MongoDB/Cursor.c @@ -349,7 +349,7 @@ static HashTable* php_phongo_cursor_get_debug_info(zend_object* object, int* is_ php_phongo_cursor_t* intern; zval retval = ZVAL_STATIC_INIT; - *is_temp = 1; + *is_temp = 0; intern = Z_OBJ_CURSOR(object); array_init_size(&retval, 10); diff --git a/src/MongoDB/Manager.c b/src/MongoDB/Manager.c index 2bf02fbdf..93e78e962 100644 --- a/src/MongoDB/Manager.c +++ b/src/MongoDB/Manager.c @@ -825,7 +825,7 @@ static HashTable* php_phongo_manager_get_debug_info(zend_object* object, int* is zval retval = ZVAL_STATIC_INIT; zval cluster; - *is_temp = 1; + *is_temp = 0; intern = Z_OBJ_MANAGER(object); array_init_size(&retval, 3); diff --git a/src/MongoDB/Monitoring/CommandFailedEvent.c b/src/MongoDB/Monitoring/CommandFailedEvent.c index e0b36a8ba..4ee18f2a7 100644 --- a/src/MongoDB/Monitoring/CommandFailedEvent.c +++ b/src/MongoDB/Monitoring/CommandFailedEvent.c @@ -219,7 +219,7 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(zend_object* obje PHONGO_BSON_INIT_STATE(reply_state); intern = Z_OBJ_COMMANDFAILEDEVENT(object); - *is_temp = 1; + *is_temp = 0; array_init_size(&retval, 10); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/CommandStartedEvent.c b/src/MongoDB/Monitoring/CommandStartedEvent.c index 5b4037659..ba9651b69 100644 --- a/src/MongoDB/Monitoring/CommandStartedEvent.c +++ b/src/MongoDB/Monitoring/CommandStartedEvent.c @@ -193,7 +193,7 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(zend_object* obj PHONGO_BSON_INIT_STATE(command_state); intern = Z_OBJ_COMMANDSTARTEDEVENT(object); - *is_temp = 1; + *is_temp = 0; array_init_size(&retval, 9); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/CommandSucceededEvent.c b/src/MongoDB/Monitoring/CommandSucceededEvent.c index cb0a0ccb9..13d6a4767 100644 --- a/src/MongoDB/Monitoring/CommandSucceededEvent.c +++ b/src/MongoDB/Monitoring/CommandSucceededEvent.c @@ -204,7 +204,7 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(zend_object* o PHONGO_BSON_INIT_STATE(reply_state); intern = Z_OBJ_COMMANDSUCCEEDEDEVENT(object); - *is_temp = 1; + *is_temp = 0; array_init_size(&retval, 9); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/ServerChangedEvent.c b/src/MongoDB/Monitoring/ServerChangedEvent.c index 065f2baee..38f4509fb 100644 --- a/src/MongoDB/Monitoring/ServerChangedEvent.c +++ b/src/MongoDB/Monitoring/ServerChangedEvent.c @@ -117,7 +117,7 @@ static HashTable* php_phongo_serverchangedevent_get_debug_info(zend_object* obje zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_SERVERCHANGEDEVENT(object); - *is_temp = 1; + *is_temp = 0; array_init_size(&retval, 4); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/ServerClosedEvent.c b/src/MongoDB/Monitoring/ServerClosedEvent.c index b540125ba..528d2d23e 100644 --- a/src/MongoDB/Monitoring/ServerClosedEvent.c +++ b/src/MongoDB/Monitoring/ServerClosedEvent.c @@ -85,7 +85,7 @@ static HashTable* php_phongo_serverclosedevent_get_debug_info(zend_object* objec zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_SERVERCLOSEDEVENT(object); - *is_temp = 1; + *is_temp = 0; array_init_size(&retval, 3); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/ServerHeartbeatFailedEvent.c b/src/MongoDB/Monitoring/ServerHeartbeatFailedEvent.c index b20b022d5..cf74bbd33 100644 --- a/src/MongoDB/Monitoring/ServerHeartbeatFailedEvent.c +++ b/src/MongoDB/Monitoring/ServerHeartbeatFailedEvent.c @@ -107,7 +107,7 @@ static HashTable* php_phongo_serverheartbeatfailedevent_get_debug_info(zend_obje zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_SERVERHEARTBEATFAILEDEVENT(object); - *is_temp = 1; + *is_temp = 0; array_init_size(&retval, 5); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/ServerHeartbeatStartedEvent.c b/src/MongoDB/Monitoring/ServerHeartbeatStartedEvent.c index 0df11d1d0..9979c1533 100644 --- a/src/MongoDB/Monitoring/ServerHeartbeatStartedEvent.c +++ b/src/MongoDB/Monitoring/ServerHeartbeatStartedEvent.c @@ -83,7 +83,7 @@ static HashTable* php_phongo_serverheartbeatstartedevent_get_debug_info(zend_obj zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_SERVERHEARTBEATSTARTEDEVENT(object); - *is_temp = 1; + *is_temp = 0; array_init_size(&retval, 4); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/ServerHeartbeatSucceededEvent.c b/src/MongoDB/Monitoring/ServerHeartbeatSucceededEvent.c index d8e213b39..1277f1847 100644 --- a/src/MongoDB/Monitoring/ServerHeartbeatSucceededEvent.c +++ b/src/MongoDB/Monitoring/ServerHeartbeatSucceededEvent.c @@ -118,7 +118,7 @@ static HashTable* php_phongo_serverheartbeatsucceededevent_get_debug_info(zend_o PHONGO_BSON_INIT_STATE(reply_state); intern = Z_OBJ_SERVERHEARTBEATSUCCEEDEDEVENT(object); - *is_temp = 1; + *is_temp = 0; array_init_size(&retval, 4); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/ServerOpeningEvent.c b/src/MongoDB/Monitoring/ServerOpeningEvent.c index ba8e53119..80a460d50 100644 --- a/src/MongoDB/Monitoring/ServerOpeningEvent.c +++ b/src/MongoDB/Monitoring/ServerOpeningEvent.c @@ -85,7 +85,7 @@ static HashTable* php_phongo_serveropeningevent_get_debug_info(zend_object* obje zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_SERVEROPENINGEVENT(object); - *is_temp = 1; + *is_temp = 0; array_init_size(&retval, 3); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/TopologyChangedEvent.c b/src/MongoDB/Monitoring/TopologyChangedEvent.c index ac44c124b..d9ab3cf93 100644 --- a/src/MongoDB/Monitoring/TopologyChangedEvent.c +++ b/src/MongoDB/Monitoring/TopologyChangedEvent.c @@ -96,7 +96,7 @@ static HashTable* php_phongo_topologychangedevent_get_debug_info(zend_object* ob zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_TOPOLOGYCHANGEDEVENT(object); - *is_temp = 1; + *is_temp = 0; array_init_size(&retval, 3); { diff --git a/src/MongoDB/Monitoring/TopologyClosedEvent.c b/src/MongoDB/Monitoring/TopologyClosedEvent.c index 383b05097..64e71543e 100644 --- a/src/MongoDB/Monitoring/TopologyClosedEvent.c +++ b/src/MongoDB/Monitoring/TopologyClosedEvent.c @@ -65,7 +65,7 @@ static HashTable* php_phongo_topologyclosedevent_get_debug_info(zend_object* obj zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_TOPOLOGYCLOSEDEVENT(object); - *is_temp = 1; + *is_temp = 0; array_init_size(&retval, 1); { diff --git a/src/MongoDB/Monitoring/TopologyOpeningEvent.c b/src/MongoDB/Monitoring/TopologyOpeningEvent.c index 4fd3d4f36..9c34d2c47 100644 --- a/src/MongoDB/Monitoring/TopologyOpeningEvent.c +++ b/src/MongoDB/Monitoring/TopologyOpeningEvent.c @@ -65,7 +65,7 @@ static HashTable* php_phongo_topologyopeningevent_get_debug_info(zend_object* ob zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_TOPOLOGYOPENINGEVENT(object); - *is_temp = 1; + *is_temp = 0; array_init_size(&retval, 1); { diff --git a/src/MongoDB/Query.c b/src/MongoDB/Query.c index 56d539d35..7c6fda135 100644 --- a/src/MongoDB/Query.c +++ b/src/MongoDB/Query.c @@ -363,7 +363,7 @@ static HashTable* php_phongo_query_get_debug_info(zend_object* object, int* is_t php_phongo_query_t* intern; zval retval = ZVAL_STATIC_INIT; - *is_temp = 1; + *is_temp = 0; intern = Z_OBJ_QUERY(object); array_init_size(&retval, 3); diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index bcb5411a0..0ba0797b2 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -207,7 +207,7 @@ static zend_object* php_phongo_readconcern_create_object(zend_class_entry* class static HashTable* php_phongo_readconcern_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_readconcern_get_properties_hash(object, true); } diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index 6e27715e5..2f5ba2ee3 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -507,7 +507,7 @@ static zend_object* php_phongo_readpreference_create_object(zend_class_entry* cl static HashTable* php_phongo_readpreference_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_readpreference_get_properties_hash(object, true); } diff --git a/src/MongoDB/Server.c b/src/MongoDB/Server.c index aaff411b5..05c6237a1 100644 --- a/src/MongoDB/Server.c +++ b/src/MongoDB/Server.c @@ -578,7 +578,7 @@ static HashTable* php_phongo_server_get_debug_info(zend_object* object, int* is_ mongoc_client_t* client; mongoc_server_description_t* sd; - *is_temp = 1; + *is_temp = 0; intern = Z_OBJ_SERVER(object); client = Z_MANAGER_OBJ_P(&intern->manager)->client; diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index 30ce583dc..d9af12881 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -235,7 +235,7 @@ static zend_object* php_phongo_serverapi_create_object(zend_class_entry* class_t static HashTable* php_phongo_serverapi_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_serverapi_get_properties_hash(object, true, true); } diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index a8235ad46..43d39330d 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -258,7 +258,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object, static HashTable* php_phongo_serverdescription_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_serverdescription_get_properties_hash(object, true); } diff --git a/src/MongoDB/Session.c b/src/MongoDB/Session.c index b52c9807c..786dac543 100644 --- a/src/MongoDB/Session.c +++ b/src/MongoDB/Session.c @@ -585,7 +585,7 @@ static HashTable* php_phongo_session_get_debug_info(zend_object* object, int* is php_phongo_session_t* intern = NULL; zval retval = ZVAL_STATIC_INIT; - *is_temp = 1; + *is_temp = 0; intern = Z_OBJ_SESSION(object); array_init(&retval); diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index 2e6513f47..c7cd2c97c 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -171,7 +171,7 @@ HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* objec static HashTable* php_phongo_topologydescription_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_topologydescription_get_properties_hash(object, true); } diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index cd2b8d213..bee10f42b 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -392,7 +392,7 @@ static zend_object* php_phongo_writeconcern_create_object(zend_class_entry* clas static HashTable* php_phongo_writeconcern_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 1; + *is_temp = 0; return php_phongo_writeconcern_get_properties_hash(object, true, false, false); } diff --git a/src/MongoDB/WriteConcernError.c b/src/MongoDB/WriteConcernError.c index edf81dd45..c5eb61a8c 100644 --- a/src/MongoDB/WriteConcernError.c +++ b/src/MongoDB/WriteConcernError.c @@ -106,7 +106,7 @@ static HashTable* php_phongo_writeconcernerror_get_debug_info(zend_object* objec php_phongo_writeconcernerror_t* intern; zval retval = ZVAL_STATIC_INIT; - *is_temp = 1; + *is_temp = 0; intern = Z_OBJ_WRITECONCERNERROR(object); array_init_size(&retval, 3); diff --git a/src/MongoDB/WriteError.c b/src/MongoDB/WriteError.c index 148a90c0d..f9ab13a25 100644 --- a/src/MongoDB/WriteError.c +++ b/src/MongoDB/WriteError.c @@ -115,7 +115,7 @@ static HashTable* php_phongo_writeerror_get_debug_info(zend_object* object, int* php_phongo_writeerror_t* intern; zval retval = ZVAL_STATIC_INIT; - *is_temp = 1; + *is_temp = 0; intern = Z_OBJ_WRITEERROR(object); array_init_size(&retval, 3); diff --git a/src/MongoDB/WriteResult.c b/src/MongoDB/WriteResult.c index c7280ee89..d90296474 100644 --- a/src/MongoDB/WriteResult.c +++ b/src/MongoDB/WriteResult.c @@ -369,7 +369,7 @@ static HashTable* php_phongo_writeresult_get_debug_info(zend_object* object, int bson_iter_t iter; intern = Z_OBJ_WRITERESULT(object); - *is_temp = 1; + *is_temp = 0; array_init_size(&retval, 10); #define PHONGO_WRITERESULT_SCP(field) \ From c8808c5a51838fdfa4d38dea4483f11c006d560a Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 17 Jul 2025 14:32:21 +0200 Subject: [PATCH 03/44] Add test --- tests/bson/bug2505.phpt | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 tests/bson/bug2505.phpt diff --git a/tests/bson/bug2505.phpt b/tests/bson/bug2505.phpt new file mode 100644 index 000000000..9ce01aa9f --- /dev/null +++ b/tests/bson/bug2505.phpt @@ -0,0 +1,54 @@ +--TEST-- +PHPC-2505: gc_collect_cycles() may interfere with using foreach to iterate objects +--FILE-- + new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], + [ 'dbpointer' => createDBPointer() ], + [ 'decimal128' => new MongoDB\BSON\Decimal128('1234.5678') ], + [ 'int64' => new MongoDB\BSON\Int64('9223372036854775807') ], + // JavaScript w/ scope may not be necessary (same code path as w/o scope), but we'll test it anyway + [ 'javascript' => new MongoDB\BSON\Javascript('function() { return 1; }') ], + [ 'javascript_ws' => new MongoDB\BSON\Javascript('function() { return a; }', ['a' => 1]) ], + // MaxKey and MinKey don't have get_properties or get_gc handlers, but we'll test them anyway + [ 'maxkey' => new MongoDB\BSON\MaxKey ], + [ 'minkey' => new MongoDB\BSON\MinKey ], + [ 'objectid' => new MongoDB\BSON\ObjectId ], + [ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ], + [ 'symbol' => createSymbol() ], + [ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ], + [ 'utcdatetime' => new MongoDB\BSON\UTCDateTime ], +]; + +ob_start(); +foreach ($tests as $test) { + echo key($test), "\n"; + + foreach ($test as $k => $v) { + var_dump($k, $v); + } +} +$buf1 = ob_end_clean(); + +ob_start(); +foreach ($tests as $test) { + echo key($test), "\n"; + + foreach ($test as $k => $v) { + var_dump($k, $v); + } +} +$buf2 = ob_end_clean(); + +if ($buf1 === $buf2) { + echo "OK!\n"; + exit(0); +} else { + echo("buf1 != buf2: $buf1\n!=\n$buf2\n"); +} + +?> +--EXPECT-- +OK! \ No newline at end of file From fe87c0ed1ed7f1101220067d63ee92fb8b3cc0aa Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 17 Jul 2025 14:42:39 +0200 Subject: [PATCH 04/44] Test --- tests/bson/bug2505.phpt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/bson/bug2505.phpt b/tests/bson/bug2505.phpt index 9ce01aa9f..661c8e925 100644 --- a/tests/bson/bug2505.phpt +++ b/tests/bson/bug2505.phpt @@ -4,6 +4,8 @@ PHPC-2505: gc_collect_cycles() may interfere with using foreach to iterate objec new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], [ 'dbpointer' => createDBPointer() ], @@ -32,6 +34,9 @@ foreach ($tests as $test) { } $buf1 = ob_end_clean(); +gc_enable(); +gc_collect_cycles(); + ob_start(); foreach ($tests as $test) { echo key($test), "\n"; From f8f1dcf54aa2ea904831c8e01dfc7c832bc5ac4b Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 17 Jul 2025 14:55:44 +0200 Subject: [PATCH 05/44] Cleanup --- src/BSON/Binary.c | 5 ----- src/BSON/DBPointer.c | 5 ----- src/BSON/Decimal128.c | 5 ----- src/BSON/Document.c | 5 ----- src/BSON/Int64.c | 5 ----- src/BSON/Iterator.c | 5 ----- src/BSON/Javascript.c | 5 ----- src/BSON/ObjectId.c | 5 ----- src/BSON/PackedArray.c | 5 ----- src/BSON/Regex.c | 5 ----- src/BSON/Symbol.c | 5 ----- src/BSON/Timestamp.c | 5 ----- src/BSON/UTCDateTime.c | 5 ----- src/MongoDB/ReadConcern.c | 5 ----- src/MongoDB/ReadPreference.c | 5 ----- src/MongoDB/ServerApi.c | 5 ----- src/MongoDB/ServerDescription.c | 5 ----- src/MongoDB/TopologyDescription.c | 5 ----- src/MongoDB/WriteConcern.c | 5 ----- src/phongo_structs.h | 19 ------------------- 20 files changed, 114 deletions(-) diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index fad2319f8..a0a172f31 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -212,11 +212,6 @@ static void php_phongo_binary_free_object(zend_object* object) if (intern->data) { efree(intern->data); } - - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } } static zend_object* php_phongo_binary_create_object(zend_class_entry* class_type) diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index fa4e94538..29a280eb1 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -175,11 +175,6 @@ static void php_phongo_dbpointer_free_object(zend_object* object) if (intern->ref) { efree(intern->ref); } - - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } } zend_object* php_phongo_dbpointer_create_object(zend_class_entry* class_type) diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 0e31e5773..43e574ff8 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -167,11 +167,6 @@ static void php_phongo_decimal128_free_object(zend_object* object) php_phongo_decimal128_t* intern = Z_OBJ_DECIMAL128(object); zend_object_std_dtor(&intern->std); - - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } } static zend_object* php_phongo_decimal128_create_object(zend_class_entry* class_type) diff --git a/src/BSON/Document.c b/src/BSON/Document.c index 2a5c685d8..785cd7dda 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -445,11 +445,6 @@ static void php_phongo_document_free_object(zend_object* object) if (intern->bson) { bson_destroy(intern->bson); } - - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } } static zend_object* php_phongo_document_create_object(zend_class_entry* class_type) diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index e243c9222..383954887 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -174,11 +174,6 @@ static void php_phongo_int64_free_object(zend_object* object) php_phongo_int64_t* intern = Z_OBJ_INT64(object); zend_object_std_dtor(&intern->std); - - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } } zend_object* php_phongo_int64_create_object(zend_class_entry* class_type) diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index 7e93058ba..2332ad55b 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -248,11 +248,6 @@ static void php_phongo_iterator_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } - php_phongo_iterator_free_current(intern); zval_ptr_dtor(&intern->bson); diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index 04bc2e44d..0883259b5 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -257,11 +257,6 @@ static void php_phongo_javascript_free_object(zend_object* object) bson_destroy(intern->scope); intern->scope = NULL; } - - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } } zend_object* php_phongo_javascript_create_object(zend_class_entry* class_type) diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 034c94440..3b6431375 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -201,11 +201,6 @@ static void php_phongo_objectid_free_object(zend_object* object) php_phongo_objectid_t* intern = Z_OBJ_OBJECTID(object); zend_object_std_dtor(&intern->std); - - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } } static zend_object* php_phongo_objectid_create_object(zend_class_entry* class_type) diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index d2c528088..8fd44ad7c 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -429,11 +429,6 @@ static void php_phongo_packedarray_free_object(zend_object* object) if (intern->bson) { bson_destroy(intern->bson); } - - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } } static zend_object* php_phongo_packedarray_create_object(zend_class_entry* class_type) diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index 90a0ef6e2..baebe9d51 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -227,11 +227,6 @@ static void php_phongo_regex_free_object(zend_object* object) if (intern->flags) { efree(intern->flags); } - - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } } static zend_object* php_phongo_regex_create_object(zend_class_entry* class_type) diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index 728ada960..9c950a791 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -149,11 +149,6 @@ static void php_phongo_symbol_free_object(zend_object* object) if (intern->symbol) { efree(intern->symbol); } - - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } } zend_object* php_phongo_symbol_create_object(zend_class_entry* class_type) diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index f23b55684..68d6dd9db 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -260,11 +260,6 @@ static void php_phongo_timestamp_free_object(zend_object* object) php_phongo_timestamp_t* intern = Z_OBJ_TIMESTAMP(object); zend_object_std_dtor(&intern->std); - - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } } static zend_object* php_phongo_timestamp_create_object(zend_class_entry* class_type) diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index 324db0cce..6b1abc0bc 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -300,11 +300,6 @@ static void php_phongo_utcdatetime_free_object(zend_object* object) php_phongo_utcdatetime_t* intern = Z_OBJ_UTCDATETIME(object); zend_object_std_dtor(&intern->std); - - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } } static zend_object* php_phongo_utcdatetime_create_object(zend_class_entry* class_type) diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index 0ba0797b2..cfe544e45 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -183,11 +183,6 @@ static void php_phongo_readconcern_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } - if (intern->read_concern) { mongoc_read_concern_destroy(intern->read_concern); } diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index 2f5ba2ee3..addb7df2d 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -483,11 +483,6 @@ static void php_phongo_readpreference_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } - if (intern->read_preference) { mongoc_read_prefs_destroy(intern->read_preference); } diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index d9af12881..d365ccef8 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -211,11 +211,6 @@ static void php_phongo_serverapi_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } - if (intern->server_api) { mongoc_server_api_destroy(intern->server_api); } diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index 43d39330d..48d6b38f8 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -158,11 +158,6 @@ static void php_phongo_serverdescription_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } - if (intern->server_description) { mongoc_server_description_destroy(intern->server_description); } diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index c7cd2c97c..1b6607b12 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -107,11 +107,6 @@ static void php_phongo_topologydescription_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } - if (intern->topology_description) { mongoc_topology_description_destroy(intern->topology_description); } diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index bee10f42b..b4aacb67a 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -368,11 +368,6 @@ static void php_phongo_writeconcern_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); - } - if (intern->write_concern) { mongoc_write_concern_destroy(intern->write_concern); } diff --git a/src/phongo_structs.h b/src/phongo_structs.h index 7b083e612..1f0fee57d 100644 --- a/src/phongo_structs.h +++ b/src/phongo_structs.h @@ -121,13 +121,11 @@ typedef struct { typedef struct { mongoc_read_concern_t* read_concern; - HashTable* properties; zend_object std; } php_phongo_readconcern_t; typedef struct { mongoc_read_prefs_t* read_preference; - HashTable* properties; zend_object std; } php_phongo_readpreference_t; @@ -140,13 +138,11 @@ typedef struct { typedef struct { mongoc_server_api_t* server_api; - HashTable* properties; zend_object std; } php_phongo_serverapi_t; typedef struct { mongoc_server_description_t* server_description; - HashTable* properties; zend_object std; } php_phongo_serverdescription_t; @@ -159,12 +155,10 @@ typedef struct { typedef struct { mongoc_topology_description_t* topology_description; - HashTable* properties; zend_object std; } php_phongo_topologydescription_t; typedef struct { - HashTable* properties; mongoc_write_concern_t* write_concern; zend_object std; } php_phongo_writeconcern_t; @@ -196,19 +190,16 @@ typedef struct { char* data; int data_len; uint8_t type; - HashTable* properties; zend_object std; } php_phongo_binary_t; typedef struct { bson_t* bson; - HashTable* properties; zend_object std; } php_phongo_packedarray_t; typedef struct { bson_t* bson; - HashTable* properties; zend_object std; } php_phongo_document_t; @@ -219,7 +210,6 @@ typedef struct { bool is_array; size_t key; zval current; - HashTable* properties; zend_object std; } php_phongo_iterator_t; @@ -227,21 +217,18 @@ typedef struct { char* ref; size_t ref_len; char id[25]; - HashTable* properties; zend_object std; } php_phongo_dbpointer_t; typedef struct { bool initialized; bson_decimal128_t decimal; - HashTable* properties; zend_object std; } php_phongo_decimal128_t; typedef struct { bool initialized; int64_t integer; - HashTable* properties; zend_object std; } php_phongo_int64_t; @@ -249,7 +236,6 @@ typedef struct { char* code; size_t code_len; bson_t* scope; - HashTable* properties; zend_object std; } php_phongo_javascript_t; @@ -264,7 +250,6 @@ typedef struct { typedef struct { bool initialized; char oid[25]; - HashTable* properties; zend_object std; } php_phongo_objectid_t; @@ -273,14 +258,12 @@ typedef struct { int pattern_len; char* flags; int flags_len; - HashTable* properties; zend_object std; } php_phongo_regex_t; typedef struct { char* symbol; size_t symbol_len; - HashTable* properties; zend_object std; } php_phongo_symbol_t; @@ -288,7 +271,6 @@ typedef struct { bool initialized; uint32_t increment; uint32_t timestamp; - HashTable* properties; zend_object std; } php_phongo_timestamp_t; @@ -299,7 +281,6 @@ typedef struct { typedef struct { bool initialized; int64_t milliseconds; - HashTable* properties; zend_object std; } php_phongo_utcdatetime_t; From 70c6c8cf1dcb83c791abc3cec467ae68ebbc1c34 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 21 Jul 2025 11:03:57 +0200 Subject: [PATCH 06/44] Small fix --- tests/bson/bug1598-002.phpt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bson/bug1598-002.phpt b/tests/bson/bug1598-002.phpt index 0b675f37a..4a55de7e6 100644 --- a/tests/bson/bug1598-002.phpt +++ b/tests/bson/bug1598-002.phpt @@ -3,7 +3,7 @@ PHPC-1598: BSON type get_gc should delegate to zend_std_get_properties --FILE-- new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], [ 'dbpointer' => createDBPointer(), ], From 1ab1886b19591b33c6d1c0a0e16660373929e4e7 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 21 Jul 2025 12:42:59 +0200 Subject: [PATCH 07/44] Tmp --- src/BSON/Binary.c | 8 ++++---- src/BSON/DBPointer.c | 8 ++++---- src/BSON/Decimal128.c | 8 ++++---- src/BSON/Document.c | 8 ++++---- src/BSON/Int64.c | 8 ++++---- src/BSON/Iterator.c | 6 +++--- src/BSON/Javascript.c | 8 ++++---- src/BSON/ObjectId.c | 8 ++++---- src/BSON/PackedArray.c | 8 ++++---- src/BSON/Regex.c | 8 ++++---- src/BSON/Symbol.c | 8 ++++---- src/BSON/Timestamp.c | 8 ++++---- src/BSON/UTCDateTime.c | 8 ++++---- src/MongoDB/ReadConcern.c | 10 +++++----- src/MongoDB/ReadPreference.c | 10 +++++----- src/MongoDB/ServerApi.c | 10 +++++----- src/MongoDB/ServerDescription.c | 6 +++--- src/MongoDB/TopologyDescription.c | 6 +++--- src/MongoDB/WriteConcern.c | 10 +++++----- src/phongo_compat.h | 7 +++++++ 20 files changed, 84 insertions(+), 77 deletions(-) diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index a0a172f31..d703c158e 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -63,7 +63,7 @@ static bool php_phongo_binary_init_from_hash(php_phongo_binary_t* intern, HashTa return false; } -static HashTable* php_phongo_binary_get_properties_hash(zend_object* object, bool is_temp) +static HashTable* php_phongo_binary_get_properties_hash(zend_object* object) { php_phongo_binary_t* intern; HashTable* props; @@ -186,7 +186,7 @@ static PHP_METHOD(MongoDB_BSON_Binary, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_binary_get_properties_hash(Z_OBJ_P(getThis()), true)); + PHONGO_RETURN_PROPERTIES_ARR(php_phongo_binary_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_Binary, __unserialize) @@ -268,12 +268,12 @@ static int php_phongo_binary_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_binary_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_binary_get_properties_hash(object, true); + return php_phongo_binary_get_properties_hash(object); } static HashTable* php_phongo_binary_get_properties(zend_object* object) { - return php_phongo_binary_get_properties_hash(object, false); + return php_phongo_binary_get_properties_hash(object); } void php_phongo_binary_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index 29a280eb1..74e6b3785 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -64,7 +64,7 @@ static bool php_phongo_dbpointer_init_from_hash(php_phongo_dbpointer_t* intern, return false; } -HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object, bool is_temp) +HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object) { php_phongo_dbpointer_t* intern; HashTable* props; @@ -149,7 +149,7 @@ static PHP_METHOD(MongoDB_BSON_DBPointer, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_dbpointer_get_properties_hash(Z_OBJ_P(getThis()), true)); + PHONGO_RETURN_PROPERTIES_ARR(php_phongo_dbpointer_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_DBPointer, __unserialize) @@ -228,12 +228,12 @@ static int php_phongo_dbpointer_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_dbpointer_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_dbpointer_get_properties_hash(object, true); + return php_phongo_dbpointer_get_properties_hash(object); } static HashTable* php_phongo_dbpointer_get_properties(zend_object* object) { - return php_phongo_dbpointer_get_properties_hash(object, false); + return php_phongo_dbpointer_get_properties_hash(object); } void php_phongo_dbpointer_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 43e574ff8..dbd66d92a 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -53,7 +53,7 @@ static bool php_phongo_decimal128_init_from_hash(php_phongo_decimal128_t* intern return false; } -static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object, bool is_temp) +static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object) { php_phongo_decimal128_t* intern; HashTable* props; @@ -145,7 +145,7 @@ static PHP_METHOD(MongoDB_BSON_Decimal128, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_decimal128_get_properties_hash(Z_OBJ_P(getThis()), true)); + PHONGO_RETURN_PROPERTIES_ARR(php_phongo_decimal128_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_Decimal128, __unserialize) @@ -203,12 +203,12 @@ static zend_object* php_phongo_decimal128_clone_object(zend_object* object) static HashTable* php_phongo_decimal128_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_decimal128_get_properties_hash(object, true); + return php_phongo_decimal128_get_properties_hash(object); } static HashTable* php_phongo_decimal128_get_properties(zend_object* object) { - return php_phongo_decimal128_get_properties_hash(object, false); + return php_phongo_decimal128_get_properties_hash(object); } void php_phongo_decimal128_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/Document.c b/src/BSON/Document.c index 785cd7dda..7af9c9df5 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -55,7 +55,7 @@ static bool php_phongo_document_init_from_hash(php_phongo_document_t* intern, Ha return false; } -static HashTable* php_phongo_document_get_properties_hash(zend_object* object, bool is_temp, int size) +static HashTable* php_phongo_document_get_properties_hash(zend_object* object, int size) { php_phongo_document_t* intern; HashTable* props; @@ -419,7 +419,7 @@ static PHP_METHOD(MongoDB_BSON_Document, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_document_get_properties_hash(Z_OBJ_P(getThis()), true, 1)); + PHONGO_RETURN_PROPERTIES_ARR(php_phongo_document_get_properties_hash(Z_OBJ_P(getThis()), 1)); } static PHP_METHOD(MongoDB_BSON_Document, __unserialize) @@ -499,7 +499,7 @@ static HashTable* php_phongo_document_get_debug_info(zend_object* object, int* i /* This get_debug_info handler reports an additional property. This does not * conflict with other uses of php_phongo_document_get_properties_hash since * we always allocated a new HashTable with is_temp=true. */ - props = php_phongo_document_get_properties_hash(object, true, 2); + props = php_phongo_document_get_properties_hash(object, 2); { php_phongo_bson_state state; @@ -520,7 +520,7 @@ static HashTable* php_phongo_document_get_debug_info(zend_object* object, int* i static HashTable* php_phongo_document_get_properties(zend_object* object) { - return php_phongo_document_get_properties_hash(object, false, 1); + return php_phongo_document_get_properties_hash(object, 1); } zval* php_phongo_document_read_property(zend_object* object, zend_string* member, int type, void** cache_slot, zval* rv) diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index 383954887..3de55d92d 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -62,7 +62,7 @@ static bool php_phongo_int64_init_from_hash(php_phongo_int64_t* intern, HashTabl return false; } -HashTable* php_phongo_int64_get_properties_hash(zend_object* object, bool is_temp) +HashTable* php_phongo_int64_get_properties_hash(zend_object* object) { php_phongo_int64_t* intern; HashTable* props; @@ -152,7 +152,7 @@ static PHP_METHOD(MongoDB_BSON_Int64, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_int64_get_properties_hash(Z_OBJ_P(getThis()), true)); + PHONGO_RETURN_PROPERTIES_ARR(php_phongo_int64_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_Int64, __unserialize) @@ -541,12 +541,12 @@ static zend_result php_phongo_int64_do_operation(zend_uchar opcode, zval* result static HashTable* php_phongo_int64_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_int64_get_properties_hash(object, true); + return php_phongo_int64_get_properties_hash(object); } static HashTable* php_phongo_int64_get_properties(zend_object* object) { - return php_phongo_int64_get_properties_hash(object, false); + return php_phongo_int64_get_properties_hash(object); } void php_phongo_int64_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index 2332ad55b..8b28c6f64 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -153,7 +153,7 @@ static void php_phongo_iterator_rewind(php_phongo_iterator_t* intern) intern->valid = bson_iter_next(&intern->iter); } -static HashTable* php_phongo_iterator_get_properties_hash(zend_object* object, bool is_temp) +static HashTable* php_phongo_iterator_get_properties_hash(zend_object* object) { php_phongo_iterator_t* intern; HashTable* props; @@ -284,12 +284,12 @@ static zend_object* php_phongo_iterator_clone_object(zend_object* object) static HashTable* php_phongo_iterator_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_iterator_get_properties_hash(object, true); + return php_phongo_iterator_get_properties_hash(object); } static HashTable* php_phongo_iterator_get_properties(zend_object* object) { - return php_phongo_iterator_get_properties_hash(object, false); + return php_phongo_iterator_get_properties_hash(object); } /* Iterator handlers */ diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index 0883259b5..615b2a501 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -69,7 +69,7 @@ static bool php_phongo_javascript_init_from_hash(php_phongo_javascript_t* intern return false; } -HashTable* php_phongo_javascript_get_properties_hash(zend_object* object, bool is_temp) +HashTable* php_phongo_javascript_get_properties_hash(zend_object* object) { php_phongo_javascript_t* intern; HashTable* props; @@ -227,7 +227,7 @@ static PHP_METHOD(MongoDB_BSON_Javascript, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_javascript_get_properties_hash(Z_OBJ_P(getThis()), true)); + PHONGO_RETURN_PROPERTIES_ARR(php_phongo_javascript_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_Javascript, __unserialize) @@ -305,12 +305,12 @@ static int php_phongo_javascript_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_javascript_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_javascript_get_properties_hash(object, true); + return php_phongo_javascript_get_properties_hash(object); } static HashTable* php_phongo_javascript_get_properties(zend_object* object) { - return php_phongo_javascript_get_properties_hash(object, false); + return php_phongo_javascript_get_properties_hash(object); } void php_phongo_javascript_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 3b6431375..8161bebb2 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -77,7 +77,7 @@ static bool php_phongo_objectid_init_from_hash(php_phongo_objectid_t* intern, Ha return false; } -static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object, bool is_temp) +static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object) { php_phongo_objectid_t* intern; HashTable* props; @@ -179,7 +179,7 @@ static PHP_METHOD(MongoDB_BSON_ObjectId, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_objectid_get_properties_hash(Z_OBJ_P(getThis()), true)); + PHONGO_RETURN_PROPERTIES_ARR(php_phongo_objectid_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_ObjectId, __unserialize) @@ -250,12 +250,12 @@ static int php_phongo_objectid_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_objectid_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_objectid_get_properties_hash(object, true); + return php_phongo_objectid_get_properties_hash(object); } static HashTable* php_phongo_objectid_get_properties(zend_object* object) { - return php_phongo_objectid_get_properties_hash(object, false); + return php_phongo_objectid_get_properties_hash(object); } void php_phongo_objectid_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index 8fd44ad7c..1c1017df9 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -56,7 +56,7 @@ static bool php_phongo_packedarray_init_from_hash(php_phongo_packedarray_t* inte return false; } -static HashTable* php_phongo_packedarray_get_properties_hash(zend_object* object, bool is_temp, int size) +static HashTable* php_phongo_packedarray_get_properties_hash(zend_object* object, int size) { php_phongo_packedarray_t* intern; HashTable* props; @@ -403,7 +403,7 @@ static PHP_METHOD(MongoDB_BSON_PackedArray, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_packedarray_get_properties_hash(Z_OBJ_P(getThis()), true, 1)); + PHONGO_RETURN_PROPERTIES_ARR(php_phongo_packedarray_get_properties_hash(Z_OBJ_P(getThis()), 1)); } static PHP_METHOD(MongoDB_BSON_PackedArray, __unserialize) @@ -483,7 +483,7 @@ static HashTable* php_phongo_packedarray_get_debug_info(zend_object* object, int /* This get_debug_info handler reports an additional property. This does not * conflict with other uses of php_phongo_document_get_properties_hash since * we always allocated a new HashTable with is_temp=true. */ - props = php_phongo_packedarray_get_properties_hash(object, true, 2); + props = php_phongo_packedarray_get_properties_hash(object, 2); { php_phongo_bson_state state; @@ -505,7 +505,7 @@ static HashTable* php_phongo_packedarray_get_debug_info(zend_object* object, int static HashTable* php_phongo_packedarray_get_properties(zend_object* object) { - return php_phongo_packedarray_get_properties_hash(object, false, 1); + return php_phongo_packedarray_get_properties_hash(object, 1); } zval* php_phongo_packedarray_read_dimension(zend_object* object, zval* offset, int type, zval* rv) diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index baebe9d51..9b98d8783 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -78,7 +78,7 @@ static bool php_phongo_regex_init_from_hash(php_phongo_regex_t* intern, HashTabl return false; } -static HashTable* php_phongo_regex_get_properties_hash(zend_object* object, bool is_temp) +static HashTable* php_phongo_regex_get_properties_hash(zend_object* object) { php_phongo_regex_t* intern; HashTable* props; @@ -197,7 +197,7 @@ static PHP_METHOD(MongoDB_BSON_Regex, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_regex_get_properties_hash(Z_OBJ_P(getThis()), true)); + PHONGO_RETURN_PROPERTIES_ARR(php_phongo_regex_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_Regex, __unserialize) @@ -281,12 +281,12 @@ static int php_phongo_regex_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_regex_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_regex_get_properties_hash(object, true); + return php_phongo_regex_get_properties_hash(object); } static HashTable* php_phongo_regex_get_properties(zend_object* object) { - return php_phongo_regex_get_properties_hash(object, false); + return php_phongo_regex_get_properties_hash(object); } void php_phongo_regex_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index 9c950a791..e5230e22b 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -52,7 +52,7 @@ static bool php_phongo_symbol_init_from_hash(php_phongo_symbol_t* intern, HashTa return false; } -HashTable* php_phongo_symbol_get_properties_hash(zend_object* object, bool is_temp) +HashTable* php_phongo_symbol_get_properties_hash(zend_object* object) { php_phongo_symbol_t* intern; HashTable* props; @@ -123,7 +123,7 @@ static PHP_METHOD(MongoDB_BSON_Symbol, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - ZVAL_ARR(return_value, php_phongo_symbol_get_properties_hash(Z_OBJ_P(getThis()), true)); + ZVAL_ARR(return_value, php_phongo_symbol_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_Symbol, __unserialize) @@ -195,12 +195,12 @@ static int php_phongo_symbol_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_symbol_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_symbol_get_properties_hash(object, true); + return php_phongo_symbol_get_properties_hash(object); } static HashTable* php_phongo_symbol_get_properties(zend_object* object) { - return php_phongo_symbol_get_properties_hash(object, false); + return php_phongo_symbol_get_properties_hash(object); } void php_phongo_symbol_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 68d6dd9db..148942d63 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -85,7 +85,7 @@ static bool php_phongo_timestamp_init_from_hash(php_phongo_timestamp_t* intern, return false; } -static HashTable* php_phongo_timestamp_get_properties_hash(zend_object* object, bool is_temp) +static HashTable* php_phongo_timestamp_get_properties_hash(zend_object* object) { php_phongo_timestamp_t* intern; HashTable* props; @@ -238,7 +238,7 @@ static PHP_METHOD(MongoDB_BSON_Timestamp, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_timestamp_get_properties_hash(Z_OBJ_P(getThis()), true)); + PHONGO_RETURN_PROPERTIES_ARR(php_phongo_timestamp_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_Timestamp, __unserialize) @@ -315,12 +315,12 @@ static int php_phongo_timestamp_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_timestamp_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_timestamp_get_properties_hash(object, true); + return php_phongo_timestamp_get_properties_hash(object); } static HashTable* php_phongo_timestamp_get_properties(zend_object* object) { - return php_phongo_timestamp_get_properties_hash(object, false); + return php_phongo_timestamp_get_properties_hash(object); } void php_phongo_timestamp_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index 6b1abc0bc..f331f363b 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -121,7 +121,7 @@ static bool php_phongo_utcdatetime_init_from_object(php_phongo_utcdatetime_t* in return false; } -static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object, bool is_temp) +static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object) { php_phongo_utcdatetime_t* intern; HashTable* props; @@ -278,7 +278,7 @@ static PHP_METHOD(MongoDB_BSON_UTCDateTime, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_utcdatetime_get_properties_hash(Z_OBJ_P(getThis()), true)); + PHONGO_RETURN_PROPERTIES_ARR(php_phongo_utcdatetime_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_UTCDateTime, __unserialize) @@ -350,12 +350,12 @@ static int php_phongo_utcdatetime_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_utcdatetime_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_utcdatetime_get_properties_hash(object, true); + return php_phongo_utcdatetime_get_properties_hash(object); } static HashTable* php_phongo_utcdatetime_get_properties(zend_object* object) { - return php_phongo_utcdatetime_get_properties_hash(object, false); + return php_phongo_utcdatetime_get_properties_hash(object); } void php_phongo_utcdatetime_init_ce(INIT_FUNC_ARGS) diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index cfe544e45..e91f1033d 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -122,7 +122,7 @@ static PHP_METHOD(MongoDB_Driver_ReadConcern, isDefault) RETURN_BOOL(mongoc_read_concern_is_default(intern->read_concern)); } -static HashTable* php_phongo_readconcern_get_properties_hash(zend_object* object, bool is_temp) +static HashTable* php_phongo_readconcern_get_properties_hash(zend_object* object) { php_phongo_readconcern_t* intern; HashTable* props; @@ -152,7 +152,7 @@ static PHP_METHOD(MongoDB_Driver_ReadConcern, bsonSerialize) { PHONGO_PARSE_PARAMETERS_NONE(); - ZVAL_ARR(return_value, php_phongo_readconcern_get_properties_hash(Z_OBJ_P(getThis()), true)); + ZVAL_ARR(return_value, php_phongo_readconcern_get_properties_hash(Z_OBJ_P(getThis()))); convert_to_object(return_value); } @@ -160,7 +160,7 @@ static PHP_METHOD(MongoDB_Driver_ReadConcern, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_readconcern_get_properties_hash(Z_OBJ_P(getThis()), true)); + PHONGO_RETURN_PROPERTIES_ARR(php_phongo_readconcern_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_Driver_ReadConcern, __unserialize) @@ -203,12 +203,12 @@ static zend_object* php_phongo_readconcern_create_object(zend_class_entry* class static HashTable* php_phongo_readconcern_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_readconcern_get_properties_hash(object, true); + return php_phongo_readconcern_get_properties_hash(object); } static HashTable* php_phongo_readconcern_get_properties(zend_object* object) { - return php_phongo_readconcern_get_properties_hash(object, false); + return php_phongo_readconcern_get_properties_hash(object); } void php_phongo_readconcern_init_ce(INIT_FUNC_ARGS) diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index addb7df2d..a1d0b482d 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -380,7 +380,7 @@ static PHP_METHOD(MongoDB_Driver_ReadPreference, getTagSets) } } -static HashTable* php_phongo_readpreference_get_properties_hash(zend_object* object, bool is_temp) +static HashTable* php_phongo_readpreference_get_properties_hash(zend_object* object) { php_phongo_readpreference_t* intern; HashTable* props; @@ -452,7 +452,7 @@ static PHP_METHOD(MongoDB_Driver_ReadPreference, bsonSerialize) { PHONGO_PARSE_PARAMETERS_NONE(); - ZVAL_ARR(return_value, php_phongo_readpreference_get_properties_hash(Z_OBJ_P(getThis()), true)); + ZVAL_ARR(return_value, php_phongo_readpreference_get_properties_hash(Z_OBJ_P(getThis()))); convert_to_object(return_value); } @@ -460,7 +460,7 @@ static PHP_METHOD(MongoDB_Driver_ReadPreference, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_readpreference_get_properties_hash(Z_OBJ_P(getThis()), true)); + PHONGO_RETURN_PROPERTIES_ARR(php_phongo_readpreference_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_Driver_ReadPreference, __unserialize) @@ -503,12 +503,12 @@ static zend_object* php_phongo_readpreference_create_object(zend_class_entry* cl static HashTable* php_phongo_readpreference_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_readpreference_get_properties_hash(object, true); + return php_phongo_readpreference_get_properties_hash(object); } static HashTable* php_phongo_readpreference_get_properties(zend_object* object) { - return php_phongo_readpreference_get_properties_hash(object, false); + return php_phongo_readpreference_get_properties_hash(object); } void php_phongo_readpreference_init_ce(INIT_FUNC_ARGS) diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index d365ccef8..ddb906a3f 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -137,7 +137,7 @@ static PHP_METHOD(MongoDB_Driver_ServerApi, __set_state) php_phongo_serverapi_init_from_hash(intern, props); } -static HashTable* php_phongo_serverapi_get_properties_hash(zend_object* object, bool is_temp, bool include_null) +static HashTable* php_phongo_serverapi_get_properties_hash(zend_object* object, bool include_null) { php_phongo_serverapi_t* intern; HashTable* props; @@ -180,7 +180,7 @@ static PHP_METHOD(MongoDB_Driver_ServerApi, bsonSerialize) { PHONGO_PARSE_PARAMETERS_NONE(); - ZVAL_ARR(return_value, php_phongo_serverapi_get_properties_hash(Z_OBJ_P(getThis()), true, false)); + ZVAL_ARR(return_value, php_phongo_serverapi_get_properties_hash(Z_OBJ_P(getThis()), false)); convert_to_object(return_value); } @@ -188,7 +188,7 @@ static PHP_METHOD(MongoDB_Driver_ServerApi, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_serverapi_get_properties_hash(Z_OBJ_P(getThis()), true, true)); + PHONGO_RETURN_PROPERTIES_ARR(php_phongo_serverapi_get_properties_hash(Z_OBJ_P(getThis()), true)); } static PHP_METHOD(MongoDB_Driver_ServerApi, __unserialize) @@ -231,12 +231,12 @@ static zend_object* php_phongo_serverapi_create_object(zend_class_entry* class_t static HashTable* php_phongo_serverapi_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_serverapi_get_properties_hash(object, true, true); + return php_phongo_serverapi_get_properties_hash(object, true); } static HashTable* php_phongo_serverapi_get_properties(zend_object* object) { - return php_phongo_serverapi_get_properties_hash(object, false, true); + return php_phongo_serverapi_get_properties_hash(object, true); } void php_phongo_serverapi_init_ce(INIT_FUNC_ARGS) diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index 48d6b38f8..efe5ee9d8 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -175,7 +175,7 @@ static zend_object* php_phongo_serverdescription_create_object(zend_class_entry* return &intern->std; } -HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object, bool is_debug) +HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object) { php_phongo_serverdescription_t* intern = NULL; HashTable* props; @@ -254,12 +254,12 @@ HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object, static HashTable* php_phongo_serverdescription_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_serverdescription_get_properties_hash(object, true); + return php_phongo_serverdescription_get_properties_hash(object); } static HashTable* php_phongo_serverdescription_get_properties(zend_object* object) { - return php_phongo_serverdescription_get_properties_hash(object, false); + return php_phongo_serverdescription_get_properties_hash(object); } void php_phongo_serverdescription_init_ce(INIT_FUNC_ARGS) diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index 1b6607b12..03b06f342 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -124,7 +124,7 @@ static zend_object* php_phongo_topologydescription_create_object(zend_class_entr return &intern->std; } -HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* object, bool is_debug) +HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* object) { php_phongo_topologydescription_t* intern = NULL; HashTable* props; @@ -167,12 +167,12 @@ HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* objec static HashTable* php_phongo_topologydescription_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_topologydescription_get_properties_hash(object, true); + return php_phongo_topologydescription_get_properties_hash(object); } static HashTable* php_phongo_topologydescription_get_properties(zend_object* object) { - return php_phongo_topologydescription_get_properties_hash(object, false); + return php_phongo_topologydescription_get_properties_hash(object); } void php_phongo_topologydescription_init_ce(INIT_FUNC_ARGS) diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index b4aacb67a..807d2b706 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -262,7 +262,7 @@ static PHP_METHOD(MongoDB_Driver_WriteConcern, isDefault) RETURN_BOOL(mongoc_write_concern_is_default(intern->write_concern)); } -static HashTable* php_phongo_writeconcern_get_properties_hash(zend_object* object, bool is_temp, bool is_bson, bool is_serialize) +static HashTable* php_phongo_writeconcern_get_properties_hash(zend_object* object, bool is_bson, bool is_serialize) { php_phongo_writeconcern_t* intern; HashTable* props; @@ -337,7 +337,7 @@ static PHP_METHOD(MongoDB_Driver_WriteConcern, bsonSerialize) { PHONGO_PARSE_PARAMETERS_NONE(); - ZVAL_ARR(return_value, php_phongo_writeconcern_get_properties_hash(Z_OBJ_P(getThis()), true, true, false)); + ZVAL_ARR(return_value, php_phongo_writeconcern_get_properties_hash(Z_OBJ_P(getThis()), true, false)); convert_to_object(return_value); } @@ -345,7 +345,7 @@ static PHP_METHOD(MongoDB_Driver_WriteConcern, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_writeconcern_get_properties_hash(Z_OBJ_P(getThis()), true, false, true)); + PHONGO_RETURN_PROPERTIES_ARR(php_phongo_writeconcern_get_properties_hash(Z_OBJ_P(getThis()), false, true)); } static PHP_METHOD(MongoDB_Driver_WriteConcern, __unserialize) @@ -388,12 +388,12 @@ static zend_object* php_phongo_writeconcern_create_object(zend_class_entry* clas static HashTable* php_phongo_writeconcern_get_debug_info(zend_object* object, int* is_temp) { *is_temp = 0; - return php_phongo_writeconcern_get_properties_hash(object, true, false, false); + return php_phongo_writeconcern_get_properties_hash(object, false, false); } static HashTable* php_phongo_writeconcern_get_properties(zend_object* object) { - return php_phongo_writeconcern_get_properties_hash(object, false, false, false); + return php_phongo_writeconcern_get_properties_hash(object, false, false); } void php_phongo_writeconcern_init_ce(INIT_FUNC_ARGS) diff --git a/src/phongo_compat.h b/src/phongo_compat.h index 1d7a7be61..be1aff27c 100644 --- a/src/phongo_compat.h +++ b/src/phongo_compat.h @@ -177,6 +177,13 @@ } \ while (0) +#define PHONGO_RETURN_PROPERTIES_ARR(value) \ + do { \ + HashTable* __ht = value; \ + GC_TRY_ADDREF(__ht); \ + RETURN_ARR(__ht); \ + } while (0) + #ifndef ZEND_PARSE_PARAMETERS_NONE #define PHONGO_PARSE_PARAMETERS_NONE() \ do { \ From bde2b37525ff5ccd3290b14c17288471d40442bb Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Mon, 21 Jul 2025 12:58:48 +0200 Subject: [PATCH 08/44] Cleanup --- src/BSON/Binary.c | 4 ++-- src/BSON/DBPointer.c | 4 ++-- src/BSON/Decimal128.c | 4 ++-- src/BSON/Document.c | 4 ++-- src/BSON/Int64.c | 4 ++-- src/BSON/Iterator.c | 2 +- src/BSON/Javascript.c | 4 ++-- src/BSON/ObjectId.c | 5 +++-- src/BSON/PackedArray.c | 4 ++-- src/BSON/Regex.c | 4 ++-- src/BSON/Symbol.c | 2 +- src/BSON/Timestamp.c | 4 ++-- src/BSON/UTCDateTime.c | 4 ++-- src/MongoDB/ReadConcern.c | 4 ++-- src/MongoDB/ReadPreference.c | 4 ++-- src/MongoDB/ServerApi.c | 4 ++-- src/MongoDB/ServerDescription.c | 2 +- src/MongoDB/TopologyDescription.c | 2 +- src/MongoDB/WriteConcern.c | 4 ++-- src/phongo_compat.h | 7 ------- 20 files changed, 35 insertions(+), 41 deletions(-) diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index d703c158e..773e6f89e 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -70,7 +70,7 @@ static HashTable* php_phongo_binary_get_properties_hash(zend_object* object) intern = Z_OBJ_BINARY(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); if (!intern->data) { return props; @@ -186,7 +186,7 @@ static PHP_METHOD(MongoDB_BSON_Binary, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - PHONGO_RETURN_PROPERTIES_ARR(php_phongo_binary_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_binary_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_Binary, __unserialize) diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index 74e6b3785..b54c7352b 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -71,7 +71,7 @@ HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object) intern = Z_OBJ_DBPOINTER(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); if (!intern->ref) { return props; @@ -149,7 +149,7 @@ static PHP_METHOD(MongoDB_BSON_DBPointer, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - PHONGO_RETURN_PROPERTIES_ARR(php_phongo_dbpointer_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_dbpointer_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_DBPointer, __unserialize) diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index dbd66d92a..6d474fa5e 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -61,7 +61,7 @@ static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object) intern = Z_OBJ_DECIMAL128(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); if (!intern->initialized) { return props; @@ -145,7 +145,7 @@ static PHP_METHOD(MongoDB_BSON_Decimal128, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - PHONGO_RETURN_PROPERTIES_ARR(php_phongo_decimal128_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_decimal128_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_Decimal128, __unserialize) diff --git a/src/BSON/Document.c b/src/BSON/Document.c index 7af9c9df5..dadeae4df 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -62,7 +62,7 @@ static HashTable* php_phongo_document_get_properties_hash(zend_object* object, i intern = Z_OBJ_DOCUMENT(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); if (!intern->bson) { return props; @@ -419,7 +419,7 @@ static PHP_METHOD(MongoDB_BSON_Document, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - PHONGO_RETURN_PROPERTIES_ARR(php_phongo_document_get_properties_hash(Z_OBJ_P(getThis()), 1)); + RETURN_ARR(php_phongo_document_get_properties_hash(Z_OBJ_P(getThis()), 1)); } static PHP_METHOD(MongoDB_BSON_Document, __unserialize) diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index 3de55d92d..dad033575 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -69,7 +69,7 @@ HashTable* php_phongo_int64_get_properties_hash(zend_object* object) intern = Z_OBJ_INT64(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); if (!intern->initialized) { return props; @@ -152,7 +152,7 @@ static PHP_METHOD(MongoDB_BSON_Int64, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - PHONGO_RETURN_PROPERTIES_ARR(php_phongo_int64_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_int64_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_Int64, __unserialize) diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index 8b28c6f64..cf6bf9668 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -160,7 +160,7 @@ static HashTable* php_phongo_iterator_get_properties_hash(zend_object* object) intern = Z_OBJ_ITERATOR(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); zend_hash_str_update(props, "bson", sizeof("bson") - 1, &intern->bson); Z_TRY_ADDREF(intern->bson); diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index 615b2a501..7f88831e0 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -76,7 +76,7 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object) intern = Z_OBJ_JAVASCRIPT(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); if (!intern->code) { return props; @@ -227,7 +227,7 @@ static PHP_METHOD(MongoDB_BSON_Javascript, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - PHONGO_RETURN_PROPERTIES_ARR(php_phongo_javascript_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_javascript_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_Javascript, __unserialize) diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 8161bebb2..333179c8d 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -84,7 +84,8 @@ static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object) intern = Z_OBJ_OBJECTID(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->initialized) { return props; @@ -179,7 +180,7 @@ static PHP_METHOD(MongoDB_BSON_ObjectId, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - PHONGO_RETURN_PROPERTIES_ARR(php_phongo_objectid_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_objectid_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_ObjectId, __unserialize) diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index 1c1017df9..1af8e92bb 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -63,7 +63,7 @@ static HashTable* php_phongo_packedarray_get_properties_hash(zend_object* object intern = Z_OBJ_PACKEDARRAY(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); if (!intern->bson) { return props; @@ -403,7 +403,7 @@ static PHP_METHOD(MongoDB_BSON_PackedArray, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - PHONGO_RETURN_PROPERTIES_ARR(php_phongo_packedarray_get_properties_hash(Z_OBJ_P(getThis()), 1)); + RETURN_ARR(php_phongo_packedarray_get_properties_hash(Z_OBJ_P(getThis()), 1)); } static PHP_METHOD(MongoDB_BSON_PackedArray, __unserialize) diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index 9b98d8783..823dc87eb 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -85,7 +85,7 @@ static HashTable* php_phongo_regex_get_properties_hash(zend_object* object) intern = Z_OBJ_REGEX(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); if (!intern->pattern) { return props; @@ -197,7 +197,7 @@ static PHP_METHOD(MongoDB_BSON_Regex, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - PHONGO_RETURN_PROPERTIES_ARR(php_phongo_regex_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_regex_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_Regex, __unserialize) diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index e5230e22b..ecf06df21 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -59,7 +59,7 @@ HashTable* php_phongo_symbol_get_properties_hash(zend_object* object) intern = Z_OBJ_SYMBOL(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); if (!intern->symbol) { return props; diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 148942d63..3301f3222 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -96,7 +96,7 @@ static HashTable* php_phongo_timestamp_get_properties_hash(zend_object* object) intern = Z_OBJ_TIMESTAMP(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); if (!intern->initialized) { return props; @@ -238,7 +238,7 @@ static PHP_METHOD(MongoDB_BSON_Timestamp, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - PHONGO_RETURN_PROPERTIES_ARR(php_phongo_timestamp_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_timestamp_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_Timestamp, __unserialize) diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index f331f363b..07cb25911 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -128,7 +128,7 @@ static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object intern = Z_OBJ_UTCDATETIME(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); if (!intern->initialized) { return props; @@ -278,7 +278,7 @@ static PHP_METHOD(MongoDB_BSON_UTCDateTime, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - PHONGO_RETURN_PROPERTIES_ARR(php_phongo_utcdatetime_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_utcdatetime_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_BSON_UTCDateTime, __unserialize) diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index e91f1033d..792cd44d0 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -130,7 +130,7 @@ static HashTable* php_phongo_readconcern_get_properties_hash(zend_object* object intern = Z_OBJ_READCONCERN(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); if (!intern->read_concern) { return props; @@ -160,7 +160,7 @@ static PHP_METHOD(MongoDB_Driver_ReadConcern, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - PHONGO_RETURN_PROPERTIES_ARR(php_phongo_readconcern_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_readconcern_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_Driver_ReadConcern, __unserialize) diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index a1d0b482d..a80aab239 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -389,7 +389,7 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zend_object* obj intern = Z_OBJ_READPREFERENCE(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); if (!intern->read_preference) { return props; @@ -460,7 +460,7 @@ static PHP_METHOD(MongoDB_Driver_ReadPreference, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - PHONGO_RETURN_PROPERTIES_ARR(php_phongo_readpreference_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_readpreference_get_properties_hash(Z_OBJ_P(getThis()))); } static PHP_METHOD(MongoDB_Driver_ReadPreference, __unserialize) diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index ddb906a3f..d05c4c7db 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -146,7 +146,7 @@ static HashTable* php_phongo_serverapi_get_properties_hash(zend_object* object, intern = Z_OBJ_SERVERAPI(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); ZVAL_STRING(&version, mongoc_server_api_version_to_string(mongoc_server_api_get_version(intern->server_api))); zend_hash_str_add(props, "version", sizeof("version") - 1, &version); @@ -188,7 +188,7 @@ static PHP_METHOD(MongoDB_Driver_ServerApi, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - PHONGO_RETURN_PROPERTIES_ARR(php_phongo_serverapi_get_properties_hash(Z_OBJ_P(getThis()), true)); + RETURN_ARR(php_phongo_serverapi_get_properties_hash(Z_OBJ_P(getThis()), true)); } static PHP_METHOD(MongoDB_Driver_ServerApi, __unserialize) diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index efe5ee9d8..18199f1ad 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -182,7 +182,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object) intern = Z_OBJ_SERVERDESCRIPTION(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); if (!intern->server_description) { return props; diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index 03b06f342..2e8994f60 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -131,7 +131,7 @@ HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* objec intern = Z_OBJ_TOPOLOGYDESCRIPTION(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); if (!intern->topology_description) { return props; diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index 807d2b706..7a830d028 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -272,7 +272,7 @@ static HashTable* php_phongo_writeconcern_get_properties_hash(zend_object* objec intern = Z_OBJ_WRITECONCERN(object); - props = zend_std_get_properties(object); + props = zend_array_dup(zend_std_get_properties(object)); if (!intern->write_concern) { return props; @@ -345,7 +345,7 @@ static PHP_METHOD(MongoDB_Driver_WriteConcern, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - PHONGO_RETURN_PROPERTIES_ARR(php_phongo_writeconcern_get_properties_hash(Z_OBJ_P(getThis()), false, true)); + RETURN_ARR(php_phongo_writeconcern_get_properties_hash(Z_OBJ_P(getThis()), false, true)); } static PHP_METHOD(MongoDB_Driver_WriteConcern, __unserialize) diff --git a/src/phongo_compat.h b/src/phongo_compat.h index be1aff27c..1d7a7be61 100644 --- a/src/phongo_compat.h +++ b/src/phongo_compat.h @@ -177,13 +177,6 @@ } \ while (0) -#define PHONGO_RETURN_PROPERTIES_ARR(value) \ - do { \ - HashTable* __ht = value; \ - GC_TRY_ADDREF(__ht); \ - RETURN_ARR(__ht); \ - } while (0) - #ifndef ZEND_PARSE_PARAMETERS_NONE #define PHONGO_PARSE_PARAMETERS_NONE() \ do { \ From 63407c030ae008af917cda1bcc58d3c902c0caf0 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 22 Jul 2025 11:56:22 +0200 Subject: [PATCH 09/44] Tmp --- src/BSON/Binary.c | 1 + src/BSON/DBPointer.c | 1 + src/BSON/Decimal128.c | 1 + src/BSON/Document.c | 1 + src/BSON/Int64.c | 1 + src/BSON/Iterator.c | 1 + src/BSON/Javascript.c | 1 + src/BSON/ObjectId.c | 1 + src/BSON/PackedArray.c | 1 + src/BSON/Regex.c | 1 + src/BSON/Symbol.c | 1 + src/BSON/Timestamp.c | 1 + src/BSON/UTCDateTime.c | 1 + src/MongoDB/ReadConcern.c | 1 + src/MongoDB/ReadPreference.c | 1 + src/MongoDB/ServerApi.c | 1 + src/MongoDB/ServerDescription.c | 1 + src/MongoDB/TopologyDescription.c | 1 + src/MongoDB/WriteConcern.c | 1 + 19 files changed, 19 insertions(+) diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index 773e6f89e..6ac8cf824 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -71,6 +71,7 @@ static HashTable* php_phongo_binary_get_properties_hash(zend_object* object) intern = Z_OBJ_BINARY(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->data) { return props; diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index b54c7352b..b88a6cba9 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -72,6 +72,7 @@ HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object) intern = Z_OBJ_DBPOINTER(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->ref) { return props; diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 6d474fa5e..8f00eb4a6 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -62,6 +62,7 @@ static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object) intern = Z_OBJ_DECIMAL128(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->initialized) { return props; diff --git a/src/BSON/Document.c b/src/BSON/Document.c index dadeae4df..8830322d7 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -63,6 +63,7 @@ static HashTable* php_phongo_document_get_properties_hash(zend_object* object, i intern = Z_OBJ_DOCUMENT(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->bson) { return props; diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index dad033575..5ffaf93cb 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -70,6 +70,7 @@ HashTable* php_phongo_int64_get_properties_hash(zend_object* object) intern = Z_OBJ_INT64(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->initialized) { return props; diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index cf6bf9668..0d68da558 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -161,6 +161,7 @@ static HashTable* php_phongo_iterator_get_properties_hash(zend_object* object) intern = Z_OBJ_ITERATOR(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); zend_hash_str_update(props, "bson", sizeof("bson") - 1, &intern->bson); Z_TRY_ADDREF(intern->bson); diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index 7f88831e0..b358f6cbf 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -77,6 +77,7 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object) intern = Z_OBJ_JAVASCRIPT(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->code) { return props; diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 333179c8d..13d393c0d 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -86,6 +86,7 @@ static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object) props = zend_array_dup(zend_std_get_properties(object)); GC_SET_REFCOUNT(props, 0); + GC_SET_REFCOUNT(props, 0); if (!intern->initialized) { return props; diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index 1af8e92bb..0b722a780 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -64,6 +64,7 @@ static HashTable* php_phongo_packedarray_get_properties_hash(zend_object* object intern = Z_OBJ_PACKEDARRAY(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->bson) { return props; diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index 823dc87eb..cf0ef1946 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -86,6 +86,7 @@ static HashTable* php_phongo_regex_get_properties_hash(zend_object* object) intern = Z_OBJ_REGEX(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->pattern) { return props; diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index ecf06df21..bf12de684 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -60,6 +60,7 @@ HashTable* php_phongo_symbol_get_properties_hash(zend_object* object) intern = Z_OBJ_SYMBOL(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->symbol) { return props; diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 3301f3222..1376c4d35 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -97,6 +97,7 @@ static HashTable* php_phongo_timestamp_get_properties_hash(zend_object* object) intern = Z_OBJ_TIMESTAMP(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->initialized) { return props; diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index 07cb25911..c6220d930 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -129,6 +129,7 @@ static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object intern = Z_OBJ_UTCDATETIME(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->initialized) { return props; diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index 792cd44d0..8e5b2f27c 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -131,6 +131,7 @@ static HashTable* php_phongo_readconcern_get_properties_hash(zend_object* object intern = Z_OBJ_READCONCERN(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->read_concern) { return props; diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index a80aab239..4ddab8663 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -390,6 +390,7 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zend_object* obj intern = Z_OBJ_READPREFERENCE(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->read_preference) { return props; diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index d05c4c7db..75e860304 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -147,6 +147,7 @@ static HashTable* php_phongo_serverapi_get_properties_hash(zend_object* object, intern = Z_OBJ_SERVERAPI(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); ZVAL_STRING(&version, mongoc_server_api_version_to_string(mongoc_server_api_get_version(intern->server_api))); zend_hash_str_add(props, "version", sizeof("version") - 1, &version); diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index 18199f1ad..06bb93b7a 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -183,6 +183,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object) intern = Z_OBJ_SERVERDESCRIPTION(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->server_description) { return props; diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index 2e8994f60..d435d59c0 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -132,6 +132,7 @@ HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* objec intern = Z_OBJ_TOPOLOGYDESCRIPTION(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->topology_description) { return props; diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index 7a830d028..10c8e0643 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -273,6 +273,7 @@ static HashTable* php_phongo_writeconcern_get_properties_hash(zend_object* objec intern = Z_OBJ_WRITECONCERN(object); props = zend_array_dup(zend_std_get_properties(object)); + GC_SET_REFCOUNT(props, 0); if (!intern->write_concern) { return props; From f83cb3faa520cbde6062ff523c9b3ac24a133683 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 22 Jul 2025 12:32:02 +0200 Subject: [PATCH 10/44] Fix test --- tests/bson/bug2505.phpt | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/bson/bug2505.phpt b/tests/bson/bug2505.phpt index 661c8e925..6274356f5 100644 --- a/tests/bson/bug2505.phpt +++ b/tests/bson/bug2505.phpt @@ -27,12 +27,13 @@ $tests = [ ob_start(); foreach ($tests as $test) { echo key($test), "\n"; + $test = reset($test); foreach ($test as $k => $v) { var_dump($k, $v); } } -$buf1 = ob_end_clean(); +$buf1 = ob_get_clean(); gc_enable(); gc_collect_cycles(); @@ -40,18 +41,20 @@ gc_collect_cycles(); ob_start(); foreach ($tests as $test) { echo key($test), "\n"; + $test = reset($test); foreach ($test as $k => $v) { var_dump($k, $v); } } -$buf2 = ob_end_clean(); +$buf2 = ob_get_clean(); if ($buf1 === $buf2) { echo "OK!\n"; exit(0); } else { - echo("buf1 != buf2: $buf1\n!=\n$buf2\n"); + echo("buf1 != buf2: $buf1\n\n IS NOT EQUAL TO \n\n$buf2\n"); + exit(1); } ?> From 9dff9d36fddc86f0154f1e35d6780a5d8be1c311 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 22 Jul 2025 12:32:44 +0200 Subject: [PATCH 11/44] Add another test --- tests/bson/bug2505_2.phpt | 62 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 tests/bson/bug2505_2.phpt diff --git a/tests/bson/bug2505_2.phpt b/tests/bson/bug2505_2.phpt new file mode 100644 index 000000000..8d7733c87 --- /dev/null +++ b/tests/bson/bug2505_2.phpt @@ -0,0 +1,62 @@ +--TEST-- +PHPC-2505: Setting and unsetting a property may interfere with using foreach to iterate objects +--FILE-- + new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], + [ 'dbpointer' => createDBPointer() ], + [ 'decimal128' => new MongoDB\BSON\Decimal128('1234.5678') ], + [ 'int64' => new MongoDB\BSON\Int64('9223372036854775807') ], + // JavaScript w/ scope may not be necessary (same code path as w/o scope), but we'll test it anyway + [ 'javascript' => new MongoDB\BSON\Javascript('function() { return 1; }') ], + [ 'javascript_ws' => new MongoDB\BSON\Javascript('function() { return a; }', ['a' => 1]) ], + // MaxKey and MinKey don't have get_properties or get_gc handlers, but we'll test them anyway + [ 'maxkey' => new MongoDB\BSON\MaxKey ], + [ 'minkey' => new MongoDB\BSON\MinKey ], + [ 'objectid' => new MongoDB\BSON\ObjectId ], + [ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ], + [ 'symbol' => createSymbol() ], + [ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ], + [ 'utcdatetime' => new MongoDB\BSON\UTCDateTime ], +]; + +ob_start(); +foreach ($tests as $test) { + echo key($test), "\n"; + $test = reset($test); + + foreach ($test as $k => $v) { + var_dump($k, $v); + } +} +$buf1 = ob_get_clean(); + +foreach ($tests as $test) { + $test = reset($test); + $test->a = 'test'; + unset($test->a); +} + +ob_start(); +foreach ($tests as $test) { + echo key($test), "\n"; + $test = reset($test); + + foreach ($test as $k => $v) { + var_dump($k, $v); + } +} +$buf2 = ob_get_clean(); + +if ($buf1 === $buf2) { + echo "OK!\n"; + exit(0); +} else { + echo("buf1 != buf2: $buf1\n!=\n$buf2\n"); +} + +?> +--EXPECT-- +OK! \ No newline at end of file From 4857be7ec1ee1c158d26ebf76ffaf4b903b4a97e Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 22 Jul 2025 12:48:54 +0200 Subject: [PATCH 12/44] Cleanup --- tests/bson/bug2505.phpt | 6 ++++++ tests/bson/bug2505_2.phpt | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/tests/bson/bug2505.phpt b/tests/bson/bug2505.phpt index 6274356f5..4f4269067 100644 --- a/tests/bson/bug2505.phpt +++ b/tests/bson/bug2505.phpt @@ -34,6 +34,9 @@ foreach ($tests as $test) { } } $buf1 = ob_get_clean(); +if ($buf1 === false) { + throw new \AssertionError("Could not flush buffer"); +} gc_enable(); gc_collect_cycles(); @@ -48,6 +51,9 @@ foreach ($tests as $test) { } } $buf2 = ob_get_clean(); +if ($buf2 === false) { + throw new \AssertionError("Could not flush buffer"); +} if ($buf1 === $buf2) { echo "OK!\n"; diff --git a/tests/bson/bug2505_2.phpt b/tests/bson/bug2505_2.phpt index 8d7733c87..0f1bd34b1 100644 --- a/tests/bson/bug2505_2.phpt +++ b/tests/bson/bug2505_2.phpt @@ -32,6 +32,9 @@ foreach ($tests as $test) { } } $buf1 = ob_get_clean(); +if ($buf1 === false) { + throw new \AssertionError("Could not flush buffer"); +} foreach ($tests as $test) { $test = reset($test); @@ -49,6 +52,9 @@ foreach ($tests as $test) { } } $buf2 = ob_get_clean(); +if ($buf2 === false) { + throw new \AssertionError("Could not flush buffer"); +} if ($buf1 === $buf2) { echo "OK!\n"; From 460aa366a0bcb4e681c1610be70b749aac43932b Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 22 Jul 2025 13:06:17 +0200 Subject: [PATCH 13/44] Cleanup --- php_phongo.c | 2 +- src/BSON/Binary.c | 18 ++++++++------ src/BSON/DBPointer.c | 18 ++++++++------ src/BSON/Decimal128.c | 18 ++++++++------ src/BSON/Document.c | 24 ++++++++++++------- src/BSON/Int64.c | 18 ++++++++------ src/BSON/Iterator.c | 16 ++++++++----- src/BSON/Javascript.c | 24 ++++++++++++------- src/BSON/ObjectId.c | 19 ++++++++------- src/BSON/PackedArray.c | 24 ++++++++++++------- src/BSON/Regex.c | 18 ++++++++------ src/BSON/Symbol.c | 18 ++++++++------ src/BSON/Timestamp.c | 18 ++++++++------ src/BSON/UTCDateTime.c | 18 ++++++++------ src/MongoDB/BulkWrite.c | 2 +- src/MongoDB/BulkWriteCommand.c | 2 +- src/MongoDB/BulkWriteCommandResult.c | 2 +- src/MongoDB/ClientEncryption.c | 2 +- src/MongoDB/Command.c | 2 +- src/MongoDB/Cursor.c | 2 +- src/MongoDB/Manager.c | 2 +- src/MongoDB/Monitoring/CommandFailedEvent.c | 2 +- src/MongoDB/Monitoring/CommandStartedEvent.c | 2 +- .../Monitoring/CommandSucceededEvent.c | 2 +- src/MongoDB/Monitoring/ServerChangedEvent.c | 2 +- src/MongoDB/Monitoring/ServerClosedEvent.c | 2 +- .../Monitoring/ServerHeartbeatFailedEvent.c | 2 +- .../Monitoring/ServerHeartbeatStartedEvent.c | 2 +- .../ServerHeartbeatSucceededEvent.c | 2 +- src/MongoDB/Monitoring/ServerOpeningEvent.c | 2 +- src/MongoDB/Monitoring/TopologyChangedEvent.c | 2 +- src/MongoDB/Monitoring/TopologyClosedEvent.c | 2 +- src/MongoDB/Monitoring/TopologyOpeningEvent.c | 2 +- src/MongoDB/Query.c | 2 +- src/MongoDB/ReadConcern.c | 20 +++++++++------- src/MongoDB/ReadPreference.c | 20 +++++++++------- src/MongoDB/Server.c | 2 +- src/MongoDB/ServerApi.c | 20 +++++++++------- src/MongoDB/ServerDescription.c | 16 ++++++++----- src/MongoDB/Session.c | 2 +- src/MongoDB/TopologyDescription.c | 16 ++++++++----- src/MongoDB/WriteConcern.c | 20 +++++++++------- src/MongoDB/WriteConcernError.c | 2 +- src/MongoDB/WriteError.c | 2 +- src/MongoDB/WriteResult.c | 2 +- src/contrib/php_array_api.h | 2 +- src/phongo_structs.h | 19 +++++++++++++++ 47 files changed, 271 insertions(+), 165 deletions(-) diff --git a/php_phongo.c b/php_phongo.c index 948ce6c69..6c9bd29fc 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -159,7 +159,7 @@ static HashTable* php_phongo_std_get_gc(zend_object* object, zval** table, int* { *table = NULL; *n = 0; - return object->handlers->get_properties(object); + return zend_std_get_properties(object); } PHP_MINIT_FUNCTION(mongodb) /* {{{ */ diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index 6ac8cf824..4583ac8ab 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -63,15 +63,14 @@ static bool php_phongo_binary_init_from_hash(php_phongo_binary_t* intern, HashTa return false; } -static HashTable* php_phongo_binary_get_properties_hash(zend_object* object) +static HashTable* php_phongo_binary_get_properties_hash(zend_object* object, bool is_temp) { php_phongo_binary_t* intern; HashTable* props; intern = Z_OBJ_BINARY(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->data) { return props; @@ -187,7 +186,7 @@ static PHP_METHOD(MongoDB_BSON_Binary, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_binary_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_binary_get_properties_hash(Z_OBJ_P(getThis()), true)); } static PHP_METHOD(MongoDB_BSON_Binary, __unserialize) @@ -213,6 +212,11 @@ static void php_phongo_binary_free_object(zend_object* object) if (intern->data) { efree(intern->data); } + + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } } static zend_object* php_phongo_binary_create_object(zend_class_entry* class_type) @@ -268,13 +272,13 @@ static int php_phongo_binary_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_binary_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_binary_get_properties_hash(object); + *is_temp = 1; + return php_phongo_binary_get_properties_hash(object, true); } static HashTable* php_phongo_binary_get_properties(zend_object* object) { - return php_phongo_binary_get_properties_hash(object); + return php_phongo_binary_get_properties_hash(object, false); } void php_phongo_binary_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index b88a6cba9..b0285732e 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -64,15 +64,14 @@ static bool php_phongo_dbpointer_init_from_hash(php_phongo_dbpointer_t* intern, return false; } -HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object) +HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object, bool is_temp) { php_phongo_dbpointer_t* intern; HashTable* props; intern = Z_OBJ_DBPOINTER(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->ref) { return props; @@ -150,7 +149,7 @@ static PHP_METHOD(MongoDB_BSON_DBPointer, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_dbpointer_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_dbpointer_get_properties_hash(Z_OBJ_P(getThis()), true)); } static PHP_METHOD(MongoDB_BSON_DBPointer, __unserialize) @@ -176,6 +175,11 @@ static void php_phongo_dbpointer_free_object(zend_object* object) if (intern->ref) { efree(intern->ref); } + + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } } zend_object* php_phongo_dbpointer_create_object(zend_class_entry* class_type) @@ -228,13 +232,13 @@ static int php_phongo_dbpointer_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_dbpointer_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_dbpointer_get_properties_hash(object); + *is_temp = 1; + return php_phongo_dbpointer_get_properties_hash(object, true); } static HashTable* php_phongo_dbpointer_get_properties(zend_object* object) { - return php_phongo_dbpointer_get_properties_hash(object); + return php_phongo_dbpointer_get_properties_hash(object, false); } void php_phongo_dbpointer_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 8f00eb4a6..970ee00e7 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -53,7 +53,7 @@ static bool php_phongo_decimal128_init_from_hash(php_phongo_decimal128_t* intern return false; } -static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object) +static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object, bool is_temp) { php_phongo_decimal128_t* intern; HashTable* props; @@ -61,8 +61,7 @@ static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object) intern = Z_OBJ_DECIMAL128(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->initialized) { return props; @@ -146,7 +145,7 @@ static PHP_METHOD(MongoDB_BSON_Decimal128, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_decimal128_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_decimal128_get_properties_hash(Z_OBJ_P(getThis()), true)); } static PHP_METHOD(MongoDB_BSON_Decimal128, __unserialize) @@ -168,6 +167,11 @@ static void php_phongo_decimal128_free_object(zend_object* object) php_phongo_decimal128_t* intern = Z_OBJ_DECIMAL128(object); zend_object_std_dtor(&intern->std); + + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } } static zend_object* php_phongo_decimal128_create_object(zend_class_entry* class_type) @@ -203,13 +207,13 @@ static zend_object* php_phongo_decimal128_clone_object(zend_object* object) static HashTable* php_phongo_decimal128_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_decimal128_get_properties_hash(object); + *is_temp = 1; + return php_phongo_decimal128_get_properties_hash(object, true); } static HashTable* php_phongo_decimal128_get_properties(zend_object* object) { - return php_phongo_decimal128_get_properties_hash(object); + return php_phongo_decimal128_get_properties_hash(object, false); } void php_phongo_decimal128_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/Document.c b/src/BSON/Document.c index 8830322d7..b0886b369 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -55,15 +55,14 @@ static bool php_phongo_document_init_from_hash(php_phongo_document_t* intern, Ha return false; } -static HashTable* php_phongo_document_get_properties_hash(zend_object* object, int size) +static HashTable* php_phongo_document_get_properties_hash(zend_object* object, bool is_temp, int size) { php_phongo_document_t* intern; HashTable* props; intern = Z_OBJ_DOCUMENT(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size); if (!intern->bson) { return props; @@ -420,7 +419,7 @@ static PHP_METHOD(MongoDB_BSON_Document, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_document_get_properties_hash(Z_OBJ_P(getThis()), 1)); + RETURN_ARR(php_phongo_document_get_properties_hash(Z_OBJ_P(getThis()), true, 1)); } static PHP_METHOD(MongoDB_BSON_Document, __unserialize) @@ -446,6 +445,11 @@ static void php_phongo_document_free_object(zend_object* object) if (intern->bson) { bson_destroy(intern->bson); } + + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } } static zend_object* php_phongo_document_create_object(zend_class_entry* class_type) @@ -494,13 +498,13 @@ static HashTable* php_phongo_document_get_debug_info(zend_object* object, int* i php_phongo_document_t* intern; HashTable* props; - *is_temp = 0; + *is_temp = 1; intern = Z_OBJ_DOCUMENT(object); /* This get_debug_info handler reports an additional property. This does not * conflict with other uses of php_phongo_document_get_properties_hash since * we always allocated a new HashTable with is_temp=true. */ - props = php_phongo_document_get_properties_hash(object, 2); + props = php_phongo_document_get_properties_hash(object, true, 2); { php_phongo_bson_state state; @@ -510,18 +514,22 @@ static HashTable* php_phongo_document_get_debug_info(zend_object* object, int* i state.map.document.type = PHONGO_TYPEMAP_BSON; if (!php_phongo_bson_to_zval_ex(intern->bson, &state)) { zval_ptr_dtor(&state.zchild); - return NULL; + goto failure; } zend_hash_str_update(props, "value", sizeof("value") - 1, &state.zchild); } return props; + +failure: + PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); + return NULL; } static HashTable* php_phongo_document_get_properties(zend_object* object) { - return php_phongo_document_get_properties_hash(object, 1); + return php_phongo_document_get_properties_hash(object, false, 1); } zval* php_phongo_document_read_property(zend_object* object, zend_string* member, int type, void** cache_slot, zval* rv) diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index 5ffaf93cb..d350f2b7b 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -62,15 +62,14 @@ static bool php_phongo_int64_init_from_hash(php_phongo_int64_t* intern, HashTabl return false; } -HashTable* php_phongo_int64_get_properties_hash(zend_object* object) +HashTable* php_phongo_int64_get_properties_hash(zend_object* object, bool is_temp) { php_phongo_int64_t* intern; HashTable* props; intern = Z_OBJ_INT64(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->initialized) { return props; @@ -153,7 +152,7 @@ static PHP_METHOD(MongoDB_BSON_Int64, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_int64_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_int64_get_properties_hash(Z_OBJ_P(getThis()), true)); } static PHP_METHOD(MongoDB_BSON_Int64, __unserialize) @@ -175,6 +174,11 @@ static void php_phongo_int64_free_object(zend_object* object) php_phongo_int64_t* intern = Z_OBJ_INT64(object); zend_object_std_dtor(&intern->std); + + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } } zend_object* php_phongo_int64_create_object(zend_class_entry* class_type) @@ -541,13 +545,13 @@ static zend_result php_phongo_int64_do_operation(zend_uchar opcode, zval* result static HashTable* php_phongo_int64_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_int64_get_properties_hash(object); + *is_temp = 1; + return php_phongo_int64_get_properties_hash(object, true); } static HashTable* php_phongo_int64_get_properties(zend_object* object) { - return php_phongo_int64_get_properties_hash(object); + return php_phongo_int64_get_properties_hash(object, false); } void php_phongo_int64_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index 0d68da558..1306dbc7d 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -153,15 +153,14 @@ static void php_phongo_iterator_rewind(php_phongo_iterator_t* intern) intern->valid = bson_iter_next(&intern->iter); } -static HashTable* php_phongo_iterator_get_properties_hash(zend_object* object) +static HashTable* php_phongo_iterator_get_properties_hash(zend_object* object, bool is_temp) { php_phongo_iterator_t* intern; HashTable* props; intern = Z_OBJ_ITERATOR(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); zend_hash_str_update(props, "bson", sizeof("bson") - 1, &intern->bson); Z_TRY_ADDREF(intern->bson); @@ -249,6 +248,11 @@ static void php_phongo_iterator_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } + php_phongo_iterator_free_current(intern); zval_ptr_dtor(&intern->bson); @@ -284,13 +288,13 @@ static zend_object* php_phongo_iterator_clone_object(zend_object* object) static HashTable* php_phongo_iterator_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_iterator_get_properties_hash(object); + *is_temp = 1; + return php_phongo_iterator_get_properties_hash(object, true); } static HashTable* php_phongo_iterator_get_properties(zend_object* object) { - return php_phongo_iterator_get_properties_hash(object); + return php_phongo_iterator_get_properties_hash(object, false); } /* Iterator handlers */ diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index b358f6cbf..38312dc2d 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -69,15 +69,14 @@ static bool php_phongo_javascript_init_from_hash(php_phongo_javascript_t* intern return false; } -HashTable* php_phongo_javascript_get_properties_hash(zend_object* object) +HashTable* php_phongo_javascript_get_properties_hash(zend_object* object, bool is_temp) { php_phongo_javascript_t* intern; HashTable* props; intern = Z_OBJ_JAVASCRIPT(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->code) { return props; @@ -95,7 +94,7 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object) PHONGO_BSON_INIT_STATE(state); if (!php_phongo_bson_to_zval_ex(intern->scope, &state)) { zval_ptr_dtor(&state.zchild); - return NULL; + goto failure; } zend_hash_str_update(props, "scope", sizeof("scope") - 1, &state.zchild); @@ -108,6 +107,10 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object) } return props; + +failure: + PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); + return NULL; } /* Construct a new BSON Javascript type. The scope is a document mapping @@ -228,7 +231,7 @@ static PHP_METHOD(MongoDB_BSON_Javascript, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_javascript_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_javascript_get_properties_hash(Z_OBJ_P(getThis()), true)); } static PHP_METHOD(MongoDB_BSON_Javascript, __unserialize) @@ -258,6 +261,11 @@ static void php_phongo_javascript_free_object(zend_object* object) bson_destroy(intern->scope); intern->scope = NULL; } + + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } } zend_object* php_phongo_javascript_create_object(zend_class_entry* class_type) @@ -305,13 +313,13 @@ static int php_phongo_javascript_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_javascript_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_javascript_get_properties_hash(object); + *is_temp = 1; + return php_phongo_javascript_get_properties_hash(object, true); } static HashTable* php_phongo_javascript_get_properties(zend_object* object) { - return php_phongo_javascript_get_properties_hash(object); + return php_phongo_javascript_get_properties_hash(object, false); } void php_phongo_javascript_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 13d393c0d..240441ac4 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -77,16 +77,14 @@ static bool php_phongo_objectid_init_from_hash(php_phongo_objectid_t* intern, Ha return false; } -static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object) +static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object, bool is_temp) { php_phongo_objectid_t* intern; HashTable* props; intern = Z_OBJ_OBJECTID(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->initialized) { return props; @@ -181,7 +179,7 @@ static PHP_METHOD(MongoDB_BSON_ObjectId, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_objectid_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_objectid_get_properties_hash(Z_OBJ_P(getThis()), true)); } static PHP_METHOD(MongoDB_BSON_ObjectId, __unserialize) @@ -203,6 +201,11 @@ static void php_phongo_objectid_free_object(zend_object* object) php_phongo_objectid_t* intern = Z_OBJ_OBJECTID(object); zend_object_std_dtor(&intern->std); + + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } } static zend_object* php_phongo_objectid_create_object(zend_class_entry* class_type) @@ -251,13 +254,13 @@ static int php_phongo_objectid_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_objectid_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_objectid_get_properties_hash(object); + *is_temp = 1; + return php_phongo_objectid_get_properties_hash(object, true); } static HashTable* php_phongo_objectid_get_properties(zend_object* object) { - return php_phongo_objectid_get_properties_hash(object); + return php_phongo_objectid_get_properties_hash(object, false); } void php_phongo_objectid_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index 0b722a780..6fdbcf575 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -56,15 +56,14 @@ static bool php_phongo_packedarray_init_from_hash(php_phongo_packedarray_t* inte return false; } -static HashTable* php_phongo_packedarray_get_properties_hash(zend_object* object, int size) +static HashTable* php_phongo_packedarray_get_properties_hash(zend_object* object, bool is_temp, int size) { php_phongo_packedarray_t* intern; HashTable* props; intern = Z_OBJ_PACKEDARRAY(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size); if (!intern->bson) { return props; @@ -404,7 +403,7 @@ static PHP_METHOD(MongoDB_BSON_PackedArray, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_packedarray_get_properties_hash(Z_OBJ_P(getThis()), 1)); + RETURN_ARR(php_phongo_packedarray_get_properties_hash(Z_OBJ_P(getThis()), true, 1)); } static PHP_METHOD(MongoDB_BSON_PackedArray, __unserialize) @@ -430,6 +429,11 @@ static void php_phongo_packedarray_free_object(zend_object* object) if (intern->bson) { bson_destroy(intern->bson); } + + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } } static zend_object* php_phongo_packedarray_create_object(zend_class_entry* class_type) @@ -478,13 +482,13 @@ static HashTable* php_phongo_packedarray_get_debug_info(zend_object* object, int php_phongo_packedarray_t* intern; HashTable* props; - *is_temp = 0; + *is_temp = 1; intern = Z_OBJ_PACKEDARRAY(object); /* This get_debug_info handler reports an additional property. This does not * conflict with other uses of php_phongo_document_get_properties_hash since * we always allocated a new HashTable with is_temp=true. */ - props = php_phongo_packedarray_get_properties_hash(object, 2); + props = php_phongo_packedarray_get_properties_hash(object, true, 2); { php_phongo_bson_state state; @@ -495,18 +499,22 @@ static HashTable* php_phongo_packedarray_get_debug_info(zend_object* object, int state.map.document.type = PHONGO_TYPEMAP_BSON; if (!php_phongo_bson_to_zval_ex(intern->bson, &state)) { zval_ptr_dtor(&state.zchild); - return NULL; + goto failure; } zend_hash_str_update(props, "value", sizeof("value") - 1, &state.zchild); } return props; + +failure: + PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); + return NULL; } static HashTable* php_phongo_packedarray_get_properties(zend_object* object) { - return php_phongo_packedarray_get_properties_hash(object, 1); + return php_phongo_packedarray_get_properties_hash(object, false, 1); } zval* php_phongo_packedarray_read_dimension(zend_object* object, zval* offset, int type, zval* rv) diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index cf0ef1946..a75b75e39 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -78,15 +78,14 @@ static bool php_phongo_regex_init_from_hash(php_phongo_regex_t* intern, HashTabl return false; } -static HashTable* php_phongo_regex_get_properties_hash(zend_object* object) +static HashTable* php_phongo_regex_get_properties_hash(zend_object* object, bool is_temp) { php_phongo_regex_t* intern; HashTable* props; intern = Z_OBJ_REGEX(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->pattern) { return props; @@ -198,7 +197,7 @@ static PHP_METHOD(MongoDB_BSON_Regex, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_regex_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_regex_get_properties_hash(Z_OBJ_P(getThis()), true)); } static PHP_METHOD(MongoDB_BSON_Regex, __unserialize) @@ -228,6 +227,11 @@ static void php_phongo_regex_free_object(zend_object* object) if (intern->flags) { efree(intern->flags); } + + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } } static zend_object* php_phongo_regex_create_object(zend_class_entry* class_type) @@ -281,13 +285,13 @@ static int php_phongo_regex_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_regex_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_regex_get_properties_hash(object); + *is_temp = 1; + return php_phongo_regex_get_properties_hash(object, true); } static HashTable* php_phongo_regex_get_properties(zend_object* object) { - return php_phongo_regex_get_properties_hash(object); + return php_phongo_regex_get_properties_hash(object, false); } void php_phongo_regex_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index bf12de684..a47b6c2fe 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -52,15 +52,14 @@ static bool php_phongo_symbol_init_from_hash(php_phongo_symbol_t* intern, HashTa return false; } -HashTable* php_phongo_symbol_get_properties_hash(zend_object* object) +HashTable* php_phongo_symbol_get_properties_hash(zend_object* object, bool is_temp) { php_phongo_symbol_t* intern; HashTable* props; intern = Z_OBJ_SYMBOL(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->symbol) { return props; @@ -124,7 +123,7 @@ static PHP_METHOD(MongoDB_BSON_Symbol, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - ZVAL_ARR(return_value, php_phongo_symbol_get_properties_hash(Z_OBJ_P(getThis()))); + ZVAL_ARR(return_value, php_phongo_symbol_get_properties_hash(Z_OBJ_P(getThis()), true)); } static PHP_METHOD(MongoDB_BSON_Symbol, __unserialize) @@ -150,6 +149,11 @@ static void php_phongo_symbol_free_object(zend_object* object) if (intern->symbol) { efree(intern->symbol); } + + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } } zend_object* php_phongo_symbol_create_object(zend_class_entry* class_type) @@ -195,13 +199,13 @@ static int php_phongo_symbol_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_symbol_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_symbol_get_properties_hash(object); + *is_temp = 1; + return php_phongo_symbol_get_properties_hash(object, true); } static HashTable* php_phongo_symbol_get_properties(zend_object* object) { - return php_phongo_symbol_get_properties_hash(object); + return php_phongo_symbol_get_properties_hash(object, false); } void php_phongo_symbol_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 1376c4d35..82cd6f537 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -85,7 +85,7 @@ static bool php_phongo_timestamp_init_from_hash(php_phongo_timestamp_t* intern, return false; } -static HashTable* php_phongo_timestamp_get_properties_hash(zend_object* object) +static HashTable* php_phongo_timestamp_get_properties_hash(zend_object* object, bool is_temp) { php_phongo_timestamp_t* intern; HashTable* props; @@ -96,8 +96,7 @@ static HashTable* php_phongo_timestamp_get_properties_hash(zend_object* object) intern = Z_OBJ_TIMESTAMP(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->initialized) { return props; @@ -239,7 +238,7 @@ static PHP_METHOD(MongoDB_BSON_Timestamp, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_timestamp_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_timestamp_get_properties_hash(Z_OBJ_P(getThis()), true)); } static PHP_METHOD(MongoDB_BSON_Timestamp, __unserialize) @@ -261,6 +260,11 @@ static void php_phongo_timestamp_free_object(zend_object* object) php_phongo_timestamp_t* intern = Z_OBJ_TIMESTAMP(object); zend_object_std_dtor(&intern->std); + + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } } static zend_object* php_phongo_timestamp_create_object(zend_class_entry* class_type) @@ -315,13 +319,13 @@ static int php_phongo_timestamp_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_timestamp_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_timestamp_get_properties_hash(object); + *is_temp = 1; + return php_phongo_timestamp_get_properties_hash(object, true); } static HashTable* php_phongo_timestamp_get_properties(zend_object* object) { - return php_phongo_timestamp_get_properties_hash(object); + return php_phongo_timestamp_get_properties_hash(object, false); } void php_phongo_timestamp_init_ce(INIT_FUNC_ARGS) diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index c6220d930..d0f169858 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -121,15 +121,14 @@ static bool php_phongo_utcdatetime_init_from_object(php_phongo_utcdatetime_t* in return false; } -static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object) +static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object, bool is_temp) { php_phongo_utcdatetime_t* intern; HashTable* props; intern = Z_OBJ_UTCDATETIME(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->initialized) { return props; @@ -279,7 +278,7 @@ static PHP_METHOD(MongoDB_BSON_UTCDateTime, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_utcdatetime_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_utcdatetime_get_properties_hash(Z_OBJ_P(getThis()), true)); } static PHP_METHOD(MongoDB_BSON_UTCDateTime, __unserialize) @@ -301,6 +300,11 @@ static void php_phongo_utcdatetime_free_object(zend_object* object) php_phongo_utcdatetime_t* intern = Z_OBJ_UTCDATETIME(object); zend_object_std_dtor(&intern->std); + + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } } static zend_object* php_phongo_utcdatetime_create_object(zend_class_entry* class_type) @@ -350,13 +354,13 @@ static int php_phongo_utcdatetime_compare_objects(zval* o1, zval* o2) static HashTable* php_phongo_utcdatetime_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_utcdatetime_get_properties_hash(object); + *is_temp = 1; + return php_phongo_utcdatetime_get_properties_hash(object, true); } static HashTable* php_phongo_utcdatetime_get_properties(zend_object* object) { - return php_phongo_utcdatetime_get_properties_hash(object); + return php_phongo_utcdatetime_get_properties_hash(object, false); } void php_phongo_utcdatetime_init_ce(INIT_FUNC_ARGS) diff --git a/src/MongoDB/BulkWrite.c b/src/MongoDB/BulkWrite.c index 9ebdec6ef..d72c4c79a 100644 --- a/src/MongoDB/BulkWrite.c +++ b/src/MongoDB/BulkWrite.c @@ -592,7 +592,7 @@ static HashTable* php_phongo_bulkwrite_get_debug_info(zend_object* object, int* zval retval = ZVAL_STATIC_INIT; php_phongo_bulkwrite_t* intern = NULL; - *is_temp = 0; + *is_temp = 1; intern = Z_OBJ_BULKWRITE(object); array_init(&retval); diff --git a/src/MongoDB/BulkWriteCommand.c b/src/MongoDB/BulkWriteCommand.c index a818b5da3..22fc35778 100644 --- a/src/MongoDB/BulkWriteCommand.c +++ b/src/MongoDB/BulkWriteCommand.c @@ -788,7 +788,7 @@ static HashTable* php_phongo_bulkwritecommand_get_debug_info(zend_object* object zval retval = ZVAL_STATIC_INIT; php_phongo_bulkwritecommand_t* intern = NULL; - *is_temp = 0; + *is_temp = 1; intern = Z_OBJ_BULKWRITECOMMAND(object); array_init(&retval); diff --git a/src/MongoDB/BulkWriteCommandResult.c b/src/MongoDB/BulkWriteCommandResult.c index 54fb61396..5b1f7813e 100644 --- a/src/MongoDB/BulkWriteCommandResult.c +++ b/src/MongoDB/BulkWriteCommandResult.c @@ -201,7 +201,7 @@ static HashTable* php_phongo_bulkwritecommandresult_get_debug_info(zend_object* zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_BULKWRITECOMMANDRESULT(object); - *is_temp = 0; + *is_temp = 1; array_init_size(&retval, 12); ADD_ASSOC_BOOL_EX(&retval, "isAcknowledged", intern->is_acknowledged); diff --git a/src/MongoDB/ClientEncryption.c b/src/MongoDB/ClientEncryption.c index 7325a6f44..c8950d551 100644 --- a/src/MongoDB/ClientEncryption.c +++ b/src/MongoDB/ClientEncryption.c @@ -514,7 +514,7 @@ static HashTable* php_phongo_clientencryption_get_debug_info(zend_object* object php_phongo_clientencryption_t* intern = NULL; zval retval = ZVAL_STATIC_INIT; - *is_temp = 0; + *is_temp = 1; intern = Z_OBJ_CLIENTENCRYPTION(object); array_init(&retval); diff --git a/src/MongoDB/Command.c b/src/MongoDB/Command.c index cbcbb0fad..93f35e56d 100644 --- a/src/MongoDB/Command.c +++ b/src/MongoDB/Command.c @@ -146,7 +146,7 @@ static HashTable* php_phongo_command_get_debug_info(zend_object* object, int* is php_phongo_command_t* intern; zval retval = ZVAL_STATIC_INIT; - *is_temp = 0; + *is_temp = 1; intern = Z_OBJ_COMMAND(object); array_init_size(&retval, 1); diff --git a/src/MongoDB/Cursor.c b/src/MongoDB/Cursor.c index 2e8a8695e..491706c9c 100644 --- a/src/MongoDB/Cursor.c +++ b/src/MongoDB/Cursor.c @@ -349,7 +349,7 @@ static HashTable* php_phongo_cursor_get_debug_info(zend_object* object, int* is_ php_phongo_cursor_t* intern; zval retval = ZVAL_STATIC_INIT; - *is_temp = 0; + *is_temp = 1; intern = Z_OBJ_CURSOR(object); array_init_size(&retval, 10); diff --git a/src/MongoDB/Manager.c b/src/MongoDB/Manager.c index 93e78e962..2bf02fbdf 100644 --- a/src/MongoDB/Manager.c +++ b/src/MongoDB/Manager.c @@ -825,7 +825,7 @@ static HashTable* php_phongo_manager_get_debug_info(zend_object* object, int* is zval retval = ZVAL_STATIC_INIT; zval cluster; - *is_temp = 0; + *is_temp = 1; intern = Z_OBJ_MANAGER(object); array_init_size(&retval, 3); diff --git a/src/MongoDB/Monitoring/CommandFailedEvent.c b/src/MongoDB/Monitoring/CommandFailedEvent.c index 4ee18f2a7..e0b36a8ba 100644 --- a/src/MongoDB/Monitoring/CommandFailedEvent.c +++ b/src/MongoDB/Monitoring/CommandFailedEvent.c @@ -219,7 +219,7 @@ static HashTable* php_phongo_commandfailedevent_get_debug_info(zend_object* obje PHONGO_BSON_INIT_STATE(reply_state); intern = Z_OBJ_COMMANDFAILEDEVENT(object); - *is_temp = 0; + *is_temp = 1; array_init_size(&retval, 10); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/CommandStartedEvent.c b/src/MongoDB/Monitoring/CommandStartedEvent.c index ba9651b69..5b4037659 100644 --- a/src/MongoDB/Monitoring/CommandStartedEvent.c +++ b/src/MongoDB/Monitoring/CommandStartedEvent.c @@ -193,7 +193,7 @@ static HashTable* php_phongo_commandstartedevent_get_debug_info(zend_object* obj PHONGO_BSON_INIT_STATE(command_state); intern = Z_OBJ_COMMANDSTARTEDEVENT(object); - *is_temp = 0; + *is_temp = 1; array_init_size(&retval, 9); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/CommandSucceededEvent.c b/src/MongoDB/Monitoring/CommandSucceededEvent.c index 13d6a4767..cb0a0ccb9 100644 --- a/src/MongoDB/Monitoring/CommandSucceededEvent.c +++ b/src/MongoDB/Monitoring/CommandSucceededEvent.c @@ -204,7 +204,7 @@ static HashTable* php_phongo_commandsucceededevent_get_debug_info(zend_object* o PHONGO_BSON_INIT_STATE(reply_state); intern = Z_OBJ_COMMANDSUCCEEDEDEVENT(object); - *is_temp = 0; + *is_temp = 1; array_init_size(&retval, 9); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/ServerChangedEvent.c b/src/MongoDB/Monitoring/ServerChangedEvent.c index 38f4509fb..065f2baee 100644 --- a/src/MongoDB/Monitoring/ServerChangedEvent.c +++ b/src/MongoDB/Monitoring/ServerChangedEvent.c @@ -117,7 +117,7 @@ static HashTable* php_phongo_serverchangedevent_get_debug_info(zend_object* obje zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_SERVERCHANGEDEVENT(object); - *is_temp = 0; + *is_temp = 1; array_init_size(&retval, 4); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/ServerClosedEvent.c b/src/MongoDB/Monitoring/ServerClosedEvent.c index 528d2d23e..b540125ba 100644 --- a/src/MongoDB/Monitoring/ServerClosedEvent.c +++ b/src/MongoDB/Monitoring/ServerClosedEvent.c @@ -85,7 +85,7 @@ static HashTable* php_phongo_serverclosedevent_get_debug_info(zend_object* objec zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_SERVERCLOSEDEVENT(object); - *is_temp = 0; + *is_temp = 1; array_init_size(&retval, 3); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/ServerHeartbeatFailedEvent.c b/src/MongoDB/Monitoring/ServerHeartbeatFailedEvent.c index cf74bbd33..b20b022d5 100644 --- a/src/MongoDB/Monitoring/ServerHeartbeatFailedEvent.c +++ b/src/MongoDB/Monitoring/ServerHeartbeatFailedEvent.c @@ -107,7 +107,7 @@ static HashTable* php_phongo_serverheartbeatfailedevent_get_debug_info(zend_obje zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_SERVERHEARTBEATFAILEDEVENT(object); - *is_temp = 0; + *is_temp = 1; array_init_size(&retval, 5); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/ServerHeartbeatStartedEvent.c b/src/MongoDB/Monitoring/ServerHeartbeatStartedEvent.c index 9979c1533..0df11d1d0 100644 --- a/src/MongoDB/Monitoring/ServerHeartbeatStartedEvent.c +++ b/src/MongoDB/Monitoring/ServerHeartbeatStartedEvent.c @@ -83,7 +83,7 @@ static HashTable* php_phongo_serverheartbeatstartedevent_get_debug_info(zend_obj zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_SERVERHEARTBEATSTARTEDEVENT(object); - *is_temp = 0; + *is_temp = 1; array_init_size(&retval, 4); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/ServerHeartbeatSucceededEvent.c b/src/MongoDB/Monitoring/ServerHeartbeatSucceededEvent.c index 1277f1847..d8e213b39 100644 --- a/src/MongoDB/Monitoring/ServerHeartbeatSucceededEvent.c +++ b/src/MongoDB/Monitoring/ServerHeartbeatSucceededEvent.c @@ -118,7 +118,7 @@ static HashTable* php_phongo_serverheartbeatsucceededevent_get_debug_info(zend_o PHONGO_BSON_INIT_STATE(reply_state); intern = Z_OBJ_SERVERHEARTBEATSUCCEEDEDEVENT(object); - *is_temp = 0; + *is_temp = 1; array_init_size(&retval, 4); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/ServerOpeningEvent.c b/src/MongoDB/Monitoring/ServerOpeningEvent.c index 80a460d50..ba8e53119 100644 --- a/src/MongoDB/Monitoring/ServerOpeningEvent.c +++ b/src/MongoDB/Monitoring/ServerOpeningEvent.c @@ -85,7 +85,7 @@ static HashTable* php_phongo_serveropeningevent_get_debug_info(zend_object* obje zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_SERVEROPENINGEVENT(object); - *is_temp = 0; + *is_temp = 1; array_init_size(&retval, 3); ADD_ASSOC_STRING(&retval, "host", intern->host.host); diff --git a/src/MongoDB/Monitoring/TopologyChangedEvent.c b/src/MongoDB/Monitoring/TopologyChangedEvent.c index d9ab3cf93..ac44c124b 100644 --- a/src/MongoDB/Monitoring/TopologyChangedEvent.c +++ b/src/MongoDB/Monitoring/TopologyChangedEvent.c @@ -96,7 +96,7 @@ static HashTable* php_phongo_topologychangedevent_get_debug_info(zend_object* ob zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_TOPOLOGYCHANGEDEVENT(object); - *is_temp = 0; + *is_temp = 1; array_init_size(&retval, 3); { diff --git a/src/MongoDB/Monitoring/TopologyClosedEvent.c b/src/MongoDB/Monitoring/TopologyClosedEvent.c index 64e71543e..383b05097 100644 --- a/src/MongoDB/Monitoring/TopologyClosedEvent.c +++ b/src/MongoDB/Monitoring/TopologyClosedEvent.c @@ -65,7 +65,7 @@ static HashTable* php_phongo_topologyclosedevent_get_debug_info(zend_object* obj zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_TOPOLOGYCLOSEDEVENT(object); - *is_temp = 0; + *is_temp = 1; array_init_size(&retval, 1); { diff --git a/src/MongoDB/Monitoring/TopologyOpeningEvent.c b/src/MongoDB/Monitoring/TopologyOpeningEvent.c index 9c34d2c47..4fd3d4f36 100644 --- a/src/MongoDB/Monitoring/TopologyOpeningEvent.c +++ b/src/MongoDB/Monitoring/TopologyOpeningEvent.c @@ -65,7 +65,7 @@ static HashTable* php_phongo_topologyopeningevent_get_debug_info(zend_object* ob zval retval = ZVAL_STATIC_INIT; intern = Z_OBJ_TOPOLOGYOPENINGEVENT(object); - *is_temp = 0; + *is_temp = 1; array_init_size(&retval, 1); { diff --git a/src/MongoDB/Query.c b/src/MongoDB/Query.c index 7c6fda135..56d539d35 100644 --- a/src/MongoDB/Query.c +++ b/src/MongoDB/Query.c @@ -363,7 +363,7 @@ static HashTable* php_phongo_query_get_debug_info(zend_object* object, int* is_t php_phongo_query_t* intern; zval retval = ZVAL_STATIC_INIT; - *is_temp = 0; + *is_temp = 1; intern = Z_OBJ_QUERY(object); array_init_size(&retval, 3); diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index 8e5b2f27c..54ed384db 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -122,7 +122,7 @@ static PHP_METHOD(MongoDB_Driver_ReadConcern, isDefault) RETURN_BOOL(mongoc_read_concern_is_default(intern->read_concern)); } -static HashTable* php_phongo_readconcern_get_properties_hash(zend_object* object) +static HashTable* php_phongo_readconcern_get_properties_hash(zend_object* object, bool is_temp) { php_phongo_readconcern_t* intern; HashTable* props; @@ -130,8 +130,7 @@ static HashTable* php_phongo_readconcern_get_properties_hash(zend_object* object intern = Z_OBJ_READCONCERN(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->read_concern) { return props; @@ -153,7 +152,7 @@ static PHP_METHOD(MongoDB_Driver_ReadConcern, bsonSerialize) { PHONGO_PARSE_PARAMETERS_NONE(); - ZVAL_ARR(return_value, php_phongo_readconcern_get_properties_hash(Z_OBJ_P(getThis()))); + ZVAL_ARR(return_value, php_phongo_readconcern_get_properties_hash(Z_OBJ_P(getThis()), true)); convert_to_object(return_value); } @@ -161,7 +160,7 @@ static PHP_METHOD(MongoDB_Driver_ReadConcern, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_readconcern_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_readconcern_get_properties_hash(Z_OBJ_P(getThis()), true)); } static PHP_METHOD(MongoDB_Driver_ReadConcern, __unserialize) @@ -184,6 +183,11 @@ static void php_phongo_readconcern_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } + if (intern->read_concern) { mongoc_read_concern_destroy(intern->read_concern); } @@ -203,13 +207,13 @@ static zend_object* php_phongo_readconcern_create_object(zend_class_entry* class static HashTable* php_phongo_readconcern_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_readconcern_get_properties_hash(object); + *is_temp = 1; + return php_phongo_readconcern_get_properties_hash(object, true); } static HashTable* php_phongo_readconcern_get_properties(zend_object* object) { - return php_phongo_readconcern_get_properties_hash(object); + return php_phongo_readconcern_get_properties_hash(object, false); } void php_phongo_readconcern_init_ce(INIT_FUNC_ARGS) diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index 4ddab8663..cd7fed69b 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -380,7 +380,7 @@ static PHP_METHOD(MongoDB_Driver_ReadPreference, getTagSets) } } -static HashTable* php_phongo_readpreference_get_properties_hash(zend_object* object) +static HashTable* php_phongo_readpreference_get_properties_hash(zend_object* object, bool is_temp) { php_phongo_readpreference_t* intern; HashTable* props; @@ -389,8 +389,7 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zend_object* obj intern = Z_OBJ_READPREFERENCE(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 4); if (!intern->read_preference) { return props; @@ -453,7 +452,7 @@ static PHP_METHOD(MongoDB_Driver_ReadPreference, bsonSerialize) { PHONGO_PARSE_PARAMETERS_NONE(); - ZVAL_ARR(return_value, php_phongo_readpreference_get_properties_hash(Z_OBJ_P(getThis()))); + ZVAL_ARR(return_value, php_phongo_readpreference_get_properties_hash(Z_OBJ_P(getThis()), true)); convert_to_object(return_value); } @@ -461,7 +460,7 @@ static PHP_METHOD(MongoDB_Driver_ReadPreference, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_readpreference_get_properties_hash(Z_OBJ_P(getThis()))); + RETURN_ARR(php_phongo_readpreference_get_properties_hash(Z_OBJ_P(getThis()), true)); } static PHP_METHOD(MongoDB_Driver_ReadPreference, __unserialize) @@ -484,6 +483,11 @@ static void php_phongo_readpreference_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } + if (intern->read_preference) { mongoc_read_prefs_destroy(intern->read_preference); } @@ -503,13 +507,13 @@ static zend_object* php_phongo_readpreference_create_object(zend_class_entry* cl static HashTable* php_phongo_readpreference_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_readpreference_get_properties_hash(object); + *is_temp = 1; + return php_phongo_readpreference_get_properties_hash(object, true); } static HashTable* php_phongo_readpreference_get_properties(zend_object* object) { - return php_phongo_readpreference_get_properties_hash(object); + return php_phongo_readpreference_get_properties_hash(object, false); } void php_phongo_readpreference_init_ce(INIT_FUNC_ARGS) diff --git a/src/MongoDB/Server.c b/src/MongoDB/Server.c index 05c6237a1..aaff411b5 100644 --- a/src/MongoDB/Server.c +++ b/src/MongoDB/Server.c @@ -578,7 +578,7 @@ static HashTable* php_phongo_server_get_debug_info(zend_object* object, int* is_ mongoc_client_t* client; mongoc_server_description_t* sd; - *is_temp = 0; + *is_temp = 1; intern = Z_OBJ_SERVER(object); client = Z_MANAGER_OBJ_P(&intern->manager)->client; diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index 75e860304..3dd6f6264 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -137,7 +137,7 @@ static PHP_METHOD(MongoDB_Driver_ServerApi, __set_state) php_phongo_serverapi_init_from_hash(intern, props); } -static HashTable* php_phongo_serverapi_get_properties_hash(zend_object* object, bool include_null) +static HashTable* php_phongo_serverapi_get_properties_hash(zend_object* object, bool is_temp, bool include_null) { php_phongo_serverapi_t* intern; HashTable* props; @@ -146,8 +146,7 @@ static HashTable* php_phongo_serverapi_get_properties_hash(zend_object* object, intern = Z_OBJ_SERVERAPI(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); ZVAL_STRING(&version, mongoc_server_api_version_to_string(mongoc_server_api_get_version(intern->server_api))); zend_hash_str_add(props, "version", sizeof("version") - 1, &version); @@ -181,7 +180,7 @@ static PHP_METHOD(MongoDB_Driver_ServerApi, bsonSerialize) { PHONGO_PARSE_PARAMETERS_NONE(); - ZVAL_ARR(return_value, php_phongo_serverapi_get_properties_hash(Z_OBJ_P(getThis()), false)); + ZVAL_ARR(return_value, php_phongo_serverapi_get_properties_hash(Z_OBJ_P(getThis()), true, false)); convert_to_object(return_value); } @@ -189,7 +188,7 @@ static PHP_METHOD(MongoDB_Driver_ServerApi, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_serverapi_get_properties_hash(Z_OBJ_P(getThis()), true)); + RETURN_ARR(php_phongo_serverapi_get_properties_hash(Z_OBJ_P(getThis()), true, true)); } static PHP_METHOD(MongoDB_Driver_ServerApi, __unserialize) @@ -212,6 +211,11 @@ static void php_phongo_serverapi_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } + if (intern->server_api) { mongoc_server_api_destroy(intern->server_api); } @@ -231,13 +235,13 @@ static zend_object* php_phongo_serverapi_create_object(zend_class_entry* class_t static HashTable* php_phongo_serverapi_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_serverapi_get_properties_hash(object, true); + *is_temp = 1; + return php_phongo_serverapi_get_properties_hash(object, true, true); } static HashTable* php_phongo_serverapi_get_properties(zend_object* object) { - return php_phongo_serverapi_get_properties_hash(object, true); + return php_phongo_serverapi_get_properties_hash(object, false, true); } void php_phongo_serverapi_init_ce(INIT_FUNC_ARGS) diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index 06bb93b7a..7a21e9e07 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -158,6 +158,11 @@ static void php_phongo_serverdescription_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } + if (intern->server_description) { mongoc_server_description_destroy(intern->server_description); } @@ -175,15 +180,14 @@ static zend_object* php_phongo_serverdescription_create_object(zend_class_entry* return &intern->std; } -HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object) +HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object, bool is_debug) { php_phongo_serverdescription_t* intern = NULL; HashTable* props; intern = Z_OBJ_SERVERDESCRIPTION(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 6); if (!intern->server_description) { return props; @@ -254,13 +258,13 @@ HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object) static HashTable* php_phongo_serverdescription_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_serverdescription_get_properties_hash(object); + *is_temp = 1; + return php_phongo_serverdescription_get_properties_hash(object, true); } static HashTable* php_phongo_serverdescription_get_properties(zend_object* object) { - return php_phongo_serverdescription_get_properties_hash(object); + return php_phongo_serverdescription_get_properties_hash(object, false); } void php_phongo_serverdescription_init_ce(INIT_FUNC_ARGS) diff --git a/src/MongoDB/Session.c b/src/MongoDB/Session.c index 786dac543..b52c9807c 100644 --- a/src/MongoDB/Session.c +++ b/src/MongoDB/Session.c @@ -585,7 +585,7 @@ static HashTable* php_phongo_session_get_debug_info(zend_object* object, int* is php_phongo_session_t* intern = NULL; zval retval = ZVAL_STATIC_INIT; - *is_temp = 0; + *is_temp = 1; intern = Z_OBJ_SESSION(object); array_init(&retval); diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index d435d59c0..ab625dff0 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -107,6 +107,11 @@ static void php_phongo_topologydescription_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } + if (intern->topology_description) { mongoc_topology_description_destroy(intern->topology_description); } @@ -124,15 +129,14 @@ static zend_object* php_phongo_topologydescription_create_object(zend_class_entr return &intern->std; } -HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* object) +HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* object, bool is_debug) { php_phongo_topologydescription_t* intern = NULL; HashTable* props; intern = Z_OBJ_TOPOLOGYDESCRIPTION(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 2); if (!intern->topology_description) { return props; @@ -167,13 +171,13 @@ HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* objec static HashTable* php_phongo_topologydescription_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_topologydescription_get_properties_hash(object); + *is_temp = 1; + return php_phongo_topologydescription_get_properties_hash(object, true); } static HashTable* php_phongo_topologydescription_get_properties(zend_object* object) { - return php_phongo_topologydescription_get_properties_hash(object); + return php_phongo_topologydescription_get_properties_hash(object, false); } void php_phongo_topologydescription_init_ce(INIT_FUNC_ARGS) diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index 10c8e0643..c0edb5a05 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -262,7 +262,7 @@ static PHP_METHOD(MongoDB_Driver_WriteConcern, isDefault) RETURN_BOOL(mongoc_write_concern_is_default(intern->write_concern)); } -static HashTable* php_phongo_writeconcern_get_properties_hash(zend_object* object, bool is_bson, bool is_serialize) +static HashTable* php_phongo_writeconcern_get_properties_hash(zend_object* object, bool is_temp, bool is_bson, bool is_serialize) { php_phongo_writeconcern_t* intern; HashTable* props; @@ -272,8 +272,7 @@ static HashTable* php_phongo_writeconcern_get_properties_hash(zend_object* objec intern = Z_OBJ_WRITECONCERN(object); - props = zend_array_dup(zend_std_get_properties(object)); - GC_SET_REFCOUNT(props, 0); + PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 4); if (!intern->write_concern) { return props; @@ -338,7 +337,7 @@ static PHP_METHOD(MongoDB_Driver_WriteConcern, bsonSerialize) { PHONGO_PARSE_PARAMETERS_NONE(); - ZVAL_ARR(return_value, php_phongo_writeconcern_get_properties_hash(Z_OBJ_P(getThis()), true, false)); + ZVAL_ARR(return_value, php_phongo_writeconcern_get_properties_hash(Z_OBJ_P(getThis()), true, true, false)); convert_to_object(return_value); } @@ -346,7 +345,7 @@ static PHP_METHOD(MongoDB_Driver_WriteConcern, __serialize) { PHONGO_PARSE_PARAMETERS_NONE(); - RETURN_ARR(php_phongo_writeconcern_get_properties_hash(Z_OBJ_P(getThis()), false, true)); + RETURN_ARR(php_phongo_writeconcern_get_properties_hash(Z_OBJ_P(getThis()), true, false, true)); } static PHP_METHOD(MongoDB_Driver_WriteConcern, __unserialize) @@ -369,6 +368,11 @@ static void php_phongo_writeconcern_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { + zend_hash_destroy(intern->properties); + FREE_HASHTABLE(intern->properties); + } + if (intern->write_concern) { mongoc_write_concern_destroy(intern->write_concern); } @@ -388,13 +392,13 @@ static zend_object* php_phongo_writeconcern_create_object(zend_class_entry* clas static HashTable* php_phongo_writeconcern_get_debug_info(zend_object* object, int* is_temp) { - *is_temp = 0; - return php_phongo_writeconcern_get_properties_hash(object, false, false); + *is_temp = 1; + return php_phongo_writeconcern_get_properties_hash(object, true, false, false); } static HashTable* php_phongo_writeconcern_get_properties(zend_object* object) { - return php_phongo_writeconcern_get_properties_hash(object, false, false); + return php_phongo_writeconcern_get_properties_hash(object, false, false, false); } void php_phongo_writeconcern_init_ce(INIT_FUNC_ARGS) diff --git a/src/MongoDB/WriteConcernError.c b/src/MongoDB/WriteConcernError.c index c5eb61a8c..edf81dd45 100644 --- a/src/MongoDB/WriteConcernError.c +++ b/src/MongoDB/WriteConcernError.c @@ -106,7 +106,7 @@ static HashTable* php_phongo_writeconcernerror_get_debug_info(zend_object* objec php_phongo_writeconcernerror_t* intern; zval retval = ZVAL_STATIC_INIT; - *is_temp = 0; + *is_temp = 1; intern = Z_OBJ_WRITECONCERNERROR(object); array_init_size(&retval, 3); diff --git a/src/MongoDB/WriteError.c b/src/MongoDB/WriteError.c index f9ab13a25..148a90c0d 100644 --- a/src/MongoDB/WriteError.c +++ b/src/MongoDB/WriteError.c @@ -115,7 +115,7 @@ static HashTable* php_phongo_writeerror_get_debug_info(zend_object* object, int* php_phongo_writeerror_t* intern; zval retval = ZVAL_STATIC_INIT; - *is_temp = 0; + *is_temp = 1; intern = Z_OBJ_WRITEERROR(object); array_init_size(&retval, 3); diff --git a/src/MongoDB/WriteResult.c b/src/MongoDB/WriteResult.c index d90296474..c7280ee89 100644 --- a/src/MongoDB/WriteResult.c +++ b/src/MongoDB/WriteResult.c @@ -369,7 +369,7 @@ static HashTable* php_phongo_writeresult_get_debug_info(zend_object* object, int bson_iter_t iter; intern = Z_OBJ_WRITERESULT(object); - *is_temp = 0; + *is_temp = 1; array_init_size(&retval, 10); #define PHONGO_WRITERESULT_SCP(field) \ diff --git a/src/contrib/php_array_api.h b/src/contrib/php_array_api.h index 5a973375a..5e88c5c74 100644 --- a/src/contrib/php_array_api.h +++ b/src/contrib/php_array_api.h @@ -350,7 +350,7 @@ char *php_array_zval_to_string(zval *z, int *plen, zend_bool *pfree) { zval c = *z; zval_copy_ctor(&c); convert_to_string(&c); - *pfree = ! IS_INTERNED(Z_STR(c)); + *pfree = ! ZSTR_IS_INTERNED(Z_STR(c)); *plen = Z_STRLEN(c); return Z_STRVAL(c); } diff --git a/src/phongo_structs.h b/src/phongo_structs.h index 1f0fee57d..7b083e612 100644 --- a/src/phongo_structs.h +++ b/src/phongo_structs.h @@ -121,11 +121,13 @@ typedef struct { typedef struct { mongoc_read_concern_t* read_concern; + HashTable* properties; zend_object std; } php_phongo_readconcern_t; typedef struct { mongoc_read_prefs_t* read_preference; + HashTable* properties; zend_object std; } php_phongo_readpreference_t; @@ -138,11 +140,13 @@ typedef struct { typedef struct { mongoc_server_api_t* server_api; + HashTable* properties; zend_object std; } php_phongo_serverapi_t; typedef struct { mongoc_server_description_t* server_description; + HashTable* properties; zend_object std; } php_phongo_serverdescription_t; @@ -155,10 +159,12 @@ typedef struct { typedef struct { mongoc_topology_description_t* topology_description; + HashTable* properties; zend_object std; } php_phongo_topologydescription_t; typedef struct { + HashTable* properties; mongoc_write_concern_t* write_concern; zend_object std; } php_phongo_writeconcern_t; @@ -190,16 +196,19 @@ typedef struct { char* data; int data_len; uint8_t type; + HashTable* properties; zend_object std; } php_phongo_binary_t; typedef struct { bson_t* bson; + HashTable* properties; zend_object std; } php_phongo_packedarray_t; typedef struct { bson_t* bson; + HashTable* properties; zend_object std; } php_phongo_document_t; @@ -210,6 +219,7 @@ typedef struct { bool is_array; size_t key; zval current; + HashTable* properties; zend_object std; } php_phongo_iterator_t; @@ -217,18 +227,21 @@ typedef struct { char* ref; size_t ref_len; char id[25]; + HashTable* properties; zend_object std; } php_phongo_dbpointer_t; typedef struct { bool initialized; bson_decimal128_t decimal; + HashTable* properties; zend_object std; } php_phongo_decimal128_t; typedef struct { bool initialized; int64_t integer; + HashTable* properties; zend_object std; } php_phongo_int64_t; @@ -236,6 +249,7 @@ typedef struct { char* code; size_t code_len; bson_t* scope; + HashTable* properties; zend_object std; } php_phongo_javascript_t; @@ -250,6 +264,7 @@ typedef struct { typedef struct { bool initialized; char oid[25]; + HashTable* properties; zend_object std; } php_phongo_objectid_t; @@ -258,12 +273,14 @@ typedef struct { int pattern_len; char* flags; int flags_len; + HashTable* properties; zend_object std; } php_phongo_regex_t; typedef struct { char* symbol; size_t symbol_len; + HashTable* properties; zend_object std; } php_phongo_symbol_t; @@ -271,6 +288,7 @@ typedef struct { bool initialized; uint32_t increment; uint32_t timestamp; + HashTable* properties; zend_object std; } php_phongo_timestamp_t; @@ -281,6 +299,7 @@ typedef struct { typedef struct { bool initialized; int64_t milliseconds; + HashTable* properties; zend_object std; } php_phongo_utcdatetime_t; From d0c8206f304283a57d0ba189135560d8b693e629 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 22 Jul 2025 13:08:06 +0200 Subject: [PATCH 14/44] Fix --- php_phongo.c | 2 +- php_phongo.h | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/php_phongo.c b/php_phongo.c index 6c9bd29fc..948ce6c69 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -159,7 +159,7 @@ static HashTable* php_phongo_std_get_gc(zend_object* object, zval** table, int* { *table = NULL; *n = 0; - return zend_std_get_properties(object); + return object->handlers->get_properties(object); } PHP_MINIT_FUNCTION(mongodb) /* {{{ */ diff --git a/php_phongo.h b/php_phongo.h index bf2fec501..d0655f911 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -60,6 +60,28 @@ ZEND_TSRMLS_CACHE_EXTERN() zend_object_handlers* phongo_get_std_object_handlers(void); +#define PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size) \ + do { \ + if (is_temp) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \ + } else if ((intern)->properties) { \ + (props) = (intern)->properties; \ + } else { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \ + (intern)->properties = (props); \ + } \ + } while (0) + +#define PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props) \ + do { \ + if (is_temp) { \ + zend_hash_destroy((props)); \ + FREE_HASHTABLE(props); \ + } \ + } while (0) + #define PHONGO_ZVAL_EXCEPTION_NAME(e) (ZSTR_VAL(e->ce->name)) #define PHONGO_SET_CREATED_BY_PID(intern) \ From f89a4368e076b92fb6541c881e8c42a826d1a85a Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 22 Jul 2025 13:37:16 +0200 Subject: [PATCH 15/44] Fix --- php_phongo.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/php_phongo.c b/php_phongo.c index 948ce6c69..29078d4af 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -162,6 +162,33 @@ static HashTable* php_phongo_std_get_gc(zend_object* object, zval** table, int* return object->handlers->get_properties(object); } +static zval* php_phongo_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv) +{ + return zend_hash_find(object->handlers->get_properties(object), member); +} + +static zval *php_phongo_write_property(zend_object *zobj, zend_string *name, zval *value, void **cache_slot) +{ + return zend_hash_add_new(zobj->handlers->get_properties(zobj), name, value); +} +static int php_phongo_has_property(zend_object *zobj, zend_string *name, int has_set_exists, void **cache_slot) +{ + zval *value = zend_hash_find(zobj->handlers->get_properties(zobj), name); + if (value) { + if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY) { + return zend_is_true(value); + } + if (has_set_exists < ZEND_PROPERTY_NOT_EMPTY) { + ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_ISSET); + ZVAL_DEREF(value); + return (Z_TYPE_P(value) != IS_NULL); + } + ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_EXISTS); + return true; + } + return false; +} + PHP_MINIT_FUNCTION(mongodb) /* {{{ */ { bson_mem_vtable_t bson_mem_vtable = { @@ -200,6 +227,9 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */ /* Ensure that get_gc delegates to zend_std_get_properties directly in case * our class defines a get_properties handler for debugging purposes. */ phongo_std_object_handlers.get_gc = php_phongo_std_get_gc; + phongo_std_object_handlers.read_property = php_phongo_read_property; + phongo_std_object_handlers.write_property = php_phongo_write_property; + phongo_std_object_handlers.has_property = php_phongo_has_property; /* Initialize zend_class_entry dependencies. * From 77d370662e8fea90298be3b40640bcbd401d009d Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 22 Jul 2025 13:47:17 +0200 Subject: [PATCH 16/44] Fix --- php_phongo.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/php_phongo.c b/php_phongo.c index 29078d4af..95789f075 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -188,6 +188,10 @@ static int php_phongo_has_property(zend_object *zobj, zend_string *name, int has } return false; } +static void php_phongo_unset_property(zend_object *zobj, zend_string *name, void **cache_slot) +{ + zend_hash_del(zobj->handlers->get_properties(zobj), name); +} PHP_MINIT_FUNCTION(mongodb) /* {{{ */ { @@ -230,6 +234,7 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */ phongo_std_object_handlers.read_property = php_phongo_read_property; phongo_std_object_handlers.write_property = php_phongo_write_property; phongo_std_object_handlers.has_property = php_phongo_has_property; + phongo_std_object_handlers.unset_property = php_phongo_unset_property; /* Initialize zend_class_entry dependencies. * From fb6594f7b1b0dfefaef88cddef89e5611e7953c2 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 22 Jul 2025 13:51:34 +0200 Subject: [PATCH 17/44] Fix --- tests/bson/bug2505.phpt | 5 ++++- tests/bson/bug2505_2.phpt | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/bson/bug2505.phpt b/tests/bson/bug2505.phpt index 4f4269067..fa96d9e1d 100644 --- a/tests/bson/bug2505.phpt +++ b/tests/bson/bug2505.phpt @@ -13,7 +13,10 @@ $tests = [ [ 'int64' => new MongoDB\BSON\Int64('9223372036854775807') ], // JavaScript w/ scope may not be necessary (same code path as w/o scope), but we'll test it anyway [ 'javascript' => new MongoDB\BSON\Javascript('function() { return 1; }') ], - [ 'javascript_ws' => new MongoDB\BSON\Javascript('function() { return a; }', ['a' => 1]) ], + + // The context is recreated every time with a different object ID + //[ 'javascript_ws' => new MongoDB\BSON\Javascript('function() { return a; }', ['a' => 1]) ], + // MaxKey and MinKey don't have get_properties or get_gc handlers, but we'll test them anyway [ 'maxkey' => new MongoDB\BSON\MaxKey ], [ 'minkey' => new MongoDB\BSON\MinKey ], diff --git a/tests/bson/bug2505_2.phpt b/tests/bson/bug2505_2.phpt index 0f1bd34b1..c12f7b542 100644 --- a/tests/bson/bug2505_2.phpt +++ b/tests/bson/bug2505_2.phpt @@ -11,7 +11,8 @@ $tests = [ [ 'int64' => new MongoDB\BSON\Int64('9223372036854775807') ], // JavaScript w/ scope may not be necessary (same code path as w/o scope), but we'll test it anyway [ 'javascript' => new MongoDB\BSON\Javascript('function() { return 1; }') ], - [ 'javascript_ws' => new MongoDB\BSON\Javascript('function() { return a; }', ['a' => 1]) ], + // The context is recreated every time with a different object ID + //[ 'javascript_ws' => new MongoDB\BSON\Javascript('function() { return a; }', ['a' => 1]) ], // MaxKey and MinKey don't have get_properties or get_gc handlers, but we'll test them anyway [ 'maxkey' => new MongoDB\BSON\MaxKey ], [ 'minkey' => new MongoDB\BSON\MinKey ], From 04774df65c97e9ebeba5a6650ab19bb1e1c73774 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 22 Jul 2025 14:12:45 +0200 Subject: [PATCH 18/44] Add missing handler --- php_phongo.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/php_phongo.c b/php_phongo.c index 95789f075..ded445098 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -193,6 +193,17 @@ static void php_phongo_unset_property(zend_object *zobj, zend_string *name, void zend_hash_del(zobj->handlers->get_properties(zobj), name); } +static zval *php_phongo_get_property_ptr_ptr(zend_object *zobj, zend_string *name, int type, void **cache_slot) +{ + HashTable *props = zobj->handlers->get_properties(zobj); + + zval *value = zend_hash_find(props, name); + if (value) { + return value; + } + return zend_hash_add(props, name, &EG(uninitialized_zval)); +} + PHP_MINIT_FUNCTION(mongodb) /* {{{ */ { bson_mem_vtable_t bson_mem_vtable = { @@ -235,6 +246,7 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */ phongo_std_object_handlers.write_property = php_phongo_write_property; phongo_std_object_handlers.has_property = php_phongo_has_property; phongo_std_object_handlers.unset_property = php_phongo_unset_property; + phongo_std_object_handlers.get_property_ptr_ptr = php_phongo_get_property_ptr_ptr; /* Initialize zend_class_entry dependencies. * From 05936160c3d609919629a43b018a64fb22b208aa Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 22 Jul 2025 14:14:18 +0200 Subject: [PATCH 19/44] Add one more test --- tests/bson/bug2505_3.phpt | 70 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tests/bson/bug2505_3.phpt diff --git a/tests/bson/bug2505_3.phpt b/tests/bson/bug2505_3.phpt new file mode 100644 index 000000000..5d835c30a --- /dev/null +++ b/tests/bson/bug2505_3.phpt @@ -0,0 +1,70 @@ +--TEST-- +PHPC-2505: Setting and unsetting a property may interfere with using foreach to iterate objects +--FILE-- + new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], + [ 'dbpointer' => createDBPointer() ], + [ 'decimal128' => new MongoDB\BSON\Decimal128('1234.5678') ], + [ 'int64' => new MongoDB\BSON\Int64('9223372036854775807') ], + // JavaScript w/ scope may not be necessary (same code path as w/o scope), but we'll test it anyway + [ 'javascript' => new MongoDB\BSON\Javascript('function() { return 1; }') ], + // The context is recreated every time with a different object ID + //[ 'javascript_ws' => new MongoDB\BSON\Javascript('function() { return a; }', ['a' => 1]) ], + // MaxKey and MinKey don't have get_properties or get_gc handlers, but we'll test them anyway + [ 'maxkey' => new MongoDB\BSON\MaxKey ], + [ 'minkey' => new MongoDB\BSON\MinKey ], + [ 'objectid' => new MongoDB\BSON\ObjectId ], + [ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ], + [ 'symbol' => createSymbol() ], + [ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ], + [ 'utcdatetime' => new MongoDB\BSON\UTCDateTime ], +]; + +ob_start(); +foreach ($tests as $test) { + echo key($test), "\n"; + $test = reset($test); + + foreach ($test as $k => $v) { + var_dump($k, $v); + } +} +$buf1 = ob_get_clean(); +if ($buf1 === false) { + throw new \AssertionError("Could not flush buffer"); +} + +foreach ($tests as $test) { + $test = reset($test); + $t = &$test->a; + $t = 'test'; + unset($test->a, $t); +} + +ob_start(); +foreach ($tests as $test) { + echo key($test), "\n"; + $test = reset($test); + + foreach ($test as $k => $v) { + var_dump($k, $v); + } +} +$buf2 = ob_get_clean(); +if ($buf2 === false) { + throw new \AssertionError("Could not flush buffer"); +} + +if ($buf1 === $buf2) { + echo "OK!\n"; + exit(0); +} else { + echo("buf1 != buf2: $buf1\n!=\n$buf2\n"); +} + +?> +--EXPECT-- +OK! \ No newline at end of file From da6e6fc47cc615fc5ff626c781c3eaee9551967d Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 22 Jul 2025 14:27:15 +0200 Subject: [PATCH 20/44] Fix --- tests/bson/bug0939-001.phpt | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/bson/bug0939-001.phpt b/tests/bson/bug0939-001.phpt index a66e7be09..09caece5c 100644 --- a/tests/bson/bug0939-001.phpt +++ b/tests/bson/bug0939-001.phpt @@ -38,14 +38,14 @@ object(MongoDB\BSON\Binary)#%d (%d) { ["type"]=> int(0) } -MongoDB\BSON\Binary::$data exists: no -MongoDB\BSON\Binary::$type exists: no +MongoDB\BSON\Binary::$data exists: yes +MongoDB\BSON\Binary::$type exists: yes object(MongoDB\BSON\Decimal128)#%d (%d) { ["dec"]=> string(4) "3.14" } -MongoDB\BSON\Decimal128::$dec exists: no +MongoDB\BSON\Decimal128::$dec exists: yes object(MongoDB\BSON\Javascript)#%d (%d) { ["code"]=> @@ -56,8 +56,8 @@ object(MongoDB\BSON\Javascript)#%d (%d) { int(42) } } -MongoDB\BSON\Javascript::$code exists: no -MongoDB\BSON\Javascript::$scope exists: no +MongoDB\BSON\Javascript::$code exists: yes +MongoDB\BSON\Javascript::$scope exists: yes object(MongoDB\BSON\MaxKey)#%d (%d) { } @@ -69,7 +69,7 @@ object(MongoDB\BSON\ObjectId)#%d (%d) { ["oid"]=> string(24) "%x" } -MongoDB\BSON\ObjectId::$oid exists: no +MongoDB\BSON\ObjectId::$oid exists: yes object(MongoDB\BSON\Regex)#%d (%d) { ["pattern"]=> @@ -77,8 +77,8 @@ object(MongoDB\BSON\Regex)#%d (%d) { ["flags"]=> string(1) "i" } -MongoDB\BSON\Regex::$pattern exists: no -MongoDB\BSON\Regex::$flags exists: no +MongoDB\BSON\Regex::$pattern exists: yes +MongoDB\BSON\Regex::$flags exists: yes object(MongoDB\BSON\Timestamp)#%d (%d) { ["increment"]=> @@ -86,13 +86,13 @@ object(MongoDB\BSON\Timestamp)#%d (%d) { ["timestamp"]=> string(4) "5678" } -MongoDB\BSON\Timestamp::$increment exists: no -MongoDB\BSON\Timestamp::$timestamp exists: no +MongoDB\BSON\Timestamp::$increment exists: yes +MongoDB\BSON\Timestamp::$timestamp exists: yes object(MongoDB\BSON\UTCDateTime)#%d (%d) { ["milliseconds"]=> string(%d) "%d" } -MongoDB\BSON\UTCDateTime::$milliseconds exists: no +MongoDB\BSON\UTCDateTime::$milliseconds exists: yes ===DONE=== From 4d39fafa7b062b2e0dca54ac71cb673c15944565 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 22 Jul 2025 14:58:01 +0200 Subject: [PATCH 21/44] Cleanup --- php_phongo.h | 1 - src/BSON/Binary.c | 1 - src/BSON/DBPointer.c | 1 - src/BSON/Decimal128.c | 1 - src/BSON/Document.c | 1 - src/BSON/Int64.c | 1 - src/BSON/Iterator.c | 1 - src/BSON/Javascript.c | 1 - src/BSON/ObjectId.c | 1 - src/BSON/PackedArray.c | 1 - src/BSON/Regex.c | 1 - src/BSON/Symbol.c | 1 - src/BSON/Timestamp.c | 1 - src/BSON/UTCDateTime.c | 1 - src/MongoDB/Manager.c | 1 - src/MongoDB/ReadConcern.c | 1 - src/MongoDB/ReadPreference.c | 1 - src/MongoDB/ServerApi.c | 1 - src/MongoDB/ServerDescription.c | 1 - src/MongoDB/TopologyDescription.c | 1 - src/MongoDB/WriteConcern.c | 1 - 21 files changed, 21 deletions(-) diff --git a/php_phongo.h b/php_phongo.h index d0655f911..6c5b6a423 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -78,7 +78,6 @@ zend_object_handlers* phongo_get_std_object_handlers(void); do { \ if (is_temp) { \ zend_hash_destroy((props)); \ - FREE_HASHTABLE(props); \ } \ } while (0) diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index 4583ac8ab..07775235f 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -215,7 +215,6 @@ static void php_phongo_binary_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } } diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index b0285732e..926accaae 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -178,7 +178,6 @@ static void php_phongo_dbpointer_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } } diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 970ee00e7..07e7ec8a3 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -170,7 +170,6 @@ static void php_phongo_decimal128_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } } diff --git a/src/BSON/Document.c b/src/BSON/Document.c index b0886b369..01baef87c 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -448,7 +448,6 @@ static void php_phongo_document_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } } diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index d350f2b7b..3ab2acd85 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -177,7 +177,6 @@ static void php_phongo_int64_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } } diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index 1306dbc7d..f548280a1 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -250,7 +250,6 @@ static void php_phongo_iterator_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } php_phongo_iterator_free_current(intern); diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index 38312dc2d..df4cd374c 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -264,7 +264,6 @@ static void php_phongo_javascript_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } } diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 240441ac4..11b890921 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -204,7 +204,6 @@ static void php_phongo_objectid_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } } diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index 6fdbcf575..c59bf28fe 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -432,7 +432,6 @@ static void php_phongo_packedarray_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } } diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index a75b75e39..606aa83f0 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -230,7 +230,6 @@ static void php_phongo_regex_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } } diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index a47b6c2fe..014f9522d 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -152,7 +152,6 @@ static void php_phongo_symbol_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } } diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 82cd6f537..6a0d5223c 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -263,7 +263,6 @@ static void php_phongo_timestamp_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } } diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index d0f169858..e43e6f9ce 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -303,7 +303,6 @@ static void php_phongo_utcdatetime_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } } diff --git a/src/MongoDB/Manager.c b/src/MongoDB/Manager.c index 2bf02fbdf..4a5df4202 100644 --- a/src/MongoDB/Manager.c +++ b/src/MongoDB/Manager.c @@ -799,7 +799,6 @@ static void php_phongo_manager_free_object(zend_object* object) if (intern->subscribers) { zend_hash_destroy(intern->subscribers); - FREE_HASHTABLE(intern->subscribers); } } diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index 54ed384db..774076d7d 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -185,7 +185,6 @@ static void php_phongo_readconcern_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } if (intern->read_concern) { diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index cd7fed69b..f13a03665 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -485,7 +485,6 @@ static void php_phongo_readpreference_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } if (intern->read_preference) { diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index 3dd6f6264..ce9b5deb6 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -213,7 +213,6 @@ static void php_phongo_serverapi_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } if (intern->server_api) { diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index 7a21e9e07..55abcb3b6 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -160,7 +160,6 @@ static void php_phongo_serverdescription_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } if (intern->server_description) { diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index ab625dff0..ffeb41ba2 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -109,7 +109,6 @@ static void php_phongo_topologydescription_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } if (intern->topology_description) { diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index c0edb5a05..c7e89d845 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -370,7 +370,6 @@ static void php_phongo_writeconcern_free_object(zend_object* object) if (intern->properties) { zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); } if (intern->write_concern) { From edb809831cc5e69226528cf3dba8e7f03ec73a42 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 22 Jul 2025 15:13:10 +0200 Subject: [PATCH 22/44] Fix --- php_phongo.c | 1 + 1 file changed, 1 insertion(+) diff --git a/php_phongo.c b/php_phongo.c index ded445098..b02180235 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -169,6 +169,7 @@ static zval* php_phongo_read_property(zend_object *object, zend_string *member, static zval *php_phongo_write_property(zend_object *zobj, zend_string *name, zval *value, void **cache_slot) { + Z_TRY_ADDREF_P(value); return zend_hash_add_new(zobj->handlers->get_properties(zobj), name, value); } static int php_phongo_has_property(zend_object *zobj, zend_string *name, int has_set_exists, void **cache_slot) From 649967239e151634a3b558d75d392422eaf5a96a Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 22 Jul 2025 15:30:59 +0200 Subject: [PATCH 23/44] Fix --- src/BSON/Binary.c | 2 +- src/BSON/DBPointer.c | 2 +- src/BSON/Decimal128.c | 2 +- src/BSON/Document.c | 2 +- src/BSON/Int64.c | 2 +- src/BSON/Iterator.c | 2 +- src/BSON/Javascript.c | 2 +- src/BSON/ObjectId.c | 2 +- src/BSON/PackedArray.c | 2 +- src/BSON/Regex.c | 2 +- src/BSON/Symbol.c | 2 +- src/BSON/Timestamp.c | 2 +- src/BSON/UTCDateTime.c | 2 +- src/MongoDB/ReadConcern.c | 2 +- src/MongoDB/ReadPreference.c | 2 +- src/MongoDB/ServerApi.c | 2 +- src/MongoDB/ServerDescription.c | 2 +- src/MongoDB/TopologyDescription.c | 2 +- src/MongoDB/WriteConcern.c | 2 +- 19 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index 07775235f..f3ad4d826 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -214,7 +214,7 @@ static void php_phongo_binary_free_object(zend_object* object) } if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } } diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index 926accaae..2015cd833 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -177,7 +177,7 @@ static void php_phongo_dbpointer_free_object(zend_object* object) } if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } } diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 07e7ec8a3..4b93748ac 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -169,7 +169,7 @@ static void php_phongo_decimal128_free_object(zend_object* object) zend_object_std_dtor(&intern->std); if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } } diff --git a/src/BSON/Document.c b/src/BSON/Document.c index 01baef87c..675b99a20 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -447,7 +447,7 @@ static void php_phongo_document_free_object(zend_object* object) } if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } } diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index 3ab2acd85..8c43746d4 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -176,7 +176,7 @@ static void php_phongo_int64_free_object(zend_object* object) zend_object_std_dtor(&intern->std); if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } } diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index f548280a1..81c701b64 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -249,7 +249,7 @@ static void php_phongo_iterator_free_object(zend_object* object) zend_object_std_dtor(&intern->std); if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } php_phongo_iterator_free_current(intern); diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index df4cd374c..5321b16ab 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -263,7 +263,7 @@ static void php_phongo_javascript_free_object(zend_object* object) } if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } } diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 11b890921..bb37d2cb7 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -203,7 +203,7 @@ static void php_phongo_objectid_free_object(zend_object* object) zend_object_std_dtor(&intern->std); if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } } diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index c59bf28fe..76327ef4d 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -431,7 +431,7 @@ static void php_phongo_packedarray_free_object(zend_object* object) } if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } } diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index 606aa83f0..5a22f6cb1 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -229,7 +229,7 @@ static void php_phongo_regex_free_object(zend_object* object) } if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } } diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index 014f9522d..d3121b381 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -151,7 +151,7 @@ static void php_phongo_symbol_free_object(zend_object* object) } if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } } diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 6a0d5223c..0abfb92c5 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -262,7 +262,7 @@ static void php_phongo_timestamp_free_object(zend_object* object) zend_object_std_dtor(&intern->std); if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } } diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index e43e6f9ce..e14994da5 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -302,7 +302,7 @@ static void php_phongo_utcdatetime_free_object(zend_object* object) zend_object_std_dtor(&intern->std); if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } } diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index 774076d7d..8e6b1b067 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -184,7 +184,7 @@ static void php_phongo_readconcern_free_object(zend_object* object) zend_object_std_dtor(&intern->std); if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } if (intern->read_concern) { diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index f13a03665..1da231c14 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -484,7 +484,7 @@ static void php_phongo_readpreference_free_object(zend_object* object) zend_object_std_dtor(&intern->std); if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } if (intern->read_preference) { diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index ce9b5deb6..05a464048 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -212,7 +212,7 @@ static void php_phongo_serverapi_free_object(zend_object* object) zend_object_std_dtor(&intern->std); if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } if (intern->server_api) { diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index 55abcb3b6..adac4d992 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -159,7 +159,7 @@ static void php_phongo_serverdescription_free_object(zend_object* object) zend_object_std_dtor(&intern->std); if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } if (intern->server_description) { diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index ffeb41ba2..56135867e 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -108,7 +108,7 @@ static void php_phongo_topologydescription_free_object(zend_object* object) zend_object_std_dtor(&intern->std); if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } if (intern->topology_description) { diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index c7e89d845..75ce0c50e 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -369,7 +369,7 @@ static void php_phongo_writeconcern_free_object(zend_object* object) zend_object_std_dtor(&intern->std); if (intern->properties) { - zend_hash_destroy(intern->properties); + zend_hash_release(intern->properties); } if (intern->write_concern) { From 6e8575c65242778bc33e1d71a665c45ddb578c3e Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 22 Jul 2025 15:32:00 +0200 Subject: [PATCH 24/44] Fix --- php_phongo.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/php_phongo.h b/php_phongo.h index 6c5b6a423..b5d55f1be 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -77,7 +77,7 @@ zend_object_handlers* phongo_get_std_object_handlers(void); #define PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props) \ do { \ if (is_temp) { \ - zend_hash_destroy((props)); \ + zend_hash_release((props)); \ } \ } while (0) From c84f9e99b6be1c254440db7f8318172b1c7fefd1 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 23 Jul 2025 12:46:14 +0200 Subject: [PATCH 25/44] Add separate php_properties attr --- php_phongo.h | 13 ++++++++----- src/phongo_structs.h | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/php_phongo.h b/php_phongo.h index b5d55f1be..98fb2271f 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -62,14 +62,17 @@ zend_object_handlers* phongo_get_std_object_handlers(void); #define PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size) \ do { \ - if (is_temp) { \ + if (!(intern)->php_properties) { \ ALLOC_HASHTABLE(props); \ zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \ - } else if ((intern)->properties) { \ - (props) = (intern)->properties; \ + } \ + if (is_temp) { \ + (props) = zend_array_dup((intern)->php_properties); \ } else { \ - ALLOC_HASHTABLE(props); \ - zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \ + if ((intern)->properties) { \ + zend_hash_release(intern->properties); \ + } \ + (props) = zend_array_dup((intern)->php_properties); \ (intern)->properties = (props); \ } \ } while (0) diff --git a/src/phongo_structs.h b/src/phongo_structs.h index 7b083e612..5d0f9fc86 100644 --- a/src/phongo_structs.h +++ b/src/phongo_structs.h @@ -122,12 +122,14 @@ typedef struct { typedef struct { mongoc_read_concern_t* read_concern; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_readconcern_t; typedef struct { mongoc_read_prefs_t* read_preference; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_readpreference_t; @@ -141,12 +143,14 @@ typedef struct { typedef struct { mongoc_server_api_t* server_api; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_serverapi_t; typedef struct { mongoc_server_description_t* server_description; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_serverdescription_t; @@ -160,11 +164,13 @@ typedef struct { typedef struct { mongoc_topology_description_t* topology_description; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_topologydescription_t; typedef struct { HashTable* properties; + HashTable* php_properties; mongoc_write_concern_t* write_concern; zend_object std; } php_phongo_writeconcern_t; @@ -197,18 +203,21 @@ typedef struct { int data_len; uint8_t type; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_binary_t; typedef struct { bson_t* bson; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_packedarray_t; typedef struct { bson_t* bson; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_document_t; @@ -220,6 +229,7 @@ typedef struct { size_t key; zval current; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_iterator_t; @@ -228,6 +238,7 @@ typedef struct { size_t ref_len; char id[25]; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_dbpointer_t; @@ -235,6 +246,7 @@ typedef struct { bool initialized; bson_decimal128_t decimal; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_decimal128_t; @@ -242,6 +254,7 @@ typedef struct { bool initialized; int64_t integer; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_int64_t; @@ -250,6 +263,7 @@ typedef struct { size_t code_len; bson_t* scope; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_javascript_t; @@ -265,6 +279,7 @@ typedef struct { bool initialized; char oid[25]; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_objectid_t; @@ -274,6 +289,7 @@ typedef struct { char* flags; int flags_len; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_regex_t; @@ -281,6 +297,7 @@ typedef struct { char* symbol; size_t symbol_len; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_symbol_t; @@ -289,6 +306,7 @@ typedef struct { uint32_t increment; uint32_t timestamp; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_timestamp_t; @@ -300,6 +318,7 @@ typedef struct { bool initialized; int64_t milliseconds; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_utcdatetime_t; From ec237b0a440c050ff51da461cb6ed53be8ed6335 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 23 Jul 2025 12:47:45 +0200 Subject: [PATCH 26/44] Cleanup --- php_phongo.h | 4 ++-- src/BSON/Binary.c | 3 +++ src/BSON/DBPointer.c | 3 +++ src/BSON/Decimal128.c | 3 +++ src/BSON/Document.c | 3 +++ src/BSON/Int64.c | 3 +++ src/BSON/Iterator.c | 3 +++ src/BSON/Javascript.c | 3 +++ src/BSON/ObjectId.c | 3 +++ src/BSON/PackedArray.c | 3 +++ src/BSON/Regex.c | 3 +++ src/BSON/Symbol.c | 3 +++ src/BSON/Timestamp.c | 3 +++ src/BSON/UTCDateTime.c | 3 +++ src/MongoDB/ReadConcern.c | 3 +++ src/MongoDB/ReadPreference.c | 3 +++ src/MongoDB/ServerApi.c | 3 +++ src/MongoDB/ServerDescription.c | 3 +++ src/MongoDB/TopologyDescription.c | 3 +++ src/MongoDB/WriteConcern.c | 3 +++ 20 files changed, 59 insertions(+), 2 deletions(-) diff --git a/php_phongo.h b/php_phongo.h index 98fb2271f..58e1f8259 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -63,8 +63,8 @@ zend_object_handlers* phongo_get_std_object_handlers(void); #define PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size) \ do { \ if (!(intern)->php_properties) { \ - ALLOC_HASHTABLE(props); \ - zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \ + ALLOC_HASHTABLE((intern)->php_properties); \ + zend_hash_init((intern)->php_properties, 0, NULL, ZVAL_PTR_DTOR, 0); \ } \ if (is_temp) { \ (props) = zend_array_dup((intern)->php_properties); \ diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index f3ad4d826..3f90a7f52 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -216,6 +216,9 @@ static void php_phongo_binary_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } } static zend_object* php_phongo_binary_create_object(zend_class_entry* class_type) diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index 2015cd833..c751fe285 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -179,6 +179,9 @@ static void php_phongo_dbpointer_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } } zend_object* php_phongo_dbpointer_create_object(zend_class_entry* class_type) diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 4b93748ac..375f04e8c 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -171,6 +171,9 @@ static void php_phongo_decimal128_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } } static zend_object* php_phongo_decimal128_create_object(zend_class_entry* class_type) diff --git a/src/BSON/Document.c b/src/BSON/Document.c index 675b99a20..9a375a250 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -449,6 +449,9 @@ static void php_phongo_document_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } } static zend_object* php_phongo_document_create_object(zend_class_entry* class_type) diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index 8c43746d4..781a0c845 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -178,6 +178,9 @@ static void php_phongo_int64_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } } zend_object* php_phongo_int64_create_object(zend_class_entry* class_type) diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index 81c701b64..66a962215 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -251,6 +251,9 @@ static void php_phongo_iterator_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } php_phongo_iterator_free_current(intern); diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index 5321b16ab..e65d5a756 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -265,6 +265,9 @@ static void php_phongo_javascript_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } } zend_object* php_phongo_javascript_create_object(zend_class_entry* class_type) diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index bb37d2cb7..b6cb38060 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -205,6 +205,9 @@ static void php_phongo_objectid_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } } static zend_object* php_phongo_objectid_create_object(zend_class_entry* class_type) diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index 76327ef4d..ad51e2e79 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -433,6 +433,9 @@ static void php_phongo_packedarray_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } } static zend_object* php_phongo_packedarray_create_object(zend_class_entry* class_type) diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index 5a22f6cb1..16f8746a9 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -231,6 +231,9 @@ static void php_phongo_regex_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } } static zend_object* php_phongo_regex_create_object(zend_class_entry* class_type) diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index d3121b381..1bfb96f73 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -153,6 +153,9 @@ static void php_phongo_symbol_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } } zend_object* php_phongo_symbol_create_object(zend_class_entry* class_type) diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 0abfb92c5..577cd4adf 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -264,6 +264,9 @@ static void php_phongo_timestamp_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } } static zend_object* php_phongo_timestamp_create_object(zend_class_entry* class_type) diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index e14994da5..4f30d00d4 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -304,6 +304,9 @@ static void php_phongo_utcdatetime_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } } static zend_object* php_phongo_utcdatetime_create_object(zend_class_entry* class_type) diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index 8e6b1b067..228200614 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -186,6 +186,9 @@ static void php_phongo_readconcern_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } if (intern->read_concern) { mongoc_read_concern_destroy(intern->read_concern); diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index 1da231c14..3956e720b 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -486,6 +486,9 @@ static void php_phongo_readpreference_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } if (intern->read_preference) { mongoc_read_prefs_destroy(intern->read_preference); diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index 05a464048..47446ac15 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -214,6 +214,9 @@ static void php_phongo_serverapi_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } if (intern->server_api) { mongoc_server_api_destroy(intern->server_api); diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index adac4d992..5cb644f82 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -161,6 +161,9 @@ static void php_phongo_serverdescription_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } if (intern->server_description) { mongoc_server_description_destroy(intern->server_description); diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index 56135867e..ab07d3d46 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -110,6 +110,9 @@ static void php_phongo_topologydescription_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } if (intern->topology_description) { mongoc_topology_description_destroy(intern->topology_description); diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index 75ce0c50e..f51a5ac6d 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -371,6 +371,9 @@ static void php_phongo_writeconcern_free_object(zend_object* object) if (intern->properties) { zend_hash_release(intern->properties); } + if (intern->php_properties) { + zend_hash_release(intern->php_properties); + } if (intern->write_concern) { mongoc_write_concern_destroy(intern->write_concern); From 2c2199557aaefeed114641e7e70d381798d93cc3 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 23 Jul 2025 13:00:16 +0200 Subject: [PATCH 27/44] Setup handlers --- php_phongo.c | 47 -------------------- php_phongo.h | 73 +++++++++++++++++++++++++++++++ src/BSON/Binary.c | 7 +++ src/BSON/DBPointer.c | 7 +++ src/BSON/Decimal128.c | 7 +++ src/BSON/Int64.c | 7 +++ src/BSON/Iterator.c | 6 +++ src/BSON/Javascript.c | 7 +++ src/BSON/ObjectId.c | 7 +++ src/BSON/Regex.c | 7 +++ src/BSON/Symbol.c | 7 +++ src/BSON/Timestamp.c | 7 +++ src/BSON/UTCDateTime.c | 7 +++ src/MongoDB/ReadConcern.c | 7 +++ src/MongoDB/ReadPreference.c | 7 +++ src/MongoDB/ServerApi.c | 7 +++ src/MongoDB/ServerDescription.c | 7 +++ src/MongoDB/TopologyDescription.c | 7 +++ src/MongoDB/WriteConcern.c | 7 +++ 19 files changed, 191 insertions(+), 47 deletions(-) diff --git a/php_phongo.c b/php_phongo.c index b02180235..e8c2a08ba 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -162,48 +162,6 @@ static HashTable* php_phongo_std_get_gc(zend_object* object, zval** table, int* return object->handlers->get_properties(object); } -static zval* php_phongo_read_property(zend_object *object, zend_string *member, int type, void **cache_slot, zval *rv) -{ - return zend_hash_find(object->handlers->get_properties(object), member); -} - -static zval *php_phongo_write_property(zend_object *zobj, zend_string *name, zval *value, void **cache_slot) -{ - Z_TRY_ADDREF_P(value); - return zend_hash_add_new(zobj->handlers->get_properties(zobj), name, value); -} -static int php_phongo_has_property(zend_object *zobj, zend_string *name, int has_set_exists, void **cache_slot) -{ - zval *value = zend_hash_find(zobj->handlers->get_properties(zobj), name); - if (value) { - if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY) { - return zend_is_true(value); - } - if (has_set_exists < ZEND_PROPERTY_NOT_EMPTY) { - ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_ISSET); - ZVAL_DEREF(value); - return (Z_TYPE_P(value) != IS_NULL); - } - ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_EXISTS); - return true; - } - return false; -} -static void php_phongo_unset_property(zend_object *zobj, zend_string *name, void **cache_slot) -{ - zend_hash_del(zobj->handlers->get_properties(zobj), name); -} - -static zval *php_phongo_get_property_ptr_ptr(zend_object *zobj, zend_string *name, int type, void **cache_slot) -{ - HashTable *props = zobj->handlers->get_properties(zobj); - - zval *value = zend_hash_find(props, name); - if (value) { - return value; - } - return zend_hash_add(props, name, &EG(uninitialized_zval)); -} PHP_MINIT_FUNCTION(mongodb) /* {{{ */ { @@ -243,11 +201,6 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */ /* Ensure that get_gc delegates to zend_std_get_properties directly in case * our class defines a get_properties handler for debugging purposes. */ phongo_std_object_handlers.get_gc = php_phongo_std_get_gc; - phongo_std_object_handlers.read_property = php_phongo_read_property; - phongo_std_object_handlers.write_property = php_phongo_write_property; - phongo_std_object_handlers.has_property = php_phongo_has_property; - phongo_std_object_handlers.unset_property = php_phongo_unset_property; - phongo_std_object_handlers.get_property_ptr_ptr = php_phongo_get_property_ptr_ptr; /* Initialize zend_class_entry dependencies. * diff --git a/php_phongo.h b/php_phongo.h index 58e1f8259..1447a1f06 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -84,6 +84,79 @@ zend_object_handlers* phongo_get_std_object_handlers(void); } \ } while (0) +#define PHONGO_GET_PROPERTY_HANDLERS(_name, _intern_extractor) \ + static zval* php_phongo_##_name##_read_property(zend_object *zobj, zend_string *member, int type, void **cache_slot, zval *rv) \ + { \ + HashTable *props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + return zend_hash_find(props, member); \ + } \ + \ + static zval *php_phongo_##_name##_write_property(zend_object *zobj, zend_string *name, zval *value, void **cache_slot) \ + { \ + Z_TRY_ADDREF_P(value); \ + HashTable *props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + return zend_hash_add_new(props, name, value); \ + } \ + static int php_phongo_##_name##_has_property(zend_object *zobj, zend_string *name, int has_set_exists, void **cache_slot) \ + { \ + HashTable *props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + zval *value = zend_hash_find(props, name); \ + if (value) { \ + if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY) { \ + return zend_is_true(value); \ + } \ + if (has_set_exists < ZEND_PROPERTY_NOT_EMPTY) { \ + ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_ISSET); \ + ZVAL_DEREF(value); \ + return (Z_TYPE_P(value) != IS_NULL); \ + } \ + ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_EXISTS); \ + return true; \ + } \ + return false; \ + } \ + static void php_phongo_##_name##_unset_property(zend_object *zobj, zend_string *name, void **cache_slot) \ + { \ + HashTable *props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + zend_hash_del(props, name); \ + } \ + \ + static zval *php_phongo_##_name##_get_property_ptr_ptr(zend_object *zobj, zend_string *name, int type, void **cache_slot) \ + { \ + HashTable *props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + \ + zval *value = zend_hash_find(props, name); \ + if (value) { \ + return value; \ + } \ + return zend_hash_add(props, name, &EG(uninitialized_zval)); \ + } + #define PHONGO_ZVAL_EXCEPTION_NAME(e) (ZSTR_VAL(e->ce->name)) #define PHONGO_SET_CREATED_BY_PID(intern) \ diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index 3f90a7f52..b3fcebaed 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -283,6 +283,8 @@ static HashTable* php_phongo_binary_get_properties(zend_object* object) return php_phongo_binary_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(binary, Z_OBJ_BINARY); + void php_phongo_binary_init_ce(INIT_FUNC_ARGS) { php_phongo_binary_ce = register_class_MongoDB_BSON_Binary(php_phongo_binary_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -293,6 +295,11 @@ void php_phongo_binary_init_ce(INIT_FUNC_ARGS) php_phongo_handler_binary.clone_obj = php_phongo_binary_clone_object; php_phongo_handler_binary.get_debug_info = php_phongo_binary_get_debug_info; php_phongo_handler_binary.get_properties = php_phongo_binary_get_properties; + php_phongo_handler_binary.read_property = php_phongo_binary_read_property; + php_phongo_handler_binary.write_property = php_phongo_binary_write_property; + php_phongo_handler_binary.has_property = php_phongo_binary_has_property; + php_phongo_handler_binary.unset_property = php_phongo_binary_unset_property; + php_phongo_handler_binary.get_property_ptr_ptr = php_phongo_binary_get_property_ptr_ptr; php_phongo_handler_binary.free_obj = php_phongo_binary_free_object; php_phongo_handler_binary.offset = XtOffsetOf(php_phongo_binary_t, std); } diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index c751fe285..4a9b5b3e6 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -243,6 +243,8 @@ static HashTable* php_phongo_dbpointer_get_properties(zend_object* object) return php_phongo_dbpointer_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(dbpointer, Z_OBJ_DBPOINTER); + void php_phongo_dbpointer_init_ce(INIT_FUNC_ARGS) { php_phongo_dbpointer_ce = register_class_MongoDB_BSON_DBPointer(php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -253,6 +255,11 @@ void php_phongo_dbpointer_init_ce(INIT_FUNC_ARGS) php_phongo_handler_dbpointer.clone_obj = php_phongo_dbpointer_clone_object; php_phongo_handler_dbpointer.get_debug_info = php_phongo_dbpointer_get_debug_info; php_phongo_handler_dbpointer.get_properties = php_phongo_dbpointer_get_properties; + php_phongo_handler_dbpointer.read_property = php_phongo_dbpointer_read_property; + php_phongo_handler_dbpointer.write_property = php_phongo_dbpointer_write_property; + php_phongo_handler_dbpointer.has_property = php_phongo_dbpointer_has_property; + php_phongo_handler_dbpointer.unset_property = php_phongo_dbpointer_unset_property; + php_phongo_handler_dbpointer.get_property_ptr_ptr = php_phongo_dbpointer_get_property_ptr_ptr; php_phongo_handler_dbpointer.free_obj = php_phongo_dbpointer_free_object; php_phongo_handler_dbpointer.offset = XtOffsetOf(php_phongo_dbpointer_t, std); } diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 375f04e8c..1541ba80e 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -218,6 +218,8 @@ static HashTable* php_phongo_decimal128_get_properties(zend_object* object) return php_phongo_decimal128_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(decimal128, Z_OBJ_DECIMAL128); + void php_phongo_decimal128_init_ce(INIT_FUNC_ARGS) { php_phongo_decimal128_ce = register_class_MongoDB_BSON_Decimal128(php_phongo_decimal128_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -227,6 +229,11 @@ void php_phongo_decimal128_init_ce(INIT_FUNC_ARGS) php_phongo_handler_decimal128.clone_obj = php_phongo_decimal128_clone_object; php_phongo_handler_decimal128.get_debug_info = php_phongo_decimal128_get_debug_info; php_phongo_handler_decimal128.get_properties = php_phongo_decimal128_get_properties; + php_phongo_handler_decimal128.read_property = php_phongo_decimal128_read_property; + php_phongo_handler_decimal128.write_property = php_phongo_decimal128_write_property; + php_phongo_handler_decimal128.has_property = php_phongo_decimal128_has_property; + php_phongo_handler_decimal128.unset_property = php_phongo_decimal128_unset_property; + php_phongo_handler_decimal128.get_property_ptr_ptr = php_phongo_decimal128_get_property_ptr_ptr; php_phongo_handler_decimal128.free_obj = php_phongo_decimal128_free_object; php_phongo_handler_decimal128.offset = XtOffsetOf(php_phongo_decimal128_t, std); } diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index 781a0c845..e04bf861f 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -556,6 +556,8 @@ static HashTable* php_phongo_int64_get_properties(zend_object* object) return php_phongo_int64_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(int64, Z_OBJ_INT64); + void php_phongo_int64_init_ce(INIT_FUNC_ARGS) { php_phongo_int64_ce = register_class_MongoDB_BSON_Int64(php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -566,6 +568,11 @@ void php_phongo_int64_init_ce(INIT_FUNC_ARGS) php_phongo_handler_int64.clone_obj = php_phongo_int64_clone_object; php_phongo_handler_int64.get_debug_info = php_phongo_int64_get_debug_info; php_phongo_handler_int64.get_properties = php_phongo_int64_get_properties; + php_phongo_handler_int64.read_property = php_phongo_int64_read_property; + php_phongo_handler_int64.write_property = php_phongo_int64_write_property; + php_phongo_handler_int64.has_property = php_phongo_int64_has_property; + php_phongo_handler_int64.unset_property = php_phongo_int64_unset_property; + php_phongo_handler_int64.get_property_ptr_ptr = php_phongo_int64_get_property_ptr_ptr; php_phongo_handler_int64.free_obj = php_phongo_int64_free_object; php_phongo_handler_int64.offset = XtOffsetOf(php_phongo_int64_t, std); php_phongo_handler_int64.cast_object = php_phongo_int64_cast_object; diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index 66a962215..96db09fb0 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -379,6 +379,7 @@ static zend_object_iterator* php_phongo_iterator_get_iterator(zend_class_entry* return iterator; } +PHONGO_GET_PROPERTY_HANDLERS(iterator, Z_OBJ_ITERATOR); void php_phongo_iterator_init_ce(INIT_FUNC_ARGS) { @@ -390,6 +391,11 @@ void php_phongo_iterator_init_ce(INIT_FUNC_ARGS) php_phongo_handler_iterator.clone_obj = php_phongo_iterator_clone_object; php_phongo_handler_iterator.get_debug_info = php_phongo_iterator_get_debug_info; php_phongo_handler_iterator.get_properties = php_phongo_iterator_get_properties; + php_phongo_handler_iterator.read_property = php_phongo_iterator_read_property; + php_phongo_handler_iterator.write_property = php_phongo_iterator_write_property; + php_phongo_handler_iterator.has_property = php_phongo_iterator_has_property; + php_phongo_handler_iterator.unset_property = php_phongo_iterator_unset_property; + php_phongo_handler_iterator.get_property_ptr_ptr = php_phongo_iterator_get_property_ptr_ptr; php_phongo_handler_iterator.free_obj = php_phongo_iterator_free_object; php_phongo_handler_iterator.offset = XtOffsetOf(php_phongo_iterator_t, std); } diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index e65d5a756..f7ab6995a 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -324,6 +324,8 @@ static HashTable* php_phongo_javascript_get_properties(zend_object* object) return php_phongo_javascript_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(javascript, Z_OBJ_JAVASCRIPT); + void php_phongo_javascript_init_ce(INIT_FUNC_ARGS) { php_phongo_javascript_ce = register_class_MongoDB_BSON_Javascript(php_phongo_javascript_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -334,6 +336,11 @@ void php_phongo_javascript_init_ce(INIT_FUNC_ARGS) php_phongo_handler_javascript.clone_obj = php_phongo_javascript_clone_object; php_phongo_handler_javascript.get_debug_info = php_phongo_javascript_get_debug_info; php_phongo_handler_javascript.get_properties = php_phongo_javascript_get_properties; + php_phongo_handler_javascript.read_property = php_phongo_javascript_read_property; + php_phongo_handler_javascript.write_property = php_phongo_javascript_write_property; + php_phongo_handler_javascript.has_property = php_phongo_javascript_has_property; + php_phongo_handler_javascript.unset_property = php_phongo_javascript_unset_property; + php_phongo_handler_javascript.get_property_ptr_ptr = php_phongo_javascript_get_property_ptr_ptr; php_phongo_handler_javascript.free_obj = php_phongo_javascript_free_object; php_phongo_handler_javascript.offset = XtOffsetOf(php_phongo_javascript_t, std); } diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index b6cb38060..65c1e9936 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -265,6 +265,8 @@ static HashTable* php_phongo_objectid_get_properties(zend_object* object) return php_phongo_objectid_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(objectid, Z_OBJ_OBJECTID); + void php_phongo_objectid_init_ce(INIT_FUNC_ARGS) { php_phongo_objectid_ce = register_class_MongoDB_BSON_ObjectId(php_phongo_objectid_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -275,6 +277,11 @@ void php_phongo_objectid_init_ce(INIT_FUNC_ARGS) php_phongo_handler_objectid.clone_obj = php_phongo_objectid_clone_object; php_phongo_handler_objectid.get_debug_info = php_phongo_objectid_get_debug_info; php_phongo_handler_objectid.get_properties = php_phongo_objectid_get_properties; + php_phongo_handler_objectid.read_property = php_phongo_objectid_read_property; + php_phongo_handler_objectid.write_property = php_phongo_objectid_write_property; + php_phongo_handler_objectid.has_property = php_phongo_objectid_has_property; + php_phongo_handler_objectid.unset_property = php_phongo_objectid_unset_property; + php_phongo_handler_objectid.get_property_ptr_ptr = php_phongo_objectid_get_property_ptr_ptr; php_phongo_handler_objectid.free_obj = php_phongo_objectid_free_object; php_phongo_handler_objectid.offset = XtOffsetOf(php_phongo_objectid_t, std); } diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index 16f8746a9..84cc0dbaa 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -296,6 +296,8 @@ static HashTable* php_phongo_regex_get_properties(zend_object* object) return php_phongo_regex_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(regex, Z_OBJ_REGEX); + void php_phongo_regex_init_ce(INIT_FUNC_ARGS) { php_phongo_regex_ce = register_class_MongoDB_BSON_Regex(php_phongo_regex_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -306,6 +308,11 @@ void php_phongo_regex_init_ce(INIT_FUNC_ARGS) php_phongo_handler_regex.clone_obj = php_phongo_regex_clone_object; php_phongo_handler_regex.get_debug_info = php_phongo_regex_get_debug_info; php_phongo_handler_regex.get_properties = php_phongo_regex_get_properties; + php_phongo_handler_regex.read_property = php_phongo_regex_read_property; + php_phongo_handler_regex.write_property = php_phongo_regex_write_property; + php_phongo_handler_regex.has_property = php_phongo_regex_has_property; + php_phongo_handler_regex.unset_property = php_phongo_regex_unset_property; + php_phongo_handler_regex.get_property_ptr_ptr = php_phongo_regex_get_property_ptr_ptr; php_phongo_handler_regex.free_obj = php_phongo_regex_free_object; php_phongo_handler_regex.offset = XtOffsetOf(php_phongo_regex_t, std); } diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index 1bfb96f73..aed3c4b16 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -210,6 +210,8 @@ static HashTable* php_phongo_symbol_get_properties(zend_object* object) return php_phongo_symbol_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(symbol, Z_OBJ_SYMBOL); + void php_phongo_symbol_init_ce(INIT_FUNC_ARGS) { php_phongo_symbol_ce = register_class_MongoDB_BSON_Symbol(php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -220,6 +222,11 @@ void php_phongo_symbol_init_ce(INIT_FUNC_ARGS) php_phongo_handler_symbol.clone_obj = php_phongo_symbol_clone_object; php_phongo_handler_symbol.get_debug_info = php_phongo_symbol_get_debug_info; php_phongo_handler_symbol.get_properties = php_phongo_symbol_get_properties; + php_phongo_handler_symbol.read_property = php_phongo_symbol_read_property; + php_phongo_handler_symbol.write_property = php_phongo_symbol_write_property; + php_phongo_handler_symbol.has_property = php_phongo_symbol_has_property; + php_phongo_handler_symbol.unset_property = php_phongo_symbol_unset_property; + php_phongo_handler_symbol.get_property_ptr_ptr = php_phongo_symbol_get_property_ptr_ptr; php_phongo_handler_symbol.free_obj = php_phongo_symbol_free_object; php_phongo_handler_symbol.offset = XtOffsetOf(php_phongo_symbol_t, std); } diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 577cd4adf..dff703837 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -330,6 +330,8 @@ static HashTable* php_phongo_timestamp_get_properties(zend_object* object) return php_phongo_timestamp_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(timestamp, Z_OBJ_TIMESTAMP); + void php_phongo_timestamp_init_ce(INIT_FUNC_ARGS) { php_phongo_timestamp_ce = register_class_MongoDB_BSON_Timestamp(php_phongo_timestamp_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -340,6 +342,11 @@ void php_phongo_timestamp_init_ce(INIT_FUNC_ARGS) php_phongo_handler_timestamp.clone_obj = php_phongo_timestamp_clone_object; php_phongo_handler_timestamp.get_debug_info = php_phongo_timestamp_get_debug_info; php_phongo_handler_timestamp.get_properties = php_phongo_timestamp_get_properties; + php_phongo_handler_timestamp.read_property = php_phongo_timestamp_read_property; + php_phongo_handler_timestamp.write_property = php_phongo_timestamp_write_property; + php_phongo_handler_timestamp.has_property = php_phongo_timestamp_has_property; + php_phongo_handler_timestamp.unset_property = php_phongo_timestamp_unset_property; + php_phongo_handler_timestamp.get_property_ptr_ptr = php_phongo_timestamp_get_property_ptr_ptr; php_phongo_handler_timestamp.free_obj = php_phongo_timestamp_free_object; php_phongo_handler_timestamp.offset = XtOffsetOf(php_phongo_timestamp_t, std); } diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index 4f30d00d4..db40f6a12 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -365,6 +365,8 @@ static HashTable* php_phongo_utcdatetime_get_properties(zend_object* object) return php_phongo_utcdatetime_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(utc_datetime, Z_OBJ_UTCDATETIME); + void php_phongo_utcdatetime_init_ce(INIT_FUNC_ARGS) { php_phongo_utcdatetime_ce = register_class_MongoDB_BSON_UTCDateTime(php_phongo_utcdatetime_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -375,6 +377,11 @@ void php_phongo_utcdatetime_init_ce(INIT_FUNC_ARGS) php_phongo_handler_utcdatetime.clone_obj = php_phongo_utcdatetime_clone_object; php_phongo_handler_utcdatetime.get_debug_info = php_phongo_utcdatetime_get_debug_info; php_phongo_handler_utcdatetime.get_properties = php_phongo_utcdatetime_get_properties; + php_phongo_handler_utcdatetime.read_property = php_phongo_utcdatetime_read_property; + php_phongo_handler_utcdatetime.write_property = php_phongo_utcdatetime_write_property; + php_phongo_handler_utcdatetime.has_property = php_phongo_utcdatetime_has_property; + php_phongo_handler_utcdatetime.unset_property = php_phongo_utcdatetime_unset_property; + php_phongo_handler_utcdatetime.get_property_ptr_ptr = php_phongo_utcdatetime_get_property_ptr_ptr; php_phongo_handler_utcdatetime.free_obj = php_phongo_utcdatetime_free_object; php_phongo_handler_utcdatetime.offset = XtOffsetOf(php_phongo_utcdatetime_t, std); } diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index 228200614..d10968150 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -218,6 +218,8 @@ static HashTable* php_phongo_readconcern_get_properties(zend_object* object) return php_phongo_readconcern_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(read_concern, Z_OBJ_READCONCERN); + void php_phongo_readconcern_init_ce(INIT_FUNC_ARGS) { php_phongo_readconcern_ce = register_class_MongoDB_Driver_ReadConcern(php_phongo_serializable_ce); @@ -226,6 +228,11 @@ void php_phongo_readconcern_init_ce(INIT_FUNC_ARGS) memcpy(&php_phongo_handler_readconcern, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); php_phongo_handler_readconcern.get_debug_info = php_phongo_readconcern_get_debug_info; php_phongo_handler_readconcern.get_properties = php_phongo_readconcern_get_properties; + php_phongo_handler_readconcern.read_property = php_phongo_readconcern_read_property; + php_phongo_handler_readconcern.write_property = php_phongo_readconcern_write_property; + php_phongo_handler_readconcern.has_property = php_phongo_readconcern_has_property; + php_phongo_handler_readconcern.unset_property = php_phongo_readconcern_unset_property; + php_phongo_handler_readconcern.get_property_ptr_ptr = php_phongo_readconcern_get_property_ptr_ptr; php_phongo_handler_readconcern.free_obj = php_phongo_readconcern_free_object; php_phongo_handler_readconcern.offset = XtOffsetOf(php_phongo_readconcern_t, std); } diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index 3956e720b..3fbeff727 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -518,6 +518,8 @@ static HashTable* php_phongo_readpreference_get_properties(zend_object* object) return php_phongo_readpreference_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(readpreference, Z_OBJ_READPREFERENCE); + void php_phongo_readpreference_init_ce(INIT_FUNC_ARGS) { php_phongo_readpreference_ce = register_class_MongoDB_Driver_ReadPreference(php_phongo_serializable_ce); @@ -526,6 +528,11 @@ void php_phongo_readpreference_init_ce(INIT_FUNC_ARGS) memcpy(&php_phongo_handler_readpreference, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); php_phongo_handler_readpreference.get_debug_info = php_phongo_readpreference_get_debug_info; php_phongo_handler_readpreference.get_properties = php_phongo_readpreference_get_properties; + php_phongo_handler_readpreference.read_property = php_phongo_readpreference_read_property; + php_phongo_handler_readpreference.write_property = php_phongo_readpreference_write_property; + php_phongo_handler_readpreference.has_property = php_phongo_readpreference_has_property; + php_phongo_handler_readpreference.unset_property = php_phongo_readpreference_unset_property; + php_phongo_handler_readpreference.get_property_ptr_ptr = php_phongo_readpreference_get_property_ptr_ptr; php_phongo_handler_readpreference.free_obj = php_phongo_readpreference_free_object; php_phongo_handler_readpreference.offset = XtOffsetOf(php_phongo_readpreference_t, std); } diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index 47446ac15..d496ab407 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -246,6 +246,8 @@ static HashTable* php_phongo_serverapi_get_properties(zend_object* object) return php_phongo_serverapi_get_properties_hash(object, false, true); } +PHONGO_GET_PROPERTY_HANDLERS(serverapi, Z_OBJ_SERVERAPI); + void php_phongo_serverapi_init_ce(INIT_FUNC_ARGS) { php_phongo_serverapi_ce = register_class_MongoDB_Driver_ServerApi(php_phongo_serializable_ce); @@ -254,6 +256,11 @@ void php_phongo_serverapi_init_ce(INIT_FUNC_ARGS) memcpy(&php_phongo_handler_serverapi, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); php_phongo_handler_serverapi.get_debug_info = php_phongo_serverapi_get_debug_info; php_phongo_handler_serverapi.get_properties = php_phongo_serverapi_get_properties; + php_phongo_handler_serverapi.read_property = php_phongo_serverapi_read_property; + php_phongo_handler_serverapi.write_property = php_phongo_serverapi_write_property; + php_phongo_handler_serverapi.has_property = php_phongo_serverapi_has_property; + php_phongo_handler_serverapi.unset_property = php_phongo_serverapi_unset_property; + php_phongo_handler_serverapi.get_property_ptr_ptr = php_phongo_serverapi_get_property_ptr_ptr; php_phongo_handler_serverapi.free_obj = php_phongo_serverapi_free_object; php_phongo_handler_serverapi.offset = XtOffsetOf(php_phongo_serverapi_t, std); } diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index 5cb644f82..8fafb7329 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -269,6 +269,8 @@ static HashTable* php_phongo_serverdescription_get_properties(zend_object* objec return php_phongo_serverdescription_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(serverdescription, Z_OBJ_SERVERDESCRIPTION); + void php_phongo_serverdescription_init_ce(INIT_FUNC_ARGS) { php_phongo_serverdescription_ce = register_class_MongoDB_Driver_ServerDescription(); @@ -277,6 +279,11 @@ void php_phongo_serverdescription_init_ce(INIT_FUNC_ARGS) memcpy(&php_phongo_handler_serverdescription, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); php_phongo_handler_serverdescription.get_debug_info = php_phongo_serverdescription_get_debug_info; php_phongo_handler_serverdescription.get_properties = php_phongo_serverdescription_get_properties; + php_phongo_handler_serverdescription.read_property = php_phongo_serverdescription_read_property; + php_phongo_handler_serverdescription.write_property = php_phongo_serverdescription_write_property; + php_phongo_handler_serverdescription.has_property = php_phongo_serverdescription_has_property; + php_phongo_handler_serverdescription.unset_property = php_phongo_serverdescription_unset_property; + php_phongo_handler_serverdescription.get_property_ptr_ptr = php_phongo_serverdescription_get_property_ptr_ptr; php_phongo_handler_serverdescription.free_obj = php_phongo_serverdescription_free_object; php_phongo_handler_serverdescription.offset = XtOffsetOf(php_phongo_serverdescription_t, std); } diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index ab07d3d46..4cede8eb2 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -182,6 +182,8 @@ static HashTable* php_phongo_topologydescription_get_properties(zend_object* obj return php_phongo_topologydescription_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(topologydescription, Z_OBJ_TOPOLOGYDESCRIPTION); + void php_phongo_topologydescription_init_ce(INIT_FUNC_ARGS) { php_phongo_topologydescription_ce = register_class_MongoDB_Driver_TopologyDescription(); @@ -190,6 +192,11 @@ void php_phongo_topologydescription_init_ce(INIT_FUNC_ARGS) memcpy(&php_phongo_handler_topologydescription, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); php_phongo_handler_topologydescription.get_debug_info = php_phongo_topologydescription_get_debug_info; php_phongo_handler_topologydescription.get_properties = php_phongo_topologydescription_get_properties; + php_phongo_handler_topologydescription.read_property = php_phongo_topologydescription_read_property; + php_phongo_handler_topologydescription.write_property = php_phongo_topologydescription_write_property; + php_phongo_handler_topologydescription.has_property = php_phongo_topologydescription_has_property; + php_phongo_handler_topologydescription.unset_property = php_phongo_topologydescription_unset_property; + php_phongo_handler_topologydescription.get_property_ptr_ptr = php_phongo_topologydescription_get_property_ptr_ptr; php_phongo_handler_topologydescription.free_obj = php_phongo_topologydescription_free_object; php_phongo_handler_topologydescription.offset = XtOffsetOf(php_phongo_topologydescription_t, std); } diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index f51a5ac6d..1b712a8d0 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -403,6 +403,8 @@ static HashTable* php_phongo_writeconcern_get_properties(zend_object* object) return php_phongo_writeconcern_get_properties_hash(object, false, false, false); } +PHONGO_GET_PROPERTY_HANDLERS(writeconcern, Z_OBJ_WRITECONCERN); + void php_phongo_writeconcern_init_ce(INIT_FUNC_ARGS) { php_phongo_writeconcern_ce = register_class_MongoDB_Driver_WriteConcern(php_phongo_serializable_ce); @@ -411,6 +413,11 @@ void php_phongo_writeconcern_init_ce(INIT_FUNC_ARGS) memcpy(&php_phongo_handler_writeconcern, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); php_phongo_handler_writeconcern.get_debug_info = php_phongo_writeconcern_get_debug_info; php_phongo_handler_writeconcern.get_properties = php_phongo_writeconcern_get_properties; + php_phongo_handler_writeconcern.read_property = php_phongo_writeconcern_read_property; + php_phongo_handler_writeconcern.write_property = php_phongo_writeconcern_write_property; + php_phongo_handler_writeconcern.has_property = php_phongo_writeconcern_has_property; + php_phongo_handler_writeconcern.unset_property = php_phongo_writeconcern_unset_property; + php_phongo_handler_writeconcern.get_property_ptr_ptr = php_phongo_writeconcern_get_property_ptr_ptr; php_phongo_handler_writeconcern.free_obj = php_phongo_writeconcern_free_object; php_phongo_handler_writeconcern.offset = XtOffsetOf(php_phongo_writeconcern_t, std); } From efb8c749969b357d9250fed680227c1fa3a3f8a8 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 23 Jul 2025 13:01:34 +0200 Subject: [PATCH 28/44] Setup handlers --- src/BSON/PackedArray.c | 7 +++++++ src/BSON/UTCDateTime.c | 2 +- src/MongoDB/ReadConcern.c | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index ad51e2e79..1227ca8d7 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -566,6 +566,8 @@ void php_phongo_packedarray_unset_dimension(zend_object* object, zval* offset) phongo_throw_exception(PHONGO_ERROR_LOGIC, "Cannot unset %s offset", ZSTR_VAL(php_phongo_packedarray_ce->name)); } +PHONGO_GET_PROPERTY_HANDLERS(packedarray, Z_OBJ_PACKEDARRAY); + void php_phongo_packedarray_init_ce(INIT_FUNC_ARGS) { php_phongo_packedarray_ce = register_class_MongoDB_BSON_PackedArray(zend_ce_aggregate, zend_ce_arrayaccess, php_phongo_type_ce, zend_ce_stringable); @@ -576,6 +578,11 @@ void php_phongo_packedarray_init_ce(INIT_FUNC_ARGS) php_phongo_handler_packedarray.clone_obj = php_phongo_packedarray_clone_object; php_phongo_handler_packedarray.get_debug_info = php_phongo_packedarray_get_debug_info; php_phongo_handler_packedarray.get_properties = php_phongo_packedarray_get_properties; + php_phongo_handler_packedarray.read_property = php_phongo_packedarray_read_property; + php_phongo_handler_packedarray.write_property = php_phongo_packedarray_write_property; + php_phongo_handler_packedarray.has_property = php_phongo_packedarray_has_property; + php_phongo_handler_packedarray.unset_property = php_phongo_packedarray_unset_property; + php_phongo_handler_packedarray.get_property_ptr_ptr = php_phongo_packedarray_get_property_ptr_ptr; php_phongo_handler_packedarray.free_obj = php_phongo_packedarray_free_object; php_phongo_handler_packedarray.read_dimension = php_phongo_packedarray_read_dimension; php_phongo_handler_packedarray.write_dimension = php_phongo_packedarray_write_dimension; diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index db40f6a12..d9c7b2f0f 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -365,7 +365,7 @@ static HashTable* php_phongo_utcdatetime_get_properties(zend_object* object) return php_phongo_utcdatetime_get_properties_hash(object, false); } -PHONGO_GET_PROPERTY_HANDLERS(utc_datetime, Z_OBJ_UTCDATETIME); +PHONGO_GET_PROPERTY_HANDLERS(utcdatetime, Z_OBJ_UTCDATETIME); void php_phongo_utcdatetime_init_ce(INIT_FUNC_ARGS) { diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index d10968150..14f3e5868 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -218,7 +218,7 @@ static HashTable* php_phongo_readconcern_get_properties(zend_object* object) return php_phongo_readconcern_get_properties_hash(object, false); } -PHONGO_GET_PROPERTY_HANDLERS(read_concern, Z_OBJ_READCONCERN); +PHONGO_GET_PROPERTY_HANDLERS(readconcern, Z_OBJ_READCONCERN); void php_phongo_readconcern_init_ce(INIT_FUNC_ARGS) { From 9d66170424a504077e97987b172fc86dc607294c Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Wed, 23 Jul 2025 14:17:33 +0200 Subject: [PATCH 29/44] Testi --- php_phongo.h | 4 +++- src/BSON/Binary.c | 9 +++++++-- src/BSON/DBPointer.c | 9 +++++++-- src/BSON/Decimal128.c | 9 +++++++-- src/BSON/Document.c | 9 +++++++-- src/BSON/Int64.c | 9 +++++++-- src/BSON/Iterator.c | 9 +++++++-- src/BSON/Javascript.c | 9 +++++++-- src/BSON/ObjectId.c | 12 ++++++++++-- src/BSON/PackedArray.c | 9 +++++++-- src/BSON/Regex.c | 9 +++++++-- src/BSON/Symbol.c | 9 +++++++-- src/BSON/Timestamp.c | 9 +++++++-- src/BSON/UTCDateTime.c | 9 +++++++-- src/MongoDB/ReadConcern.c | 9 +++++++-- src/MongoDB/ReadPreference.c | 9 +++++++-- src/MongoDB/ServerApi.c | 9 +++++++-- src/MongoDB/ServerDescription.c | 9 +++++++-- src/MongoDB/TopologyDescription.c | 9 +++++++-- src/MongoDB/WriteConcern.c | 9 +++++++-- 20 files changed, 139 insertions(+), 39 deletions(-) diff --git a/php_phongo.h b/php_phongo.h index 1447a1f06..c2a1e873b 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -70,7 +70,9 @@ zend_object_handlers* phongo_get_std_object_handlers(void); (props) = zend_array_dup((intern)->php_properties); \ } else { \ if ((intern)->properties) { \ - zend_hash_release(intern->properties); \ + (props) = (intern)->properties; \ + (intern)->properties = NULL; \ + zend_hash_release(props); \ } \ (props) = zend_array_dup((intern)->php_properties); \ (intern)->properties = (props); \ diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index b3fcebaed..615157812 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -213,11 +213,16 @@ static void php_phongo_binary_free_object(zend_object* object) efree(intern->data); } + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index 4a9b5b3e6..af1cd9a88 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -176,11 +176,16 @@ static void php_phongo_dbpointer_free_object(zend_object* object) efree(intern->ref); } + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 1541ba80e..5875af284 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -168,11 +168,16 @@ static void php_phongo_decimal128_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } diff --git a/src/BSON/Document.c b/src/BSON/Document.c index 9a375a250..fd63454b7 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -446,11 +446,16 @@ static void php_phongo_document_free_object(zend_object* object) bson_destroy(intern->bson); } + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index e04bf861f..e7e6a000c 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -175,11 +175,16 @@ static void php_phongo_int64_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index 96db09fb0..e1f405aa0 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -248,11 +248,16 @@ static void php_phongo_iterator_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } php_phongo_iterator_free_current(intern); diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index f7ab6995a..79bc00f8d 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -262,11 +262,16 @@ static void php_phongo_javascript_free_object(zend_object* object) intern->scope = NULL; } + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 65c1e9936..41c7e3393 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -96,6 +96,9 @@ static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object, b ZVAL_STRING(&zv, intern->oid); zend_hash_str_update(props, "oid", sizeof("oid") - 1, &zv); } + if (!is_temp) { + GC_ADDREF(props); + } return props; } @@ -202,11 +205,16 @@ static void php_phongo_objectid_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index 1227ca8d7..897059d48 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -430,11 +430,16 @@ static void php_phongo_packedarray_free_object(zend_object* object) bson_destroy(intern->bson); } + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index 84cc0dbaa..6f8055b69 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -228,11 +228,16 @@ static void php_phongo_regex_free_object(zend_object* object) efree(intern->flags); } + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index aed3c4b16..a6b2cb2fe 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -150,11 +150,16 @@ static void php_phongo_symbol_free_object(zend_object* object) efree(intern->symbol); } + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index dff703837..f88f7f876 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -261,11 +261,16 @@ static void php_phongo_timestamp_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index d9c7b2f0f..d66feb4bf 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -301,11 +301,16 @@ static void php_phongo_utcdatetime_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index 14f3e5868..b633e5ae5 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -183,11 +183,16 @@ static void php_phongo_readconcern_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } if (intern->read_concern) { diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index 3fbeff727..d4f8a50ff 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -483,11 +483,16 @@ static void php_phongo_readpreference_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } if (intern->read_preference) { diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index d496ab407..7c2bf29f8 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -211,11 +211,16 @@ static void php_phongo_serverapi_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } if (intern->server_api) { diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index 8fafb7329..629c58757 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -158,11 +158,16 @@ static void php_phongo_serverdescription_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } if (intern->server_description) { diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index 4cede8eb2..fcdd36bb4 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -107,11 +107,16 @@ static void php_phongo_topologydescription_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } if (intern->topology_description) { diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index 1b712a8d0..bc7936049 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -368,11 +368,16 @@ static void php_phongo_writeconcern_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_release(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); } if (intern->php_properties) { - zend_hash_release(intern->php_properties); + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } if (intern->write_concern) { From be65b64be6fdb87019835c703a10ed47746a324c Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 24 Jul 2025 11:36:08 +0200 Subject: [PATCH 30/44] Fixup ordering --- php_phongo.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/php_phongo.h b/php_phongo.h index c2a1e873b..04d73e1bb 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -65,16 +65,17 @@ zend_object_handlers* phongo_get_std_object_handlers(void); if (!(intern)->php_properties) { \ ALLOC_HASHTABLE((intern)->php_properties); \ zend_hash_init((intern)->php_properties, 0, NULL, ZVAL_PTR_DTOR, 0); \ + GC_ADDREF((intern)->php_properties); \ } \ if (is_temp) { \ (props) = zend_array_dup((intern)->php_properties); \ } else { \ + (props) = zend_array_dup((intern)->php_properties); \ if ((intern)->properties) { \ - (props) = (intern)->properties; \ + HashTable *__tmp = (intern)->properties; \ (intern)->properties = NULL; \ - zend_hash_release(props); \ + zend_hash_release(__tmp); \ } \ - (props) = zend_array_dup((intern)->php_properties); \ (intern)->properties = (props); \ } \ } while (0) From 7850762710d5ab9795b249b7dcea6946078cd3ae Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 24 Jul 2025 11:45:09 +0200 Subject: [PATCH 31/44] Fixup --- php_phongo.h | 6 ++++++ src/BSON/Binary.c | 4 ++-- src/BSON/DBPointer.c | 4 ++-- src/BSON/Decimal128.c | 4 ++-- src/BSON/Document.c | 6 +++--- src/BSON/Int64.c | 4 ++-- src/BSON/Iterator.c | 2 +- src/BSON/Javascript.c | 4 ++-- src/BSON/ObjectId.c | 7 ++----- src/BSON/PackedArray.c | 6 +++--- src/BSON/Regex.c | 4 ++-- src/BSON/Symbol.c | 4 ++-- src/BSON/Timestamp.c | 4 ++-- src/BSON/UTCDateTime.c | 4 ++-- src/MongoDB/ReadConcern.c | 4 ++-- src/MongoDB/ReadPreference.c | 4 ++-- src/MongoDB/ServerApi.c | 2 +- src/MongoDB/ServerDescription.c | 4 ++-- src/MongoDB/TopologyDescription.c | 4 ++-- src/MongoDB/WriteConcern.c | 4 ++-- 20 files changed, 44 insertions(+), 41 deletions(-) diff --git a/php_phongo.h b/php_phongo.h index 04d73e1bb..596e27a86 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -60,6 +60,12 @@ ZEND_TSRMLS_CACHE_EXTERN() zend_object_handlers* phongo_get_std_object_handlers(void); +#define PHONGO_RETURN_PROPS(is_temp, props) \ + if (!(is_temp)) { \ + GC_ADDREF(props); \ + } \ + return props; + #define PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size) \ do { \ if (!(intern)->php_properties) { \ diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index 615157812..e3aa7e877 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -73,7 +73,7 @@ static HashTable* php_phongo_binary_get_properties_hash(zend_object* object, boo PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->data) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -86,7 +86,7 @@ static HashTable* php_phongo_binary_get_properties_hash(zend_object* object, boo zend_hash_str_update(props, "type", sizeof("type") - 1, &type); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } /* Construct a new BSON binary type */ diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index af1cd9a88..af63f45e2 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -74,7 +74,7 @@ HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object, bool is PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->ref) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -86,7 +86,7 @@ HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object, bool is zend_hash_str_update(props, "id", sizeof("id") - 1, &id); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_DBPointer) diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 5875af284..078eeac8a 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -64,7 +64,7 @@ static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object, PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->initialized) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } bson_decimal128_to_string(&intern->decimal, outbuf); @@ -76,7 +76,7 @@ static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object, zend_hash_str_update(props, "dec", sizeof("dec") - 1, &dec); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } /* Construct a new BSON Decimal128 type */ diff --git a/src/BSON/Document.c b/src/BSON/Document.c index fd63454b7..8bd26a6ae 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -65,7 +65,7 @@ static HashTable* php_phongo_document_get_properties_hash(zend_object* object, b PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size); if (!intern->bson) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -75,7 +75,7 @@ static HashTable* php_phongo_document_get_properties_hash(zend_object* object, b zend_hash_str_update(props, "data", sizeof("data") - 1, &data); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_Document) @@ -527,7 +527,7 @@ static HashTable* php_phongo_document_get_debug_info(zend_object* object, int* i zend_hash_str_update(props, "value", sizeof("value") - 1, &state.zchild); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); failure: PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index e7e6a000c..7ac0efb3f 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -72,7 +72,7 @@ HashTable* php_phongo_int64_get_properties_hash(zend_object* object, bool is_tem PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->initialized) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -82,7 +82,7 @@ HashTable* php_phongo_int64_get_properties_hash(zend_object* object, bool is_tem zend_hash_str_update(props, "integer", sizeof("integer") - 1, &value); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } static PHP_METHOD(MongoDB_BSON_Int64, __construct) diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index e1f405aa0..b285e459d 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -165,7 +165,7 @@ static HashTable* php_phongo_iterator_get_properties_hash(zend_object* object, b zend_hash_str_update(props, "bson", sizeof("bson") - 1, &intern->bson); Z_TRY_ADDREF(intern->bson); - return props; + PHONGO_RETURN_PROPS(is_temp, props); } PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_Iterator) diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index 79bc00f8d..4c9ce6af6 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -79,7 +79,7 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object, bool i PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->code) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -106,7 +106,7 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object, bool i } } - return props; + PHONGO_RETURN_PROPS(is_temp, props); failure: PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 41c7e3393..4e6a460fe 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -87,7 +87,7 @@ static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object, b PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->initialized) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -96,11 +96,8 @@ static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object, b ZVAL_STRING(&zv, intern->oid); zend_hash_str_update(props, "oid", sizeof("oid") - 1, &zv); } - if (!is_temp) { - GC_ADDREF(props); - } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } /* Constructs a new BSON ObjectId type, optionally from a hex string. */ diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index 897059d48..2d6ce8b33 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -66,7 +66,7 @@ static HashTable* php_phongo_packedarray_get_properties_hash(zend_object* object PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size); if (!intern->bson) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -76,7 +76,7 @@ static HashTable* php_phongo_packedarray_get_properties_hash(zend_object* object zend_hash_str_update(props, "data", sizeof("data") - 1, &data); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } static bool php_phongo_packedarray_to_json(zval* return_value, bson_json_mode_t mode, const bson_t* bson) @@ -512,7 +512,7 @@ static HashTable* php_phongo_packedarray_get_debug_info(zend_object* object, int zend_hash_str_update(props, "value", sizeof("value") - 1, &state.zchild); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); failure: PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index 6f8055b69..b25f9620b 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -88,7 +88,7 @@ static HashTable* php_phongo_regex_get_properties_hash(zend_object* object, bool PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->pattern) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -101,7 +101,7 @@ static HashTable* php_phongo_regex_get_properties_hash(zend_object* object, bool zend_hash_str_update(props, "flags", sizeof("flags") - 1, &flags); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } /* Constructs a new BSON regular expression type. */ diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index a6b2cb2fe..20ed21a09 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -62,7 +62,7 @@ HashTable* php_phongo_symbol_get_properties_hash(zend_object* object, bool is_te PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->symbol) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -72,7 +72,7 @@ HashTable* php_phongo_symbol_get_properties_hash(zend_object* object, bool is_te zend_hash_str_update(props, "symbol", sizeof("symbol") - 1, &symbol); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_Symbol) diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index f88f7f876..66121d325 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -99,7 +99,7 @@ static HashTable* php_phongo_timestamp_get_properties_hash(zend_object* object, PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->initialized) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } s_increment_len = snprintf(s_increment, sizeof(s_increment), "%" PRIu32, intern->increment); @@ -115,7 +115,7 @@ static HashTable* php_phongo_timestamp_get_properties_hash(zend_object* object, zend_hash_str_update(props, "timestamp", sizeof("timestamp") - 1, ×tamp); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } /* Construct a new BSON timestamp type, which consists of a 4-byte increment and diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index d66feb4bf..6af94f7b7 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -131,7 +131,7 @@ static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->initialized) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -141,7 +141,7 @@ static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object zend_hash_str_update(props, "milliseconds", sizeof("milliseconds") - 1, &milliseconds); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } static void php_phongo_utcdatetime_to_php_date(zval* return_value, const zval* this, zend_class_entry* ce) diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index b633e5ae5..af0eaafac 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -133,7 +133,7 @@ static HashTable* php_phongo_readconcern_get_properties_hash(zend_object* object PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->read_concern) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } level = mongoc_read_concern_get_level(intern->read_concern); @@ -145,7 +145,7 @@ static HashTable* php_phongo_readconcern_get_properties_hash(zend_object* object zend_hash_str_update(props, "level", sizeof("level") - 1, &z_level); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } static PHP_METHOD(MongoDB_Driver_ReadConcern, bsonSerialize) diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index d4f8a50ff..e8955bc24 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -392,7 +392,7 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zend_object* obj PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 4); if (!intern->read_preference) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } tags = mongoc_read_prefs_get_tags(intern->read_preference); @@ -445,7 +445,7 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zend_object* obj } done: - return props; + PHONGO_RETURN_PROPS(is_temp, props); } static PHP_METHOD(MongoDB_Driver_ReadPreference, bsonSerialize) diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index 7c2bf29f8..899df8bc1 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -173,7 +173,7 @@ static HashTable* php_phongo_serverapi_get_properties_hash(zend_object* object, zend_hash_str_add(props, "deprecationErrors", sizeof("deprecationErrors") - 1, &deprecation_errors); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } static PHP_METHOD(MongoDB_Driver_ServerApi, bsonSerialize) diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index 629c58757..1c0e88900 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -197,7 +197,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object, PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 6); if (!intern->server_description) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -260,7 +260,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object, } done: - return props; + PHONGO_RETURN_PROPS(is_temp, props); } static HashTable* php_phongo_serverdescription_get_debug_info(zend_object* object, int* is_temp) diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index fcdd36bb4..2246e8651 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -146,7 +146,7 @@ HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* objec PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 2); if (!intern->topology_description) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -173,7 +173,7 @@ HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* objec zend_hash_str_update(props, "type", sizeof("type") - 1, &type); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } static HashTable* php_phongo_topologydescription_get_debug_info(zend_object* object, int* is_temp) diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index bc7936049..2510619b0 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -275,7 +275,7 @@ static HashTable* php_phongo_writeconcern_get_properties_hash(zend_object* objec PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 4); if (!intern->write_concern) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } wtag = mongoc_write_concern_get_wtag(intern->write_concern); @@ -330,7 +330,7 @@ static HashTable* php_phongo_writeconcern_get_properties_hash(zend_object* objec } } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } static PHP_METHOD(MongoDB_Driver_WriteConcern, bsonSerialize) From 458469856f3b8b2db58101ce5d3ab7b51fed0c32 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 24 Jul 2025 11:46:03 +0200 Subject: [PATCH 32/44] Fixup --- src/MongoDB/ServerDescription.c | 4 ++-- src/MongoDB/TopologyDescription.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index 1c0e88900..9508d95d3 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -197,7 +197,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object, PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 6); if (!intern->server_description) { - PHONGO_RETURN_PROPS(is_temp, props); + PHONGO_RETURN_PROPS(is_debug, props); } { @@ -260,7 +260,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object, } done: - PHONGO_RETURN_PROPS(is_temp, props); + PHONGO_RETURN_PROPS(is_debug, props); } static HashTable* php_phongo_serverdescription_get_debug_info(zend_object* object, int* is_temp) diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index 2246e8651..ecbe54547 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -146,7 +146,7 @@ HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* objec PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 2); if (!intern->topology_description) { - PHONGO_RETURN_PROPS(is_temp, props); + PHONGO_RETURN_PROPS(is_debug, props); } { @@ -173,7 +173,7 @@ HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* objec zend_hash_str_update(props, "type", sizeof("type") - 1, &type); } - PHONGO_RETURN_PROPS(is_temp, props); + PHONGO_RETURN_PROPS(is_debug, props); } static HashTable* php_phongo_topologydescription_get_debug_info(zend_object* object, int* is_temp) From 7cd8bc2f1e413975dcb12c22fc8efa42c313bf18 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 24 Jul 2025 12:10:10 +0200 Subject: [PATCH 33/44] Bump --- php_phongo.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/php_phongo.c b/php_phongo.c index e8c2a08ba..710cff685 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -198,8 +198,6 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */ /* Disable cloning by default. Individual classes can opt in if they need to * support this (e.g. BSON objects). */ phongo_std_object_handlers.clone_obj = NULL; - /* Ensure that get_gc delegates to zend_std_get_properties directly in case - * our class defines a get_properties handler for debugging purposes. */ phongo_std_object_handlers.get_gc = php_phongo_std_get_gc; /* Initialize zend_class_entry dependencies. From 78cb221c1fa7aaf759193c9c7894ab34d7286ebd Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 24 Jul 2025 12:10:58 +0200 Subject: [PATCH 34/44] Fix foreach after the garbage collector is invoked or after a dynamic property is used --- php_phongo.c | 5 +- php_phongo.h | 100 +++++++++++++++++++++++--- src/BSON/Binary.c | 22 ++++-- src/BSON/DBPointer.c | 22 ++++-- src/BSON/Decimal128.c | 22 ++++-- src/BSON/Document.c | 17 +++-- src/BSON/Int64.c | 22 ++++-- src/BSON/Iterator.c | 19 ++++- src/BSON/Javascript.c | 22 ++++-- src/BSON/ObjectId.c | 22 ++++-- src/BSON/PackedArray.c | 24 +++++-- src/BSON/Regex.c | 22 ++++-- src/BSON/Symbol.c | 22 ++++-- src/BSON/Timestamp.c | 22 ++++-- src/BSON/UTCDateTime.c | 22 ++++-- src/MongoDB/Manager.c | 1 - src/MongoDB/ReadConcern.c | 22 ++++-- src/MongoDB/ReadPreference.c | 22 ++++-- src/MongoDB/ServerApi.c | 20 +++++- src/MongoDB/ServerDescription.c | 22 ++++-- src/MongoDB/TopologyDescription.c | 22 ++++-- src/MongoDB/WriteConcern.c | 22 ++++-- src/phongo_structs.h | 19 +++++ tests/bson/bug0939-001.phpt | 22 +++--- tests/bson/bug1598-002.phpt | 5 +- tests/bson/bug2505.phpt | 71 ++++++++++++++++++ tests/bson/bug2505_2.phpt | 69 ++++++++++++++++++ tests/bson/bug2505_3.phpt | 70 ++++++++++++++++++ tests/readConcern/bug1598-002.phpt | 3 - tests/readPreference/bug1598-002.phpt | 3 - tests/writeConcern/bug1598-002.phpt | 3 - 31 files changed, 669 insertions(+), 112 deletions(-) create mode 100644 tests/bson/bug2505.phpt create mode 100644 tests/bson/bug2505_2.phpt create mode 100644 tests/bson/bug2505_3.phpt diff --git a/php_phongo.c b/php_phongo.c index 6c9bd29fc..710cff685 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -159,9 +159,10 @@ static HashTable* php_phongo_std_get_gc(zend_object* object, zval** table, int* { *table = NULL; *n = 0; - return zend_std_get_properties(object); + return object->handlers->get_properties(object); } + PHP_MINIT_FUNCTION(mongodb) /* {{{ */ { bson_mem_vtable_t bson_mem_vtable = { @@ -197,8 +198,6 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */ /* Disable cloning by default. Individual classes can opt in if they need to * support this (e.g. BSON objects). */ phongo_std_object_handlers.clone_obj = NULL; - /* Ensure that get_gc delegates to zend_std_get_properties directly in case - * our class defines a get_properties handler for debugging purposes. */ phongo_std_object_handlers.get_gc = php_phongo_std_get_gc; /* Initialize zend_class_entry dependencies. diff --git a/php_phongo.h b/php_phongo.h index d0655f911..596e27a86 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -60,16 +60,28 @@ ZEND_TSRMLS_CACHE_EXTERN() zend_object_handlers* phongo_get_std_object_handlers(void); +#define PHONGO_RETURN_PROPS(is_temp, props) \ + if (!(is_temp)) { \ + GC_ADDREF(props); \ + } \ + return props; + #define PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size) \ do { \ + if (!(intern)->php_properties) { \ + ALLOC_HASHTABLE((intern)->php_properties); \ + zend_hash_init((intern)->php_properties, 0, NULL, ZVAL_PTR_DTOR, 0); \ + GC_ADDREF((intern)->php_properties); \ + } \ if (is_temp) { \ - ALLOC_HASHTABLE(props); \ - zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \ - } else if ((intern)->properties) { \ - (props) = (intern)->properties; \ + (props) = zend_array_dup((intern)->php_properties); \ } else { \ - ALLOC_HASHTABLE(props); \ - zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \ + (props) = zend_array_dup((intern)->php_properties); \ + if ((intern)->properties) { \ + HashTable *__tmp = (intern)->properties; \ + (intern)->properties = NULL; \ + zend_hash_release(__tmp); \ + } \ (intern)->properties = (props); \ } \ } while (0) @@ -77,11 +89,83 @@ zend_object_handlers* phongo_get_std_object_handlers(void); #define PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props) \ do { \ if (is_temp) { \ - zend_hash_destroy((props)); \ - FREE_HASHTABLE(props); \ + zend_hash_release((props)); \ } \ } while (0) +#define PHONGO_GET_PROPERTY_HANDLERS(_name, _intern_extractor) \ + static zval* php_phongo_##_name##_read_property(zend_object *zobj, zend_string *member, int type, void **cache_slot, zval *rv) \ + { \ + HashTable *props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + return zend_hash_find(props, member); \ + } \ + \ + static zval *php_phongo_##_name##_write_property(zend_object *zobj, zend_string *name, zval *value, void **cache_slot) \ + { \ + Z_TRY_ADDREF_P(value); \ + HashTable *props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + return zend_hash_add_new(props, name, value); \ + } \ + static int php_phongo_##_name##_has_property(zend_object *zobj, zend_string *name, int has_set_exists, void **cache_slot) \ + { \ + HashTable *props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + zval *value = zend_hash_find(props, name); \ + if (value) { \ + if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY) { \ + return zend_is_true(value); \ + } \ + if (has_set_exists < ZEND_PROPERTY_NOT_EMPTY) { \ + ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_ISSET); \ + ZVAL_DEREF(value); \ + return (Z_TYPE_P(value) != IS_NULL); \ + } \ + ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_EXISTS); \ + return true; \ + } \ + return false; \ + } \ + static void php_phongo_##_name##_unset_property(zend_object *zobj, zend_string *name, void **cache_slot) \ + { \ + HashTable *props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + zend_hash_del(props, name); \ + } \ + \ + static zval *php_phongo_##_name##_get_property_ptr_ptr(zend_object *zobj, zend_string *name, int type, void **cache_slot) \ + { \ + HashTable *props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + \ + zval *value = zend_hash_find(props, name); \ + if (value) { \ + return value; \ + } \ + return zend_hash_add(props, name, &EG(uninitialized_zval)); \ + } + #define PHONGO_ZVAL_EXCEPTION_NAME(e) (ZSTR_VAL(e->ce->name)) #define PHONGO_SET_CREATED_BY_PID(intern) \ diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index 4583ac8ab..e3aa7e877 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -73,7 +73,7 @@ static HashTable* php_phongo_binary_get_properties_hash(zend_object* object, boo PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->data) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -86,7 +86,7 @@ static HashTable* php_phongo_binary_get_properties_hash(zend_object* object, boo zend_hash_str_update(props, "type", sizeof("type") - 1, &type); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } /* Construct a new BSON binary type */ @@ -213,9 +213,16 @@ static void php_phongo_binary_free_object(zend_object* object) efree(intern->data); } + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } @@ -281,6 +288,8 @@ static HashTable* php_phongo_binary_get_properties(zend_object* object) return php_phongo_binary_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(binary, Z_OBJ_BINARY); + void php_phongo_binary_init_ce(INIT_FUNC_ARGS) { php_phongo_binary_ce = register_class_MongoDB_BSON_Binary(php_phongo_binary_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -291,6 +300,11 @@ void php_phongo_binary_init_ce(INIT_FUNC_ARGS) php_phongo_handler_binary.clone_obj = php_phongo_binary_clone_object; php_phongo_handler_binary.get_debug_info = php_phongo_binary_get_debug_info; php_phongo_handler_binary.get_properties = php_phongo_binary_get_properties; + php_phongo_handler_binary.read_property = php_phongo_binary_read_property; + php_phongo_handler_binary.write_property = php_phongo_binary_write_property; + php_phongo_handler_binary.has_property = php_phongo_binary_has_property; + php_phongo_handler_binary.unset_property = php_phongo_binary_unset_property; + php_phongo_handler_binary.get_property_ptr_ptr = php_phongo_binary_get_property_ptr_ptr; php_phongo_handler_binary.free_obj = php_phongo_binary_free_object; php_phongo_handler_binary.offset = XtOffsetOf(php_phongo_binary_t, std); } diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index b0285732e..af63f45e2 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -74,7 +74,7 @@ HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object, bool is PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->ref) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -86,7 +86,7 @@ HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object, bool is zend_hash_str_update(props, "id", sizeof("id") - 1, &id); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_DBPointer) @@ -176,9 +176,16 @@ static void php_phongo_dbpointer_free_object(zend_object* object) efree(intern->ref); } + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } @@ -241,6 +248,8 @@ static HashTable* php_phongo_dbpointer_get_properties(zend_object* object) return php_phongo_dbpointer_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(dbpointer, Z_OBJ_DBPOINTER); + void php_phongo_dbpointer_init_ce(INIT_FUNC_ARGS) { php_phongo_dbpointer_ce = register_class_MongoDB_BSON_DBPointer(php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -251,6 +260,11 @@ void php_phongo_dbpointer_init_ce(INIT_FUNC_ARGS) php_phongo_handler_dbpointer.clone_obj = php_phongo_dbpointer_clone_object; php_phongo_handler_dbpointer.get_debug_info = php_phongo_dbpointer_get_debug_info; php_phongo_handler_dbpointer.get_properties = php_phongo_dbpointer_get_properties; + php_phongo_handler_dbpointer.read_property = php_phongo_dbpointer_read_property; + php_phongo_handler_dbpointer.write_property = php_phongo_dbpointer_write_property; + php_phongo_handler_dbpointer.has_property = php_phongo_dbpointer_has_property; + php_phongo_handler_dbpointer.unset_property = php_phongo_dbpointer_unset_property; + php_phongo_handler_dbpointer.get_property_ptr_ptr = php_phongo_dbpointer_get_property_ptr_ptr; php_phongo_handler_dbpointer.free_obj = php_phongo_dbpointer_free_object; php_phongo_handler_dbpointer.offset = XtOffsetOf(php_phongo_dbpointer_t, std); } diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 970ee00e7..078eeac8a 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -64,7 +64,7 @@ static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object, PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->initialized) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } bson_decimal128_to_string(&intern->decimal, outbuf); @@ -76,7 +76,7 @@ static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object, zend_hash_str_update(props, "dec", sizeof("dec") - 1, &dec); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } /* Construct a new BSON Decimal128 type */ @@ -168,9 +168,16 @@ static void php_phongo_decimal128_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } @@ -216,6 +223,8 @@ static HashTable* php_phongo_decimal128_get_properties(zend_object* object) return php_phongo_decimal128_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(decimal128, Z_OBJ_DECIMAL128); + void php_phongo_decimal128_init_ce(INIT_FUNC_ARGS) { php_phongo_decimal128_ce = register_class_MongoDB_BSON_Decimal128(php_phongo_decimal128_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -225,6 +234,11 @@ void php_phongo_decimal128_init_ce(INIT_FUNC_ARGS) php_phongo_handler_decimal128.clone_obj = php_phongo_decimal128_clone_object; php_phongo_handler_decimal128.get_debug_info = php_phongo_decimal128_get_debug_info; php_phongo_handler_decimal128.get_properties = php_phongo_decimal128_get_properties; + php_phongo_handler_decimal128.read_property = php_phongo_decimal128_read_property; + php_phongo_handler_decimal128.write_property = php_phongo_decimal128_write_property; + php_phongo_handler_decimal128.has_property = php_phongo_decimal128_has_property; + php_phongo_handler_decimal128.unset_property = php_phongo_decimal128_unset_property; + php_phongo_handler_decimal128.get_property_ptr_ptr = php_phongo_decimal128_get_property_ptr_ptr; php_phongo_handler_decimal128.free_obj = php_phongo_decimal128_free_object; php_phongo_handler_decimal128.offset = XtOffsetOf(php_phongo_decimal128_t, std); } diff --git a/src/BSON/Document.c b/src/BSON/Document.c index b0886b369..8bd26a6ae 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -65,7 +65,7 @@ static HashTable* php_phongo_document_get_properties_hash(zend_object* object, b PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size); if (!intern->bson) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -75,7 +75,7 @@ static HashTable* php_phongo_document_get_properties_hash(zend_object* object, b zend_hash_str_update(props, "data", sizeof("data") - 1, &data); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_Document) @@ -446,9 +446,16 @@ static void php_phongo_document_free_object(zend_object* object) bson_destroy(intern->bson); } + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } @@ -520,7 +527,7 @@ static HashTable* php_phongo_document_get_debug_info(zend_object* object, int* i zend_hash_str_update(props, "value", sizeof("value") - 1, &state.zchild); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); failure: PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index d350f2b7b..7ac0efb3f 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -72,7 +72,7 @@ HashTable* php_phongo_int64_get_properties_hash(zend_object* object, bool is_tem PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->initialized) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -82,7 +82,7 @@ HashTable* php_phongo_int64_get_properties_hash(zend_object* object, bool is_tem zend_hash_str_update(props, "integer", sizeof("integer") - 1, &value); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } static PHP_METHOD(MongoDB_BSON_Int64, __construct) @@ -175,9 +175,16 @@ static void php_phongo_int64_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } @@ -554,6 +561,8 @@ static HashTable* php_phongo_int64_get_properties(zend_object* object) return php_phongo_int64_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(int64, Z_OBJ_INT64); + void php_phongo_int64_init_ce(INIT_FUNC_ARGS) { php_phongo_int64_ce = register_class_MongoDB_BSON_Int64(php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -564,6 +573,11 @@ void php_phongo_int64_init_ce(INIT_FUNC_ARGS) php_phongo_handler_int64.clone_obj = php_phongo_int64_clone_object; php_phongo_handler_int64.get_debug_info = php_phongo_int64_get_debug_info; php_phongo_handler_int64.get_properties = php_phongo_int64_get_properties; + php_phongo_handler_int64.read_property = php_phongo_int64_read_property; + php_phongo_handler_int64.write_property = php_phongo_int64_write_property; + php_phongo_handler_int64.has_property = php_phongo_int64_has_property; + php_phongo_handler_int64.unset_property = php_phongo_int64_unset_property; + php_phongo_handler_int64.get_property_ptr_ptr = php_phongo_int64_get_property_ptr_ptr; php_phongo_handler_int64.free_obj = php_phongo_int64_free_object; php_phongo_handler_int64.offset = XtOffsetOf(php_phongo_int64_t, std); php_phongo_handler_int64.cast_object = php_phongo_int64_cast_object; diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index 1306dbc7d..b285e459d 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -165,7 +165,7 @@ static HashTable* php_phongo_iterator_get_properties_hash(zend_object* object, b zend_hash_str_update(props, "bson", sizeof("bson") - 1, &intern->bson); Z_TRY_ADDREF(intern->bson); - return props; + PHONGO_RETURN_PROPS(is_temp, props); } PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_Iterator) @@ -248,9 +248,16 @@ static void php_phongo_iterator_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } php_phongo_iterator_free_current(intern); @@ -377,6 +384,7 @@ static zend_object_iterator* php_phongo_iterator_get_iterator(zend_class_entry* return iterator; } +PHONGO_GET_PROPERTY_HANDLERS(iterator, Z_OBJ_ITERATOR); void php_phongo_iterator_init_ce(INIT_FUNC_ARGS) { @@ -388,6 +396,11 @@ void php_phongo_iterator_init_ce(INIT_FUNC_ARGS) php_phongo_handler_iterator.clone_obj = php_phongo_iterator_clone_object; php_phongo_handler_iterator.get_debug_info = php_phongo_iterator_get_debug_info; php_phongo_handler_iterator.get_properties = php_phongo_iterator_get_properties; + php_phongo_handler_iterator.read_property = php_phongo_iterator_read_property; + php_phongo_handler_iterator.write_property = php_phongo_iterator_write_property; + php_phongo_handler_iterator.has_property = php_phongo_iterator_has_property; + php_phongo_handler_iterator.unset_property = php_phongo_iterator_unset_property; + php_phongo_handler_iterator.get_property_ptr_ptr = php_phongo_iterator_get_property_ptr_ptr; php_phongo_handler_iterator.free_obj = php_phongo_iterator_free_object; php_phongo_handler_iterator.offset = XtOffsetOf(php_phongo_iterator_t, std); } diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index 38312dc2d..4c9ce6af6 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -79,7 +79,7 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object, bool i PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->code) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -106,7 +106,7 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object, bool i } } - return props; + PHONGO_RETURN_PROPS(is_temp, props); failure: PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); @@ -262,9 +262,16 @@ static void php_phongo_javascript_free_object(zend_object* object) intern->scope = NULL; } + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } @@ -322,6 +329,8 @@ static HashTable* php_phongo_javascript_get_properties(zend_object* object) return php_phongo_javascript_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(javascript, Z_OBJ_JAVASCRIPT); + void php_phongo_javascript_init_ce(INIT_FUNC_ARGS) { php_phongo_javascript_ce = register_class_MongoDB_BSON_Javascript(php_phongo_javascript_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -332,6 +341,11 @@ void php_phongo_javascript_init_ce(INIT_FUNC_ARGS) php_phongo_handler_javascript.clone_obj = php_phongo_javascript_clone_object; php_phongo_handler_javascript.get_debug_info = php_phongo_javascript_get_debug_info; php_phongo_handler_javascript.get_properties = php_phongo_javascript_get_properties; + php_phongo_handler_javascript.read_property = php_phongo_javascript_read_property; + php_phongo_handler_javascript.write_property = php_phongo_javascript_write_property; + php_phongo_handler_javascript.has_property = php_phongo_javascript_has_property; + php_phongo_handler_javascript.unset_property = php_phongo_javascript_unset_property; + php_phongo_handler_javascript.get_property_ptr_ptr = php_phongo_javascript_get_property_ptr_ptr; php_phongo_handler_javascript.free_obj = php_phongo_javascript_free_object; php_phongo_handler_javascript.offset = XtOffsetOf(php_phongo_javascript_t, std); } diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 240441ac4..4e6a460fe 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -87,7 +87,7 @@ static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object, b PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->initialized) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -97,7 +97,7 @@ static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object, b zend_hash_str_update(props, "oid", sizeof("oid") - 1, &zv); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } /* Constructs a new BSON ObjectId type, optionally from a hex string. */ @@ -202,9 +202,16 @@ static void php_phongo_objectid_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } @@ -263,6 +270,8 @@ static HashTable* php_phongo_objectid_get_properties(zend_object* object) return php_phongo_objectid_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(objectid, Z_OBJ_OBJECTID); + void php_phongo_objectid_init_ce(INIT_FUNC_ARGS) { php_phongo_objectid_ce = register_class_MongoDB_BSON_ObjectId(php_phongo_objectid_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -273,6 +282,11 @@ void php_phongo_objectid_init_ce(INIT_FUNC_ARGS) php_phongo_handler_objectid.clone_obj = php_phongo_objectid_clone_object; php_phongo_handler_objectid.get_debug_info = php_phongo_objectid_get_debug_info; php_phongo_handler_objectid.get_properties = php_phongo_objectid_get_properties; + php_phongo_handler_objectid.read_property = php_phongo_objectid_read_property; + php_phongo_handler_objectid.write_property = php_phongo_objectid_write_property; + php_phongo_handler_objectid.has_property = php_phongo_objectid_has_property; + php_phongo_handler_objectid.unset_property = php_phongo_objectid_unset_property; + php_phongo_handler_objectid.get_property_ptr_ptr = php_phongo_objectid_get_property_ptr_ptr; php_phongo_handler_objectid.free_obj = php_phongo_objectid_free_object; php_phongo_handler_objectid.offset = XtOffsetOf(php_phongo_objectid_t, std); } diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index 6fdbcf575..2d6ce8b33 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -66,7 +66,7 @@ static HashTable* php_phongo_packedarray_get_properties_hash(zend_object* object PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size); if (!intern->bson) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -76,7 +76,7 @@ static HashTable* php_phongo_packedarray_get_properties_hash(zend_object* object zend_hash_str_update(props, "data", sizeof("data") - 1, &data); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } static bool php_phongo_packedarray_to_json(zval* return_value, bson_json_mode_t mode, const bson_t* bson) @@ -430,9 +430,16 @@ static void php_phongo_packedarray_free_object(zend_object* object) bson_destroy(intern->bson); } + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } @@ -505,7 +512,7 @@ static HashTable* php_phongo_packedarray_get_debug_info(zend_object* object, int zend_hash_str_update(props, "value", sizeof("value") - 1, &state.zchild); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); failure: PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); @@ -564,6 +571,8 @@ void php_phongo_packedarray_unset_dimension(zend_object* object, zval* offset) phongo_throw_exception(PHONGO_ERROR_LOGIC, "Cannot unset %s offset", ZSTR_VAL(php_phongo_packedarray_ce->name)); } +PHONGO_GET_PROPERTY_HANDLERS(packedarray, Z_OBJ_PACKEDARRAY); + void php_phongo_packedarray_init_ce(INIT_FUNC_ARGS) { php_phongo_packedarray_ce = register_class_MongoDB_BSON_PackedArray(zend_ce_aggregate, zend_ce_arrayaccess, php_phongo_type_ce, zend_ce_stringable); @@ -574,6 +583,11 @@ void php_phongo_packedarray_init_ce(INIT_FUNC_ARGS) php_phongo_handler_packedarray.clone_obj = php_phongo_packedarray_clone_object; php_phongo_handler_packedarray.get_debug_info = php_phongo_packedarray_get_debug_info; php_phongo_handler_packedarray.get_properties = php_phongo_packedarray_get_properties; + php_phongo_handler_packedarray.read_property = php_phongo_packedarray_read_property; + php_phongo_handler_packedarray.write_property = php_phongo_packedarray_write_property; + php_phongo_handler_packedarray.has_property = php_phongo_packedarray_has_property; + php_phongo_handler_packedarray.unset_property = php_phongo_packedarray_unset_property; + php_phongo_handler_packedarray.get_property_ptr_ptr = php_phongo_packedarray_get_property_ptr_ptr; php_phongo_handler_packedarray.free_obj = php_phongo_packedarray_free_object; php_phongo_handler_packedarray.read_dimension = php_phongo_packedarray_read_dimension; php_phongo_handler_packedarray.write_dimension = php_phongo_packedarray_write_dimension; diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index a75b75e39..b25f9620b 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -88,7 +88,7 @@ static HashTable* php_phongo_regex_get_properties_hash(zend_object* object, bool PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->pattern) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -101,7 +101,7 @@ static HashTable* php_phongo_regex_get_properties_hash(zend_object* object, bool zend_hash_str_update(props, "flags", sizeof("flags") - 1, &flags); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } /* Constructs a new BSON regular expression type. */ @@ -228,9 +228,16 @@ static void php_phongo_regex_free_object(zend_object* object) efree(intern->flags); } + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } @@ -294,6 +301,8 @@ static HashTable* php_phongo_regex_get_properties(zend_object* object) return php_phongo_regex_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(regex, Z_OBJ_REGEX); + void php_phongo_regex_init_ce(INIT_FUNC_ARGS) { php_phongo_regex_ce = register_class_MongoDB_BSON_Regex(php_phongo_regex_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -304,6 +313,11 @@ void php_phongo_regex_init_ce(INIT_FUNC_ARGS) php_phongo_handler_regex.clone_obj = php_phongo_regex_clone_object; php_phongo_handler_regex.get_debug_info = php_phongo_regex_get_debug_info; php_phongo_handler_regex.get_properties = php_phongo_regex_get_properties; + php_phongo_handler_regex.read_property = php_phongo_regex_read_property; + php_phongo_handler_regex.write_property = php_phongo_regex_write_property; + php_phongo_handler_regex.has_property = php_phongo_regex_has_property; + php_phongo_handler_regex.unset_property = php_phongo_regex_unset_property; + php_phongo_handler_regex.get_property_ptr_ptr = php_phongo_regex_get_property_ptr_ptr; php_phongo_handler_regex.free_obj = php_phongo_regex_free_object; php_phongo_handler_regex.offset = XtOffsetOf(php_phongo_regex_t, std); } diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index a47b6c2fe..20ed21a09 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -62,7 +62,7 @@ HashTable* php_phongo_symbol_get_properties_hash(zend_object* object, bool is_te PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->symbol) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -72,7 +72,7 @@ HashTable* php_phongo_symbol_get_properties_hash(zend_object* object, bool is_te zend_hash_str_update(props, "symbol", sizeof("symbol") - 1, &symbol); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_Symbol) @@ -150,9 +150,16 @@ static void php_phongo_symbol_free_object(zend_object* object) efree(intern->symbol); } + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } @@ -208,6 +215,8 @@ static HashTable* php_phongo_symbol_get_properties(zend_object* object) return php_phongo_symbol_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(symbol, Z_OBJ_SYMBOL); + void php_phongo_symbol_init_ce(INIT_FUNC_ARGS) { php_phongo_symbol_ce = register_class_MongoDB_BSON_Symbol(php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -218,6 +227,11 @@ void php_phongo_symbol_init_ce(INIT_FUNC_ARGS) php_phongo_handler_symbol.clone_obj = php_phongo_symbol_clone_object; php_phongo_handler_symbol.get_debug_info = php_phongo_symbol_get_debug_info; php_phongo_handler_symbol.get_properties = php_phongo_symbol_get_properties; + php_phongo_handler_symbol.read_property = php_phongo_symbol_read_property; + php_phongo_handler_symbol.write_property = php_phongo_symbol_write_property; + php_phongo_handler_symbol.has_property = php_phongo_symbol_has_property; + php_phongo_handler_symbol.unset_property = php_phongo_symbol_unset_property; + php_phongo_handler_symbol.get_property_ptr_ptr = php_phongo_symbol_get_property_ptr_ptr; php_phongo_handler_symbol.free_obj = php_phongo_symbol_free_object; php_phongo_handler_symbol.offset = XtOffsetOf(php_phongo_symbol_t, std); } diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 82cd6f537..66121d325 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -99,7 +99,7 @@ static HashTable* php_phongo_timestamp_get_properties_hash(zend_object* object, PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->initialized) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } s_increment_len = snprintf(s_increment, sizeof(s_increment), "%" PRIu32, intern->increment); @@ -115,7 +115,7 @@ static HashTable* php_phongo_timestamp_get_properties_hash(zend_object* object, zend_hash_str_update(props, "timestamp", sizeof("timestamp") - 1, ×tamp); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } /* Construct a new BSON timestamp type, which consists of a 4-byte increment and @@ -261,9 +261,16 @@ static void php_phongo_timestamp_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } @@ -328,6 +335,8 @@ static HashTable* php_phongo_timestamp_get_properties(zend_object* object) return php_phongo_timestamp_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(timestamp, Z_OBJ_TIMESTAMP); + void php_phongo_timestamp_init_ce(INIT_FUNC_ARGS) { php_phongo_timestamp_ce = register_class_MongoDB_BSON_Timestamp(php_phongo_timestamp_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -338,6 +347,11 @@ void php_phongo_timestamp_init_ce(INIT_FUNC_ARGS) php_phongo_handler_timestamp.clone_obj = php_phongo_timestamp_clone_object; php_phongo_handler_timestamp.get_debug_info = php_phongo_timestamp_get_debug_info; php_phongo_handler_timestamp.get_properties = php_phongo_timestamp_get_properties; + php_phongo_handler_timestamp.read_property = php_phongo_timestamp_read_property; + php_phongo_handler_timestamp.write_property = php_phongo_timestamp_write_property; + php_phongo_handler_timestamp.has_property = php_phongo_timestamp_has_property; + php_phongo_handler_timestamp.unset_property = php_phongo_timestamp_unset_property; + php_phongo_handler_timestamp.get_property_ptr_ptr = php_phongo_timestamp_get_property_ptr_ptr; php_phongo_handler_timestamp.free_obj = php_phongo_timestamp_free_object; php_phongo_handler_timestamp.offset = XtOffsetOf(php_phongo_timestamp_t, std); } diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index d0f169858..6af94f7b7 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -131,7 +131,7 @@ static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->initialized) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } { @@ -141,7 +141,7 @@ static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object zend_hash_str_update(props, "milliseconds", sizeof("milliseconds") - 1, &milliseconds); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } static void php_phongo_utcdatetime_to_php_date(zval* return_value, const zval* this, zend_class_entry* ce) @@ -301,9 +301,16 @@ static void php_phongo_utcdatetime_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } } @@ -363,6 +370,8 @@ static HashTable* php_phongo_utcdatetime_get_properties(zend_object* object) return php_phongo_utcdatetime_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(utcdatetime, Z_OBJ_UTCDATETIME); + void php_phongo_utcdatetime_init_ce(INIT_FUNC_ARGS) { php_phongo_utcdatetime_ce = register_class_MongoDB_BSON_UTCDateTime(php_phongo_utcdatetime_interface_ce, php_phongo_json_serializable_ce, php_phongo_type_ce, zend_ce_stringable); @@ -373,6 +382,11 @@ void php_phongo_utcdatetime_init_ce(INIT_FUNC_ARGS) php_phongo_handler_utcdatetime.clone_obj = php_phongo_utcdatetime_clone_object; php_phongo_handler_utcdatetime.get_debug_info = php_phongo_utcdatetime_get_debug_info; php_phongo_handler_utcdatetime.get_properties = php_phongo_utcdatetime_get_properties; + php_phongo_handler_utcdatetime.read_property = php_phongo_utcdatetime_read_property; + php_phongo_handler_utcdatetime.write_property = php_phongo_utcdatetime_write_property; + php_phongo_handler_utcdatetime.has_property = php_phongo_utcdatetime_has_property; + php_phongo_handler_utcdatetime.unset_property = php_phongo_utcdatetime_unset_property; + php_phongo_handler_utcdatetime.get_property_ptr_ptr = php_phongo_utcdatetime_get_property_ptr_ptr; php_phongo_handler_utcdatetime.free_obj = php_phongo_utcdatetime_free_object; php_phongo_handler_utcdatetime.offset = XtOffsetOf(php_phongo_utcdatetime_t, std); } diff --git a/src/MongoDB/Manager.c b/src/MongoDB/Manager.c index 2bf02fbdf..4a5df4202 100644 --- a/src/MongoDB/Manager.c +++ b/src/MongoDB/Manager.c @@ -799,7 +799,6 @@ static void php_phongo_manager_free_object(zend_object* object) if (intern->subscribers) { zend_hash_destroy(intern->subscribers); - FREE_HASHTABLE(intern->subscribers); } } diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index 54ed384db..af0eaafac 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -133,7 +133,7 @@ static HashTable* php_phongo_readconcern_get_properties_hash(zend_object* object PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->read_concern) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } level = mongoc_read_concern_get_level(intern->read_concern); @@ -145,7 +145,7 @@ static HashTable* php_phongo_readconcern_get_properties_hash(zend_object* object zend_hash_str_update(props, "level", sizeof("level") - 1, &z_level); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } static PHP_METHOD(MongoDB_Driver_ReadConcern, bsonSerialize) @@ -183,9 +183,16 @@ static void php_phongo_readconcern_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } if (intern->read_concern) { @@ -216,6 +223,8 @@ static HashTable* php_phongo_readconcern_get_properties(zend_object* object) return php_phongo_readconcern_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(readconcern, Z_OBJ_READCONCERN); + void php_phongo_readconcern_init_ce(INIT_FUNC_ARGS) { php_phongo_readconcern_ce = register_class_MongoDB_Driver_ReadConcern(php_phongo_serializable_ce); @@ -224,6 +233,11 @@ void php_phongo_readconcern_init_ce(INIT_FUNC_ARGS) memcpy(&php_phongo_handler_readconcern, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); php_phongo_handler_readconcern.get_debug_info = php_phongo_readconcern_get_debug_info; php_phongo_handler_readconcern.get_properties = php_phongo_readconcern_get_properties; + php_phongo_handler_readconcern.read_property = php_phongo_readconcern_read_property; + php_phongo_handler_readconcern.write_property = php_phongo_readconcern_write_property; + php_phongo_handler_readconcern.has_property = php_phongo_readconcern_has_property; + php_phongo_handler_readconcern.unset_property = php_phongo_readconcern_unset_property; + php_phongo_handler_readconcern.get_property_ptr_ptr = php_phongo_readconcern_get_property_ptr_ptr; php_phongo_handler_readconcern.free_obj = php_phongo_readconcern_free_object; php_phongo_handler_readconcern.offset = XtOffsetOf(php_phongo_readconcern_t, std); } diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index cd7fed69b..e8955bc24 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -392,7 +392,7 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zend_object* obj PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 4); if (!intern->read_preference) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } tags = mongoc_read_prefs_get_tags(intern->read_preference); @@ -445,7 +445,7 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zend_object* obj } done: - return props; + PHONGO_RETURN_PROPS(is_temp, props); } static PHP_METHOD(MongoDB_Driver_ReadPreference, bsonSerialize) @@ -483,9 +483,16 @@ static void php_phongo_readpreference_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } if (intern->read_preference) { @@ -516,6 +523,8 @@ static HashTable* php_phongo_readpreference_get_properties(zend_object* object) return php_phongo_readpreference_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(readpreference, Z_OBJ_READPREFERENCE); + void php_phongo_readpreference_init_ce(INIT_FUNC_ARGS) { php_phongo_readpreference_ce = register_class_MongoDB_Driver_ReadPreference(php_phongo_serializable_ce); @@ -524,6 +533,11 @@ void php_phongo_readpreference_init_ce(INIT_FUNC_ARGS) memcpy(&php_phongo_handler_readpreference, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); php_phongo_handler_readpreference.get_debug_info = php_phongo_readpreference_get_debug_info; php_phongo_handler_readpreference.get_properties = php_phongo_readpreference_get_properties; + php_phongo_handler_readpreference.read_property = php_phongo_readpreference_read_property; + php_phongo_handler_readpreference.write_property = php_phongo_readpreference_write_property; + php_phongo_handler_readpreference.has_property = php_phongo_readpreference_has_property; + php_phongo_handler_readpreference.unset_property = php_phongo_readpreference_unset_property; + php_phongo_handler_readpreference.get_property_ptr_ptr = php_phongo_readpreference_get_property_ptr_ptr; php_phongo_handler_readpreference.free_obj = php_phongo_readpreference_free_object; php_phongo_handler_readpreference.offset = XtOffsetOf(php_phongo_readpreference_t, std); } diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index 3dd6f6264..899df8bc1 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -173,7 +173,7 @@ static HashTable* php_phongo_serverapi_get_properties_hash(zend_object* object, zend_hash_str_add(props, "deprecationErrors", sizeof("deprecationErrors") - 1, &deprecation_errors); } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } static PHP_METHOD(MongoDB_Driver_ServerApi, bsonSerialize) @@ -211,9 +211,16 @@ static void php_phongo_serverapi_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } if (intern->server_api) { @@ -244,6 +251,8 @@ static HashTable* php_phongo_serverapi_get_properties(zend_object* object) return php_phongo_serverapi_get_properties_hash(object, false, true); } +PHONGO_GET_PROPERTY_HANDLERS(serverapi, Z_OBJ_SERVERAPI); + void php_phongo_serverapi_init_ce(INIT_FUNC_ARGS) { php_phongo_serverapi_ce = register_class_MongoDB_Driver_ServerApi(php_phongo_serializable_ce); @@ -252,6 +261,11 @@ void php_phongo_serverapi_init_ce(INIT_FUNC_ARGS) memcpy(&php_phongo_handler_serverapi, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); php_phongo_handler_serverapi.get_debug_info = php_phongo_serverapi_get_debug_info; php_phongo_handler_serverapi.get_properties = php_phongo_serverapi_get_properties; + php_phongo_handler_serverapi.read_property = php_phongo_serverapi_read_property; + php_phongo_handler_serverapi.write_property = php_phongo_serverapi_write_property; + php_phongo_handler_serverapi.has_property = php_phongo_serverapi_has_property; + php_phongo_handler_serverapi.unset_property = php_phongo_serverapi_unset_property; + php_phongo_handler_serverapi.get_property_ptr_ptr = php_phongo_serverapi_get_property_ptr_ptr; php_phongo_handler_serverapi.free_obj = php_phongo_serverapi_free_object; php_phongo_handler_serverapi.offset = XtOffsetOf(php_phongo_serverapi_t, std); } diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index 7a21e9e07..9508d95d3 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -158,9 +158,16 @@ static void php_phongo_serverdescription_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } if (intern->server_description) { @@ -190,7 +197,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object, PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 6); if (!intern->server_description) { - return props; + PHONGO_RETURN_PROPS(is_debug, props); } { @@ -253,7 +260,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object, } done: - return props; + PHONGO_RETURN_PROPS(is_debug, props); } static HashTable* php_phongo_serverdescription_get_debug_info(zend_object* object, int* is_temp) @@ -267,6 +274,8 @@ static HashTable* php_phongo_serverdescription_get_properties(zend_object* objec return php_phongo_serverdescription_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(serverdescription, Z_OBJ_SERVERDESCRIPTION); + void php_phongo_serverdescription_init_ce(INIT_FUNC_ARGS) { php_phongo_serverdescription_ce = register_class_MongoDB_Driver_ServerDescription(); @@ -275,6 +284,11 @@ void php_phongo_serverdescription_init_ce(INIT_FUNC_ARGS) memcpy(&php_phongo_handler_serverdescription, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); php_phongo_handler_serverdescription.get_debug_info = php_phongo_serverdescription_get_debug_info; php_phongo_handler_serverdescription.get_properties = php_phongo_serverdescription_get_properties; + php_phongo_handler_serverdescription.read_property = php_phongo_serverdescription_read_property; + php_phongo_handler_serverdescription.write_property = php_phongo_serverdescription_write_property; + php_phongo_handler_serverdescription.has_property = php_phongo_serverdescription_has_property; + php_phongo_handler_serverdescription.unset_property = php_phongo_serverdescription_unset_property; + php_phongo_handler_serverdescription.get_property_ptr_ptr = php_phongo_serverdescription_get_property_ptr_ptr; php_phongo_handler_serverdescription.free_obj = php_phongo_serverdescription_free_object; php_phongo_handler_serverdescription.offset = XtOffsetOf(php_phongo_serverdescription_t, std); } diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index ab625dff0..ecbe54547 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -107,9 +107,16 @@ static void php_phongo_topologydescription_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } if (intern->topology_description) { @@ -139,7 +146,7 @@ HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* objec PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 2); if (!intern->topology_description) { - return props; + PHONGO_RETURN_PROPS(is_debug, props); } { @@ -166,7 +173,7 @@ HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* objec zend_hash_str_update(props, "type", sizeof("type") - 1, &type); } - return props; + PHONGO_RETURN_PROPS(is_debug, props); } static HashTable* php_phongo_topologydescription_get_debug_info(zend_object* object, int* is_temp) @@ -180,6 +187,8 @@ static HashTable* php_phongo_topologydescription_get_properties(zend_object* obj return php_phongo_topologydescription_get_properties_hash(object, false); } +PHONGO_GET_PROPERTY_HANDLERS(topologydescription, Z_OBJ_TOPOLOGYDESCRIPTION); + void php_phongo_topologydescription_init_ce(INIT_FUNC_ARGS) { php_phongo_topologydescription_ce = register_class_MongoDB_Driver_TopologyDescription(); @@ -188,6 +197,11 @@ void php_phongo_topologydescription_init_ce(INIT_FUNC_ARGS) memcpy(&php_phongo_handler_topologydescription, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); php_phongo_handler_topologydescription.get_debug_info = php_phongo_topologydescription_get_debug_info; php_phongo_handler_topologydescription.get_properties = php_phongo_topologydescription_get_properties; + php_phongo_handler_topologydescription.read_property = php_phongo_topologydescription_read_property; + php_phongo_handler_topologydescription.write_property = php_phongo_topologydescription_write_property; + php_phongo_handler_topologydescription.has_property = php_phongo_topologydescription_has_property; + php_phongo_handler_topologydescription.unset_property = php_phongo_topologydescription_unset_property; + php_phongo_handler_topologydescription.get_property_ptr_ptr = php_phongo_topologydescription_get_property_ptr_ptr; php_phongo_handler_topologydescription.free_obj = php_phongo_topologydescription_free_object; php_phongo_handler_topologydescription.offset = XtOffsetOf(php_phongo_topologydescription_t, std); } diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index c0edb5a05..2510619b0 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -275,7 +275,7 @@ static HashTable* php_phongo_writeconcern_get_properties_hash(zend_object* objec PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 4); if (!intern->write_concern) { - return props; + PHONGO_RETURN_PROPS(is_temp, props); } wtag = mongoc_write_concern_get_wtag(intern->write_concern); @@ -330,7 +330,7 @@ static HashTable* php_phongo_writeconcern_get_properties_hash(zend_object* objec } } - return props; + PHONGO_RETURN_PROPS(is_temp, props); } static PHP_METHOD(MongoDB_Driver_WriteConcern, bsonSerialize) @@ -368,9 +368,16 @@ static void php_phongo_writeconcern_free_object(zend_object* object) zend_object_std_dtor(&intern->std); + if (intern->properties) { - zend_hash_destroy(intern->properties); - FREE_HASHTABLE(intern->properties); + HashTable* props = intern->properties; + intern->properties = NULL; + zend_hash_release(props); + } + if (intern->php_properties) { + HashTable* props = intern->php_properties; + intern->php_properties = NULL; + zend_hash_release(props); } if (intern->write_concern) { @@ -401,6 +408,8 @@ static HashTable* php_phongo_writeconcern_get_properties(zend_object* object) return php_phongo_writeconcern_get_properties_hash(object, false, false, false); } +PHONGO_GET_PROPERTY_HANDLERS(writeconcern, Z_OBJ_WRITECONCERN); + void php_phongo_writeconcern_init_ce(INIT_FUNC_ARGS) { php_phongo_writeconcern_ce = register_class_MongoDB_Driver_WriteConcern(php_phongo_serializable_ce); @@ -409,6 +418,11 @@ void php_phongo_writeconcern_init_ce(INIT_FUNC_ARGS) memcpy(&php_phongo_handler_writeconcern, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); php_phongo_handler_writeconcern.get_debug_info = php_phongo_writeconcern_get_debug_info; php_phongo_handler_writeconcern.get_properties = php_phongo_writeconcern_get_properties; + php_phongo_handler_writeconcern.read_property = php_phongo_writeconcern_read_property; + php_phongo_handler_writeconcern.write_property = php_phongo_writeconcern_write_property; + php_phongo_handler_writeconcern.has_property = php_phongo_writeconcern_has_property; + php_phongo_handler_writeconcern.unset_property = php_phongo_writeconcern_unset_property; + php_phongo_handler_writeconcern.get_property_ptr_ptr = php_phongo_writeconcern_get_property_ptr_ptr; php_phongo_handler_writeconcern.free_obj = php_phongo_writeconcern_free_object; php_phongo_handler_writeconcern.offset = XtOffsetOf(php_phongo_writeconcern_t, std); } diff --git a/src/phongo_structs.h b/src/phongo_structs.h index 7b083e612..5d0f9fc86 100644 --- a/src/phongo_structs.h +++ b/src/phongo_structs.h @@ -122,12 +122,14 @@ typedef struct { typedef struct { mongoc_read_concern_t* read_concern; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_readconcern_t; typedef struct { mongoc_read_prefs_t* read_preference; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_readpreference_t; @@ -141,12 +143,14 @@ typedef struct { typedef struct { mongoc_server_api_t* server_api; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_serverapi_t; typedef struct { mongoc_server_description_t* server_description; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_serverdescription_t; @@ -160,11 +164,13 @@ typedef struct { typedef struct { mongoc_topology_description_t* topology_description; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_topologydescription_t; typedef struct { HashTable* properties; + HashTable* php_properties; mongoc_write_concern_t* write_concern; zend_object std; } php_phongo_writeconcern_t; @@ -197,18 +203,21 @@ typedef struct { int data_len; uint8_t type; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_binary_t; typedef struct { bson_t* bson; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_packedarray_t; typedef struct { bson_t* bson; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_document_t; @@ -220,6 +229,7 @@ typedef struct { size_t key; zval current; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_iterator_t; @@ -228,6 +238,7 @@ typedef struct { size_t ref_len; char id[25]; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_dbpointer_t; @@ -235,6 +246,7 @@ typedef struct { bool initialized; bson_decimal128_t decimal; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_decimal128_t; @@ -242,6 +254,7 @@ typedef struct { bool initialized; int64_t integer; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_int64_t; @@ -250,6 +263,7 @@ typedef struct { size_t code_len; bson_t* scope; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_javascript_t; @@ -265,6 +279,7 @@ typedef struct { bool initialized; char oid[25]; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_objectid_t; @@ -274,6 +289,7 @@ typedef struct { char* flags; int flags_len; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_regex_t; @@ -281,6 +297,7 @@ typedef struct { char* symbol; size_t symbol_len; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_symbol_t; @@ -289,6 +306,7 @@ typedef struct { uint32_t increment; uint32_t timestamp; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_timestamp_t; @@ -300,6 +318,7 @@ typedef struct { bool initialized; int64_t milliseconds; HashTable* properties; + HashTable* php_properties; zend_object std; } php_phongo_utcdatetime_t; diff --git a/tests/bson/bug0939-001.phpt b/tests/bson/bug0939-001.phpt index a66e7be09..09caece5c 100644 --- a/tests/bson/bug0939-001.phpt +++ b/tests/bson/bug0939-001.phpt @@ -38,14 +38,14 @@ object(MongoDB\BSON\Binary)#%d (%d) { ["type"]=> int(0) } -MongoDB\BSON\Binary::$data exists: no -MongoDB\BSON\Binary::$type exists: no +MongoDB\BSON\Binary::$data exists: yes +MongoDB\BSON\Binary::$type exists: yes object(MongoDB\BSON\Decimal128)#%d (%d) { ["dec"]=> string(4) "3.14" } -MongoDB\BSON\Decimal128::$dec exists: no +MongoDB\BSON\Decimal128::$dec exists: yes object(MongoDB\BSON\Javascript)#%d (%d) { ["code"]=> @@ -56,8 +56,8 @@ object(MongoDB\BSON\Javascript)#%d (%d) { int(42) } } -MongoDB\BSON\Javascript::$code exists: no -MongoDB\BSON\Javascript::$scope exists: no +MongoDB\BSON\Javascript::$code exists: yes +MongoDB\BSON\Javascript::$scope exists: yes object(MongoDB\BSON\MaxKey)#%d (%d) { } @@ -69,7 +69,7 @@ object(MongoDB\BSON\ObjectId)#%d (%d) { ["oid"]=> string(24) "%x" } -MongoDB\BSON\ObjectId::$oid exists: no +MongoDB\BSON\ObjectId::$oid exists: yes object(MongoDB\BSON\Regex)#%d (%d) { ["pattern"]=> @@ -77,8 +77,8 @@ object(MongoDB\BSON\Regex)#%d (%d) { ["flags"]=> string(1) "i" } -MongoDB\BSON\Regex::$pattern exists: no -MongoDB\BSON\Regex::$flags exists: no +MongoDB\BSON\Regex::$pattern exists: yes +MongoDB\BSON\Regex::$flags exists: yes object(MongoDB\BSON\Timestamp)#%d (%d) { ["increment"]=> @@ -86,13 +86,13 @@ object(MongoDB\BSON\Timestamp)#%d (%d) { ["timestamp"]=> string(4) "5678" } -MongoDB\BSON\Timestamp::$increment exists: no -MongoDB\BSON\Timestamp::$timestamp exists: no +MongoDB\BSON\Timestamp::$increment exists: yes +MongoDB\BSON\Timestamp::$timestamp exists: yes object(MongoDB\BSON\UTCDateTime)#%d (%d) { ["milliseconds"]=> string(%d) "%d" } -MongoDB\BSON\UTCDateTime::$milliseconds exists: no +MongoDB\BSON\UTCDateTime::$milliseconds exists: yes ===DONE=== diff --git a/tests/bson/bug1598-002.phpt b/tests/bson/bug1598-002.phpt index de32da9a8..4a55de7e6 100644 --- a/tests/bson/bug1598-002.phpt +++ b/tests/bson/bug1598-002.phpt @@ -1,12 +1,9 @@ --TEST-- PHPC-1598: BSON type get_gc should delegate to zend_std_get_properties ---SKIPIF-- - -=', '8.1.99'); ?> --FILE-- new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], [ 'dbpointer' => createDBPointer(), ], diff --git a/tests/bson/bug2505.phpt b/tests/bson/bug2505.phpt new file mode 100644 index 000000000..fa96d9e1d --- /dev/null +++ b/tests/bson/bug2505.phpt @@ -0,0 +1,71 @@ +--TEST-- +PHPC-2505: gc_collect_cycles() may interfere with using foreach to iterate objects +--FILE-- + new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], + [ 'dbpointer' => createDBPointer() ], + [ 'decimal128' => new MongoDB\BSON\Decimal128('1234.5678') ], + [ 'int64' => new MongoDB\BSON\Int64('9223372036854775807') ], + // JavaScript w/ scope may not be necessary (same code path as w/o scope), but we'll test it anyway + [ 'javascript' => new MongoDB\BSON\Javascript('function() { return 1; }') ], + + // The context is recreated every time with a different object ID + //[ 'javascript_ws' => new MongoDB\BSON\Javascript('function() { return a; }', ['a' => 1]) ], + + // MaxKey and MinKey don't have get_properties or get_gc handlers, but we'll test them anyway + [ 'maxkey' => new MongoDB\BSON\MaxKey ], + [ 'minkey' => new MongoDB\BSON\MinKey ], + [ 'objectid' => new MongoDB\BSON\ObjectId ], + [ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ], + [ 'symbol' => createSymbol() ], + [ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ], + [ 'utcdatetime' => new MongoDB\BSON\UTCDateTime ], +]; + +ob_start(); +foreach ($tests as $test) { + echo key($test), "\n"; + $test = reset($test); + + foreach ($test as $k => $v) { + var_dump($k, $v); + } +} +$buf1 = ob_get_clean(); +if ($buf1 === false) { + throw new \AssertionError("Could not flush buffer"); +} + +gc_enable(); +gc_collect_cycles(); + +ob_start(); +foreach ($tests as $test) { + echo key($test), "\n"; + $test = reset($test); + + foreach ($test as $k => $v) { + var_dump($k, $v); + } +} +$buf2 = ob_get_clean(); +if ($buf2 === false) { + throw new \AssertionError("Could not flush buffer"); +} + +if ($buf1 === $buf2) { + echo "OK!\n"; + exit(0); +} else { + echo("buf1 != buf2: $buf1\n\n IS NOT EQUAL TO \n\n$buf2\n"); + exit(1); +} + +?> +--EXPECT-- +OK! \ No newline at end of file diff --git a/tests/bson/bug2505_2.phpt b/tests/bson/bug2505_2.phpt new file mode 100644 index 000000000..c12f7b542 --- /dev/null +++ b/tests/bson/bug2505_2.phpt @@ -0,0 +1,69 @@ +--TEST-- +PHPC-2505: Setting and unsetting a property may interfere with using foreach to iterate objects +--FILE-- + new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], + [ 'dbpointer' => createDBPointer() ], + [ 'decimal128' => new MongoDB\BSON\Decimal128('1234.5678') ], + [ 'int64' => new MongoDB\BSON\Int64('9223372036854775807') ], + // JavaScript w/ scope may not be necessary (same code path as w/o scope), but we'll test it anyway + [ 'javascript' => new MongoDB\BSON\Javascript('function() { return 1; }') ], + // The context is recreated every time with a different object ID + //[ 'javascript_ws' => new MongoDB\BSON\Javascript('function() { return a; }', ['a' => 1]) ], + // MaxKey and MinKey don't have get_properties or get_gc handlers, but we'll test them anyway + [ 'maxkey' => new MongoDB\BSON\MaxKey ], + [ 'minkey' => new MongoDB\BSON\MinKey ], + [ 'objectid' => new MongoDB\BSON\ObjectId ], + [ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ], + [ 'symbol' => createSymbol() ], + [ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ], + [ 'utcdatetime' => new MongoDB\BSON\UTCDateTime ], +]; + +ob_start(); +foreach ($tests as $test) { + echo key($test), "\n"; + $test = reset($test); + + foreach ($test as $k => $v) { + var_dump($k, $v); + } +} +$buf1 = ob_get_clean(); +if ($buf1 === false) { + throw new \AssertionError("Could not flush buffer"); +} + +foreach ($tests as $test) { + $test = reset($test); + $test->a = 'test'; + unset($test->a); +} + +ob_start(); +foreach ($tests as $test) { + echo key($test), "\n"; + $test = reset($test); + + foreach ($test as $k => $v) { + var_dump($k, $v); + } +} +$buf2 = ob_get_clean(); +if ($buf2 === false) { + throw new \AssertionError("Could not flush buffer"); +} + +if ($buf1 === $buf2) { + echo "OK!\n"; + exit(0); +} else { + echo("buf1 != buf2: $buf1\n!=\n$buf2\n"); +} + +?> +--EXPECT-- +OK! \ No newline at end of file diff --git a/tests/bson/bug2505_3.phpt b/tests/bson/bug2505_3.phpt new file mode 100644 index 000000000..5d835c30a --- /dev/null +++ b/tests/bson/bug2505_3.phpt @@ -0,0 +1,70 @@ +--TEST-- +PHPC-2505: Setting and unsetting a property may interfere with using foreach to iterate objects +--FILE-- + new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], + [ 'dbpointer' => createDBPointer() ], + [ 'decimal128' => new MongoDB\BSON\Decimal128('1234.5678') ], + [ 'int64' => new MongoDB\BSON\Int64('9223372036854775807') ], + // JavaScript w/ scope may not be necessary (same code path as w/o scope), but we'll test it anyway + [ 'javascript' => new MongoDB\BSON\Javascript('function() { return 1; }') ], + // The context is recreated every time with a different object ID + //[ 'javascript_ws' => new MongoDB\BSON\Javascript('function() { return a; }', ['a' => 1]) ], + // MaxKey and MinKey don't have get_properties or get_gc handlers, but we'll test them anyway + [ 'maxkey' => new MongoDB\BSON\MaxKey ], + [ 'minkey' => new MongoDB\BSON\MinKey ], + [ 'objectid' => new MongoDB\BSON\ObjectId ], + [ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ], + [ 'symbol' => createSymbol() ], + [ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ], + [ 'utcdatetime' => new MongoDB\BSON\UTCDateTime ], +]; + +ob_start(); +foreach ($tests as $test) { + echo key($test), "\n"; + $test = reset($test); + + foreach ($test as $k => $v) { + var_dump($k, $v); + } +} +$buf1 = ob_get_clean(); +if ($buf1 === false) { + throw new \AssertionError("Could not flush buffer"); +} + +foreach ($tests as $test) { + $test = reset($test); + $t = &$test->a; + $t = 'test'; + unset($test->a, $t); +} + +ob_start(); +foreach ($tests as $test) { + echo key($test), "\n"; + $test = reset($test); + + foreach ($test as $k => $v) { + var_dump($k, $v); + } +} +$buf2 = ob_get_clean(); +if ($buf2 === false) { + throw new \AssertionError("Could not flush buffer"); +} + +if ($buf1 === $buf2) { + echo "OK!\n"; + exit(0); +} else { + echo("buf1 != buf2: $buf1\n!=\n$buf2\n"); +} + +?> +--EXPECT-- +OK! \ No newline at end of file diff --git a/tests/readConcern/bug1598-002.phpt b/tests/readConcern/bug1598-002.phpt index fb7450f7c..a343f81de 100644 --- a/tests/readConcern/bug1598-002.phpt +++ b/tests/readConcern/bug1598-002.phpt @@ -1,8 +1,5 @@ --TEST-- PHPC-1598: ReadConcern get_gc should delegate to zend_std_get_properties ---SKIPIF-- - -=', '8.1.99'); ?> --FILE-- -=', '8.1.99'); ?> --FILE-- -=', '8.1.99'); ?> --FILE-- Date: Thu, 24 Jul 2025 12:18:45 +0200 Subject: [PATCH 35/44] Fix --- php_phongo.h | 1 - 1 file changed, 1 deletion(-) diff --git a/php_phongo.h b/php_phongo.h index 596e27a86..6b1d0f1e2 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -71,7 +71,6 @@ zend_object_handlers* phongo_get_std_object_handlers(void); if (!(intern)->php_properties) { \ ALLOC_HASHTABLE((intern)->php_properties); \ zend_hash_init((intern)->php_properties, 0, NULL, ZVAL_PTR_DTOR, 0); \ - GC_ADDREF((intern)->php_properties); \ } \ if (is_temp) { \ (props) = zend_array_dup((intern)->php_properties); \ From 7d477cc63412036674c74da98fee3055bae6ac63 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 24 Jul 2025 13:05:18 +0200 Subject: [PATCH 36/44] The test is now correct --- tests/bson/bug0939-001.phpt | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/bson/bug0939-001.phpt b/tests/bson/bug0939-001.phpt index 09caece5c..a66e7be09 100644 --- a/tests/bson/bug0939-001.phpt +++ b/tests/bson/bug0939-001.phpt @@ -38,14 +38,14 @@ object(MongoDB\BSON\Binary)#%d (%d) { ["type"]=> int(0) } -MongoDB\BSON\Binary::$data exists: yes -MongoDB\BSON\Binary::$type exists: yes +MongoDB\BSON\Binary::$data exists: no +MongoDB\BSON\Binary::$type exists: no object(MongoDB\BSON\Decimal128)#%d (%d) { ["dec"]=> string(4) "3.14" } -MongoDB\BSON\Decimal128::$dec exists: yes +MongoDB\BSON\Decimal128::$dec exists: no object(MongoDB\BSON\Javascript)#%d (%d) { ["code"]=> @@ -56,8 +56,8 @@ object(MongoDB\BSON\Javascript)#%d (%d) { int(42) } } -MongoDB\BSON\Javascript::$code exists: yes -MongoDB\BSON\Javascript::$scope exists: yes +MongoDB\BSON\Javascript::$code exists: no +MongoDB\BSON\Javascript::$scope exists: no object(MongoDB\BSON\MaxKey)#%d (%d) { } @@ -69,7 +69,7 @@ object(MongoDB\BSON\ObjectId)#%d (%d) { ["oid"]=> string(24) "%x" } -MongoDB\BSON\ObjectId::$oid exists: yes +MongoDB\BSON\ObjectId::$oid exists: no object(MongoDB\BSON\Regex)#%d (%d) { ["pattern"]=> @@ -77,8 +77,8 @@ object(MongoDB\BSON\Regex)#%d (%d) { ["flags"]=> string(1) "i" } -MongoDB\BSON\Regex::$pattern exists: yes -MongoDB\BSON\Regex::$flags exists: yes +MongoDB\BSON\Regex::$pattern exists: no +MongoDB\BSON\Regex::$flags exists: no object(MongoDB\BSON\Timestamp)#%d (%d) { ["increment"]=> @@ -86,13 +86,13 @@ object(MongoDB\BSON\Timestamp)#%d (%d) { ["timestamp"]=> string(4) "5678" } -MongoDB\BSON\Timestamp::$increment exists: yes -MongoDB\BSON\Timestamp::$timestamp exists: yes +MongoDB\BSON\Timestamp::$increment exists: no +MongoDB\BSON\Timestamp::$timestamp exists: no object(MongoDB\BSON\UTCDateTime)#%d (%d) { ["milliseconds"]=> string(%d) "%d" } -MongoDB\BSON\UTCDateTime::$milliseconds exists: yes +MongoDB\BSON\UTCDateTime::$milliseconds exists: no ===DONE=== From 263b20c085b2ff36ed8c0dcd42cc07246ac8821e Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Thu, 24 Jul 2025 17:33:32 +0200 Subject: [PATCH 37/44] Add custom gc handlers --- php_phongo.c | 8 -------- php_phongo.h | 10 ++++++++++ src/BSON/Binary.c | 1 + src/BSON/DBPointer.c | 1 + src/BSON/Decimal128.c | 1 + src/BSON/Int64.c | 1 + src/BSON/Iterator.c | 1 + src/BSON/Javascript.c | 1 + src/BSON/ObjectId.c | 1 + src/BSON/PackedArray.c | 1 + src/BSON/Regex.c | 1 + src/BSON/Symbol.c | 1 + src/BSON/Timestamp.c | 1 + src/BSON/UTCDateTime.c | 1 + src/MongoDB/ReadConcern.c | 1 + src/MongoDB/ReadPreference.c | 1 + src/MongoDB/ServerApi.c | 1 + src/MongoDB/ServerDescription.c | 1 + src/MongoDB/TopologyDescription.c | 1 + src/MongoDB/WriteConcern.c | 1 + 20 files changed, 28 insertions(+), 8 deletions(-) diff --git a/php_phongo.c b/php_phongo.c index 710cff685..d020f2b9a 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -155,13 +155,6 @@ static zend_class_entry* php_phongo_fetch_internal_class(const char* class_name, return NULL; } -static HashTable* php_phongo_std_get_gc(zend_object* object, zval** table, int* n) -{ - *table = NULL; - *n = 0; - return object->handlers->get_properties(object); -} - PHP_MINIT_FUNCTION(mongodb) /* {{{ */ { @@ -198,7 +191,6 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */ /* Disable cloning by default. Individual classes can opt in if they need to * support this (e.g. BSON objects). */ phongo_std_object_handlers.clone_obj = NULL; - phongo_std_object_handlers.get_gc = php_phongo_std_get_gc; /* Initialize zend_class_entry dependencies. * diff --git a/php_phongo.h b/php_phongo.h index 6b1d0f1e2..4df0b814b 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -93,6 +93,16 @@ zend_object_handlers* phongo_get_std_object_handlers(void); } while (0) #define PHONGO_GET_PROPERTY_HANDLERS(_name, _intern_extractor) \ + PHONGO_GET_PROPERTY_HANDLERS_NO_GC(_name, _intern_extractor) \ + \ + static HashTable* php_phongo_##_name##_get_gc(zend_object* zobj, zval** table, int* n) \ + { \ + *table = NULL; \ + *n = 0; \ + return _intern_extractor(zobj)->php_properties; \ + } + +#define PHONGO_GET_PROPERTY_HANDLERS_NO_GC(_name, _intern_extractor) \ static zval* php_phongo_##_name##_read_property(zend_object *zobj, zend_string *member, int type, void **cache_slot, zval *rv) \ { \ HashTable *props = _intern_extractor(zobj)->php_properties; \ diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index e3aa7e877..5d45083a8 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -305,6 +305,7 @@ void php_phongo_binary_init_ce(INIT_FUNC_ARGS) php_phongo_handler_binary.has_property = php_phongo_binary_has_property; php_phongo_handler_binary.unset_property = php_phongo_binary_unset_property; php_phongo_handler_binary.get_property_ptr_ptr = php_phongo_binary_get_property_ptr_ptr; + php_phongo_handler_binary.get_gc = php_phongo_binary_get_gc; php_phongo_handler_binary.free_obj = php_phongo_binary_free_object; php_phongo_handler_binary.offset = XtOffsetOf(php_phongo_binary_t, std); } diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index af63f45e2..8a6a7ba31 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -265,6 +265,7 @@ void php_phongo_dbpointer_init_ce(INIT_FUNC_ARGS) php_phongo_handler_dbpointer.has_property = php_phongo_dbpointer_has_property; php_phongo_handler_dbpointer.unset_property = php_phongo_dbpointer_unset_property; php_phongo_handler_dbpointer.get_property_ptr_ptr = php_phongo_dbpointer_get_property_ptr_ptr; + php_phongo_handler_dbpointer.get_gc = php_phongo_dbpointer_get_gc; php_phongo_handler_dbpointer.free_obj = php_phongo_dbpointer_free_object; php_phongo_handler_dbpointer.offset = XtOffsetOf(php_phongo_dbpointer_t, std); } diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 078eeac8a..e3904b5a9 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -239,6 +239,7 @@ void php_phongo_decimal128_init_ce(INIT_FUNC_ARGS) php_phongo_handler_decimal128.has_property = php_phongo_decimal128_has_property; php_phongo_handler_decimal128.unset_property = php_phongo_decimal128_unset_property; php_phongo_handler_decimal128.get_property_ptr_ptr = php_phongo_decimal128_get_property_ptr_ptr; + php_phongo_handler_decimal128.get_gc = php_phongo_decimal128_get_gc; php_phongo_handler_decimal128.free_obj = php_phongo_decimal128_free_object; php_phongo_handler_decimal128.offset = XtOffsetOf(php_phongo_decimal128_t, std); } diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index 7ac0efb3f..5e84e7d58 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -578,6 +578,7 @@ void php_phongo_int64_init_ce(INIT_FUNC_ARGS) php_phongo_handler_int64.has_property = php_phongo_int64_has_property; php_phongo_handler_int64.unset_property = php_phongo_int64_unset_property; php_phongo_handler_int64.get_property_ptr_ptr = php_phongo_int64_get_property_ptr_ptr; + php_phongo_handler_int64.get_gc = php_phongo_int64_get_gc; php_phongo_handler_int64.free_obj = php_phongo_int64_free_object; php_phongo_handler_int64.offset = XtOffsetOf(php_phongo_int64_t, std); php_phongo_handler_int64.cast_object = php_phongo_int64_cast_object; diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index b285e459d..08a9bc20c 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -401,6 +401,7 @@ void php_phongo_iterator_init_ce(INIT_FUNC_ARGS) php_phongo_handler_iterator.has_property = php_phongo_iterator_has_property; php_phongo_handler_iterator.unset_property = php_phongo_iterator_unset_property; php_phongo_handler_iterator.get_property_ptr_ptr = php_phongo_iterator_get_property_ptr_ptr; + php_phongo_handler_iterator.get_gc = php_phongo_iterator_get_gc; php_phongo_handler_iterator.free_obj = php_phongo_iterator_free_object; php_phongo_handler_iterator.offset = XtOffsetOf(php_phongo_iterator_t, std); } diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index 4c9ce6af6..74a93bc51 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -346,6 +346,7 @@ void php_phongo_javascript_init_ce(INIT_FUNC_ARGS) php_phongo_handler_javascript.has_property = php_phongo_javascript_has_property; php_phongo_handler_javascript.unset_property = php_phongo_javascript_unset_property; php_phongo_handler_javascript.get_property_ptr_ptr = php_phongo_javascript_get_property_ptr_ptr; + php_phongo_handler_javascript.get_gc = php_phongo_javascript_get_gc; php_phongo_handler_javascript.free_obj = php_phongo_javascript_free_object; php_phongo_handler_javascript.offset = XtOffsetOf(php_phongo_javascript_t, std); } diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 4e6a460fe..bebf253ff 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -287,6 +287,7 @@ void php_phongo_objectid_init_ce(INIT_FUNC_ARGS) php_phongo_handler_objectid.has_property = php_phongo_objectid_has_property; php_phongo_handler_objectid.unset_property = php_phongo_objectid_unset_property; php_phongo_handler_objectid.get_property_ptr_ptr = php_phongo_objectid_get_property_ptr_ptr; + php_phongo_handler_objectid.get_gc = php_phongo_objectid_get_gc; php_phongo_handler_objectid.free_obj = php_phongo_objectid_free_object; php_phongo_handler_objectid.offset = XtOffsetOf(php_phongo_objectid_t, std); } diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index 2d6ce8b33..adc4c5e12 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -588,6 +588,7 @@ void php_phongo_packedarray_init_ce(INIT_FUNC_ARGS) php_phongo_handler_packedarray.has_property = php_phongo_packedarray_has_property; php_phongo_handler_packedarray.unset_property = php_phongo_packedarray_unset_property; php_phongo_handler_packedarray.get_property_ptr_ptr = php_phongo_packedarray_get_property_ptr_ptr; + php_phongo_handler_packedarray.get_gc = php_phongo_packedarray_get_gc; php_phongo_handler_packedarray.free_obj = php_phongo_packedarray_free_object; php_phongo_handler_packedarray.read_dimension = php_phongo_packedarray_read_dimension; php_phongo_handler_packedarray.write_dimension = php_phongo_packedarray_write_dimension; diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index b25f9620b..ae064e93d 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -318,6 +318,7 @@ void php_phongo_regex_init_ce(INIT_FUNC_ARGS) php_phongo_handler_regex.has_property = php_phongo_regex_has_property; php_phongo_handler_regex.unset_property = php_phongo_regex_unset_property; php_phongo_handler_regex.get_property_ptr_ptr = php_phongo_regex_get_property_ptr_ptr; + php_phongo_handler_regex.get_gc = php_phongo_regex_get_gc; php_phongo_handler_regex.free_obj = php_phongo_regex_free_object; php_phongo_handler_regex.offset = XtOffsetOf(php_phongo_regex_t, std); } diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index 20ed21a09..f39b82a4b 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -232,6 +232,7 @@ void php_phongo_symbol_init_ce(INIT_FUNC_ARGS) php_phongo_handler_symbol.has_property = php_phongo_symbol_has_property; php_phongo_handler_symbol.unset_property = php_phongo_symbol_unset_property; php_phongo_handler_symbol.get_property_ptr_ptr = php_phongo_symbol_get_property_ptr_ptr; + php_phongo_handler_symbol.get_gc = php_phongo_symbol_get_gc; php_phongo_handler_symbol.free_obj = php_phongo_symbol_free_object; php_phongo_handler_symbol.offset = XtOffsetOf(php_phongo_symbol_t, std); } diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 66121d325..d2dfd3d97 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -352,6 +352,7 @@ void php_phongo_timestamp_init_ce(INIT_FUNC_ARGS) php_phongo_handler_timestamp.has_property = php_phongo_timestamp_has_property; php_phongo_handler_timestamp.unset_property = php_phongo_timestamp_unset_property; php_phongo_handler_timestamp.get_property_ptr_ptr = php_phongo_timestamp_get_property_ptr_ptr; + php_phongo_handler_timestamp.get_gc = php_phongo_timestamp_get_gc; php_phongo_handler_timestamp.free_obj = php_phongo_timestamp_free_object; php_phongo_handler_timestamp.offset = XtOffsetOf(php_phongo_timestamp_t, std); } diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index 6af94f7b7..51f8d3166 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -387,6 +387,7 @@ void php_phongo_utcdatetime_init_ce(INIT_FUNC_ARGS) php_phongo_handler_utcdatetime.has_property = php_phongo_utcdatetime_has_property; php_phongo_handler_utcdatetime.unset_property = php_phongo_utcdatetime_unset_property; php_phongo_handler_utcdatetime.get_property_ptr_ptr = php_phongo_utcdatetime_get_property_ptr_ptr; + php_phongo_handler_utcdatetime.get_gc = php_phongo_utcdatetime_get_gc; php_phongo_handler_utcdatetime.free_obj = php_phongo_utcdatetime_free_object; php_phongo_handler_utcdatetime.offset = XtOffsetOf(php_phongo_utcdatetime_t, std); } diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index af0eaafac..dbb3fb6a4 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -238,6 +238,7 @@ void php_phongo_readconcern_init_ce(INIT_FUNC_ARGS) php_phongo_handler_readconcern.has_property = php_phongo_readconcern_has_property; php_phongo_handler_readconcern.unset_property = php_phongo_readconcern_unset_property; php_phongo_handler_readconcern.get_property_ptr_ptr = php_phongo_readconcern_get_property_ptr_ptr; + php_phongo_handler_readconcern.get_gc = php_phongo_readconcern_get_gc; php_phongo_handler_readconcern.free_obj = php_phongo_readconcern_free_object; php_phongo_handler_readconcern.offset = XtOffsetOf(php_phongo_readconcern_t, std); } diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index e8955bc24..8b4aa968b 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -538,6 +538,7 @@ void php_phongo_readpreference_init_ce(INIT_FUNC_ARGS) php_phongo_handler_readpreference.has_property = php_phongo_readpreference_has_property; php_phongo_handler_readpreference.unset_property = php_phongo_readpreference_unset_property; php_phongo_handler_readpreference.get_property_ptr_ptr = php_phongo_readpreference_get_property_ptr_ptr; + php_phongo_handler_readpreference.get_gc = php_phongo_readpreference_get_gc; php_phongo_handler_readpreference.free_obj = php_phongo_readpreference_free_object; php_phongo_handler_readpreference.offset = XtOffsetOf(php_phongo_readpreference_t, std); } diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index 899df8bc1..7cb73878d 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -266,6 +266,7 @@ void php_phongo_serverapi_init_ce(INIT_FUNC_ARGS) php_phongo_handler_serverapi.has_property = php_phongo_serverapi_has_property; php_phongo_handler_serverapi.unset_property = php_phongo_serverapi_unset_property; php_phongo_handler_serverapi.get_property_ptr_ptr = php_phongo_serverapi_get_property_ptr_ptr; + php_phongo_handler_serverapi.get_gc = php_phongo_serverapi_get_gc; php_phongo_handler_serverapi.free_obj = php_phongo_serverapi_free_object; php_phongo_handler_serverapi.offset = XtOffsetOf(php_phongo_serverapi_t, std); } diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index 9508d95d3..1994dc291 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -289,6 +289,7 @@ void php_phongo_serverdescription_init_ce(INIT_FUNC_ARGS) php_phongo_handler_serverdescription.has_property = php_phongo_serverdescription_has_property; php_phongo_handler_serverdescription.unset_property = php_phongo_serverdescription_unset_property; php_phongo_handler_serverdescription.get_property_ptr_ptr = php_phongo_serverdescription_get_property_ptr_ptr; + php_phongo_handler_serverdescription.get_gc = php_phongo_serverdescription_get_gc; php_phongo_handler_serverdescription.free_obj = php_phongo_serverdescription_free_object; php_phongo_handler_serverdescription.offset = XtOffsetOf(php_phongo_serverdescription_t, std); } diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index ecbe54547..a832b0e2c 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -202,6 +202,7 @@ void php_phongo_topologydescription_init_ce(INIT_FUNC_ARGS) php_phongo_handler_topologydescription.has_property = php_phongo_topologydescription_has_property; php_phongo_handler_topologydescription.unset_property = php_phongo_topologydescription_unset_property; php_phongo_handler_topologydescription.get_property_ptr_ptr = php_phongo_topologydescription_get_property_ptr_ptr; + php_phongo_handler_topologydescription.get_gc = php_phongo_topologydescription_get_gc; php_phongo_handler_topologydescription.free_obj = php_phongo_topologydescription_free_object; php_phongo_handler_topologydescription.offset = XtOffsetOf(php_phongo_topologydescription_t, std); } diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index 2510619b0..1045e4eb1 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -423,6 +423,7 @@ void php_phongo_writeconcern_init_ce(INIT_FUNC_ARGS) php_phongo_handler_writeconcern.has_property = php_phongo_writeconcern_has_property; php_phongo_handler_writeconcern.unset_property = php_phongo_writeconcern_unset_property; php_phongo_handler_writeconcern.get_property_ptr_ptr = php_phongo_writeconcern_get_property_ptr_ptr; + php_phongo_handler_writeconcern.get_gc = php_phongo_writeconcern_get_gc; php_phongo_handler_writeconcern.free_obj = php_phongo_writeconcern_free_object; php_phongo_handler_writeconcern.offset = XtOffsetOf(php_phongo_writeconcern_t, std); } From 3b4f176b8018b7154dac5d4a01fe4fee2116d1c4 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 25 Jul 2025 10:31:53 +0200 Subject: [PATCH 38/44] clang-format --- php_phongo.c | 1 - php_phongo.h | 194 +++++++++++++++--------------- src/BSON/Binary.c | 27 ++--- src/BSON/DBPointer.c | 27 ++--- src/BSON/Decimal128.c | 25 ++-- src/BSON/Document.c | 5 +- src/BSON/Int64.c | 31 +++-- src/BSON/Iterator.c | 25 ++-- src/BSON/Javascript.c | 27 ++--- src/BSON/ObjectId.c | 27 ++--- src/BSON/PackedArray.c | 35 +++--- src/BSON/Regex.c | 27 ++--- src/BSON/Symbol.c | 27 ++--- src/BSON/Timestamp.c | 27 ++--- src/BSON/UTCDateTime.c | 27 ++--- src/MongoDB/ReadConcern.c | 23 ++-- src/MongoDB/ReadPreference.c | 23 ++-- src/MongoDB/ServerApi.c | 23 ++-- src/MongoDB/ServerDescription.c | 23 ++-- src/MongoDB/TopologyDescription.c | 23 ++-- src/MongoDB/WriteConcern.c | 23 ++-- src/phongo_compat.h | 4 +- 22 files changed, 326 insertions(+), 348 deletions(-) diff --git a/php_phongo.c b/php_phongo.c index d020f2b9a..595eb1352 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -155,7 +155,6 @@ static zend_class_entry* php_phongo_fetch_internal_class(const char* class_name, return NULL; } - PHP_MINIT_FUNCTION(mongodb) /* {{{ */ { bson_mem_vtable_t bson_mem_vtable = { diff --git a/php_phongo.h b/php_phongo.h index 4df0b814b..2ebf7cab5 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -61,28 +61,28 @@ ZEND_TSRMLS_CACHE_EXTERN() zend_object_handlers* phongo_get_std_object_handlers(void); #define PHONGO_RETURN_PROPS(is_temp, props) \ - if (!(is_temp)) { \ - GC_ADDREF(props); \ - } \ + if (!(is_temp)) { \ + GC_ADDREF(props); \ + } \ return props; -#define PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size) \ - do { \ - if (!(intern)->php_properties) { \ - ALLOC_HASHTABLE((intern)->php_properties); \ +#define PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size) \ + do { \ + if (!(intern)->php_properties) { \ + ALLOC_HASHTABLE((intern)->php_properties); \ zend_hash_init((intern)->php_properties, 0, NULL, ZVAL_PTR_DTOR, 0); \ - } \ - if (is_temp) { \ - (props) = zend_array_dup((intern)->php_properties); \ - } else { \ - (props) = zend_array_dup((intern)->php_properties); \ - if ((intern)->properties) { \ - HashTable *__tmp = (intern)->properties; \ - (intern)->properties = NULL; \ - zend_hash_release(__tmp); \ - } \ - (intern)->properties = (props); \ - } \ + } \ + if (is_temp) { \ + (props) = zend_array_dup((intern)->php_properties); \ + } else { \ + (props) = zend_array_dup((intern)->php_properties); \ + if ((intern)->properties) { \ + HashTable* __tmp = (intern)->properties; \ + (intern)->properties = NULL; \ + zend_hash_release(__tmp); \ + } \ + (intern)->properties = (props); \ + } \ } while (0) #define PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props) \ @@ -92,87 +92,87 @@ zend_object_handlers* phongo_get_std_object_handlers(void); } \ } while (0) -#define PHONGO_GET_PROPERTY_HANDLERS(_name, _intern_extractor) \ - PHONGO_GET_PROPERTY_HANDLERS_NO_GC(_name, _intern_extractor) \ - \ +#define PHONGO_GET_PROPERTY_HANDLERS(_name, _intern_extractor) \ + PHONGO_GET_PROPERTY_HANDLERS_NO_GC(_name, _intern_extractor) \ + \ static HashTable* php_phongo_##_name##_get_gc(zend_object* zobj, zval** table, int* n) \ - { \ - *table = NULL; \ - *n = 0; \ - return _intern_extractor(zobj)->php_properties; \ + { \ + *table = NULL; \ + *n = 0; \ + return _intern_extractor(zobj)->php_properties; \ } -#define PHONGO_GET_PROPERTY_HANDLERS_NO_GC(_name, _intern_extractor) \ - static zval* php_phongo_##_name##_read_property(zend_object *zobj, zend_string *member, int type, void **cache_slot, zval *rv) \ - { \ - HashTable *props = _intern_extractor(zobj)->php_properties; \ - if (!props) { \ - ALLOC_HASHTABLE(props); \ - zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ - _intern_extractor(zobj)->php_properties = props; \ - } \ - return zend_hash_find(props, member); \ - } \ - \ - static zval *php_phongo_##_name##_write_property(zend_object *zobj, zend_string *name, zval *value, void **cache_slot) \ - { \ - Z_TRY_ADDREF_P(value); \ - HashTable *props = _intern_extractor(zobj)->php_properties; \ - if (!props) { \ - ALLOC_HASHTABLE(props); \ - zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ - _intern_extractor(zobj)->php_properties = props; \ - } \ - return zend_hash_add_new(props, name, value); \ - } \ - static int php_phongo_##_name##_has_property(zend_object *zobj, zend_string *name, int has_set_exists, void **cache_slot) \ - { \ - HashTable *props = _intern_extractor(zobj)->php_properties; \ - if (!props) { \ - ALLOC_HASHTABLE(props); \ - zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ - _intern_extractor(zobj)->php_properties = props; \ - } \ - zval *value = zend_hash_find(props, name); \ - if (value) { \ - if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY) { \ - return zend_is_true(value); \ - } \ - if (has_set_exists < ZEND_PROPERTY_NOT_EMPTY) { \ - ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_ISSET); \ - ZVAL_DEREF(value); \ - return (Z_TYPE_P(value) != IS_NULL); \ - } \ - ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_EXISTS); \ - return true; \ - } \ - return false; \ - } \ - static void php_phongo_##_name##_unset_property(zend_object *zobj, zend_string *name, void **cache_slot) \ - { \ - HashTable *props = _intern_extractor(zobj)->php_properties; \ - if (!props) { \ - ALLOC_HASHTABLE(props); \ - zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ - _intern_extractor(zobj)->php_properties = props; \ - } \ - zend_hash_del(props, name); \ - } \ - \ - static zval *php_phongo_##_name##_get_property_ptr_ptr(zend_object *zobj, zend_string *name, int type, void **cache_slot) \ - { \ - HashTable *props = _intern_extractor(zobj)->php_properties; \ - if (!props) { \ - ALLOC_HASHTABLE(props); \ - zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ - _intern_extractor(zobj)->php_properties = props; \ - } \ - \ - zval *value = zend_hash_find(props, name); \ - if (value) { \ - return value; \ - } \ - return zend_hash_add(props, name, &EG(uninitialized_zval)); \ +#define PHONGO_GET_PROPERTY_HANDLERS_NO_GC(_name, _intern_extractor) \ + static zval* php_phongo_##_name##_read_property(zend_object* zobj, zend_string* member, int type, void** cache_slot, zval* rv) \ + { \ + HashTable* props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + return zend_hash_find(props, member); \ + } \ + \ + static zval* php_phongo_##_name##_write_property(zend_object* zobj, zend_string* name, zval* value, void** cache_slot) \ + { \ + Z_TRY_ADDREF_P(value); \ + HashTable* props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + return zend_hash_add_new(props, name, value); \ + } \ + static int php_phongo_##_name##_has_property(zend_object* zobj, zend_string* name, int has_set_exists, void** cache_slot) \ + { \ + HashTable* props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + zval* value = zend_hash_find(props, name); \ + if (value) { \ + if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY) { \ + return zend_is_true(value); \ + } \ + if (has_set_exists < ZEND_PROPERTY_NOT_EMPTY) { \ + ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_ISSET); \ + ZVAL_DEREF(value); \ + return (Z_TYPE_P(value) != IS_NULL); \ + } \ + ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_EXISTS); \ + return true; \ + } \ + return false; \ + } \ + static void php_phongo_##_name##_unset_property(zend_object* zobj, zend_string* name, void** cache_slot) \ + { \ + HashTable* props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + zend_hash_del(props, name); \ + } \ + \ + static zval* php_phongo_##_name##_get_property_ptr_ptr(zend_object* zobj, zend_string* name, int type, void** cache_slot) \ + { \ + HashTable* props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + \ + zval* value = zend_hash_find(props, name); \ + if (value) { \ + return value; \ + } \ + return zend_hash_add(props, name, &EG(uninitialized_zval)); \ } #define PHONGO_ZVAL_EXCEPTION_NAME(e) (ZSTR_VAL(e->ce->name)) diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index 5d45083a8..3c91f67f5 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -213,14 +213,13 @@ static void php_phongo_binary_free_object(zend_object* object) efree(intern->data); } - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -296,18 +295,18 @@ void php_phongo_binary_init_ce(INIT_FUNC_ARGS) php_phongo_binary_ce->create_object = php_phongo_binary_create_object; memcpy(&php_phongo_handler_binary, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_binary.compare = php_phongo_binary_compare_objects; - php_phongo_handler_binary.clone_obj = php_phongo_binary_clone_object; - php_phongo_handler_binary.get_debug_info = php_phongo_binary_get_debug_info; - php_phongo_handler_binary.get_properties = php_phongo_binary_get_properties; - php_phongo_handler_binary.read_property = php_phongo_binary_read_property; - php_phongo_handler_binary.write_property = php_phongo_binary_write_property; - php_phongo_handler_binary.has_property = php_phongo_binary_has_property; - php_phongo_handler_binary.unset_property = php_phongo_binary_unset_property; + php_phongo_handler_binary.compare = php_phongo_binary_compare_objects; + php_phongo_handler_binary.clone_obj = php_phongo_binary_clone_object; + php_phongo_handler_binary.get_debug_info = php_phongo_binary_get_debug_info; + php_phongo_handler_binary.get_properties = php_phongo_binary_get_properties; + php_phongo_handler_binary.read_property = php_phongo_binary_read_property; + php_phongo_handler_binary.write_property = php_phongo_binary_write_property; + php_phongo_handler_binary.has_property = php_phongo_binary_has_property; + php_phongo_handler_binary.unset_property = php_phongo_binary_unset_property; php_phongo_handler_binary.get_property_ptr_ptr = php_phongo_binary_get_property_ptr_ptr; - php_phongo_handler_binary.get_gc = php_phongo_binary_get_gc; - php_phongo_handler_binary.free_obj = php_phongo_binary_free_object; - php_phongo_handler_binary.offset = XtOffsetOf(php_phongo_binary_t, std); + php_phongo_handler_binary.get_gc = php_phongo_binary_get_gc; + php_phongo_handler_binary.free_obj = php_phongo_binary_free_object; + php_phongo_handler_binary.offset = XtOffsetOf(php_phongo_binary_t, std); } bool phongo_binary_new(zval* object, const char* data, size_t data_len, bson_subtype_t type) diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index 8a6a7ba31..89e69f5a2 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -176,14 +176,13 @@ static void php_phongo_dbpointer_free_object(zend_object* object) efree(intern->ref); } - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -256,18 +255,18 @@ void php_phongo_dbpointer_init_ce(INIT_FUNC_ARGS) php_phongo_dbpointer_ce->create_object = php_phongo_dbpointer_create_object; memcpy(&php_phongo_handler_dbpointer, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_dbpointer.compare = php_phongo_dbpointer_compare_objects; - php_phongo_handler_dbpointer.clone_obj = php_phongo_dbpointer_clone_object; - php_phongo_handler_dbpointer.get_debug_info = php_phongo_dbpointer_get_debug_info; - php_phongo_handler_dbpointer.get_properties = php_phongo_dbpointer_get_properties; - php_phongo_handler_dbpointer.read_property = php_phongo_dbpointer_read_property; - php_phongo_handler_dbpointer.write_property = php_phongo_dbpointer_write_property; - php_phongo_handler_dbpointer.has_property = php_phongo_dbpointer_has_property; - php_phongo_handler_dbpointer.unset_property = php_phongo_dbpointer_unset_property; + php_phongo_handler_dbpointer.compare = php_phongo_dbpointer_compare_objects; + php_phongo_handler_dbpointer.clone_obj = php_phongo_dbpointer_clone_object; + php_phongo_handler_dbpointer.get_debug_info = php_phongo_dbpointer_get_debug_info; + php_phongo_handler_dbpointer.get_properties = php_phongo_dbpointer_get_properties; + php_phongo_handler_dbpointer.read_property = php_phongo_dbpointer_read_property; + php_phongo_handler_dbpointer.write_property = php_phongo_dbpointer_write_property; + php_phongo_handler_dbpointer.has_property = php_phongo_dbpointer_has_property; + php_phongo_handler_dbpointer.unset_property = php_phongo_dbpointer_unset_property; php_phongo_handler_dbpointer.get_property_ptr_ptr = php_phongo_dbpointer_get_property_ptr_ptr; - php_phongo_handler_dbpointer.get_gc = php_phongo_dbpointer_get_gc; - php_phongo_handler_dbpointer.free_obj = php_phongo_dbpointer_free_object; - php_phongo_handler_dbpointer.offset = XtOffsetOf(php_phongo_dbpointer_t, std); + php_phongo_handler_dbpointer.get_gc = php_phongo_dbpointer_get_gc; + php_phongo_handler_dbpointer.free_obj = php_phongo_dbpointer_free_object; + php_phongo_handler_dbpointer.offset = XtOffsetOf(php_phongo_dbpointer_t, std); } bool phongo_dbpointer_new(zval* object, const char* ref, size_t ref_len, const bson_oid_t* oid) diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index e3904b5a9..1bdf7fd73 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -168,14 +168,13 @@ static void php_phongo_decimal128_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -231,17 +230,17 @@ void php_phongo_decimal128_init_ce(INIT_FUNC_ARGS) php_phongo_decimal128_ce->create_object = php_phongo_decimal128_create_object; memcpy(&php_phongo_handler_decimal128, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_decimal128.clone_obj = php_phongo_decimal128_clone_object; - php_phongo_handler_decimal128.get_debug_info = php_phongo_decimal128_get_debug_info; - php_phongo_handler_decimal128.get_properties = php_phongo_decimal128_get_properties; - php_phongo_handler_decimal128.read_property = php_phongo_decimal128_read_property; - php_phongo_handler_decimal128.write_property = php_phongo_decimal128_write_property; - php_phongo_handler_decimal128.has_property = php_phongo_decimal128_has_property; - php_phongo_handler_decimal128.unset_property = php_phongo_decimal128_unset_property; + php_phongo_handler_decimal128.clone_obj = php_phongo_decimal128_clone_object; + php_phongo_handler_decimal128.get_debug_info = php_phongo_decimal128_get_debug_info; + php_phongo_handler_decimal128.get_properties = php_phongo_decimal128_get_properties; + php_phongo_handler_decimal128.read_property = php_phongo_decimal128_read_property; + php_phongo_handler_decimal128.write_property = php_phongo_decimal128_write_property; + php_phongo_handler_decimal128.has_property = php_phongo_decimal128_has_property; + php_phongo_handler_decimal128.unset_property = php_phongo_decimal128_unset_property; php_phongo_handler_decimal128.get_property_ptr_ptr = php_phongo_decimal128_get_property_ptr_ptr; - php_phongo_handler_decimal128.get_gc = php_phongo_decimal128_get_gc; - php_phongo_handler_decimal128.free_obj = php_phongo_decimal128_free_object; - php_phongo_handler_decimal128.offset = XtOffsetOf(php_phongo_decimal128_t, std); + php_phongo_handler_decimal128.get_gc = php_phongo_decimal128_get_gc; + php_phongo_handler_decimal128.free_obj = php_phongo_decimal128_free_object; + php_phongo_handler_decimal128.offset = XtOffsetOf(php_phongo_decimal128_t, std); } bool phongo_decimal128_new(zval* object, const bson_decimal128_t* decimal) diff --git a/src/BSON/Document.c b/src/BSON/Document.c index 8bd26a6ae..e3e074825 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -446,14 +446,13 @@ static void php_phongo_document_free_object(zend_object* object) bson_destroy(intern->bson); } - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index 5e84e7d58..02feb7bd7 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -175,14 +175,13 @@ static void php_phongo_int64_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -569,20 +568,20 @@ void php_phongo_int64_init_ce(INIT_FUNC_ARGS) php_phongo_int64_ce->create_object = php_phongo_int64_create_object; memcpy(&php_phongo_handler_int64, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_int64.compare = php_phongo_int64_compare_objects; - php_phongo_handler_int64.clone_obj = php_phongo_int64_clone_object; - php_phongo_handler_int64.get_debug_info = php_phongo_int64_get_debug_info; - php_phongo_handler_int64.get_properties = php_phongo_int64_get_properties; - php_phongo_handler_int64.read_property = php_phongo_int64_read_property; - php_phongo_handler_int64.write_property = php_phongo_int64_write_property; - php_phongo_handler_int64.has_property = php_phongo_int64_has_property; - php_phongo_handler_int64.unset_property = php_phongo_int64_unset_property; + php_phongo_handler_int64.compare = php_phongo_int64_compare_objects; + php_phongo_handler_int64.clone_obj = php_phongo_int64_clone_object; + php_phongo_handler_int64.get_debug_info = php_phongo_int64_get_debug_info; + php_phongo_handler_int64.get_properties = php_phongo_int64_get_properties; + php_phongo_handler_int64.read_property = php_phongo_int64_read_property; + php_phongo_handler_int64.write_property = php_phongo_int64_write_property; + php_phongo_handler_int64.has_property = php_phongo_int64_has_property; + php_phongo_handler_int64.unset_property = php_phongo_int64_unset_property; php_phongo_handler_int64.get_property_ptr_ptr = php_phongo_int64_get_property_ptr_ptr; - php_phongo_handler_int64.get_gc = php_phongo_int64_get_gc; - php_phongo_handler_int64.free_obj = php_phongo_int64_free_object; - php_phongo_handler_int64.offset = XtOffsetOf(php_phongo_int64_t, std); - php_phongo_handler_int64.cast_object = php_phongo_int64_cast_object; - php_phongo_handler_int64.do_operation = php_phongo_int64_do_operation; + php_phongo_handler_int64.get_gc = php_phongo_int64_get_gc; + php_phongo_handler_int64.free_obj = php_phongo_int64_free_object; + php_phongo_handler_int64.offset = XtOffsetOf(php_phongo_int64_t, std); + php_phongo_handler_int64.cast_object = php_phongo_int64_cast_object; + php_phongo_handler_int64.do_operation = php_phongo_int64_do_operation; } bool phongo_int64_new(zval* object, int64_t integer) diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index 08a9bc20c..e6a56df55 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -248,14 +248,13 @@ static void php_phongo_iterator_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -393,15 +392,15 @@ void php_phongo_iterator_init_ce(INIT_FUNC_ARGS) php_phongo_iterator_ce->get_iterator = php_phongo_iterator_get_iterator; memcpy(&php_phongo_handler_iterator, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_iterator.clone_obj = php_phongo_iterator_clone_object; - php_phongo_handler_iterator.get_debug_info = php_phongo_iterator_get_debug_info; - php_phongo_handler_iterator.get_properties = php_phongo_iterator_get_properties; - php_phongo_handler_iterator.read_property = php_phongo_iterator_read_property; - php_phongo_handler_iterator.write_property = php_phongo_iterator_write_property; - php_phongo_handler_iterator.has_property = php_phongo_iterator_has_property; - php_phongo_handler_iterator.unset_property = php_phongo_iterator_unset_property; + php_phongo_handler_iterator.clone_obj = php_phongo_iterator_clone_object; + php_phongo_handler_iterator.get_debug_info = php_phongo_iterator_get_debug_info; + php_phongo_handler_iterator.get_properties = php_phongo_iterator_get_properties; + php_phongo_handler_iterator.read_property = php_phongo_iterator_read_property; + php_phongo_handler_iterator.write_property = php_phongo_iterator_write_property; + php_phongo_handler_iterator.has_property = php_phongo_iterator_has_property; + php_phongo_handler_iterator.unset_property = php_phongo_iterator_unset_property; php_phongo_handler_iterator.get_property_ptr_ptr = php_phongo_iterator_get_property_ptr_ptr; - php_phongo_handler_iterator.get_gc = php_phongo_iterator_get_gc; - php_phongo_handler_iterator.free_obj = php_phongo_iterator_free_object; - php_phongo_handler_iterator.offset = XtOffsetOf(php_phongo_iterator_t, std); + php_phongo_handler_iterator.get_gc = php_phongo_iterator_get_gc; + php_phongo_handler_iterator.free_obj = php_phongo_iterator_free_object; + php_phongo_handler_iterator.offset = XtOffsetOf(php_phongo_iterator_t, std); } diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index 74a93bc51..29f97dfe2 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -262,14 +262,13 @@ static void php_phongo_javascript_free_object(zend_object* object) intern->scope = NULL; } - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -337,18 +336,18 @@ void php_phongo_javascript_init_ce(INIT_FUNC_ARGS) php_phongo_javascript_ce->create_object = php_phongo_javascript_create_object; memcpy(&php_phongo_handler_javascript, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_javascript.compare = php_phongo_javascript_compare_objects; - php_phongo_handler_javascript.clone_obj = php_phongo_javascript_clone_object; - php_phongo_handler_javascript.get_debug_info = php_phongo_javascript_get_debug_info; - php_phongo_handler_javascript.get_properties = php_phongo_javascript_get_properties; - php_phongo_handler_javascript.read_property = php_phongo_javascript_read_property; - php_phongo_handler_javascript.write_property = php_phongo_javascript_write_property; - php_phongo_handler_javascript.has_property = php_phongo_javascript_has_property; - php_phongo_handler_javascript.unset_property = php_phongo_javascript_unset_property; + php_phongo_handler_javascript.compare = php_phongo_javascript_compare_objects; + php_phongo_handler_javascript.clone_obj = php_phongo_javascript_clone_object; + php_phongo_handler_javascript.get_debug_info = php_phongo_javascript_get_debug_info; + php_phongo_handler_javascript.get_properties = php_phongo_javascript_get_properties; + php_phongo_handler_javascript.read_property = php_phongo_javascript_read_property; + php_phongo_handler_javascript.write_property = php_phongo_javascript_write_property; + php_phongo_handler_javascript.has_property = php_phongo_javascript_has_property; + php_phongo_handler_javascript.unset_property = php_phongo_javascript_unset_property; php_phongo_handler_javascript.get_property_ptr_ptr = php_phongo_javascript_get_property_ptr_ptr; - php_phongo_handler_javascript.get_gc = php_phongo_javascript_get_gc; - php_phongo_handler_javascript.free_obj = php_phongo_javascript_free_object; - php_phongo_handler_javascript.offset = XtOffsetOf(php_phongo_javascript_t, std); + php_phongo_handler_javascript.get_gc = php_phongo_javascript_get_gc; + php_phongo_handler_javascript.free_obj = php_phongo_javascript_free_object; + php_phongo_handler_javascript.offset = XtOffsetOf(php_phongo_javascript_t, std); } bool phongo_javascript_new(zval* object, const char* code, size_t code_len, const bson_t* scope) diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index bebf253ff..1fc485644 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -202,14 +202,13 @@ static void php_phongo_objectid_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -278,18 +277,18 @@ void php_phongo_objectid_init_ce(INIT_FUNC_ARGS) php_phongo_objectid_ce->create_object = php_phongo_objectid_create_object; memcpy(&php_phongo_handler_objectid, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_objectid.compare = php_phongo_objectid_compare_objects; - php_phongo_handler_objectid.clone_obj = php_phongo_objectid_clone_object; - php_phongo_handler_objectid.get_debug_info = php_phongo_objectid_get_debug_info; - php_phongo_handler_objectid.get_properties = php_phongo_objectid_get_properties; - php_phongo_handler_objectid.read_property = php_phongo_objectid_read_property; - php_phongo_handler_objectid.write_property = php_phongo_objectid_write_property; - php_phongo_handler_objectid.has_property = php_phongo_objectid_has_property; - php_phongo_handler_objectid.unset_property = php_phongo_objectid_unset_property; + php_phongo_handler_objectid.compare = php_phongo_objectid_compare_objects; + php_phongo_handler_objectid.clone_obj = php_phongo_objectid_clone_object; + php_phongo_handler_objectid.get_debug_info = php_phongo_objectid_get_debug_info; + php_phongo_handler_objectid.get_properties = php_phongo_objectid_get_properties; + php_phongo_handler_objectid.read_property = php_phongo_objectid_read_property; + php_phongo_handler_objectid.write_property = php_phongo_objectid_write_property; + php_phongo_handler_objectid.has_property = php_phongo_objectid_has_property; + php_phongo_handler_objectid.unset_property = php_phongo_objectid_unset_property; php_phongo_handler_objectid.get_property_ptr_ptr = php_phongo_objectid_get_property_ptr_ptr; - php_phongo_handler_objectid.get_gc = php_phongo_objectid_get_gc; - php_phongo_handler_objectid.free_obj = php_phongo_objectid_free_object; - php_phongo_handler_objectid.offset = XtOffsetOf(php_phongo_objectid_t, std); + php_phongo_handler_objectid.get_gc = php_phongo_objectid_get_gc; + php_phongo_handler_objectid.free_obj = php_phongo_objectid_free_object; + php_phongo_handler_objectid.offset = XtOffsetOf(php_phongo_objectid_t, std); } bool phongo_objectid_new(zval* return_value, const bson_oid_t* oid) diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index adc4c5e12..b5ed1bafc 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -430,14 +430,13 @@ static void php_phongo_packedarray_free_object(zend_object* object) bson_destroy(intern->bson); } - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -579,22 +578,22 @@ void php_phongo_packedarray_init_ce(INIT_FUNC_ARGS) php_phongo_packedarray_ce->create_object = php_phongo_packedarray_create_object; memcpy(&php_phongo_handler_packedarray, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_packedarray.compare = php_phongo_packedarray_compare_objects; - php_phongo_handler_packedarray.clone_obj = php_phongo_packedarray_clone_object; - php_phongo_handler_packedarray.get_debug_info = php_phongo_packedarray_get_debug_info; - php_phongo_handler_packedarray.get_properties = php_phongo_packedarray_get_properties; - php_phongo_handler_packedarray.read_property = php_phongo_packedarray_read_property; - php_phongo_handler_packedarray.write_property = php_phongo_packedarray_write_property; - php_phongo_handler_packedarray.has_property = php_phongo_packedarray_has_property; - php_phongo_handler_packedarray.unset_property = php_phongo_packedarray_unset_property; + php_phongo_handler_packedarray.compare = php_phongo_packedarray_compare_objects; + php_phongo_handler_packedarray.clone_obj = php_phongo_packedarray_clone_object; + php_phongo_handler_packedarray.get_debug_info = php_phongo_packedarray_get_debug_info; + php_phongo_handler_packedarray.get_properties = php_phongo_packedarray_get_properties; + php_phongo_handler_packedarray.read_property = php_phongo_packedarray_read_property; + php_phongo_handler_packedarray.write_property = php_phongo_packedarray_write_property; + php_phongo_handler_packedarray.has_property = php_phongo_packedarray_has_property; + php_phongo_handler_packedarray.unset_property = php_phongo_packedarray_unset_property; php_phongo_handler_packedarray.get_property_ptr_ptr = php_phongo_packedarray_get_property_ptr_ptr; - php_phongo_handler_packedarray.get_gc = php_phongo_packedarray_get_gc; - php_phongo_handler_packedarray.free_obj = php_phongo_packedarray_free_object; - php_phongo_handler_packedarray.read_dimension = php_phongo_packedarray_read_dimension; - php_phongo_handler_packedarray.write_dimension = php_phongo_packedarray_write_dimension; - php_phongo_handler_packedarray.has_dimension = php_phongo_packedarray_has_dimension; - php_phongo_handler_packedarray.unset_dimension = php_phongo_packedarray_unset_dimension; - php_phongo_handler_packedarray.offset = XtOffsetOf(php_phongo_packedarray_t, std); + php_phongo_handler_packedarray.get_gc = php_phongo_packedarray_get_gc; + php_phongo_handler_packedarray.free_obj = php_phongo_packedarray_free_object; + php_phongo_handler_packedarray.read_dimension = php_phongo_packedarray_read_dimension; + php_phongo_handler_packedarray.write_dimension = php_phongo_packedarray_write_dimension; + php_phongo_handler_packedarray.has_dimension = php_phongo_packedarray_has_dimension; + php_phongo_handler_packedarray.unset_dimension = php_phongo_packedarray_unset_dimension; + php_phongo_handler_packedarray.offset = XtOffsetOf(php_phongo_packedarray_t, std); } bool phongo_packedarray_new(zval* object, bson_t* bson, bool copy) diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index ae064e93d..265f28124 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -228,14 +228,13 @@ static void php_phongo_regex_free_object(zend_object* object) efree(intern->flags); } - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -309,18 +308,18 @@ void php_phongo_regex_init_ce(INIT_FUNC_ARGS) php_phongo_regex_ce->create_object = php_phongo_regex_create_object; memcpy(&php_phongo_handler_regex, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_regex.compare = php_phongo_regex_compare_objects; - php_phongo_handler_regex.clone_obj = php_phongo_regex_clone_object; - php_phongo_handler_regex.get_debug_info = php_phongo_regex_get_debug_info; - php_phongo_handler_regex.get_properties = php_phongo_regex_get_properties; - php_phongo_handler_regex.read_property = php_phongo_regex_read_property; - php_phongo_handler_regex.write_property = php_phongo_regex_write_property; - php_phongo_handler_regex.has_property = php_phongo_regex_has_property; - php_phongo_handler_regex.unset_property = php_phongo_regex_unset_property; + php_phongo_handler_regex.compare = php_phongo_regex_compare_objects; + php_phongo_handler_regex.clone_obj = php_phongo_regex_clone_object; + php_phongo_handler_regex.get_debug_info = php_phongo_regex_get_debug_info; + php_phongo_handler_regex.get_properties = php_phongo_regex_get_properties; + php_phongo_handler_regex.read_property = php_phongo_regex_read_property; + php_phongo_handler_regex.write_property = php_phongo_regex_write_property; + php_phongo_handler_regex.has_property = php_phongo_regex_has_property; + php_phongo_handler_regex.unset_property = php_phongo_regex_unset_property; php_phongo_handler_regex.get_property_ptr_ptr = php_phongo_regex_get_property_ptr_ptr; - php_phongo_handler_regex.get_gc = php_phongo_regex_get_gc; - php_phongo_handler_regex.free_obj = php_phongo_regex_free_object; - php_phongo_handler_regex.offset = XtOffsetOf(php_phongo_regex_t, std); + php_phongo_handler_regex.get_gc = php_phongo_regex_get_gc; + php_phongo_handler_regex.free_obj = php_phongo_regex_free_object; + php_phongo_handler_regex.offset = XtOffsetOf(php_phongo_regex_t, std); } bool phongo_regex_new(zval* object, const char* pattern, const char* flags) diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index f39b82a4b..a06be9017 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -150,14 +150,13 @@ static void php_phongo_symbol_free_object(zend_object* object) efree(intern->symbol); } - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -223,18 +222,18 @@ void php_phongo_symbol_init_ce(INIT_FUNC_ARGS) php_phongo_symbol_ce->create_object = php_phongo_symbol_create_object; memcpy(&php_phongo_handler_symbol, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_symbol.compare = php_phongo_symbol_compare_objects; - php_phongo_handler_symbol.clone_obj = php_phongo_symbol_clone_object; - php_phongo_handler_symbol.get_debug_info = php_phongo_symbol_get_debug_info; - php_phongo_handler_symbol.get_properties = php_phongo_symbol_get_properties; - php_phongo_handler_symbol.read_property = php_phongo_symbol_read_property; - php_phongo_handler_symbol.write_property = php_phongo_symbol_write_property; - php_phongo_handler_symbol.has_property = php_phongo_symbol_has_property; - php_phongo_handler_symbol.unset_property = php_phongo_symbol_unset_property; + php_phongo_handler_symbol.compare = php_phongo_symbol_compare_objects; + php_phongo_handler_symbol.clone_obj = php_phongo_symbol_clone_object; + php_phongo_handler_symbol.get_debug_info = php_phongo_symbol_get_debug_info; + php_phongo_handler_symbol.get_properties = php_phongo_symbol_get_properties; + php_phongo_handler_symbol.read_property = php_phongo_symbol_read_property; + php_phongo_handler_symbol.write_property = php_phongo_symbol_write_property; + php_phongo_handler_symbol.has_property = php_phongo_symbol_has_property; + php_phongo_handler_symbol.unset_property = php_phongo_symbol_unset_property; php_phongo_handler_symbol.get_property_ptr_ptr = php_phongo_symbol_get_property_ptr_ptr; - php_phongo_handler_symbol.get_gc = php_phongo_symbol_get_gc; - php_phongo_handler_symbol.free_obj = php_phongo_symbol_free_object; - php_phongo_handler_symbol.offset = XtOffsetOf(php_phongo_symbol_t, std); + php_phongo_handler_symbol.get_gc = php_phongo_symbol_get_gc; + php_phongo_handler_symbol.free_obj = php_phongo_symbol_free_object; + php_phongo_handler_symbol.offset = XtOffsetOf(php_phongo_symbol_t, std); } bool phongo_symbol_new(zval* object, const char* symbol, size_t symbol_len) diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index d2dfd3d97..4d532bd07 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -261,14 +261,13 @@ static void php_phongo_timestamp_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -343,18 +342,18 @@ void php_phongo_timestamp_init_ce(INIT_FUNC_ARGS) php_phongo_timestamp_ce->create_object = php_phongo_timestamp_create_object; memcpy(&php_phongo_handler_timestamp, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_timestamp.compare = php_phongo_timestamp_compare_objects; - php_phongo_handler_timestamp.clone_obj = php_phongo_timestamp_clone_object; - php_phongo_handler_timestamp.get_debug_info = php_phongo_timestamp_get_debug_info; - php_phongo_handler_timestamp.get_properties = php_phongo_timestamp_get_properties; - php_phongo_handler_timestamp.read_property = php_phongo_timestamp_read_property; - php_phongo_handler_timestamp.write_property = php_phongo_timestamp_write_property; - php_phongo_handler_timestamp.has_property = php_phongo_timestamp_has_property; - php_phongo_handler_timestamp.unset_property = php_phongo_timestamp_unset_property; + php_phongo_handler_timestamp.compare = php_phongo_timestamp_compare_objects; + php_phongo_handler_timestamp.clone_obj = php_phongo_timestamp_clone_object; + php_phongo_handler_timestamp.get_debug_info = php_phongo_timestamp_get_debug_info; + php_phongo_handler_timestamp.get_properties = php_phongo_timestamp_get_properties; + php_phongo_handler_timestamp.read_property = php_phongo_timestamp_read_property; + php_phongo_handler_timestamp.write_property = php_phongo_timestamp_write_property; + php_phongo_handler_timestamp.has_property = php_phongo_timestamp_has_property; + php_phongo_handler_timestamp.unset_property = php_phongo_timestamp_unset_property; php_phongo_handler_timestamp.get_property_ptr_ptr = php_phongo_timestamp_get_property_ptr_ptr; - php_phongo_handler_timestamp.get_gc = php_phongo_timestamp_get_gc; - php_phongo_handler_timestamp.free_obj = php_phongo_timestamp_free_object; - php_phongo_handler_timestamp.offset = XtOffsetOf(php_phongo_timestamp_t, std); + php_phongo_handler_timestamp.get_gc = php_phongo_timestamp_get_gc; + php_phongo_handler_timestamp.free_obj = php_phongo_timestamp_free_object; + php_phongo_handler_timestamp.offset = XtOffsetOf(php_phongo_timestamp_t, std); } bool phongo_timestamp_new(zval* object, uint32_t increment, uint32_t timestamp) diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index 51f8d3166..ab775a02a 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -301,14 +301,13 @@ static void php_phongo_utcdatetime_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -378,18 +377,18 @@ void php_phongo_utcdatetime_init_ce(INIT_FUNC_ARGS) php_phongo_utcdatetime_ce->create_object = php_phongo_utcdatetime_create_object; memcpy(&php_phongo_handler_utcdatetime, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_utcdatetime.compare = php_phongo_utcdatetime_compare_objects; - php_phongo_handler_utcdatetime.clone_obj = php_phongo_utcdatetime_clone_object; - php_phongo_handler_utcdatetime.get_debug_info = php_phongo_utcdatetime_get_debug_info; - php_phongo_handler_utcdatetime.get_properties = php_phongo_utcdatetime_get_properties; - php_phongo_handler_utcdatetime.read_property = php_phongo_utcdatetime_read_property; - php_phongo_handler_utcdatetime.write_property = php_phongo_utcdatetime_write_property; - php_phongo_handler_utcdatetime.has_property = php_phongo_utcdatetime_has_property; - php_phongo_handler_utcdatetime.unset_property = php_phongo_utcdatetime_unset_property; + php_phongo_handler_utcdatetime.compare = php_phongo_utcdatetime_compare_objects; + php_phongo_handler_utcdatetime.clone_obj = php_phongo_utcdatetime_clone_object; + php_phongo_handler_utcdatetime.get_debug_info = php_phongo_utcdatetime_get_debug_info; + php_phongo_handler_utcdatetime.get_properties = php_phongo_utcdatetime_get_properties; + php_phongo_handler_utcdatetime.read_property = php_phongo_utcdatetime_read_property; + php_phongo_handler_utcdatetime.write_property = php_phongo_utcdatetime_write_property; + php_phongo_handler_utcdatetime.has_property = php_phongo_utcdatetime_has_property; + php_phongo_handler_utcdatetime.unset_property = php_phongo_utcdatetime_unset_property; php_phongo_handler_utcdatetime.get_property_ptr_ptr = php_phongo_utcdatetime_get_property_ptr_ptr; - php_phongo_handler_utcdatetime.get_gc = php_phongo_utcdatetime_get_gc; - php_phongo_handler_utcdatetime.free_obj = php_phongo_utcdatetime_free_object; - php_phongo_handler_utcdatetime.offset = XtOffsetOf(php_phongo_utcdatetime_t, std); + php_phongo_handler_utcdatetime.get_gc = php_phongo_utcdatetime_get_gc; + php_phongo_handler_utcdatetime.free_obj = php_phongo_utcdatetime_free_object; + php_phongo_handler_utcdatetime.offset = XtOffsetOf(php_phongo_utcdatetime_t, std); } bool phongo_utcdatetime_new(zval* object, int64_t msec_since_epoch) diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index dbb3fb6a4..ad6836aa4 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -183,14 +183,13 @@ static void php_phongo_readconcern_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -231,16 +230,16 @@ void php_phongo_readconcern_init_ce(INIT_FUNC_ARGS) php_phongo_readconcern_ce->create_object = php_phongo_readconcern_create_object; memcpy(&php_phongo_handler_readconcern, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_readconcern.get_debug_info = php_phongo_readconcern_get_debug_info; - php_phongo_handler_readconcern.get_properties = php_phongo_readconcern_get_properties; - php_phongo_handler_readconcern.read_property = php_phongo_readconcern_read_property; - php_phongo_handler_readconcern.write_property = php_phongo_readconcern_write_property; - php_phongo_handler_readconcern.has_property = php_phongo_readconcern_has_property; - php_phongo_handler_readconcern.unset_property = php_phongo_readconcern_unset_property; + php_phongo_handler_readconcern.get_debug_info = php_phongo_readconcern_get_debug_info; + php_phongo_handler_readconcern.get_properties = php_phongo_readconcern_get_properties; + php_phongo_handler_readconcern.read_property = php_phongo_readconcern_read_property; + php_phongo_handler_readconcern.write_property = php_phongo_readconcern_write_property; + php_phongo_handler_readconcern.has_property = php_phongo_readconcern_has_property; + php_phongo_handler_readconcern.unset_property = php_phongo_readconcern_unset_property; php_phongo_handler_readconcern.get_property_ptr_ptr = php_phongo_readconcern_get_property_ptr_ptr; - php_phongo_handler_readconcern.get_gc = php_phongo_readconcern_get_gc; - php_phongo_handler_readconcern.free_obj = php_phongo_readconcern_free_object; - php_phongo_handler_readconcern.offset = XtOffsetOf(php_phongo_readconcern_t, std); + php_phongo_handler_readconcern.get_gc = php_phongo_readconcern_get_gc; + php_phongo_handler_readconcern.free_obj = php_phongo_readconcern_free_object; + php_phongo_handler_readconcern.offset = XtOffsetOf(php_phongo_readconcern_t, std); } void phongo_readconcern_init(zval* return_value, const mongoc_read_concern_t* read_concern) diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index 8b4aa968b..8ad299700 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -483,14 +483,13 @@ static void php_phongo_readpreference_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -531,16 +530,16 @@ void php_phongo_readpreference_init_ce(INIT_FUNC_ARGS) php_phongo_readpreference_ce->create_object = php_phongo_readpreference_create_object; memcpy(&php_phongo_handler_readpreference, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_readpreference.get_debug_info = php_phongo_readpreference_get_debug_info; - php_phongo_handler_readpreference.get_properties = php_phongo_readpreference_get_properties; - php_phongo_handler_readpreference.read_property = php_phongo_readpreference_read_property; - php_phongo_handler_readpreference.write_property = php_phongo_readpreference_write_property; - php_phongo_handler_readpreference.has_property = php_phongo_readpreference_has_property; - php_phongo_handler_readpreference.unset_property = php_phongo_readpreference_unset_property; + php_phongo_handler_readpreference.get_debug_info = php_phongo_readpreference_get_debug_info; + php_phongo_handler_readpreference.get_properties = php_phongo_readpreference_get_properties; + php_phongo_handler_readpreference.read_property = php_phongo_readpreference_read_property; + php_phongo_handler_readpreference.write_property = php_phongo_readpreference_write_property; + php_phongo_handler_readpreference.has_property = php_phongo_readpreference_has_property; + php_phongo_handler_readpreference.unset_property = php_phongo_readpreference_unset_property; php_phongo_handler_readpreference.get_property_ptr_ptr = php_phongo_readpreference_get_property_ptr_ptr; - php_phongo_handler_readpreference.get_gc = php_phongo_readpreference_get_gc; - php_phongo_handler_readpreference.free_obj = php_phongo_readpreference_free_object; - php_phongo_handler_readpreference.offset = XtOffsetOf(php_phongo_readpreference_t, std); + php_phongo_handler_readpreference.get_gc = php_phongo_readpreference_get_gc; + php_phongo_handler_readpreference.free_obj = php_phongo_readpreference_free_object; + php_phongo_handler_readpreference.offset = XtOffsetOf(php_phongo_readpreference_t, std); } void phongo_readpreference_init(zval* return_value, const mongoc_read_prefs_t* read_prefs) diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index 7cb73878d..3866a7f18 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -211,14 +211,13 @@ static void php_phongo_serverapi_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -259,14 +258,14 @@ void php_phongo_serverapi_init_ce(INIT_FUNC_ARGS) php_phongo_serverapi_ce->create_object = php_phongo_serverapi_create_object; memcpy(&php_phongo_handler_serverapi, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_serverapi.get_debug_info = php_phongo_serverapi_get_debug_info; - php_phongo_handler_serverapi.get_properties = php_phongo_serverapi_get_properties; - php_phongo_handler_serverapi.read_property = php_phongo_serverapi_read_property; - php_phongo_handler_serverapi.write_property = php_phongo_serverapi_write_property; - php_phongo_handler_serverapi.has_property = php_phongo_serverapi_has_property; - php_phongo_handler_serverapi.unset_property = php_phongo_serverapi_unset_property; + php_phongo_handler_serverapi.get_debug_info = php_phongo_serverapi_get_debug_info; + php_phongo_handler_serverapi.get_properties = php_phongo_serverapi_get_properties; + php_phongo_handler_serverapi.read_property = php_phongo_serverapi_read_property; + php_phongo_handler_serverapi.write_property = php_phongo_serverapi_write_property; + php_phongo_handler_serverapi.has_property = php_phongo_serverapi_has_property; + php_phongo_handler_serverapi.unset_property = php_phongo_serverapi_unset_property; php_phongo_handler_serverapi.get_property_ptr_ptr = php_phongo_serverapi_get_property_ptr_ptr; - php_phongo_handler_serverapi.get_gc = php_phongo_serverapi_get_gc; - php_phongo_handler_serverapi.free_obj = php_phongo_serverapi_free_object; - php_phongo_handler_serverapi.offset = XtOffsetOf(php_phongo_serverapi_t, std); + php_phongo_handler_serverapi.get_gc = php_phongo_serverapi_get_gc; + php_phongo_handler_serverapi.free_obj = php_phongo_serverapi_free_object; + php_phongo_handler_serverapi.offset = XtOffsetOf(php_phongo_serverapi_t, std); } diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index 1994dc291..c2fd86cc7 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -158,14 +158,13 @@ static void php_phongo_serverdescription_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -282,16 +281,16 @@ void php_phongo_serverdescription_init_ce(INIT_FUNC_ARGS) php_phongo_serverdescription_ce->create_object = php_phongo_serverdescription_create_object; memcpy(&php_phongo_handler_serverdescription, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_serverdescription.get_debug_info = php_phongo_serverdescription_get_debug_info; - php_phongo_handler_serverdescription.get_properties = php_phongo_serverdescription_get_properties; - php_phongo_handler_serverdescription.read_property = php_phongo_serverdescription_read_property; - php_phongo_handler_serverdescription.write_property = php_phongo_serverdescription_write_property; - php_phongo_handler_serverdescription.has_property = php_phongo_serverdescription_has_property; - php_phongo_handler_serverdescription.unset_property = php_phongo_serverdescription_unset_property; + php_phongo_handler_serverdescription.get_debug_info = php_phongo_serverdescription_get_debug_info; + php_phongo_handler_serverdescription.get_properties = php_phongo_serverdescription_get_properties; + php_phongo_handler_serverdescription.read_property = php_phongo_serverdescription_read_property; + php_phongo_handler_serverdescription.write_property = php_phongo_serverdescription_write_property; + php_phongo_handler_serverdescription.has_property = php_phongo_serverdescription_has_property; + php_phongo_handler_serverdescription.unset_property = php_phongo_serverdescription_unset_property; php_phongo_handler_serverdescription.get_property_ptr_ptr = php_phongo_serverdescription_get_property_ptr_ptr; - php_phongo_handler_serverdescription.get_gc = php_phongo_serverdescription_get_gc; - php_phongo_handler_serverdescription.free_obj = php_phongo_serverdescription_free_object; - php_phongo_handler_serverdescription.offset = XtOffsetOf(php_phongo_serverdescription_t, std); + php_phongo_handler_serverdescription.get_gc = php_phongo_serverdescription_get_gc; + php_phongo_handler_serverdescription.free_obj = php_phongo_serverdescription_free_object; + php_phongo_handler_serverdescription.offset = XtOffsetOf(php_phongo_serverdescription_t, std); } void phongo_serverdescription_init_ex(zval* return_value, mongoc_server_description_t* server_description, bool copy) diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index a832b0e2c..b8f176ad9 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -107,14 +107,13 @@ static void php_phongo_topologydescription_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -195,16 +194,16 @@ void php_phongo_topologydescription_init_ce(INIT_FUNC_ARGS) php_phongo_topologydescription_ce->create_object = php_phongo_topologydescription_create_object; memcpy(&php_phongo_handler_topologydescription, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_topologydescription.get_debug_info = php_phongo_topologydescription_get_debug_info; - php_phongo_handler_topologydescription.get_properties = php_phongo_topologydescription_get_properties; - php_phongo_handler_topologydescription.read_property = php_phongo_topologydescription_read_property; - php_phongo_handler_topologydescription.write_property = php_phongo_topologydescription_write_property; - php_phongo_handler_topologydescription.has_property = php_phongo_topologydescription_has_property; - php_phongo_handler_topologydescription.unset_property = php_phongo_topologydescription_unset_property; + php_phongo_handler_topologydescription.get_debug_info = php_phongo_topologydescription_get_debug_info; + php_phongo_handler_topologydescription.get_properties = php_phongo_topologydescription_get_properties; + php_phongo_handler_topologydescription.read_property = php_phongo_topologydescription_read_property; + php_phongo_handler_topologydescription.write_property = php_phongo_topologydescription_write_property; + php_phongo_handler_topologydescription.has_property = php_phongo_topologydescription_has_property; + php_phongo_handler_topologydescription.unset_property = php_phongo_topologydescription_unset_property; php_phongo_handler_topologydescription.get_property_ptr_ptr = php_phongo_topologydescription_get_property_ptr_ptr; - php_phongo_handler_topologydescription.get_gc = php_phongo_topologydescription_get_gc; - php_phongo_handler_topologydescription.free_obj = php_phongo_topologydescription_free_object; - php_phongo_handler_topologydescription.offset = XtOffsetOf(php_phongo_topologydescription_t, std); + php_phongo_handler_topologydescription.get_gc = php_phongo_topologydescription_get_gc; + php_phongo_handler_topologydescription.free_obj = php_phongo_topologydescription_free_object; + php_phongo_handler_topologydescription.offset = XtOffsetOf(php_phongo_topologydescription_t, std); } void phongo_topologydescription_init(zval* return_value, mongoc_topology_description_t* topology_description) diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index 1045e4eb1..db0900403 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -368,14 +368,13 @@ static void php_phongo_writeconcern_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -416,16 +415,16 @@ void php_phongo_writeconcern_init_ce(INIT_FUNC_ARGS) php_phongo_writeconcern_ce->create_object = php_phongo_writeconcern_create_object; memcpy(&php_phongo_handler_writeconcern, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_writeconcern.get_debug_info = php_phongo_writeconcern_get_debug_info; - php_phongo_handler_writeconcern.get_properties = php_phongo_writeconcern_get_properties; - php_phongo_handler_writeconcern.read_property = php_phongo_writeconcern_read_property; - php_phongo_handler_writeconcern.write_property = php_phongo_writeconcern_write_property; - php_phongo_handler_writeconcern.has_property = php_phongo_writeconcern_has_property; - php_phongo_handler_writeconcern.unset_property = php_phongo_writeconcern_unset_property; + php_phongo_handler_writeconcern.get_debug_info = php_phongo_writeconcern_get_debug_info; + php_phongo_handler_writeconcern.get_properties = php_phongo_writeconcern_get_properties; + php_phongo_handler_writeconcern.read_property = php_phongo_writeconcern_read_property; + php_phongo_handler_writeconcern.write_property = php_phongo_writeconcern_write_property; + php_phongo_handler_writeconcern.has_property = php_phongo_writeconcern_has_property; + php_phongo_handler_writeconcern.unset_property = php_phongo_writeconcern_unset_property; php_phongo_handler_writeconcern.get_property_ptr_ptr = php_phongo_writeconcern_get_property_ptr_ptr; - php_phongo_handler_writeconcern.get_gc = php_phongo_writeconcern_get_gc; - php_phongo_handler_writeconcern.free_obj = php_phongo_writeconcern_free_object; - php_phongo_handler_writeconcern.offset = XtOffsetOf(php_phongo_writeconcern_t, std); + php_phongo_handler_writeconcern.get_gc = php_phongo_writeconcern_get_gc; + php_phongo_handler_writeconcern.free_obj = php_phongo_writeconcern_free_object; + php_phongo_handler_writeconcern.offset = XtOffsetOf(php_phongo_writeconcern_t, std); } void phongo_writeconcern_init(zval* return_value, const mongoc_write_concern_t* write_concern) diff --git a/src/phongo_compat.h b/src/phongo_compat.h index 1d7a7be61..b9a213153 100644 --- a/src/phongo_compat.h +++ b/src/phongo_compat.h @@ -99,9 +99,7 @@ #define PHONGO_RETVAL_SMART_STR(val) RETVAL_STRINGL(ZSTR_VAL((val).s), ZSTR_LEN((val).s)); #define ZVAL_STATIC_INIT \ { \ - { \ - 0 \ - } \ + { 0 } \ } #define ADD_NEXT_INDEX_INT64_OBJ(_zv, _value) \ From 2520bfca02a53ba9652ae3da66922dd4ba8b90eb Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 25 Jul 2025 11:44:54 +0200 Subject: [PATCH 39/44] More fixes --- php_phongo.h | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/php_phongo.h b/php_phongo.h index 596e27a86..6e3fc80a5 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -68,20 +68,14 @@ zend_object_handlers* phongo_get_std_object_handlers(void); #define PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size) \ do { \ - if (!(intern)->php_properties) { \ - ALLOC_HASHTABLE((intern)->php_properties); \ - zend_hash_init((intern)->php_properties, 0, NULL, ZVAL_PTR_DTOR, 0); \ - GC_ADDREF((intern)->php_properties); \ - } \ if (is_temp) { \ - (props) = zend_array_dup((intern)->php_properties); \ + ALLOC_HASHTABLE(props); \ + zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \ + } else if ((intern)->properties) { \ + (props) = (intern)->properties; \ } else { \ - (props) = zend_array_dup((intern)->php_properties); \ - if ((intern)->properties) { \ - HashTable *__tmp = (intern)->properties; \ - (intern)->properties = NULL; \ - zend_hash_release(__tmp); \ - } \ + ALLOC_HASHTABLE(props); \ + zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \ (intern)->properties = (props); \ } \ } while (0) @@ -102,7 +96,11 @@ zend_object_handlers* phongo_get_std_object_handlers(void); zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ _intern_extractor(zobj)->php_properties = props; \ } \ - return zend_hash_find(props, member); \ + zval *ret = zend_hash_find(props, member); \ + if (ret) { \ + return ret; \ + } \ + return &EG(uninitialized_zval); \ } \ \ static zval *php_phongo_##_name##_write_property(zend_object *zobj, zend_string *name, zval *value, void **cache_slot) \ From a3c767dd60e6287f6c54270380f8651b09b04bca Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 25 Jul 2025 11:48:27 +0200 Subject: [PATCH 40/44] Add get_gc handler --- php_phongo.c | 9 -- php_phongo.h | 166 ++++++++++++++++-------------- src/BSON/Binary.c | 26 ++--- src/BSON/DBPointer.c | 26 ++--- src/BSON/Decimal128.c | 24 ++--- src/BSON/Document.c | 5 +- src/BSON/Int64.c | 30 +++--- src/BSON/Iterator.c | 24 ++--- src/BSON/Javascript.c | 26 ++--- src/BSON/ObjectId.c | 26 ++--- src/BSON/PackedArray.c | 34 +++--- src/BSON/Regex.c | 26 ++--- src/BSON/Symbol.c | 26 ++--- src/BSON/Timestamp.c | 26 ++--- src/BSON/UTCDateTime.c | 26 ++--- src/MongoDB/ReadConcern.c | 22 ++-- src/MongoDB/ReadPreference.c | 22 ++-- src/MongoDB/ServerApi.c | 22 ++-- src/MongoDB/ServerDescription.c | 22 ++-- src/MongoDB/TopologyDescription.c | 22 ++-- src/MongoDB/WriteConcern.c | 22 ++-- src/phongo_compat.h | 4 +- 22 files changed, 317 insertions(+), 319 deletions(-) diff --git a/php_phongo.c b/php_phongo.c index 710cff685..595eb1352 100644 --- a/php_phongo.c +++ b/php_phongo.c @@ -155,14 +155,6 @@ static zend_class_entry* php_phongo_fetch_internal_class(const char* class_name, return NULL; } -static HashTable* php_phongo_std_get_gc(zend_object* object, zval** table, int* n) -{ - *table = NULL; - *n = 0; - return object->handlers->get_properties(object); -} - - PHP_MINIT_FUNCTION(mongodb) /* {{{ */ { bson_mem_vtable_t bson_mem_vtable = { @@ -198,7 +190,6 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */ /* Disable cloning by default. Individual classes can opt in if they need to * support this (e.g. BSON objects). */ phongo_std_object_handlers.clone_obj = NULL; - phongo_std_object_handlers.get_gc = php_phongo_std_get_gc; /* Initialize zend_class_entry dependencies. * diff --git a/php_phongo.h b/php_phongo.h index 6e3fc80a5..63e44e893 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -61,9 +61,9 @@ ZEND_TSRMLS_CACHE_EXTERN() zend_object_handlers* phongo_get_std_object_handlers(void); #define PHONGO_RETURN_PROPS(is_temp, props) \ - if (!(is_temp)) { \ - GC_ADDREF(props); \ - } \ + if (!(is_temp)) { \ + GC_ADDREF(props); \ + } \ return props; #define PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size) \ @@ -87,81 +87,91 @@ zend_object_handlers* phongo_get_std_object_handlers(void); } \ } while (0) -#define PHONGO_GET_PROPERTY_HANDLERS(_name, _intern_extractor) \ - static zval* php_phongo_##_name##_read_property(zend_object *zobj, zend_string *member, int type, void **cache_slot, zval *rv) \ - { \ - HashTable *props = _intern_extractor(zobj)->php_properties; \ - if (!props) { \ - ALLOC_HASHTABLE(props); \ - zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ - _intern_extractor(zobj)->php_properties = props; \ - } \ - zval *ret = zend_hash_find(props, member); \ - if (ret) { \ - return ret; \ - } \ - return &EG(uninitialized_zval); \ - } \ - \ - static zval *php_phongo_##_name##_write_property(zend_object *zobj, zend_string *name, zval *value, void **cache_slot) \ - { \ - Z_TRY_ADDREF_P(value); \ - HashTable *props = _intern_extractor(zobj)->php_properties; \ - if (!props) { \ - ALLOC_HASHTABLE(props); \ - zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ - _intern_extractor(zobj)->php_properties = props; \ - } \ - return zend_hash_add_new(props, name, value); \ - } \ - static int php_phongo_##_name##_has_property(zend_object *zobj, zend_string *name, int has_set_exists, void **cache_slot) \ - { \ - HashTable *props = _intern_extractor(zobj)->php_properties; \ - if (!props) { \ - ALLOC_HASHTABLE(props); \ - zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ - _intern_extractor(zobj)->php_properties = props; \ - } \ - zval *value = zend_hash_find(props, name); \ - if (value) { \ - if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY) { \ - return zend_is_true(value); \ - } \ - if (has_set_exists < ZEND_PROPERTY_NOT_EMPTY) { \ - ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_ISSET); \ - ZVAL_DEREF(value); \ - return (Z_TYPE_P(value) != IS_NULL); \ - } \ - ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_EXISTS); \ - return true; \ - } \ - return false; \ - } \ - static void php_phongo_##_name##_unset_property(zend_object *zobj, zend_string *name, void **cache_slot) \ - { \ - HashTable *props = _intern_extractor(zobj)->php_properties; \ - if (!props) { \ - ALLOC_HASHTABLE(props); \ - zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ - _intern_extractor(zobj)->php_properties = props; \ - } \ - zend_hash_del(props, name); \ - } \ - \ - static zval *php_phongo_##_name##_get_property_ptr_ptr(zend_object *zobj, zend_string *name, int type, void **cache_slot) \ - { \ - HashTable *props = _intern_extractor(zobj)->php_properties; \ - if (!props) { \ - ALLOC_HASHTABLE(props); \ - zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ - _intern_extractor(zobj)->php_properties = props; \ - } \ - \ - zval *value = zend_hash_find(props, name); \ - if (value) { \ - return value; \ - } \ - return zend_hash_add(props, name, &EG(uninitialized_zval)); \ +#define PHONGO_GET_PROPERTY_HANDLERS(_name, _intern_extractor) \ + PHONGO_GET_PROPERTY_HANDLERS_NO_GC(_name, _intern_extractor) \ + \ + static HashTable* php_phongo_##_name##_get_gc(zend_object* zobj, zval** table, int* n) \ + { \ + *table = NULL; \ + *n = 0; \ + return _intern_extractor(zobj)->php_properties; \ + } + +#define PHONGO_GET_PROPERTY_HANDLERS_NO_GC(_name, _intern_extractor) \ + static zval* php_phongo_##_name##_read_property(zend_object* zobj, zend_string* member, int type, void** cache_slot, zval* rv) \ + { \ + HashTable* props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + zval* ret = zend_hash_find(props, member); \ + if (ret) { \ + return ret; \ + } \ + return &EG(uninitialized_zval); \ + } \ + \ + static zval* php_phongo_##_name##_write_property(zend_object* zobj, zend_string* name, zval* value, void** cache_slot) \ + { \ + Z_TRY_ADDREF_P(value); \ + HashTable* props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + return zend_hash_add_new(props, name, value); \ + } \ + static int php_phongo_##_name##_has_property(zend_object* zobj, zend_string* name, int has_set_exists, void** cache_slot) \ + { \ + HashTable* props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + zval* value = zend_hash_find(props, name); \ + if (value) { \ + if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY) { \ + return zend_is_true(value); \ + } \ + if (has_set_exists < ZEND_PROPERTY_NOT_EMPTY) { \ + ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_ISSET); \ + ZVAL_DEREF(value); \ + return (Z_TYPE_P(value) != IS_NULL); \ + } \ + ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_EXISTS); \ + return true; \ + } \ + return false; \ + } \ + static void php_phongo_##_name##_unset_property(zend_object* zobj, zend_string* name, void** cache_slot) \ + { \ + HashTable* props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + zend_hash_del(props, name); \ + } \ + \ + static zval* php_phongo_##_name##_get_property_ptr_ptr(zend_object* zobj, zend_string* name, int type, void** cache_slot) \ + { \ + HashTable* props = _intern_extractor(zobj)->php_properties; \ + if (!props) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \ + _intern_extractor(zobj)->php_properties = props; \ + } \ + \ + zval* value = zend_hash_find(props, name); \ + if (value) { \ + return value; \ + } \ + return zend_hash_add(props, name, &EG(uninitialized_zval)); \ } #define PHONGO_ZVAL_EXCEPTION_NAME(e) (ZSTR_VAL(e->ce->name)) diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index e3aa7e877..3c91f67f5 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -213,14 +213,13 @@ static void php_phongo_binary_free_object(zend_object* object) efree(intern->data); } - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -296,17 +295,18 @@ void php_phongo_binary_init_ce(INIT_FUNC_ARGS) php_phongo_binary_ce->create_object = php_phongo_binary_create_object; memcpy(&php_phongo_handler_binary, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_binary.compare = php_phongo_binary_compare_objects; - php_phongo_handler_binary.clone_obj = php_phongo_binary_clone_object; - php_phongo_handler_binary.get_debug_info = php_phongo_binary_get_debug_info; - php_phongo_handler_binary.get_properties = php_phongo_binary_get_properties; - php_phongo_handler_binary.read_property = php_phongo_binary_read_property; - php_phongo_handler_binary.write_property = php_phongo_binary_write_property; - php_phongo_handler_binary.has_property = php_phongo_binary_has_property; - php_phongo_handler_binary.unset_property = php_phongo_binary_unset_property; + php_phongo_handler_binary.compare = php_phongo_binary_compare_objects; + php_phongo_handler_binary.clone_obj = php_phongo_binary_clone_object; + php_phongo_handler_binary.get_debug_info = php_phongo_binary_get_debug_info; + php_phongo_handler_binary.get_properties = php_phongo_binary_get_properties; + php_phongo_handler_binary.read_property = php_phongo_binary_read_property; + php_phongo_handler_binary.write_property = php_phongo_binary_write_property; + php_phongo_handler_binary.has_property = php_phongo_binary_has_property; + php_phongo_handler_binary.unset_property = php_phongo_binary_unset_property; php_phongo_handler_binary.get_property_ptr_ptr = php_phongo_binary_get_property_ptr_ptr; - php_phongo_handler_binary.free_obj = php_phongo_binary_free_object; - php_phongo_handler_binary.offset = XtOffsetOf(php_phongo_binary_t, std); + php_phongo_handler_binary.get_gc = php_phongo_binary_get_gc; + php_phongo_handler_binary.free_obj = php_phongo_binary_free_object; + php_phongo_handler_binary.offset = XtOffsetOf(php_phongo_binary_t, std); } bool phongo_binary_new(zval* object, const char* data, size_t data_len, bson_subtype_t type) diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index af63f45e2..89e69f5a2 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -176,14 +176,13 @@ static void php_phongo_dbpointer_free_object(zend_object* object) efree(intern->ref); } - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -256,17 +255,18 @@ void php_phongo_dbpointer_init_ce(INIT_FUNC_ARGS) php_phongo_dbpointer_ce->create_object = php_phongo_dbpointer_create_object; memcpy(&php_phongo_handler_dbpointer, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_dbpointer.compare = php_phongo_dbpointer_compare_objects; - php_phongo_handler_dbpointer.clone_obj = php_phongo_dbpointer_clone_object; - php_phongo_handler_dbpointer.get_debug_info = php_phongo_dbpointer_get_debug_info; - php_phongo_handler_dbpointer.get_properties = php_phongo_dbpointer_get_properties; - php_phongo_handler_dbpointer.read_property = php_phongo_dbpointer_read_property; - php_phongo_handler_dbpointer.write_property = php_phongo_dbpointer_write_property; - php_phongo_handler_dbpointer.has_property = php_phongo_dbpointer_has_property; - php_phongo_handler_dbpointer.unset_property = php_phongo_dbpointer_unset_property; + php_phongo_handler_dbpointer.compare = php_phongo_dbpointer_compare_objects; + php_phongo_handler_dbpointer.clone_obj = php_phongo_dbpointer_clone_object; + php_phongo_handler_dbpointer.get_debug_info = php_phongo_dbpointer_get_debug_info; + php_phongo_handler_dbpointer.get_properties = php_phongo_dbpointer_get_properties; + php_phongo_handler_dbpointer.read_property = php_phongo_dbpointer_read_property; + php_phongo_handler_dbpointer.write_property = php_phongo_dbpointer_write_property; + php_phongo_handler_dbpointer.has_property = php_phongo_dbpointer_has_property; + php_phongo_handler_dbpointer.unset_property = php_phongo_dbpointer_unset_property; php_phongo_handler_dbpointer.get_property_ptr_ptr = php_phongo_dbpointer_get_property_ptr_ptr; - php_phongo_handler_dbpointer.free_obj = php_phongo_dbpointer_free_object; - php_phongo_handler_dbpointer.offset = XtOffsetOf(php_phongo_dbpointer_t, std); + php_phongo_handler_dbpointer.get_gc = php_phongo_dbpointer_get_gc; + php_phongo_handler_dbpointer.free_obj = php_phongo_dbpointer_free_object; + php_phongo_handler_dbpointer.offset = XtOffsetOf(php_phongo_dbpointer_t, std); } bool phongo_dbpointer_new(zval* object, const char* ref, size_t ref_len, const bson_oid_t* oid) diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 078eeac8a..1bdf7fd73 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -168,14 +168,13 @@ static void php_phongo_decimal128_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -231,16 +230,17 @@ void php_phongo_decimal128_init_ce(INIT_FUNC_ARGS) php_phongo_decimal128_ce->create_object = php_phongo_decimal128_create_object; memcpy(&php_phongo_handler_decimal128, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_decimal128.clone_obj = php_phongo_decimal128_clone_object; - php_phongo_handler_decimal128.get_debug_info = php_phongo_decimal128_get_debug_info; - php_phongo_handler_decimal128.get_properties = php_phongo_decimal128_get_properties; - php_phongo_handler_decimal128.read_property = php_phongo_decimal128_read_property; - php_phongo_handler_decimal128.write_property = php_phongo_decimal128_write_property; - php_phongo_handler_decimal128.has_property = php_phongo_decimal128_has_property; - php_phongo_handler_decimal128.unset_property = php_phongo_decimal128_unset_property; + php_phongo_handler_decimal128.clone_obj = php_phongo_decimal128_clone_object; + php_phongo_handler_decimal128.get_debug_info = php_phongo_decimal128_get_debug_info; + php_phongo_handler_decimal128.get_properties = php_phongo_decimal128_get_properties; + php_phongo_handler_decimal128.read_property = php_phongo_decimal128_read_property; + php_phongo_handler_decimal128.write_property = php_phongo_decimal128_write_property; + php_phongo_handler_decimal128.has_property = php_phongo_decimal128_has_property; + php_phongo_handler_decimal128.unset_property = php_phongo_decimal128_unset_property; php_phongo_handler_decimal128.get_property_ptr_ptr = php_phongo_decimal128_get_property_ptr_ptr; - php_phongo_handler_decimal128.free_obj = php_phongo_decimal128_free_object; - php_phongo_handler_decimal128.offset = XtOffsetOf(php_phongo_decimal128_t, std); + php_phongo_handler_decimal128.get_gc = php_phongo_decimal128_get_gc; + php_phongo_handler_decimal128.free_obj = php_phongo_decimal128_free_object; + php_phongo_handler_decimal128.offset = XtOffsetOf(php_phongo_decimal128_t, std); } bool phongo_decimal128_new(zval* object, const bson_decimal128_t* decimal) diff --git a/src/BSON/Document.c b/src/BSON/Document.c index 8bd26a6ae..e3e074825 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -446,14 +446,13 @@ static void php_phongo_document_free_object(zend_object* object) bson_destroy(intern->bson); } - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index 7ac0efb3f..02feb7bd7 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -175,14 +175,13 @@ static void php_phongo_int64_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -569,19 +568,20 @@ void php_phongo_int64_init_ce(INIT_FUNC_ARGS) php_phongo_int64_ce->create_object = php_phongo_int64_create_object; memcpy(&php_phongo_handler_int64, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_int64.compare = php_phongo_int64_compare_objects; - php_phongo_handler_int64.clone_obj = php_phongo_int64_clone_object; - php_phongo_handler_int64.get_debug_info = php_phongo_int64_get_debug_info; - php_phongo_handler_int64.get_properties = php_phongo_int64_get_properties; - php_phongo_handler_int64.read_property = php_phongo_int64_read_property; - php_phongo_handler_int64.write_property = php_phongo_int64_write_property; - php_phongo_handler_int64.has_property = php_phongo_int64_has_property; - php_phongo_handler_int64.unset_property = php_phongo_int64_unset_property; + php_phongo_handler_int64.compare = php_phongo_int64_compare_objects; + php_phongo_handler_int64.clone_obj = php_phongo_int64_clone_object; + php_phongo_handler_int64.get_debug_info = php_phongo_int64_get_debug_info; + php_phongo_handler_int64.get_properties = php_phongo_int64_get_properties; + php_phongo_handler_int64.read_property = php_phongo_int64_read_property; + php_phongo_handler_int64.write_property = php_phongo_int64_write_property; + php_phongo_handler_int64.has_property = php_phongo_int64_has_property; + php_phongo_handler_int64.unset_property = php_phongo_int64_unset_property; php_phongo_handler_int64.get_property_ptr_ptr = php_phongo_int64_get_property_ptr_ptr; - php_phongo_handler_int64.free_obj = php_phongo_int64_free_object; - php_phongo_handler_int64.offset = XtOffsetOf(php_phongo_int64_t, std); - php_phongo_handler_int64.cast_object = php_phongo_int64_cast_object; - php_phongo_handler_int64.do_operation = php_phongo_int64_do_operation; + php_phongo_handler_int64.get_gc = php_phongo_int64_get_gc; + php_phongo_handler_int64.free_obj = php_phongo_int64_free_object; + php_phongo_handler_int64.offset = XtOffsetOf(php_phongo_int64_t, std); + php_phongo_handler_int64.cast_object = php_phongo_int64_cast_object; + php_phongo_handler_int64.do_operation = php_phongo_int64_do_operation; } bool phongo_int64_new(zval* object, int64_t integer) diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index b285e459d..e6a56df55 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -248,14 +248,13 @@ static void php_phongo_iterator_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -393,14 +392,15 @@ void php_phongo_iterator_init_ce(INIT_FUNC_ARGS) php_phongo_iterator_ce->get_iterator = php_phongo_iterator_get_iterator; memcpy(&php_phongo_handler_iterator, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_iterator.clone_obj = php_phongo_iterator_clone_object; - php_phongo_handler_iterator.get_debug_info = php_phongo_iterator_get_debug_info; - php_phongo_handler_iterator.get_properties = php_phongo_iterator_get_properties; - php_phongo_handler_iterator.read_property = php_phongo_iterator_read_property; - php_phongo_handler_iterator.write_property = php_phongo_iterator_write_property; - php_phongo_handler_iterator.has_property = php_phongo_iterator_has_property; - php_phongo_handler_iterator.unset_property = php_phongo_iterator_unset_property; + php_phongo_handler_iterator.clone_obj = php_phongo_iterator_clone_object; + php_phongo_handler_iterator.get_debug_info = php_phongo_iterator_get_debug_info; + php_phongo_handler_iterator.get_properties = php_phongo_iterator_get_properties; + php_phongo_handler_iterator.read_property = php_phongo_iterator_read_property; + php_phongo_handler_iterator.write_property = php_phongo_iterator_write_property; + php_phongo_handler_iterator.has_property = php_phongo_iterator_has_property; + php_phongo_handler_iterator.unset_property = php_phongo_iterator_unset_property; php_phongo_handler_iterator.get_property_ptr_ptr = php_phongo_iterator_get_property_ptr_ptr; - php_phongo_handler_iterator.free_obj = php_phongo_iterator_free_object; - php_phongo_handler_iterator.offset = XtOffsetOf(php_phongo_iterator_t, std); + php_phongo_handler_iterator.get_gc = php_phongo_iterator_get_gc; + php_phongo_handler_iterator.free_obj = php_phongo_iterator_free_object; + php_phongo_handler_iterator.offset = XtOffsetOf(php_phongo_iterator_t, std); } diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index 4c9ce6af6..29f97dfe2 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -262,14 +262,13 @@ static void php_phongo_javascript_free_object(zend_object* object) intern->scope = NULL; } - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -337,17 +336,18 @@ void php_phongo_javascript_init_ce(INIT_FUNC_ARGS) php_phongo_javascript_ce->create_object = php_phongo_javascript_create_object; memcpy(&php_phongo_handler_javascript, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_javascript.compare = php_phongo_javascript_compare_objects; - php_phongo_handler_javascript.clone_obj = php_phongo_javascript_clone_object; - php_phongo_handler_javascript.get_debug_info = php_phongo_javascript_get_debug_info; - php_phongo_handler_javascript.get_properties = php_phongo_javascript_get_properties; - php_phongo_handler_javascript.read_property = php_phongo_javascript_read_property; - php_phongo_handler_javascript.write_property = php_phongo_javascript_write_property; - php_phongo_handler_javascript.has_property = php_phongo_javascript_has_property; - php_phongo_handler_javascript.unset_property = php_phongo_javascript_unset_property; + php_phongo_handler_javascript.compare = php_phongo_javascript_compare_objects; + php_phongo_handler_javascript.clone_obj = php_phongo_javascript_clone_object; + php_phongo_handler_javascript.get_debug_info = php_phongo_javascript_get_debug_info; + php_phongo_handler_javascript.get_properties = php_phongo_javascript_get_properties; + php_phongo_handler_javascript.read_property = php_phongo_javascript_read_property; + php_phongo_handler_javascript.write_property = php_phongo_javascript_write_property; + php_phongo_handler_javascript.has_property = php_phongo_javascript_has_property; + php_phongo_handler_javascript.unset_property = php_phongo_javascript_unset_property; php_phongo_handler_javascript.get_property_ptr_ptr = php_phongo_javascript_get_property_ptr_ptr; - php_phongo_handler_javascript.free_obj = php_phongo_javascript_free_object; - php_phongo_handler_javascript.offset = XtOffsetOf(php_phongo_javascript_t, std); + php_phongo_handler_javascript.get_gc = php_phongo_javascript_get_gc; + php_phongo_handler_javascript.free_obj = php_phongo_javascript_free_object; + php_phongo_handler_javascript.offset = XtOffsetOf(php_phongo_javascript_t, std); } bool phongo_javascript_new(zval* object, const char* code, size_t code_len, const bson_t* scope) diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 4e6a460fe..1fc485644 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -202,14 +202,13 @@ static void php_phongo_objectid_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -278,17 +277,18 @@ void php_phongo_objectid_init_ce(INIT_FUNC_ARGS) php_phongo_objectid_ce->create_object = php_phongo_objectid_create_object; memcpy(&php_phongo_handler_objectid, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_objectid.compare = php_phongo_objectid_compare_objects; - php_phongo_handler_objectid.clone_obj = php_phongo_objectid_clone_object; - php_phongo_handler_objectid.get_debug_info = php_phongo_objectid_get_debug_info; - php_phongo_handler_objectid.get_properties = php_phongo_objectid_get_properties; - php_phongo_handler_objectid.read_property = php_phongo_objectid_read_property; - php_phongo_handler_objectid.write_property = php_phongo_objectid_write_property; - php_phongo_handler_objectid.has_property = php_phongo_objectid_has_property; - php_phongo_handler_objectid.unset_property = php_phongo_objectid_unset_property; + php_phongo_handler_objectid.compare = php_phongo_objectid_compare_objects; + php_phongo_handler_objectid.clone_obj = php_phongo_objectid_clone_object; + php_phongo_handler_objectid.get_debug_info = php_phongo_objectid_get_debug_info; + php_phongo_handler_objectid.get_properties = php_phongo_objectid_get_properties; + php_phongo_handler_objectid.read_property = php_phongo_objectid_read_property; + php_phongo_handler_objectid.write_property = php_phongo_objectid_write_property; + php_phongo_handler_objectid.has_property = php_phongo_objectid_has_property; + php_phongo_handler_objectid.unset_property = php_phongo_objectid_unset_property; php_phongo_handler_objectid.get_property_ptr_ptr = php_phongo_objectid_get_property_ptr_ptr; - php_phongo_handler_objectid.free_obj = php_phongo_objectid_free_object; - php_phongo_handler_objectid.offset = XtOffsetOf(php_phongo_objectid_t, std); + php_phongo_handler_objectid.get_gc = php_phongo_objectid_get_gc; + php_phongo_handler_objectid.free_obj = php_phongo_objectid_free_object; + php_phongo_handler_objectid.offset = XtOffsetOf(php_phongo_objectid_t, std); } bool phongo_objectid_new(zval* return_value, const bson_oid_t* oid) diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index 2d6ce8b33..b5ed1bafc 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -430,14 +430,13 @@ static void php_phongo_packedarray_free_object(zend_object* object) bson_destroy(intern->bson); } - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -579,21 +578,22 @@ void php_phongo_packedarray_init_ce(INIT_FUNC_ARGS) php_phongo_packedarray_ce->create_object = php_phongo_packedarray_create_object; memcpy(&php_phongo_handler_packedarray, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_packedarray.compare = php_phongo_packedarray_compare_objects; - php_phongo_handler_packedarray.clone_obj = php_phongo_packedarray_clone_object; - php_phongo_handler_packedarray.get_debug_info = php_phongo_packedarray_get_debug_info; - php_phongo_handler_packedarray.get_properties = php_phongo_packedarray_get_properties; - php_phongo_handler_packedarray.read_property = php_phongo_packedarray_read_property; - php_phongo_handler_packedarray.write_property = php_phongo_packedarray_write_property; - php_phongo_handler_packedarray.has_property = php_phongo_packedarray_has_property; - php_phongo_handler_packedarray.unset_property = php_phongo_packedarray_unset_property; + php_phongo_handler_packedarray.compare = php_phongo_packedarray_compare_objects; + php_phongo_handler_packedarray.clone_obj = php_phongo_packedarray_clone_object; + php_phongo_handler_packedarray.get_debug_info = php_phongo_packedarray_get_debug_info; + php_phongo_handler_packedarray.get_properties = php_phongo_packedarray_get_properties; + php_phongo_handler_packedarray.read_property = php_phongo_packedarray_read_property; + php_phongo_handler_packedarray.write_property = php_phongo_packedarray_write_property; + php_phongo_handler_packedarray.has_property = php_phongo_packedarray_has_property; + php_phongo_handler_packedarray.unset_property = php_phongo_packedarray_unset_property; php_phongo_handler_packedarray.get_property_ptr_ptr = php_phongo_packedarray_get_property_ptr_ptr; - php_phongo_handler_packedarray.free_obj = php_phongo_packedarray_free_object; - php_phongo_handler_packedarray.read_dimension = php_phongo_packedarray_read_dimension; - php_phongo_handler_packedarray.write_dimension = php_phongo_packedarray_write_dimension; - php_phongo_handler_packedarray.has_dimension = php_phongo_packedarray_has_dimension; - php_phongo_handler_packedarray.unset_dimension = php_phongo_packedarray_unset_dimension; - php_phongo_handler_packedarray.offset = XtOffsetOf(php_phongo_packedarray_t, std); + php_phongo_handler_packedarray.get_gc = php_phongo_packedarray_get_gc; + php_phongo_handler_packedarray.free_obj = php_phongo_packedarray_free_object; + php_phongo_handler_packedarray.read_dimension = php_phongo_packedarray_read_dimension; + php_phongo_handler_packedarray.write_dimension = php_phongo_packedarray_write_dimension; + php_phongo_handler_packedarray.has_dimension = php_phongo_packedarray_has_dimension; + php_phongo_handler_packedarray.unset_dimension = php_phongo_packedarray_unset_dimension; + php_phongo_handler_packedarray.offset = XtOffsetOf(php_phongo_packedarray_t, std); } bool phongo_packedarray_new(zval* object, bson_t* bson, bool copy) diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index b25f9620b..265f28124 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -228,14 +228,13 @@ static void php_phongo_regex_free_object(zend_object* object) efree(intern->flags); } - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -309,17 +308,18 @@ void php_phongo_regex_init_ce(INIT_FUNC_ARGS) php_phongo_regex_ce->create_object = php_phongo_regex_create_object; memcpy(&php_phongo_handler_regex, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_regex.compare = php_phongo_regex_compare_objects; - php_phongo_handler_regex.clone_obj = php_phongo_regex_clone_object; - php_phongo_handler_regex.get_debug_info = php_phongo_regex_get_debug_info; - php_phongo_handler_regex.get_properties = php_phongo_regex_get_properties; - php_phongo_handler_regex.read_property = php_phongo_regex_read_property; - php_phongo_handler_regex.write_property = php_phongo_regex_write_property; - php_phongo_handler_regex.has_property = php_phongo_regex_has_property; - php_phongo_handler_regex.unset_property = php_phongo_regex_unset_property; + php_phongo_handler_regex.compare = php_phongo_regex_compare_objects; + php_phongo_handler_regex.clone_obj = php_phongo_regex_clone_object; + php_phongo_handler_regex.get_debug_info = php_phongo_regex_get_debug_info; + php_phongo_handler_regex.get_properties = php_phongo_regex_get_properties; + php_phongo_handler_regex.read_property = php_phongo_regex_read_property; + php_phongo_handler_regex.write_property = php_phongo_regex_write_property; + php_phongo_handler_regex.has_property = php_phongo_regex_has_property; + php_phongo_handler_regex.unset_property = php_phongo_regex_unset_property; php_phongo_handler_regex.get_property_ptr_ptr = php_phongo_regex_get_property_ptr_ptr; - php_phongo_handler_regex.free_obj = php_phongo_regex_free_object; - php_phongo_handler_regex.offset = XtOffsetOf(php_phongo_regex_t, std); + php_phongo_handler_regex.get_gc = php_phongo_regex_get_gc; + php_phongo_handler_regex.free_obj = php_phongo_regex_free_object; + php_phongo_handler_regex.offset = XtOffsetOf(php_phongo_regex_t, std); } bool phongo_regex_new(zval* object, const char* pattern, const char* flags) diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index 20ed21a09..a06be9017 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -150,14 +150,13 @@ static void php_phongo_symbol_free_object(zend_object* object) efree(intern->symbol); } - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -223,17 +222,18 @@ void php_phongo_symbol_init_ce(INIT_FUNC_ARGS) php_phongo_symbol_ce->create_object = php_phongo_symbol_create_object; memcpy(&php_phongo_handler_symbol, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_symbol.compare = php_phongo_symbol_compare_objects; - php_phongo_handler_symbol.clone_obj = php_phongo_symbol_clone_object; - php_phongo_handler_symbol.get_debug_info = php_phongo_symbol_get_debug_info; - php_phongo_handler_symbol.get_properties = php_phongo_symbol_get_properties; - php_phongo_handler_symbol.read_property = php_phongo_symbol_read_property; - php_phongo_handler_symbol.write_property = php_phongo_symbol_write_property; - php_phongo_handler_symbol.has_property = php_phongo_symbol_has_property; - php_phongo_handler_symbol.unset_property = php_phongo_symbol_unset_property; + php_phongo_handler_symbol.compare = php_phongo_symbol_compare_objects; + php_phongo_handler_symbol.clone_obj = php_phongo_symbol_clone_object; + php_phongo_handler_symbol.get_debug_info = php_phongo_symbol_get_debug_info; + php_phongo_handler_symbol.get_properties = php_phongo_symbol_get_properties; + php_phongo_handler_symbol.read_property = php_phongo_symbol_read_property; + php_phongo_handler_symbol.write_property = php_phongo_symbol_write_property; + php_phongo_handler_symbol.has_property = php_phongo_symbol_has_property; + php_phongo_handler_symbol.unset_property = php_phongo_symbol_unset_property; php_phongo_handler_symbol.get_property_ptr_ptr = php_phongo_symbol_get_property_ptr_ptr; - php_phongo_handler_symbol.free_obj = php_phongo_symbol_free_object; - php_phongo_handler_symbol.offset = XtOffsetOf(php_phongo_symbol_t, std); + php_phongo_handler_symbol.get_gc = php_phongo_symbol_get_gc; + php_phongo_handler_symbol.free_obj = php_phongo_symbol_free_object; + php_phongo_handler_symbol.offset = XtOffsetOf(php_phongo_symbol_t, std); } bool phongo_symbol_new(zval* object, const char* symbol, size_t symbol_len) diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 66121d325..4d532bd07 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -261,14 +261,13 @@ static void php_phongo_timestamp_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -343,17 +342,18 @@ void php_phongo_timestamp_init_ce(INIT_FUNC_ARGS) php_phongo_timestamp_ce->create_object = php_phongo_timestamp_create_object; memcpy(&php_phongo_handler_timestamp, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_timestamp.compare = php_phongo_timestamp_compare_objects; - php_phongo_handler_timestamp.clone_obj = php_phongo_timestamp_clone_object; - php_phongo_handler_timestamp.get_debug_info = php_phongo_timestamp_get_debug_info; - php_phongo_handler_timestamp.get_properties = php_phongo_timestamp_get_properties; - php_phongo_handler_timestamp.read_property = php_phongo_timestamp_read_property; - php_phongo_handler_timestamp.write_property = php_phongo_timestamp_write_property; - php_phongo_handler_timestamp.has_property = php_phongo_timestamp_has_property; - php_phongo_handler_timestamp.unset_property = php_phongo_timestamp_unset_property; + php_phongo_handler_timestamp.compare = php_phongo_timestamp_compare_objects; + php_phongo_handler_timestamp.clone_obj = php_phongo_timestamp_clone_object; + php_phongo_handler_timestamp.get_debug_info = php_phongo_timestamp_get_debug_info; + php_phongo_handler_timestamp.get_properties = php_phongo_timestamp_get_properties; + php_phongo_handler_timestamp.read_property = php_phongo_timestamp_read_property; + php_phongo_handler_timestamp.write_property = php_phongo_timestamp_write_property; + php_phongo_handler_timestamp.has_property = php_phongo_timestamp_has_property; + php_phongo_handler_timestamp.unset_property = php_phongo_timestamp_unset_property; php_phongo_handler_timestamp.get_property_ptr_ptr = php_phongo_timestamp_get_property_ptr_ptr; - php_phongo_handler_timestamp.free_obj = php_phongo_timestamp_free_object; - php_phongo_handler_timestamp.offset = XtOffsetOf(php_phongo_timestamp_t, std); + php_phongo_handler_timestamp.get_gc = php_phongo_timestamp_get_gc; + php_phongo_handler_timestamp.free_obj = php_phongo_timestamp_free_object; + php_phongo_handler_timestamp.offset = XtOffsetOf(php_phongo_timestamp_t, std); } bool phongo_timestamp_new(zval* object, uint32_t increment, uint32_t timestamp) diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index 6af94f7b7..ab775a02a 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -301,14 +301,13 @@ static void php_phongo_utcdatetime_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -378,17 +377,18 @@ void php_phongo_utcdatetime_init_ce(INIT_FUNC_ARGS) php_phongo_utcdatetime_ce->create_object = php_phongo_utcdatetime_create_object; memcpy(&php_phongo_handler_utcdatetime, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_utcdatetime.compare = php_phongo_utcdatetime_compare_objects; - php_phongo_handler_utcdatetime.clone_obj = php_phongo_utcdatetime_clone_object; - php_phongo_handler_utcdatetime.get_debug_info = php_phongo_utcdatetime_get_debug_info; - php_phongo_handler_utcdatetime.get_properties = php_phongo_utcdatetime_get_properties; - php_phongo_handler_utcdatetime.read_property = php_phongo_utcdatetime_read_property; - php_phongo_handler_utcdatetime.write_property = php_phongo_utcdatetime_write_property; - php_phongo_handler_utcdatetime.has_property = php_phongo_utcdatetime_has_property; - php_phongo_handler_utcdatetime.unset_property = php_phongo_utcdatetime_unset_property; + php_phongo_handler_utcdatetime.compare = php_phongo_utcdatetime_compare_objects; + php_phongo_handler_utcdatetime.clone_obj = php_phongo_utcdatetime_clone_object; + php_phongo_handler_utcdatetime.get_debug_info = php_phongo_utcdatetime_get_debug_info; + php_phongo_handler_utcdatetime.get_properties = php_phongo_utcdatetime_get_properties; + php_phongo_handler_utcdatetime.read_property = php_phongo_utcdatetime_read_property; + php_phongo_handler_utcdatetime.write_property = php_phongo_utcdatetime_write_property; + php_phongo_handler_utcdatetime.has_property = php_phongo_utcdatetime_has_property; + php_phongo_handler_utcdatetime.unset_property = php_phongo_utcdatetime_unset_property; php_phongo_handler_utcdatetime.get_property_ptr_ptr = php_phongo_utcdatetime_get_property_ptr_ptr; - php_phongo_handler_utcdatetime.free_obj = php_phongo_utcdatetime_free_object; - php_phongo_handler_utcdatetime.offset = XtOffsetOf(php_phongo_utcdatetime_t, std); + php_phongo_handler_utcdatetime.get_gc = php_phongo_utcdatetime_get_gc; + php_phongo_handler_utcdatetime.free_obj = php_phongo_utcdatetime_free_object; + php_phongo_handler_utcdatetime.offset = XtOffsetOf(php_phongo_utcdatetime_t, std); } bool phongo_utcdatetime_new(zval* object, int64_t msec_since_epoch) diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index af0eaafac..ad6836aa4 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -183,14 +183,13 @@ static void php_phongo_readconcern_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -231,15 +230,16 @@ void php_phongo_readconcern_init_ce(INIT_FUNC_ARGS) php_phongo_readconcern_ce->create_object = php_phongo_readconcern_create_object; memcpy(&php_phongo_handler_readconcern, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_readconcern.get_debug_info = php_phongo_readconcern_get_debug_info; - php_phongo_handler_readconcern.get_properties = php_phongo_readconcern_get_properties; - php_phongo_handler_readconcern.read_property = php_phongo_readconcern_read_property; - php_phongo_handler_readconcern.write_property = php_phongo_readconcern_write_property; - php_phongo_handler_readconcern.has_property = php_phongo_readconcern_has_property; - php_phongo_handler_readconcern.unset_property = php_phongo_readconcern_unset_property; + php_phongo_handler_readconcern.get_debug_info = php_phongo_readconcern_get_debug_info; + php_phongo_handler_readconcern.get_properties = php_phongo_readconcern_get_properties; + php_phongo_handler_readconcern.read_property = php_phongo_readconcern_read_property; + php_phongo_handler_readconcern.write_property = php_phongo_readconcern_write_property; + php_phongo_handler_readconcern.has_property = php_phongo_readconcern_has_property; + php_phongo_handler_readconcern.unset_property = php_phongo_readconcern_unset_property; php_phongo_handler_readconcern.get_property_ptr_ptr = php_phongo_readconcern_get_property_ptr_ptr; - php_phongo_handler_readconcern.free_obj = php_phongo_readconcern_free_object; - php_phongo_handler_readconcern.offset = XtOffsetOf(php_phongo_readconcern_t, std); + php_phongo_handler_readconcern.get_gc = php_phongo_readconcern_get_gc; + php_phongo_handler_readconcern.free_obj = php_phongo_readconcern_free_object; + php_phongo_handler_readconcern.offset = XtOffsetOf(php_phongo_readconcern_t, std); } void phongo_readconcern_init(zval* return_value, const mongoc_read_concern_t* read_concern) diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index e8955bc24..8ad299700 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -483,14 +483,13 @@ static void php_phongo_readpreference_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -531,15 +530,16 @@ void php_phongo_readpreference_init_ce(INIT_FUNC_ARGS) php_phongo_readpreference_ce->create_object = php_phongo_readpreference_create_object; memcpy(&php_phongo_handler_readpreference, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_readpreference.get_debug_info = php_phongo_readpreference_get_debug_info; - php_phongo_handler_readpreference.get_properties = php_phongo_readpreference_get_properties; - php_phongo_handler_readpreference.read_property = php_phongo_readpreference_read_property; - php_phongo_handler_readpreference.write_property = php_phongo_readpreference_write_property; - php_phongo_handler_readpreference.has_property = php_phongo_readpreference_has_property; - php_phongo_handler_readpreference.unset_property = php_phongo_readpreference_unset_property; + php_phongo_handler_readpreference.get_debug_info = php_phongo_readpreference_get_debug_info; + php_phongo_handler_readpreference.get_properties = php_phongo_readpreference_get_properties; + php_phongo_handler_readpreference.read_property = php_phongo_readpreference_read_property; + php_phongo_handler_readpreference.write_property = php_phongo_readpreference_write_property; + php_phongo_handler_readpreference.has_property = php_phongo_readpreference_has_property; + php_phongo_handler_readpreference.unset_property = php_phongo_readpreference_unset_property; php_phongo_handler_readpreference.get_property_ptr_ptr = php_phongo_readpreference_get_property_ptr_ptr; - php_phongo_handler_readpreference.free_obj = php_phongo_readpreference_free_object; - php_phongo_handler_readpreference.offset = XtOffsetOf(php_phongo_readpreference_t, std); + php_phongo_handler_readpreference.get_gc = php_phongo_readpreference_get_gc; + php_phongo_handler_readpreference.free_obj = php_phongo_readpreference_free_object; + php_phongo_handler_readpreference.offset = XtOffsetOf(php_phongo_readpreference_t, std); } void phongo_readpreference_init(zval* return_value, const mongoc_read_prefs_t* read_prefs) diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index 899df8bc1..3866a7f18 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -211,14 +211,13 @@ static void php_phongo_serverapi_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -259,13 +258,14 @@ void php_phongo_serverapi_init_ce(INIT_FUNC_ARGS) php_phongo_serverapi_ce->create_object = php_phongo_serverapi_create_object; memcpy(&php_phongo_handler_serverapi, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_serverapi.get_debug_info = php_phongo_serverapi_get_debug_info; - php_phongo_handler_serverapi.get_properties = php_phongo_serverapi_get_properties; - php_phongo_handler_serverapi.read_property = php_phongo_serverapi_read_property; - php_phongo_handler_serverapi.write_property = php_phongo_serverapi_write_property; - php_phongo_handler_serverapi.has_property = php_phongo_serverapi_has_property; - php_phongo_handler_serverapi.unset_property = php_phongo_serverapi_unset_property; + php_phongo_handler_serverapi.get_debug_info = php_phongo_serverapi_get_debug_info; + php_phongo_handler_serverapi.get_properties = php_phongo_serverapi_get_properties; + php_phongo_handler_serverapi.read_property = php_phongo_serverapi_read_property; + php_phongo_handler_serverapi.write_property = php_phongo_serverapi_write_property; + php_phongo_handler_serverapi.has_property = php_phongo_serverapi_has_property; + php_phongo_handler_serverapi.unset_property = php_phongo_serverapi_unset_property; php_phongo_handler_serverapi.get_property_ptr_ptr = php_phongo_serverapi_get_property_ptr_ptr; - php_phongo_handler_serverapi.free_obj = php_phongo_serverapi_free_object; - php_phongo_handler_serverapi.offset = XtOffsetOf(php_phongo_serverapi_t, std); + php_phongo_handler_serverapi.get_gc = php_phongo_serverapi_get_gc; + php_phongo_handler_serverapi.free_obj = php_phongo_serverapi_free_object; + php_phongo_handler_serverapi.offset = XtOffsetOf(php_phongo_serverapi_t, std); } diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index 9508d95d3..c2fd86cc7 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -158,14 +158,13 @@ static void php_phongo_serverdescription_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -282,15 +281,16 @@ void php_phongo_serverdescription_init_ce(INIT_FUNC_ARGS) php_phongo_serverdescription_ce->create_object = php_phongo_serverdescription_create_object; memcpy(&php_phongo_handler_serverdescription, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_serverdescription.get_debug_info = php_phongo_serverdescription_get_debug_info; - php_phongo_handler_serverdescription.get_properties = php_phongo_serverdescription_get_properties; - php_phongo_handler_serverdescription.read_property = php_phongo_serverdescription_read_property; - php_phongo_handler_serverdescription.write_property = php_phongo_serverdescription_write_property; - php_phongo_handler_serverdescription.has_property = php_phongo_serverdescription_has_property; - php_phongo_handler_serverdescription.unset_property = php_phongo_serverdescription_unset_property; + php_phongo_handler_serverdescription.get_debug_info = php_phongo_serverdescription_get_debug_info; + php_phongo_handler_serverdescription.get_properties = php_phongo_serverdescription_get_properties; + php_phongo_handler_serverdescription.read_property = php_phongo_serverdescription_read_property; + php_phongo_handler_serverdescription.write_property = php_phongo_serverdescription_write_property; + php_phongo_handler_serverdescription.has_property = php_phongo_serverdescription_has_property; + php_phongo_handler_serverdescription.unset_property = php_phongo_serverdescription_unset_property; php_phongo_handler_serverdescription.get_property_ptr_ptr = php_phongo_serverdescription_get_property_ptr_ptr; - php_phongo_handler_serverdescription.free_obj = php_phongo_serverdescription_free_object; - php_phongo_handler_serverdescription.offset = XtOffsetOf(php_phongo_serverdescription_t, std); + php_phongo_handler_serverdescription.get_gc = php_phongo_serverdescription_get_gc; + php_phongo_handler_serverdescription.free_obj = php_phongo_serverdescription_free_object; + php_phongo_handler_serverdescription.offset = XtOffsetOf(php_phongo_serverdescription_t, std); } void phongo_serverdescription_init_ex(zval* return_value, mongoc_server_description_t* server_description, bool copy) diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index ecbe54547..b8f176ad9 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -107,14 +107,13 @@ static void php_phongo_topologydescription_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -195,15 +194,16 @@ void php_phongo_topologydescription_init_ce(INIT_FUNC_ARGS) php_phongo_topologydescription_ce->create_object = php_phongo_topologydescription_create_object; memcpy(&php_phongo_handler_topologydescription, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_topologydescription.get_debug_info = php_phongo_topologydescription_get_debug_info; - php_phongo_handler_topologydescription.get_properties = php_phongo_topologydescription_get_properties; - php_phongo_handler_topologydescription.read_property = php_phongo_topologydescription_read_property; - php_phongo_handler_topologydescription.write_property = php_phongo_topologydescription_write_property; - php_phongo_handler_topologydescription.has_property = php_phongo_topologydescription_has_property; - php_phongo_handler_topologydescription.unset_property = php_phongo_topologydescription_unset_property; + php_phongo_handler_topologydescription.get_debug_info = php_phongo_topologydescription_get_debug_info; + php_phongo_handler_topologydescription.get_properties = php_phongo_topologydescription_get_properties; + php_phongo_handler_topologydescription.read_property = php_phongo_topologydescription_read_property; + php_phongo_handler_topologydescription.write_property = php_phongo_topologydescription_write_property; + php_phongo_handler_topologydescription.has_property = php_phongo_topologydescription_has_property; + php_phongo_handler_topologydescription.unset_property = php_phongo_topologydescription_unset_property; php_phongo_handler_topologydescription.get_property_ptr_ptr = php_phongo_topologydescription_get_property_ptr_ptr; - php_phongo_handler_topologydescription.free_obj = php_phongo_topologydescription_free_object; - php_phongo_handler_topologydescription.offset = XtOffsetOf(php_phongo_topologydescription_t, std); + php_phongo_handler_topologydescription.get_gc = php_phongo_topologydescription_get_gc; + php_phongo_handler_topologydescription.free_obj = php_phongo_topologydescription_free_object; + php_phongo_handler_topologydescription.offset = XtOffsetOf(php_phongo_topologydescription_t, std); } void phongo_topologydescription_init(zval* return_value, mongoc_topology_description_t* topology_description) diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index 2510619b0..db0900403 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -368,14 +368,13 @@ static void php_phongo_writeconcern_free_object(zend_object* object) zend_object_std_dtor(&intern->std); - if (intern->properties) { - HashTable* props = intern->properties; + HashTable* props = intern->properties; intern->properties = NULL; zend_hash_release(props); } if (intern->php_properties) { - HashTable* props = intern->php_properties; + HashTable* props = intern->php_properties; intern->php_properties = NULL; zend_hash_release(props); } @@ -416,15 +415,16 @@ void php_phongo_writeconcern_init_ce(INIT_FUNC_ARGS) php_phongo_writeconcern_ce->create_object = php_phongo_writeconcern_create_object; memcpy(&php_phongo_handler_writeconcern, phongo_get_std_object_handlers(), sizeof(zend_object_handlers)); - php_phongo_handler_writeconcern.get_debug_info = php_phongo_writeconcern_get_debug_info; - php_phongo_handler_writeconcern.get_properties = php_phongo_writeconcern_get_properties; - php_phongo_handler_writeconcern.read_property = php_phongo_writeconcern_read_property; - php_phongo_handler_writeconcern.write_property = php_phongo_writeconcern_write_property; - php_phongo_handler_writeconcern.has_property = php_phongo_writeconcern_has_property; - php_phongo_handler_writeconcern.unset_property = php_phongo_writeconcern_unset_property; + php_phongo_handler_writeconcern.get_debug_info = php_phongo_writeconcern_get_debug_info; + php_phongo_handler_writeconcern.get_properties = php_phongo_writeconcern_get_properties; + php_phongo_handler_writeconcern.read_property = php_phongo_writeconcern_read_property; + php_phongo_handler_writeconcern.write_property = php_phongo_writeconcern_write_property; + php_phongo_handler_writeconcern.has_property = php_phongo_writeconcern_has_property; + php_phongo_handler_writeconcern.unset_property = php_phongo_writeconcern_unset_property; php_phongo_handler_writeconcern.get_property_ptr_ptr = php_phongo_writeconcern_get_property_ptr_ptr; - php_phongo_handler_writeconcern.free_obj = php_phongo_writeconcern_free_object; - php_phongo_handler_writeconcern.offset = XtOffsetOf(php_phongo_writeconcern_t, std); + php_phongo_handler_writeconcern.get_gc = php_phongo_writeconcern_get_gc; + php_phongo_handler_writeconcern.free_obj = php_phongo_writeconcern_free_object; + php_phongo_handler_writeconcern.offset = XtOffsetOf(php_phongo_writeconcern_t, std); } void phongo_writeconcern_init(zval* return_value, const mongoc_write_concern_t* write_concern) diff --git a/src/phongo_compat.h b/src/phongo_compat.h index 1d7a7be61..b9a213153 100644 --- a/src/phongo_compat.h +++ b/src/phongo_compat.h @@ -99,9 +99,7 @@ #define PHONGO_RETVAL_SMART_STR(val) RETVAL_STRINGL(ZSTR_VAL((val).s), ZSTR_LEN((val).s)); #define ZVAL_STATIC_INIT \ { \ - { \ - 0 \ - } \ + { 0 } \ } #define ADD_NEXT_INDEX_INT64_OBJ(_zv, _value) \ From 85bd3617d14a15afff76eff60536e4b8fd7c4d70 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 25 Jul 2025 12:11:52 +0200 Subject: [PATCH 41/44] Fixes --- php_phongo.h | 6 ------ src/BSON/Binary.c | 4 ++-- src/BSON/DBPointer.c | 4 ++-- src/BSON/Decimal128.c | 4 ++-- src/BSON/Document.c | 6 +++--- src/BSON/Int64.c | 4 ++-- src/BSON/Iterator.c | 2 +- src/BSON/Javascript.c | 4 ++-- src/BSON/ObjectId.c | 4 ++-- src/BSON/PackedArray.c | 6 +++--- src/BSON/Regex.c | 4 ++-- src/BSON/Symbol.c | 4 ++-- src/BSON/Timestamp.c | 4 ++-- src/BSON/UTCDateTime.c | 4 ++-- src/MongoDB/ReadConcern.c | 4 ++-- src/MongoDB/ReadPreference.c | 4 ++-- src/MongoDB/ServerApi.c | 2 +- src/MongoDB/ServerDescription.c | 4 ++-- src/MongoDB/TopologyDescription.c | 4 ++-- src/MongoDB/WriteConcern.c | 4 ++-- tests/bson/bug0939-001.phpt | 22 +++++++++++----------- tests/bson/bug2505_2.phpt | 2 ++ tests/bson/bug2505_3.phpt | 2 ++ 23 files changed, 53 insertions(+), 55 deletions(-) diff --git a/php_phongo.h b/php_phongo.h index 63e44e893..9292d7e3d 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -60,12 +60,6 @@ ZEND_TSRMLS_CACHE_EXTERN() zend_object_handlers* phongo_get_std_object_handlers(void); -#define PHONGO_RETURN_PROPS(is_temp, props) \ - if (!(is_temp)) { \ - GC_ADDREF(props); \ - } \ - return props; - #define PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size) \ do { \ if (is_temp) { \ diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index 3c91f67f5..a7c6d53ea 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -73,7 +73,7 @@ static HashTable* php_phongo_binary_get_properties_hash(zend_object* object, boo PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->data) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -86,7 +86,7 @@ static HashTable* php_phongo_binary_get_properties_hash(zend_object* object, boo zend_hash_str_update(props, "type", sizeof("type") - 1, &type); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } /* Construct a new BSON binary type */ diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index 89e69f5a2..fb955d96f 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -74,7 +74,7 @@ HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object, bool is PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->ref) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -86,7 +86,7 @@ HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object, bool is zend_hash_str_update(props, "id", sizeof("id") - 1, &id); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_DBPointer) diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 1bdf7fd73..9619a06fc 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -64,7 +64,7 @@ static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object, PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->initialized) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } bson_decimal128_to_string(&intern->decimal, outbuf); @@ -76,7 +76,7 @@ static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object, zend_hash_str_update(props, "dec", sizeof("dec") - 1, &dec); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } /* Construct a new BSON Decimal128 type */ diff --git a/src/BSON/Document.c b/src/BSON/Document.c index e3e074825..83ed55e27 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -65,7 +65,7 @@ static HashTable* php_phongo_document_get_properties_hash(zend_object* object, b PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size); if (!intern->bson) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -75,7 +75,7 @@ static HashTable* php_phongo_document_get_properties_hash(zend_object* object, b zend_hash_str_update(props, "data", sizeof("data") - 1, &data); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_Document) @@ -526,7 +526,7 @@ static HashTable* php_phongo_document_get_debug_info(zend_object* object, int* i zend_hash_str_update(props, "value", sizeof("value") - 1, &state.zchild); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; failure: PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index 02feb7bd7..7737db156 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -72,7 +72,7 @@ HashTable* php_phongo_int64_get_properties_hash(zend_object* object, bool is_tem PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->initialized) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -82,7 +82,7 @@ HashTable* php_phongo_int64_get_properties_hash(zend_object* object, bool is_tem zend_hash_str_update(props, "integer", sizeof("integer") - 1, &value); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } static PHP_METHOD(MongoDB_BSON_Int64, __construct) diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index e6a56df55..de0a80bfe 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -165,7 +165,7 @@ static HashTable* php_phongo_iterator_get_properties_hash(zend_object* object, b zend_hash_str_update(props, "bson", sizeof("bson") - 1, &intern->bson); Z_TRY_ADDREF(intern->bson); - PHONGO_RETURN_PROPS(is_temp, props); + return props; } PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_Iterator) diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index 29f97dfe2..676239f94 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -79,7 +79,7 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object, bool i PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->code) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -106,7 +106,7 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object, bool i } } - PHONGO_RETURN_PROPS(is_temp, props); + return props; failure: PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 1fc485644..7d15aca21 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -87,7 +87,7 @@ static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object, b PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->initialized) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -97,7 +97,7 @@ static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object, b zend_hash_str_update(props, "oid", sizeof("oid") - 1, &zv); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } /* Constructs a new BSON ObjectId type, optionally from a hex string. */ diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index b5ed1bafc..321a09a05 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -66,7 +66,7 @@ static HashTable* php_phongo_packedarray_get_properties_hash(zend_object* object PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size); if (!intern->bson) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -76,7 +76,7 @@ static HashTable* php_phongo_packedarray_get_properties_hash(zend_object* object zend_hash_str_update(props, "data", sizeof("data") - 1, &data); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } static bool php_phongo_packedarray_to_json(zval* return_value, bson_json_mode_t mode, const bson_t* bson) @@ -511,7 +511,7 @@ static HashTable* php_phongo_packedarray_get_debug_info(zend_object* object, int zend_hash_str_update(props, "value", sizeof("value") - 1, &state.zchild); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; failure: PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index 265f28124..61c498d5e 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -88,7 +88,7 @@ static HashTable* php_phongo_regex_get_properties_hash(zend_object* object, bool PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->pattern) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -101,7 +101,7 @@ static HashTable* php_phongo_regex_get_properties_hash(zend_object* object, bool zend_hash_str_update(props, "flags", sizeof("flags") - 1, &flags); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } /* Constructs a new BSON regular expression type. */ diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index a06be9017..20c636124 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -62,7 +62,7 @@ HashTable* php_phongo_symbol_get_properties_hash(zend_object* object, bool is_te PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->symbol) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -72,7 +72,7 @@ HashTable* php_phongo_symbol_get_properties_hash(zend_object* object, bool is_te zend_hash_str_update(props, "symbol", sizeof("symbol") - 1, &symbol); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_Symbol) diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 4d532bd07..232bd38a4 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -99,7 +99,7 @@ static HashTable* php_phongo_timestamp_get_properties_hash(zend_object* object, PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->initialized) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } s_increment_len = snprintf(s_increment, sizeof(s_increment), "%" PRIu32, intern->increment); @@ -115,7 +115,7 @@ static HashTable* php_phongo_timestamp_get_properties_hash(zend_object* object, zend_hash_str_update(props, "timestamp", sizeof("timestamp") - 1, ×tamp); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } /* Construct a new BSON timestamp type, which consists of a 4-byte increment and diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index ab775a02a..e6293db97 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -131,7 +131,7 @@ static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->initialized) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -141,7 +141,7 @@ static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object zend_hash_str_update(props, "milliseconds", sizeof("milliseconds") - 1, &milliseconds); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } static void php_phongo_utcdatetime_to_php_date(zval* return_value, const zval* this, zend_class_entry* ce) diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index ad6836aa4..38a2693af 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -133,7 +133,7 @@ static HashTable* php_phongo_readconcern_get_properties_hash(zend_object* object PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->read_concern) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } level = mongoc_read_concern_get_level(intern->read_concern); @@ -145,7 +145,7 @@ static HashTable* php_phongo_readconcern_get_properties_hash(zend_object* object zend_hash_str_update(props, "level", sizeof("level") - 1, &z_level); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } static PHP_METHOD(MongoDB_Driver_ReadConcern, bsonSerialize) diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index 8ad299700..100ba4a79 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -392,7 +392,7 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zend_object* obj PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 4); if (!intern->read_preference) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } tags = mongoc_read_prefs_get_tags(intern->read_preference); @@ -445,7 +445,7 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zend_object* obj } done: - PHONGO_RETURN_PROPS(is_temp, props); + return props; } static PHP_METHOD(MongoDB_Driver_ReadPreference, bsonSerialize) diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index 3866a7f18..ebec9f5cc 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -173,7 +173,7 @@ static HashTable* php_phongo_serverapi_get_properties_hash(zend_object* object, zend_hash_str_add(props, "deprecationErrors", sizeof("deprecationErrors") - 1, &deprecation_errors); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } static PHP_METHOD(MongoDB_Driver_ServerApi, bsonSerialize) diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index c2fd86cc7..360020c2c 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -196,7 +196,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object, PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 6); if (!intern->server_description) { - PHONGO_RETURN_PROPS(is_debug, props); + return props; } { @@ -259,7 +259,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object, } done: - PHONGO_RETURN_PROPS(is_debug, props); + return props; } static HashTable* php_phongo_serverdescription_get_debug_info(zend_object* object, int* is_temp) diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index b8f176ad9..dca234aab 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -145,7 +145,7 @@ HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* objec PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 2); if (!intern->topology_description) { - PHONGO_RETURN_PROPS(is_debug, props); + return props; } { @@ -172,7 +172,7 @@ HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* objec zend_hash_str_update(props, "type", sizeof("type") - 1, &type); } - PHONGO_RETURN_PROPS(is_debug, props); + return props; } static HashTable* php_phongo_topologydescription_get_debug_info(zend_object* object, int* is_temp) diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index db0900403..619cc9506 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -275,7 +275,7 @@ static HashTable* php_phongo_writeconcern_get_properties_hash(zend_object* objec PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 4); if (!intern->write_concern) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } wtag = mongoc_write_concern_get_wtag(intern->write_concern); @@ -330,7 +330,7 @@ static HashTable* php_phongo_writeconcern_get_properties_hash(zend_object* objec } } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } static PHP_METHOD(MongoDB_Driver_WriteConcern, bsonSerialize) diff --git a/tests/bson/bug0939-001.phpt b/tests/bson/bug0939-001.phpt index 09caece5c..a66e7be09 100644 --- a/tests/bson/bug0939-001.phpt +++ b/tests/bson/bug0939-001.phpt @@ -38,14 +38,14 @@ object(MongoDB\BSON\Binary)#%d (%d) { ["type"]=> int(0) } -MongoDB\BSON\Binary::$data exists: yes -MongoDB\BSON\Binary::$type exists: yes +MongoDB\BSON\Binary::$data exists: no +MongoDB\BSON\Binary::$type exists: no object(MongoDB\BSON\Decimal128)#%d (%d) { ["dec"]=> string(4) "3.14" } -MongoDB\BSON\Decimal128::$dec exists: yes +MongoDB\BSON\Decimal128::$dec exists: no object(MongoDB\BSON\Javascript)#%d (%d) { ["code"]=> @@ -56,8 +56,8 @@ object(MongoDB\BSON\Javascript)#%d (%d) { int(42) } } -MongoDB\BSON\Javascript::$code exists: yes -MongoDB\BSON\Javascript::$scope exists: yes +MongoDB\BSON\Javascript::$code exists: no +MongoDB\BSON\Javascript::$scope exists: no object(MongoDB\BSON\MaxKey)#%d (%d) { } @@ -69,7 +69,7 @@ object(MongoDB\BSON\ObjectId)#%d (%d) { ["oid"]=> string(24) "%x" } -MongoDB\BSON\ObjectId::$oid exists: yes +MongoDB\BSON\ObjectId::$oid exists: no object(MongoDB\BSON\Regex)#%d (%d) { ["pattern"]=> @@ -77,8 +77,8 @@ object(MongoDB\BSON\Regex)#%d (%d) { ["flags"]=> string(1) "i" } -MongoDB\BSON\Regex::$pattern exists: yes -MongoDB\BSON\Regex::$flags exists: yes +MongoDB\BSON\Regex::$pattern exists: no +MongoDB\BSON\Regex::$flags exists: no object(MongoDB\BSON\Timestamp)#%d (%d) { ["increment"]=> @@ -86,13 +86,13 @@ object(MongoDB\BSON\Timestamp)#%d (%d) { ["timestamp"]=> string(4) "5678" } -MongoDB\BSON\Timestamp::$increment exists: yes -MongoDB\BSON\Timestamp::$timestamp exists: yes +MongoDB\BSON\Timestamp::$increment exists: no +MongoDB\BSON\Timestamp::$timestamp exists: no object(MongoDB\BSON\UTCDateTime)#%d (%d) { ["milliseconds"]=> string(%d) "%d" } -MongoDB\BSON\UTCDateTime::$milliseconds exists: yes +MongoDB\BSON\UTCDateTime::$milliseconds exists: no ===DONE=== diff --git a/tests/bson/bug2505_2.phpt b/tests/bson/bug2505_2.phpt index c12f7b542..78aaa7467 100644 --- a/tests/bson/bug2505_2.phpt +++ b/tests/bson/bug2505_2.phpt @@ -4,6 +4,8 @@ PHPC-2505: Setting and unsetting a property may interfere with using foreach to new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], [ 'dbpointer' => createDBPointer() ], diff --git a/tests/bson/bug2505_3.phpt b/tests/bson/bug2505_3.phpt index 5d835c30a..9327f1e7d 100644 --- a/tests/bson/bug2505_3.phpt +++ b/tests/bson/bug2505_3.phpt @@ -4,6 +4,8 @@ PHPC-2505: Setting and unsetting a property may interfere with using foreach to new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], [ 'dbpointer' => createDBPointer() ], From 9343af50eb47bd8efd67b76ef06006d0a8e948fb Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Fri, 25 Jul 2025 12:15:58 +0200 Subject: [PATCH 42/44] Fix --- php_phongo.h | 35 +++++++++++-------------------- src/BSON/Binary.c | 4 ++-- src/BSON/DBPointer.c | 4 ++-- src/BSON/Decimal128.c | 4 ++-- src/BSON/Document.c | 6 +++--- src/BSON/Int64.c | 4 ++-- src/BSON/Iterator.c | 2 +- src/BSON/Javascript.c | 4 ++-- src/BSON/ObjectId.c | 4 ++-- src/BSON/PackedArray.c | 6 +++--- src/BSON/Regex.c | 4 ++-- src/BSON/Symbol.c | 4 ++-- src/BSON/Timestamp.c | 4 ++-- src/BSON/UTCDateTime.c | 4 ++-- src/MongoDB/ReadConcern.c | 4 ++-- src/MongoDB/ReadPreference.c | 4 ++-- src/MongoDB/ServerApi.c | 2 +- src/MongoDB/ServerDescription.c | 4 ++-- src/MongoDB/TopologyDescription.c | 4 ++-- src/MongoDB/WriteConcern.c | 4 ++-- 20 files changed, 50 insertions(+), 61 deletions(-) diff --git a/php_phongo.h b/php_phongo.h index d7efc6da4..9292d7e3d 100644 --- a/php_phongo.h +++ b/php_phongo.h @@ -60,29 +60,18 @@ ZEND_TSRMLS_CACHE_EXTERN() zend_object_handlers* phongo_get_std_object_handlers(void); -#define PHONGO_RETURN_PROPS(is_temp, props) \ - if (!(is_temp)) { \ - GC_ADDREF(props); \ - } \ - return props; - -#define PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size) \ - do { \ - if (!(intern)->php_properties) { \ - ALLOC_HASHTABLE((intern)->php_properties); \ - zend_hash_init((intern)->php_properties, 0, NULL, ZVAL_PTR_DTOR, 0); \ - } \ - if (is_temp) { \ - (props) = zend_array_dup((intern)->php_properties); \ - } else { \ - (props) = zend_array_dup((intern)->php_properties); \ - if ((intern)->properties) { \ - HashTable* __tmp = (intern)->properties; \ - (intern)->properties = NULL; \ - zend_hash_release(__tmp); \ - } \ - (intern)->properties = (props); \ - } \ +#define PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size) \ + do { \ + if (is_temp) { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \ + } else if ((intern)->properties) { \ + (props) = (intern)->properties; \ + } else { \ + ALLOC_HASHTABLE(props); \ + zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \ + (intern)->properties = (props); \ + } \ } while (0) #define PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props) \ diff --git a/src/BSON/Binary.c b/src/BSON/Binary.c index 3c91f67f5..a7c6d53ea 100644 --- a/src/BSON/Binary.c +++ b/src/BSON/Binary.c @@ -73,7 +73,7 @@ static HashTable* php_phongo_binary_get_properties_hash(zend_object* object, boo PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->data) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -86,7 +86,7 @@ static HashTable* php_phongo_binary_get_properties_hash(zend_object* object, boo zend_hash_str_update(props, "type", sizeof("type") - 1, &type); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } /* Construct a new BSON binary type */ diff --git a/src/BSON/DBPointer.c b/src/BSON/DBPointer.c index 89e69f5a2..fb955d96f 100644 --- a/src/BSON/DBPointer.c +++ b/src/BSON/DBPointer.c @@ -74,7 +74,7 @@ HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object, bool is PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->ref) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -86,7 +86,7 @@ HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object, bool is zend_hash_str_update(props, "id", sizeof("id") - 1, &id); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_DBPointer) diff --git a/src/BSON/Decimal128.c b/src/BSON/Decimal128.c index 1bdf7fd73..9619a06fc 100644 --- a/src/BSON/Decimal128.c +++ b/src/BSON/Decimal128.c @@ -64,7 +64,7 @@ static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object, PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->initialized) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } bson_decimal128_to_string(&intern->decimal, outbuf); @@ -76,7 +76,7 @@ static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object, zend_hash_str_update(props, "dec", sizeof("dec") - 1, &dec); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } /* Construct a new BSON Decimal128 type */ diff --git a/src/BSON/Document.c b/src/BSON/Document.c index e3e074825..83ed55e27 100644 --- a/src/BSON/Document.c +++ b/src/BSON/Document.c @@ -65,7 +65,7 @@ static HashTable* php_phongo_document_get_properties_hash(zend_object* object, b PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size); if (!intern->bson) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -75,7 +75,7 @@ static HashTable* php_phongo_document_get_properties_hash(zend_object* object, b zend_hash_str_update(props, "data", sizeof("data") - 1, &data); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_Document) @@ -526,7 +526,7 @@ static HashTable* php_phongo_document_get_debug_info(zend_object* object, int* i zend_hash_str_update(props, "value", sizeof("value") - 1, &state.zchild); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; failure: PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); diff --git a/src/BSON/Int64.c b/src/BSON/Int64.c index 02feb7bd7..7737db156 100644 --- a/src/BSON/Int64.c +++ b/src/BSON/Int64.c @@ -72,7 +72,7 @@ HashTable* php_phongo_int64_get_properties_hash(zend_object* object, bool is_tem PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->initialized) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -82,7 +82,7 @@ HashTable* php_phongo_int64_get_properties_hash(zend_object* object, bool is_tem zend_hash_str_update(props, "integer", sizeof("integer") - 1, &value); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } static PHP_METHOD(MongoDB_BSON_Int64, __construct) diff --git a/src/BSON/Iterator.c b/src/BSON/Iterator.c index e6a56df55..de0a80bfe 100644 --- a/src/BSON/Iterator.c +++ b/src/BSON/Iterator.c @@ -165,7 +165,7 @@ static HashTable* php_phongo_iterator_get_properties_hash(zend_object* object, b zend_hash_str_update(props, "bson", sizeof("bson") - 1, &intern->bson); Z_TRY_ADDREF(intern->bson); - PHONGO_RETURN_PROPS(is_temp, props); + return props; } PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_Iterator) diff --git a/src/BSON/Javascript.c b/src/BSON/Javascript.c index 29f97dfe2..676239f94 100644 --- a/src/BSON/Javascript.c +++ b/src/BSON/Javascript.c @@ -79,7 +79,7 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object, bool i PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->code) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -106,7 +106,7 @@ HashTable* php_phongo_javascript_get_properties_hash(zend_object* object, bool i } } - PHONGO_RETURN_PROPS(is_temp, props); + return props; failure: PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); diff --git a/src/BSON/ObjectId.c b/src/BSON/ObjectId.c index 1fc485644..7d15aca21 100644 --- a/src/BSON/ObjectId.c +++ b/src/BSON/ObjectId.c @@ -87,7 +87,7 @@ static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object, b PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->initialized) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -97,7 +97,7 @@ static HashTable* php_phongo_objectid_get_properties_hash(zend_object* object, b zend_hash_str_update(props, "oid", sizeof("oid") - 1, &zv); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } /* Constructs a new BSON ObjectId type, optionally from a hex string. */ diff --git a/src/BSON/PackedArray.c b/src/BSON/PackedArray.c index b5ed1bafc..321a09a05 100644 --- a/src/BSON/PackedArray.c +++ b/src/BSON/PackedArray.c @@ -66,7 +66,7 @@ static HashTable* php_phongo_packedarray_get_properties_hash(zend_object* object PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size); if (!intern->bson) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -76,7 +76,7 @@ static HashTable* php_phongo_packedarray_get_properties_hash(zend_object* object zend_hash_str_update(props, "data", sizeof("data") - 1, &data); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } static bool php_phongo_packedarray_to_json(zval* return_value, bson_json_mode_t mode, const bson_t* bson) @@ -511,7 +511,7 @@ static HashTable* php_phongo_packedarray_get_debug_info(zend_object* object, int zend_hash_str_update(props, "value", sizeof("value") - 1, &state.zchild); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; failure: PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props); diff --git a/src/BSON/Regex.c b/src/BSON/Regex.c index 265f28124..61c498d5e 100644 --- a/src/BSON/Regex.c +++ b/src/BSON/Regex.c @@ -88,7 +88,7 @@ static HashTable* php_phongo_regex_get_properties_hash(zend_object* object, bool PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->pattern) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -101,7 +101,7 @@ static HashTable* php_phongo_regex_get_properties_hash(zend_object* object, bool zend_hash_str_update(props, "flags", sizeof("flags") - 1, &flags); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } /* Constructs a new BSON regular expression type. */ diff --git a/src/BSON/Symbol.c b/src/BSON/Symbol.c index a06be9017..20c636124 100644 --- a/src/BSON/Symbol.c +++ b/src/BSON/Symbol.c @@ -62,7 +62,7 @@ HashTable* php_phongo_symbol_get_properties_hash(zend_object* object, bool is_te PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->symbol) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -72,7 +72,7 @@ HashTable* php_phongo_symbol_get_properties_hash(zend_object* object, bool is_te zend_hash_str_update(props, "symbol", sizeof("symbol") - 1, &symbol); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } PHONGO_DISABLED_CONSTRUCTOR(MongoDB_BSON_Symbol) diff --git a/src/BSON/Timestamp.c b/src/BSON/Timestamp.c index 4d532bd07..232bd38a4 100644 --- a/src/BSON/Timestamp.c +++ b/src/BSON/Timestamp.c @@ -99,7 +99,7 @@ static HashTable* php_phongo_timestamp_get_properties_hash(zend_object* object, PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2); if (!intern->initialized) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } s_increment_len = snprintf(s_increment, sizeof(s_increment), "%" PRIu32, intern->increment); @@ -115,7 +115,7 @@ static HashTable* php_phongo_timestamp_get_properties_hash(zend_object* object, zend_hash_str_update(props, "timestamp", sizeof("timestamp") - 1, ×tamp); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } /* Construct a new BSON timestamp type, which consists of a 4-byte increment and diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index ab775a02a..e6293db97 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -131,7 +131,7 @@ static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->initialized) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } { @@ -141,7 +141,7 @@ static HashTable* php_phongo_utcdatetime_get_properties_hash(zend_object* object zend_hash_str_update(props, "milliseconds", sizeof("milliseconds") - 1, &milliseconds); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } static void php_phongo_utcdatetime_to_php_date(zval* return_value, const zval* this, zend_class_entry* ce) diff --git a/src/MongoDB/ReadConcern.c b/src/MongoDB/ReadConcern.c index ad6836aa4..38a2693af 100644 --- a/src/MongoDB/ReadConcern.c +++ b/src/MongoDB/ReadConcern.c @@ -133,7 +133,7 @@ static HashTable* php_phongo_readconcern_get_properties_hash(zend_object* object PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1); if (!intern->read_concern) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } level = mongoc_read_concern_get_level(intern->read_concern); @@ -145,7 +145,7 @@ static HashTable* php_phongo_readconcern_get_properties_hash(zend_object* object zend_hash_str_update(props, "level", sizeof("level") - 1, &z_level); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } static PHP_METHOD(MongoDB_Driver_ReadConcern, bsonSerialize) diff --git a/src/MongoDB/ReadPreference.c b/src/MongoDB/ReadPreference.c index 8ad299700..100ba4a79 100644 --- a/src/MongoDB/ReadPreference.c +++ b/src/MongoDB/ReadPreference.c @@ -392,7 +392,7 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zend_object* obj PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 4); if (!intern->read_preference) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } tags = mongoc_read_prefs_get_tags(intern->read_preference); @@ -445,7 +445,7 @@ static HashTable* php_phongo_readpreference_get_properties_hash(zend_object* obj } done: - PHONGO_RETURN_PROPS(is_temp, props); + return props; } static PHP_METHOD(MongoDB_Driver_ReadPreference, bsonSerialize) diff --git a/src/MongoDB/ServerApi.c b/src/MongoDB/ServerApi.c index 3866a7f18..ebec9f5cc 100644 --- a/src/MongoDB/ServerApi.c +++ b/src/MongoDB/ServerApi.c @@ -173,7 +173,7 @@ static HashTable* php_phongo_serverapi_get_properties_hash(zend_object* object, zend_hash_str_add(props, "deprecationErrors", sizeof("deprecationErrors") - 1, &deprecation_errors); } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } static PHP_METHOD(MongoDB_Driver_ServerApi, bsonSerialize) diff --git a/src/MongoDB/ServerDescription.c b/src/MongoDB/ServerDescription.c index c2fd86cc7..360020c2c 100644 --- a/src/MongoDB/ServerDescription.c +++ b/src/MongoDB/ServerDescription.c @@ -196,7 +196,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object, PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 6); if (!intern->server_description) { - PHONGO_RETURN_PROPS(is_debug, props); + return props; } { @@ -259,7 +259,7 @@ HashTable* php_phongo_serverdescription_get_properties_hash(zend_object* object, } done: - PHONGO_RETURN_PROPS(is_debug, props); + return props; } static HashTable* php_phongo_serverdescription_get_debug_info(zend_object* object, int* is_temp) diff --git a/src/MongoDB/TopologyDescription.c b/src/MongoDB/TopologyDescription.c index b8f176ad9..dca234aab 100644 --- a/src/MongoDB/TopologyDescription.c +++ b/src/MongoDB/TopologyDescription.c @@ -145,7 +145,7 @@ HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* objec PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_debug, intern, props, 2); if (!intern->topology_description) { - PHONGO_RETURN_PROPS(is_debug, props); + return props; } { @@ -172,7 +172,7 @@ HashTable* php_phongo_topologydescription_get_properties_hash(zend_object* objec zend_hash_str_update(props, "type", sizeof("type") - 1, &type); } - PHONGO_RETURN_PROPS(is_debug, props); + return props; } static HashTable* php_phongo_topologydescription_get_debug_info(zend_object* object, int* is_temp) diff --git a/src/MongoDB/WriteConcern.c b/src/MongoDB/WriteConcern.c index db0900403..619cc9506 100644 --- a/src/MongoDB/WriteConcern.c +++ b/src/MongoDB/WriteConcern.c @@ -275,7 +275,7 @@ static HashTable* php_phongo_writeconcern_get_properties_hash(zend_object* objec PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 4); if (!intern->write_concern) { - PHONGO_RETURN_PROPS(is_temp, props); + return props; } wtag = mongoc_write_concern_get_wtag(intern->write_concern); @@ -330,7 +330,7 @@ static HashTable* php_phongo_writeconcern_get_properties_hash(zend_object* objec } } - PHONGO_RETURN_PROPS(is_temp, props); + return props; } static PHP_METHOD(MongoDB_Driver_WriteConcern, bsonSerialize) From cb339116b7ea84fe4077a8135d8f09dc7e4e1588 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 29 Jul 2025 12:33:04 +0200 Subject: [PATCH 43/44] Fix leak --- src/MongoDB/Manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MongoDB/Manager.c b/src/MongoDB/Manager.c index 4a5df4202..b3846bba0 100644 --- a/src/MongoDB/Manager.c +++ b/src/MongoDB/Manager.c @@ -798,7 +798,7 @@ static void php_phongo_manager_free_object(zend_object* object) } if (intern->subscribers) { - zend_hash_destroy(intern->subscribers); + zend_hash_release(intern->subscribers); } } From 262d68cbe7f2bd25499c7b8fc2bdf78d79a35cfa Mon Sep 17 00:00:00 2001 From: Andreas Braun Date: Tue, 29 Jul 2025 13:30:38 +0200 Subject: [PATCH 44/44] Fix wrong format caused by clang-format --- src/phongo_compat.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/phongo_compat.h b/src/phongo_compat.h index b9a213153..1d7a7be61 100644 --- a/src/phongo_compat.h +++ b/src/phongo_compat.h @@ -99,7 +99,9 @@ #define PHONGO_RETVAL_SMART_STR(val) RETVAL_STRINGL(ZSTR_VAL((val).s), ZSTR_LEN((val).s)); #define ZVAL_STATIC_INIT \ { \ - { 0 } \ + { \ + 0 \ + } \ } #define ADD_NEXT_INDEX_INT64_OBJ(_zv, _value) \