Skip to content

Commit 460aa36

Browse files
committed
Cleanup
1 parent 4857be7 commit 460aa36

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+271
-165
lines changed

php_phongo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ static HashTable* php_phongo_std_get_gc(zend_object* object, zval** table, int*
159159
{
160160
*table = NULL;
161161
*n = 0;
162-
return object->handlers->get_properties(object);
162+
return zend_std_get_properties(object);
163163
}
164164

165165
PHP_MINIT_FUNCTION(mongodb) /* {{{ */

src/BSON/Binary.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,14 @@ static bool php_phongo_binary_init_from_hash(php_phongo_binary_t* intern, HashTa
6363
return false;
6464
}
6565

66-
static HashTable* php_phongo_binary_get_properties_hash(zend_object* object)
66+
static HashTable* php_phongo_binary_get_properties_hash(zend_object* object, bool is_temp)
6767
{
6868
php_phongo_binary_t* intern;
6969
HashTable* props;
7070

7171
intern = Z_OBJ_BINARY(object);
7272

73-
props = zend_array_dup(zend_std_get_properties(object));
74-
GC_SET_REFCOUNT(props, 0);
73+
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2);
7574

7675
if (!intern->data) {
7776
return props;
@@ -187,7 +186,7 @@ static PHP_METHOD(MongoDB_BSON_Binary, __serialize)
187186
{
188187
PHONGO_PARSE_PARAMETERS_NONE();
189188

190-
RETURN_ARR(php_phongo_binary_get_properties_hash(Z_OBJ_P(getThis())));
189+
RETURN_ARR(php_phongo_binary_get_properties_hash(Z_OBJ_P(getThis()), true));
191190
}
192191

193192
static PHP_METHOD(MongoDB_BSON_Binary, __unserialize)
@@ -213,6 +212,11 @@ static void php_phongo_binary_free_object(zend_object* object)
213212
if (intern->data) {
214213
efree(intern->data);
215214
}
215+
216+
if (intern->properties) {
217+
zend_hash_destroy(intern->properties);
218+
FREE_HASHTABLE(intern->properties);
219+
}
216220
}
217221

218222
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)
268272

269273
static HashTable* php_phongo_binary_get_debug_info(zend_object* object, int* is_temp)
270274
{
271-
*is_temp = 0;
272-
return php_phongo_binary_get_properties_hash(object);
275+
*is_temp = 1;
276+
return php_phongo_binary_get_properties_hash(object, true);
273277
}
274278

275279
static HashTable* php_phongo_binary_get_properties(zend_object* object)
276280
{
277-
return php_phongo_binary_get_properties_hash(object);
281+
return php_phongo_binary_get_properties_hash(object, false);
278282
}
279283

280284
void php_phongo_binary_init_ce(INIT_FUNC_ARGS)

src/BSON/DBPointer.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,14 @@ static bool php_phongo_dbpointer_init_from_hash(php_phongo_dbpointer_t* intern,
6464
return false;
6565
}
6666

67-
HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object)
67+
HashTable* php_phongo_dbpointer_get_properties_hash(zend_object* object, bool is_temp)
6868
{
6969
php_phongo_dbpointer_t* intern;
7070
HashTable* props;
7171

7272
intern = Z_OBJ_DBPOINTER(object);
7373

74-
props = zend_array_dup(zend_std_get_properties(object));
75-
GC_SET_REFCOUNT(props, 0);
74+
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2);
7675

7776
if (!intern->ref) {
7877
return props;
@@ -150,7 +149,7 @@ static PHP_METHOD(MongoDB_BSON_DBPointer, __serialize)
150149
{
151150
PHONGO_PARSE_PARAMETERS_NONE();
152151

153-
RETURN_ARR(php_phongo_dbpointer_get_properties_hash(Z_OBJ_P(getThis())));
152+
RETURN_ARR(php_phongo_dbpointer_get_properties_hash(Z_OBJ_P(getThis()), true));
154153
}
155154

156155
static PHP_METHOD(MongoDB_BSON_DBPointer, __unserialize)
@@ -176,6 +175,11 @@ static void php_phongo_dbpointer_free_object(zend_object* object)
176175
if (intern->ref) {
177176
efree(intern->ref);
178177
}
178+
179+
if (intern->properties) {
180+
zend_hash_destroy(intern->properties);
181+
FREE_HASHTABLE(intern->properties);
182+
}
179183
}
180184

181185
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)
228232

229233
static HashTable* php_phongo_dbpointer_get_debug_info(zend_object* object, int* is_temp)
230234
{
231-
*is_temp = 0;
232-
return php_phongo_dbpointer_get_properties_hash(object);
235+
*is_temp = 1;
236+
return php_phongo_dbpointer_get_properties_hash(object, true);
233237
}
234238

235239
static HashTable* php_phongo_dbpointer_get_properties(zend_object* object)
236240
{
237-
return php_phongo_dbpointer_get_properties_hash(object);
241+
return php_phongo_dbpointer_get_properties_hash(object, false);
238242
}
239243

240244
void php_phongo_dbpointer_init_ce(INIT_FUNC_ARGS)

src/BSON/Decimal128.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,15 @@ static bool php_phongo_decimal128_init_from_hash(php_phongo_decimal128_t* intern
5353
return false;
5454
}
5555

56-
static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object)
56+
static HashTable* php_phongo_decimal128_get_properties_hash(zend_object* object, bool is_temp)
5757
{
5858
php_phongo_decimal128_t* intern;
5959
HashTable* props;
6060
char outbuf[BSON_DECIMAL128_STRING] = "";
6161

6262
intern = Z_OBJ_DECIMAL128(object);
6363

64-
props = zend_array_dup(zend_std_get_properties(object));
65-
GC_SET_REFCOUNT(props, 0);
64+
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1);
6665

6766
if (!intern->initialized) {
6867
return props;
@@ -146,7 +145,7 @@ static PHP_METHOD(MongoDB_BSON_Decimal128, __serialize)
146145
{
147146
PHONGO_PARSE_PARAMETERS_NONE();
148147

149-
RETURN_ARR(php_phongo_decimal128_get_properties_hash(Z_OBJ_P(getThis())));
148+
RETURN_ARR(php_phongo_decimal128_get_properties_hash(Z_OBJ_P(getThis()), true));
150149
}
151150

152151
static PHP_METHOD(MongoDB_BSON_Decimal128, __unserialize)
@@ -168,6 +167,11 @@ static void php_phongo_decimal128_free_object(zend_object* object)
168167
php_phongo_decimal128_t* intern = Z_OBJ_DECIMAL128(object);
169168

170169
zend_object_std_dtor(&intern->std);
170+
171+
if (intern->properties) {
172+
zend_hash_destroy(intern->properties);
173+
FREE_HASHTABLE(intern->properties);
174+
}
171175
}
172176

173177
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)
203207

204208
static HashTable* php_phongo_decimal128_get_debug_info(zend_object* object, int* is_temp)
205209
{
206-
*is_temp = 0;
207-
return php_phongo_decimal128_get_properties_hash(object);
210+
*is_temp = 1;
211+
return php_phongo_decimal128_get_properties_hash(object, true);
208212
}
209213

210214
static HashTable* php_phongo_decimal128_get_properties(zend_object* object)
211215
{
212-
return php_phongo_decimal128_get_properties_hash(object);
216+
return php_phongo_decimal128_get_properties_hash(object, false);
213217
}
214218

215219
void php_phongo_decimal128_init_ce(INIT_FUNC_ARGS)

src/BSON/Document.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,14 @@ static bool php_phongo_document_init_from_hash(php_phongo_document_t* intern, Ha
5555
return false;
5656
}
5757

58-
static HashTable* php_phongo_document_get_properties_hash(zend_object* object, int size)
58+
static HashTable* php_phongo_document_get_properties_hash(zend_object* object, bool is_temp, int size)
5959
{
6060
php_phongo_document_t* intern;
6161
HashTable* props;
6262

6363
intern = Z_OBJ_DOCUMENT(object);
6464

65-
props = zend_array_dup(zend_std_get_properties(object));
66-
GC_SET_REFCOUNT(props, 0);
65+
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, size);
6766

6867
if (!intern->bson) {
6968
return props;
@@ -420,7 +419,7 @@ static PHP_METHOD(MongoDB_BSON_Document, __serialize)
420419
{
421420
PHONGO_PARSE_PARAMETERS_NONE();
422421

423-
RETURN_ARR(php_phongo_document_get_properties_hash(Z_OBJ_P(getThis()), 1));
422+
RETURN_ARR(php_phongo_document_get_properties_hash(Z_OBJ_P(getThis()), true, 1));
424423
}
425424

426425
static PHP_METHOD(MongoDB_BSON_Document, __unserialize)
@@ -446,6 +445,11 @@ static void php_phongo_document_free_object(zend_object* object)
446445
if (intern->bson) {
447446
bson_destroy(intern->bson);
448447
}
448+
449+
if (intern->properties) {
450+
zend_hash_destroy(intern->properties);
451+
FREE_HASHTABLE(intern->properties);
452+
}
449453
}
450454

451455
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
494498
php_phongo_document_t* intern;
495499
HashTable* props;
496500

497-
*is_temp = 0;
501+
*is_temp = 1;
498502
intern = Z_OBJ_DOCUMENT(object);
499503

500504
/* This get_debug_info handler reports an additional property. This does not
501505
* conflict with other uses of php_phongo_document_get_properties_hash since
502506
* we always allocated a new HashTable with is_temp=true. */
503-
props = php_phongo_document_get_properties_hash(object, 2);
507+
props = php_phongo_document_get_properties_hash(object, true, 2);
504508

505509
{
506510
php_phongo_bson_state state;
@@ -510,18 +514,22 @@ static HashTable* php_phongo_document_get_debug_info(zend_object* object, int* i
510514
state.map.document.type = PHONGO_TYPEMAP_BSON;
511515
if (!php_phongo_bson_to_zval_ex(intern->bson, &state)) {
512516
zval_ptr_dtor(&state.zchild);
513-
return NULL;
517+
goto failure;
514518
}
515519

516520
zend_hash_str_update(props, "value", sizeof("value") - 1, &state.zchild);
517521
}
518522

519523
return props;
524+
525+
failure:
526+
PHONGO_GET_PROPERTY_HASH_FREE_PROPS(is_temp, props);
527+
return NULL;
520528
}
521529

522530
static HashTable* php_phongo_document_get_properties(zend_object* object)
523531
{
524-
return php_phongo_document_get_properties_hash(object, 1);
532+
return php_phongo_document_get_properties_hash(object, false, 1);
525533
}
526534

527535
zval* php_phongo_document_read_property(zend_object* object, zend_string* member, int type, void** cache_slot, zval* rv)

src/BSON/Int64.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,14 @@ static bool php_phongo_int64_init_from_hash(php_phongo_int64_t* intern, HashTabl
6262
return false;
6363
}
6464

65-
HashTable* php_phongo_int64_get_properties_hash(zend_object* object)
65+
HashTable* php_phongo_int64_get_properties_hash(zend_object* object, bool is_temp)
6666
{
6767
php_phongo_int64_t* intern;
6868
HashTable* props;
6969

7070
intern = Z_OBJ_INT64(object);
7171

72-
props = zend_array_dup(zend_std_get_properties(object));
73-
GC_SET_REFCOUNT(props, 0);
72+
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 2);
7473

7574
if (!intern->initialized) {
7675
return props;
@@ -153,7 +152,7 @@ static PHP_METHOD(MongoDB_BSON_Int64, __serialize)
153152
{
154153
PHONGO_PARSE_PARAMETERS_NONE();
155154

156-
RETURN_ARR(php_phongo_int64_get_properties_hash(Z_OBJ_P(getThis())));
155+
RETURN_ARR(php_phongo_int64_get_properties_hash(Z_OBJ_P(getThis()), true));
157156
}
158157

159158
static PHP_METHOD(MongoDB_BSON_Int64, __unserialize)
@@ -175,6 +174,11 @@ static void php_phongo_int64_free_object(zend_object* object)
175174
php_phongo_int64_t* intern = Z_OBJ_INT64(object);
176175

177176
zend_object_std_dtor(&intern->std);
177+
178+
if (intern->properties) {
179+
zend_hash_destroy(intern->properties);
180+
FREE_HASHTABLE(intern->properties);
181+
}
178182
}
179183

180184
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
541545

542546
static HashTable* php_phongo_int64_get_debug_info(zend_object* object, int* is_temp)
543547
{
544-
*is_temp = 0;
545-
return php_phongo_int64_get_properties_hash(object);
548+
*is_temp = 1;
549+
return php_phongo_int64_get_properties_hash(object, true);
546550
}
547551

548552
static HashTable* php_phongo_int64_get_properties(zend_object* object)
549553
{
550-
return php_phongo_int64_get_properties_hash(object);
554+
return php_phongo_int64_get_properties_hash(object, false);
551555
}
552556

553557
void php_phongo_int64_init_ce(INIT_FUNC_ARGS)

src/BSON/Iterator.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,14 @@ static void php_phongo_iterator_rewind(php_phongo_iterator_t* intern)
153153
intern->valid = bson_iter_next(&intern->iter);
154154
}
155155

156-
static HashTable* php_phongo_iterator_get_properties_hash(zend_object* object)
156+
static HashTable* php_phongo_iterator_get_properties_hash(zend_object* object, bool is_temp)
157157
{
158158
php_phongo_iterator_t* intern;
159159
HashTable* props;
160160

161161
intern = Z_OBJ_ITERATOR(object);
162162

163-
props = zend_array_dup(zend_std_get_properties(object));
164-
GC_SET_REFCOUNT(props, 0);
163+
PHONGO_GET_PROPERTY_HASH_INIT_PROPS(is_temp, intern, props, 1);
165164

166165
zend_hash_str_update(props, "bson", sizeof("bson") - 1, &intern->bson);
167166
Z_TRY_ADDREF(intern->bson);
@@ -249,6 +248,11 @@ static void php_phongo_iterator_free_object(zend_object* object)
249248

250249
zend_object_std_dtor(&intern->std);
251250

251+
if (intern->properties) {
252+
zend_hash_destroy(intern->properties);
253+
FREE_HASHTABLE(intern->properties);
254+
}
255+
252256
php_phongo_iterator_free_current(intern);
253257

254258
zval_ptr_dtor(&intern->bson);
@@ -284,13 +288,13 @@ static zend_object* php_phongo_iterator_clone_object(zend_object* object)
284288

285289
static HashTable* php_phongo_iterator_get_debug_info(zend_object* object, int* is_temp)
286290
{
287-
*is_temp = 0;
288-
return php_phongo_iterator_get_properties_hash(object);
291+
*is_temp = 1;
292+
return php_phongo_iterator_get_properties_hash(object, true);
289293
}
290294

291295
static HashTable* php_phongo_iterator_get_properties(zend_object* object)
292296
{
293-
return php_phongo_iterator_get_properties_hash(object);
297+
return php_phongo_iterator_get_properties_hash(object, false);
294298
}
295299

296300
/* Iterator handlers */

0 commit comments

Comments
 (0)