@@ -60,28 +60,112 @@ ZEND_TSRMLS_CACHE_EXTERN()
6060
6161zend_object_handlers * phongo_get_std_object_handlers (void );
6262
63+ #define PHONGO_RETURN_PROPS (is_temp , props ) \
64+ if (!(is_temp)) { \
65+ GC_ADDREF(props); \
66+ } \
67+ return props;
68+
6369#define PHONGO_GET_PROPERTY_HASH_INIT_PROPS (is_temp , intern , props , size ) \
6470 do { \
71+ if (!(intern)->php_properties) { \
72+ ALLOC_HASHTABLE((intern)->php_properties); \
73+ zend_hash_init((intern)->php_properties, 0, NULL, ZVAL_PTR_DTOR, 0); \
74+ GC_ADDREF((intern)->php_properties); \
75+ } \
6576 if (is_temp) { \
66- ALLOC_HASHTABLE(props); \
67- zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \
68- } else if ((intern)->properties) { \
69- (props) = (intern)->properties; \
77+ (props) = zend_array_dup((intern)->php_properties); \
7078 } else { \
71- ALLOC_HASHTABLE(props); \
72- zend_hash_init((props), (size), NULL, ZVAL_PTR_DTOR, 0); \
79+ (props) = zend_array_dup((intern)->php_properties); \
80+ if ((intern)->properties) { \
81+ HashTable *__tmp = (intern)->properties; \
82+ (intern)->properties = NULL; \
83+ zend_hash_release(__tmp); \
84+ } \
7385 (intern)->properties = (props); \
7486 } \
7587 } while (0)
7688
7789#define PHONGO_GET_PROPERTY_HASH_FREE_PROPS (is_temp , props ) \
7890 do { \
7991 if (is_temp) { \
80- zend_hash_destroy((props)); \
81- FREE_HASHTABLE(props); \
92+ zend_hash_release((props)); \
8293 } \
8394 } while (0)
8495
96+ #define PHONGO_GET_PROPERTY_HANDLERS (_name , _intern_extractor ) \
97+ static zval* php_phongo_##_name##_read_property(zend_object *zobj, zend_string *member, int type, void **cache_slot, zval *rv) \
98+ { \
99+ HashTable *props = _intern_extractor(zobj)->php_properties; \
100+ if (!props) { \
101+ ALLOC_HASHTABLE(props); \
102+ zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
103+ _intern_extractor(zobj)->php_properties = props; \
104+ } \
105+ return zend_hash_find(props, member); \
106+ } \
107+ \
108+ static zval *php_phongo_##_name##_write_property(zend_object *zobj, zend_string *name, zval *value, void **cache_slot) \
109+ { \
110+ Z_TRY_ADDREF_P(value); \
111+ HashTable *props = _intern_extractor(zobj)->php_properties; \
112+ if (!props) { \
113+ ALLOC_HASHTABLE(props); \
114+ zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
115+ _intern_extractor(zobj)->php_properties = props; \
116+ } \
117+ return zend_hash_add_new(props, name, value); \
118+ } \
119+ static int php_phongo_##_name##_has_property(zend_object *zobj, zend_string *name, int has_set_exists, void **cache_slot) \
120+ { \
121+ HashTable *props = _intern_extractor(zobj)->php_properties; \
122+ if (!props) { \
123+ ALLOC_HASHTABLE(props); \
124+ zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
125+ _intern_extractor(zobj)->php_properties = props; \
126+ } \
127+ zval *value = zend_hash_find(props, name); \
128+ if (value) { \
129+ if (has_set_exists == ZEND_PROPERTY_NOT_EMPTY) { \
130+ return zend_is_true(value); \
131+ } \
132+ if (has_set_exists < ZEND_PROPERTY_NOT_EMPTY) { \
133+ ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_ISSET); \
134+ ZVAL_DEREF(value); \
135+ return (Z_TYPE_P(value) != IS_NULL); \
136+ } \
137+ ZEND_ASSERT(has_set_exists == ZEND_PROPERTY_EXISTS); \
138+ return true; \
139+ } \
140+ return false; \
141+ } \
142+ static void php_phongo_##_name##_unset_property(zend_object *zobj, zend_string *name, void **cache_slot) \
143+ { \
144+ HashTable *props = _intern_extractor(zobj)->php_properties; \
145+ if (!props) { \
146+ ALLOC_HASHTABLE(props); \
147+ zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
148+ _intern_extractor(zobj)->php_properties = props; \
149+ } \
150+ zend_hash_del(props, name); \
151+ } \
152+ \
153+ static zval *php_phongo_##_name##_get_property_ptr_ptr(zend_object *zobj, zend_string *name, int type, void **cache_slot) \
154+ { \
155+ HashTable *props = _intern_extractor(zobj)->php_properties; \
156+ if (!props) { \
157+ ALLOC_HASHTABLE(props); \
158+ zend_hash_init(props, 0, NULL, ZVAL_PTR_DTOR, 0); \
159+ _intern_extractor(zobj)->php_properties = props; \
160+ } \
161+ \
162+ zval *value = zend_hash_find(props, name); \
163+ if (value) { \
164+ return value; \
165+ } \
166+ return zend_hash_add(props, name, &EG(uninitialized_zval)); \
167+ }
168+
85169#define PHONGO_ZVAL_EXCEPTION_NAME (e ) (ZSTR_VAL(e->ce->name))
86170
87171#define PHONGO_SET_CREATED_BY_PID (intern ) \
0 commit comments