16
16
#include "zend_exceptions.h"
17
17
#include "zend_interfaces.h"
18
18
19
- #ifdef PHP_REF_PATCH_SPL_OBJECT_HASH
20
- #include "ext/spl/spl_observer.h"
21
- #endif
22
-
23
19
zend_class_entry * php_ref_abstract_reference_class_entry ;
24
20
zend_class_entry * php_ref_soft_reference_class_entry ;
25
21
zend_class_entry * php_ref_weak_reference_class_entry ;
@@ -28,10 +24,6 @@ zend_class_entry *php_ref_weak_reference_class_entry;
28
24
29
25
zend_object_handlers php_ref_reference_object_handlers ;
30
26
31
- #ifdef PHP_REF_PATCH_SPL_OBJECT_HASH
32
- static zend_object_get_debug_info_t spl_object_storage_get_debug_info_orig_handler ;
33
- #endif
34
-
35
27
php_ref_reference_t * php_ref_reference_init (zval * this_ptr , zval * referent_zv , zval * notifier_zv );
36
28
37
29
static inline void php_ref_store_exceptions (zval * exceptions , zval * tmp );
@@ -52,110 +44,6 @@ php_ref_referent_t *php_ref_referent_find_ptr(zend_ulong h) /* {{{ */
52
44
return (php_ref_referent_t * ) zend_hash_index_find_ptr (PHP_REF_G (referents ), h );
53
45
} /* }}} */
54
46
55
- #ifdef PHP_REF_PATCH_SPL_OBJECT_HASH
56
- static HashTable * spl_object_storage_debug_info (zval * obj , int * is_temp ) /* {{{ */
57
- {
58
- HashTable * debug_info ;
59
- zend_string * md5str ;
60
- zend_string * zname ;
61
- zval * val ;
62
- zval * val_obj ;
63
-
64
- zval tmp_storage ;
65
-
66
- zname = zend_mangle_property_name (ZSTR_VAL (spl_ce_SplObjectStorage -> name ), ZSTR_LEN (spl_ce_SplObjectStorage -> name ), "storage" , sizeof ("storage" )- 1 , 0 );
67
-
68
- debug_info = spl_object_storage_get_debug_info_orig_handler (obj , is_temp );
69
-
70
- zval * storage = zend_hash_find (debug_info , zname );
71
-
72
- assert (NULL != storage );
73
- array_init (& tmp_storage );
74
-
75
- ZEND_HASH_FOREACH_VAL (Z_ARR_P (storage ), val ) {
76
- val_obj = zend_hash_str_find (Z_ARR_P (val ), "obj" , sizeof ("obj" ) - 1 );
77
- assert (NULL != val_obj );
78
-
79
- php_ref_referent_t * referent = php_ref_referent_find_ptr ((zend_ulong )Z_OBJ_HANDLE_P (val_obj ));
80
-
81
- if (NULL != referent ) {
82
- Z_OBJ_P (val_obj )-> handlers = referent -> original_handlers ;
83
- md5str = php_spl_object_hash (val_obj );
84
- Z_OBJ_P (val_obj )-> handlers = & referent -> custom_handlers ;
85
- } else {
86
- md5str = php_spl_object_hash (val_obj );
87
- }
88
-
89
- zend_hash_update (Z_ARRVAL (tmp_storage ), md5str , val );
90
- zval_add_ref (val );
91
- zend_string_release (md5str );
92
- } ZEND_HASH_FOREACH_END ();
93
-
94
- zend_symtable_update (debug_info , zname , & tmp_storage );
95
- zend_string_release (zname );
96
-
97
- return debug_info ;
98
- } /* }}} */
99
- #endif
100
-
101
- #ifdef PHP_REF_PATCH_SPL_OBJECT_HASH
102
- static PHP_FUNCTION (spl_object_hash_patched )
103
- {
104
- zval * obj ;
105
- zend_string * hash = NULL ;
106
-
107
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "o" , & obj ) == FAILURE ) {
108
- return ;
109
- }
110
-
111
- php_ref_referent_t * referent = php_ref_referent_find_ptr ((zend_ulong )Z_OBJ_HANDLE_P (obj ));
112
-
113
- if (NULL != referent ) {
114
- Z_OBJ_P (obj )-> handlers = referent -> original_handlers ;
115
- hash = php_spl_object_hash (obj );
116
- Z_OBJ_P (obj )-> handlers = & referent -> custom_handlers ;
117
- }
118
-
119
- if (NULL == hash ) {
120
- hash = php_spl_object_hash (obj );
121
- }
122
-
123
- RETURN_NEW_STR (hash );
124
- } /* }}} */
125
- #endif
126
-
127
- #ifdef PHP_REF_PATCH_SPL_OBJECT_HASH
128
- static void php_ref_patch_spl_hash () /* {{{ */
129
- {
130
- if (PHP_REF_G (spl_hash_replaced )) {
131
- return ;
132
- }
133
-
134
- /* Replace spl_object_hash() */
135
- zend_function * spl_object_hash = zend_hash_str_find_ptr (EG (function_table ), "spl_object_hash" , sizeof ("spl_object_hash" )- 1 );
136
- assert (NULL != spl_object_hash );
137
- spl_object_hash -> internal_function .handler = zif_spl_object_hash_patched ;
138
-
139
- /* Replace SplObjectStorage::getHash() */
140
-
141
- zend_function * spl_object_storage_getHash = zend_hash_str_find_ptr (& spl_ce_SplObjectStorage -> function_table , "gethash" , sizeof ("gethash" ) - 1 );
142
- assert (NULL != spl_object_storage_getHash );
143
- spl_object_storage_getHash -> internal_function .handler = zif_spl_object_hash_patched ;
144
-
145
- /* Replace SplObjectStorage get_debug_info object handler */
146
- zval tmp ;
147
- object_init_ex (& tmp , spl_ce_SplObjectStorage );
148
-
149
- spl_object_storage_get_debug_info_orig_handler = Z_OBJ (tmp )-> handlers -> get_debug_info ;
150
- /* Casting const to non-const type is undefined behavior by C standard, but it should works in our case */
151
- ((zend_object_handlers * ) Z_OBJ (tmp )-> handlers )-> get_debug_info = spl_object_storage_debug_info ;
152
-
153
- zval_ptr_dtor (& tmp );
154
-
155
- PHP_REF_G (spl_hash_replaced ) = 1 ;
156
- } /* }}} */
157
- #endif
158
-
159
47
void php_ref_reference_call_notifier (zval * reference , zval * notifier ) /* {{{ */
160
48
{
161
49
zval args ;
@@ -337,10 +225,6 @@ php_ref_referent_t *php_ref_referent_get_or_create(zval *referent_zv) /* {{{ */
337
225
return referent ;
338
226
}
339
227
340
- #ifdef PHP_REF_PATCH_SPL_OBJECT_HASH
341
- php_ref_patch_spl_hash ();
342
- #endif
343
-
344
228
referent = (php_ref_referent_t * ) ecalloc (1 , sizeof (php_ref_referent_t ));
345
229
346
230
zend_hash_init (& referent -> soft_references , 0 , NULL , NULL , 0 );
0 commit comments