Skip to content

Commit a3c767d

Browse files
committed
Add get_gc handler
1 parent 2520bfc commit a3c767d

22 files changed

+317
-319
lines changed

php_phongo.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,6 @@ static zend_class_entry* php_phongo_fetch_internal_class(const char* class_name,
155155
return NULL;
156156
}
157157

158-
static HashTable* php_phongo_std_get_gc(zend_object* object, zval** table, int* n)
159-
{
160-
*table = NULL;
161-
*n = 0;
162-
return object->handlers->get_properties(object);
163-
}
164-
165-
166158
PHP_MINIT_FUNCTION(mongodb) /* {{{ */
167159
{
168160
bson_mem_vtable_t bson_mem_vtable = {
@@ -198,7 +190,6 @@ PHP_MINIT_FUNCTION(mongodb) /* {{{ */
198190
/* Disable cloning by default. Individual classes can opt in if they need to
199191
* support this (e.g. BSON objects). */
200192
phongo_std_object_handlers.clone_obj = NULL;
201-
phongo_std_object_handlers.get_gc = php_phongo_std_get_gc;
202193

203194
/* Initialize zend_class_entry dependencies.
204195
*

php_phongo.h

Lines changed: 88 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ ZEND_TSRMLS_CACHE_EXTERN()
6161
zend_object_handlers* phongo_get_std_object_handlers(void);
6262

6363
#define PHONGO_RETURN_PROPS(is_temp, props) \
64-
if (!(is_temp)) { \
65-
GC_ADDREF(props); \
66-
} \
64+
if (!(is_temp)) { \
65+
GC_ADDREF(props); \
66+
} \
6767
return props;
6868

6969
#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);
8787
} \
8888
} while (0)
8989

90-
#define PHONGO_GET_PROPERTY_HANDLERS(_name, _intern_extractor) \
91-
static zval* php_phongo_##_name##_read_property(zend_object *zobj, zend_string *member, int type, void **cache_slot, zval *rv) \
92-
{ \
93-
HashTable *props = _intern_extractor(zobj)->php_properties; \
94-
if (!props) { \
95-
ALLOC_HASHTABLE(props); \
96-
zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
97-
_intern_extractor(zobj)->php_properties = props; \
98-
} \
99-
zval *ret = zend_hash_find(props, member); \
100-
if (ret) { \
101-
return ret; \
102-
} \
103-
return &EG(uninitialized_zval); \
104-
} \
105-
\
106-
static zval *php_phongo_##_name##_write_property(zend_object *zobj, zend_string *name, zval *value, void **cache_slot) \
107-
{ \
108-
Z_TRY_ADDREF_P(value); \
109-
HashTable *props = _intern_extractor(zobj)->php_properties; \
110-
if (!props) { \
111-
ALLOC_HASHTABLE(props); \
112-
zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
113-
_intern_extractor(zobj)->php_properties = props; \
114-
} \
115-
return zend_hash_add_new(props, name, value); \
116-
} \
117-
static int php_phongo_##_name##_has_property(zend_object *zobj, zend_string *name, int has_set_exists, void **cache_slot) \
118-
{ \
119-
HashTable *props = _intern_extractor(zobj)->php_properties; \
120-
if (!props) { \
121-
ALLOC_HASHTABLE(props); \
122-
zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
123-
_intern_extractor(zobj)->php_properties = props; \
124-
} \
125-
zval *value = zend_hash_find(props, name); \
126-
if (value) { \
127-
if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY) { \
128-
return zend_is_true(value); \
129-
} \
130-
if (has_set_exists < ZEND_PROPERTY_NOT_EMPTY) { \
131-
ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_ISSET); \
132-
ZVAL_DEREF(value); \
133-
return (Z_TYPE_P(value) != IS_NULL); \
134-
} \
135-
ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_EXISTS); \
136-
return true; \
137-
} \
138-
return false; \
139-
} \
140-
static void php_phongo_##_name##_unset_property(zend_object *zobj, zend_string *name, void **cache_slot) \
141-
{ \
142-
HashTable *props = _intern_extractor(zobj)->php_properties; \
143-
if (!props) { \
144-
ALLOC_HASHTABLE(props); \
145-
zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
146-
_intern_extractor(zobj)->php_properties = props; \
147-
} \
148-
zend_hash_del(props, name); \
149-
} \
150-
\
151-
static zval *php_phongo_##_name##_get_property_ptr_ptr(zend_object *zobj, zend_string *name, int type, void **cache_slot) \
152-
{ \
153-
HashTable *props = _intern_extractor(zobj)->php_properties; \
154-
if (!props) { \
155-
ALLOC_HASHTABLE(props); \
156-
zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
157-
_intern_extractor(zobj)->php_properties = props; \
158-
} \
159-
\
160-
zval *value = zend_hash_find(props, name); \
161-
if (value) { \
162-
return value; \
163-
} \
164-
return zend_hash_add(props, name, &EG(uninitialized_zval)); \
90+
#define PHONGO_GET_PROPERTY_HANDLERS(_name, _intern_extractor) \
91+
PHONGO_GET_PROPERTY_HANDLERS_NO_GC(_name, _intern_extractor) \
92+
\
93+
static HashTable* php_phongo_##_name##_get_gc(zend_object* zobj, zval** table, int* n) \
94+
{ \
95+
*table = NULL; \
96+
*n = 0; \
97+
return _intern_extractor(zobj)->php_properties; \
98+
}
99+
100+
#define PHONGO_GET_PROPERTY_HANDLERS_NO_GC(_name, _intern_extractor) \
101+
static zval* php_phongo_##_name##_read_property(zend_object* zobj, zend_string* member, int type, void** cache_slot, zval* rv) \
102+
{ \
103+
HashTable* props = _intern_extractor(zobj)->php_properties; \
104+
if (!props) { \
105+
ALLOC_HASHTABLE(props); \
106+
zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
107+
_intern_extractor(zobj)->php_properties = props; \
108+
} \
109+
zval* ret = zend_hash_find(props, member); \
110+
if (ret) { \
111+
return ret; \
112+
} \
113+
return &EG(uninitialized_zval); \
114+
} \
115+
\
116+
static zval* php_phongo_##_name##_write_property(zend_object* zobj, zend_string* name, zval* value, void** cache_slot) \
117+
{ \
118+
Z_TRY_ADDREF_P(value); \
119+
HashTable* props = _intern_extractor(zobj)->php_properties; \
120+
if (!props) { \
121+
ALLOC_HASHTABLE(props); \
122+
zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
123+
_intern_extractor(zobj)->php_properties = props; \
124+
} \
125+
return zend_hash_add_new(props, name, value); \
126+
} \
127+
static int php_phongo_##_name##_has_property(zend_object* zobj, zend_string* name, int has_set_exists, void** cache_slot) \
128+
{ \
129+
HashTable* props = _intern_extractor(zobj)->php_properties; \
130+
if (!props) { \
131+
ALLOC_HASHTABLE(props); \
132+
zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
133+
_intern_extractor(zobj)->php_properties = props; \
134+
} \
135+
zval* value = zend_hash_find(props, name); \
136+
if (value) { \
137+
if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY) { \
138+
return zend_is_true(value); \
139+
} \
140+
if (has_set_exists < ZEND_PROPERTY_NOT_EMPTY) { \
141+
ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_ISSET); \
142+
ZVAL_DEREF(value); \
143+
return (Z_TYPE_P(value) != IS_NULL); \
144+
} \
145+
ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_EXISTS); \
146+
return true; \
147+
} \
148+
return false; \
149+
} \
150+
static void php_phongo_##_name##_unset_property(zend_object* zobj, zend_string* name, void** cache_slot) \
151+
{ \
152+
HashTable* props = _intern_extractor(zobj)->php_properties; \
153+
if (!props) { \
154+
ALLOC_HASHTABLE(props); \
155+
zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
156+
_intern_extractor(zobj)->php_properties = props; \
157+
} \
158+
zend_hash_del(props, name); \
159+
} \
160+
\
161+
static zval* php_phongo_##_name##_get_property_ptr_ptr(zend_object* zobj, zend_string* name, int type, void** cache_slot) \
162+
{ \
163+
HashTable* props = _intern_extractor(zobj)->php_properties; \
164+
if (!props) { \
165+
ALLOC_HASHTABLE(props); \
166+
zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
167+
_intern_extractor(zobj)->php_properties = props; \
168+
} \
169+
\
170+
zval* value = zend_hash_find(props, name); \
171+
if (value) { \
172+
return value; \
173+
} \
174+
return zend_hash_add(props, name, &EG(uninitialized_zval)); \
165175
}
166176

167177
#define PHONGO_ZVAL_EXCEPTION_NAME(e) (ZSTR_VAL(e->ce->name))

src/BSON/Binary.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -213,14 +213,13 @@ static void php_phongo_binary_free_object(zend_object* object)
213213
efree(intern->data);
214214
}
215215

216-
217216
if (intern->properties) {
218-
HashTable* props = intern->properties;
217+
HashTable* props = intern->properties;
219218
intern->properties = NULL;
220219
zend_hash_release(props);
221220
}
222221
if (intern->php_properties) {
223-
HashTable* props = intern->php_properties;
222+
HashTable* props = intern->php_properties;
224223
intern->php_properties = NULL;
225224
zend_hash_release(props);
226225
}
@@ -296,17 +295,18 @@ void php_phongo_binary_init_ce(INIT_FUNC_ARGS)
296295
php_phongo_binary_ce->create_object = php_phongo_binary_create_object;
297296

298297
memcpy(&php_phongo_handler_binary, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
299-
php_phongo_handler_binary.compare = php_phongo_binary_compare_objects;
300-
php_phongo_handler_binary.clone_obj = php_phongo_binary_clone_object;
301-
php_phongo_handler_binary.get_debug_info = php_phongo_binary_get_debug_info;
302-
php_phongo_handler_binary.get_properties = php_phongo_binary_get_properties;
303-
php_phongo_handler_binary.read_property = php_phongo_binary_read_property;
304-
php_phongo_handler_binary.write_property = php_phongo_binary_write_property;
305-
php_phongo_handler_binary.has_property = php_phongo_binary_has_property;
306-
php_phongo_handler_binary.unset_property = php_phongo_binary_unset_property;
298+
php_phongo_handler_binary.compare = php_phongo_binary_compare_objects;
299+
php_phongo_handler_binary.clone_obj = php_phongo_binary_clone_object;
300+
php_phongo_handler_binary.get_debug_info = php_phongo_binary_get_debug_info;
301+
php_phongo_handler_binary.get_properties = php_phongo_binary_get_properties;
302+
php_phongo_handler_binary.read_property = php_phongo_binary_read_property;
303+
php_phongo_handler_binary.write_property = php_phongo_binary_write_property;
304+
php_phongo_handler_binary.has_property = php_phongo_binary_has_property;
305+
php_phongo_handler_binary.unset_property = php_phongo_binary_unset_property;
307306
php_phongo_handler_binary.get_property_ptr_ptr = php_phongo_binary_get_property_ptr_ptr;
308-
php_phongo_handler_binary.free_obj = php_phongo_binary_free_object;
309-
php_phongo_handler_binary.offset = XtOffsetOf(php_phongo_binary_t, std);
307+
php_phongo_handler_binary.get_gc = php_phongo_binary_get_gc;
308+
php_phongo_handler_binary.free_obj = php_phongo_binary_free_object;
309+
php_phongo_handler_binary.offset = XtOffsetOf(php_phongo_binary_t, std);
310310
}
311311

312312
bool phongo_binary_new(zval* object, const char* data, size_t data_len, bson_subtype_t type)

src/BSON/DBPointer.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,13 @@ static void php_phongo_dbpointer_free_object(zend_object* object)
176176
efree(intern->ref);
177177
}
178178

179-
180179
if (intern->properties) {
181-
HashTable* props = intern->properties;
180+
HashTable* props = intern->properties;
182181
intern->properties = NULL;
183182
zend_hash_release(props);
184183
}
185184
if (intern->php_properties) {
186-
HashTable* props = intern->php_properties;
185+
HashTable* props = intern->php_properties;
187186
intern->php_properties = NULL;
188187
zend_hash_release(props);
189188
}
@@ -256,17 +255,18 @@ void php_phongo_dbpointer_init_ce(INIT_FUNC_ARGS)
256255
php_phongo_dbpointer_ce->create_object = php_phongo_dbpointer_create_object;
257256

258257
memcpy(&php_phongo_handler_dbpointer, phongo_get_std_object_handlers(), sizeof(zend_object_handlers));
259-
php_phongo_handler_dbpointer.compare = php_phongo_dbpointer_compare_objects;
260-
php_phongo_handler_dbpointer.clone_obj = php_phongo_dbpointer_clone_object;
261-
php_phongo_handler_dbpointer.get_debug_info = php_phongo_dbpointer_get_debug_info;
262-
php_phongo_handler_dbpointer.get_properties = php_phongo_dbpointer_get_properties;
263-
php_phongo_handler_dbpointer.read_property = php_phongo_dbpointer_read_property;
264-
php_phongo_handler_dbpointer.write_property = php_phongo_dbpointer_write_property;
265-
php_phongo_handler_dbpointer.has_property = php_phongo_dbpointer_has_property;
266-
php_phongo_handler_dbpointer.unset_property = php_phongo_dbpointer_unset_property;
258+
php_phongo_handler_dbpointer.compare = php_phongo_dbpointer_compare_objects;
259+
php_phongo_handler_dbpointer.clone_obj = php_phongo_dbpointer_clone_object;
260+
php_phongo_handler_dbpointer.get_debug_info = php_phongo_dbpointer_get_debug_info;
261+
php_phongo_handler_dbpointer.get_properties = php_phongo_dbpointer_get_properties;
262+
php_phongo_handler_dbpointer.read_property = php_phongo_dbpointer_read_property;
263+
php_phongo_handler_dbpointer.write_property = php_phongo_dbpointer_write_property;
264+
php_phongo_handler_dbpointer.has_property = php_phongo_dbpointer_has_property;
265+
php_phongo_handler_dbpointer.unset_property = php_phongo_dbpointer_unset_property;
267266
php_phongo_handler_dbpointer.get_property_ptr_ptr = php_phongo_dbpointer_get_property_ptr_ptr;
268-
php_phongo_handler_dbpointer.free_obj = php_phongo_dbpointer_free_object;
269-
php_phongo_handler_dbpointer.offset = XtOffsetOf(php_phongo_dbpointer_t, std);
267+
php_phongo_handler_dbpointer.get_gc = php_phongo_dbpointer_get_gc;
268+
php_phongo_handler_dbpointer.free_obj = php_phongo_dbpointer_free_object;
269+
php_phongo_handler_dbpointer.offset = XtOffsetOf(php_phongo_dbpointer_t, std);
270270
}
271271

272272
bool phongo_dbpointer_new(zval* object, const char* ref, size_t ref_len, const bson_oid_t* oid)

0 commit comments

Comments
 (0)