Skip to content

Commit 7eb045d

Browse files
committed
API cleanup. Removed unused functions (kept compatibility macros).
1 parent e080fb6 commit 7eb045d

8 files changed

+34
-118
lines changed

Diff for: Zend/zend.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ ZEND_API void zend_print_flat_zval_r(zval *expr) /* {{{ */
415415
zend_print_flat_zval_r(Z_REFVAL_P(expr));
416416
break;
417417
default:
418-
zend_print_variable(expr);
418+
zend_print_zval(expr, 0);
419419
break;
420420
}
421421
}

Diff for: Zend/zend.h

+4
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ ZEND_API size_t zend_print_zval(zval *expr, int indent);
243243
ZEND_API void zend_print_zval_r(zval *expr, int indent);
244244
ZEND_API zend_string *zend_print_zval_r_to_str(zval *expr, int indent);
245245
ZEND_API void zend_print_flat_zval_r(zval *expr);
246+
247+
#define zend_print_variable(var) \
248+
zend_print_zval((var), 0)
249+
246250
ZEND_API ZEND_COLD void zend_output_debug_string(zend_bool trigger_break, const char *format, ...) ZEND_ATTRIBUTE_FORMAT(printf, 2, 3);
247251

248252
ZEND_API void zend_activate(void);

Diff for: Zend/zend_constants.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ void free_zend_constant(zval *zv)
4646
}
4747
efree(c);
4848
} else {
49-
zval_internal_dtor(&c->value);
49+
zval_internal_ptr_dtor(&c->value);
5050
if (c->name) {
5151
zend_string_release_ex(c->name, 1);
5252
}

Diff for: Zend/zend_execute_API.c

-17
Original file line numberDiff line numberDiff line change
@@ -528,23 +528,6 @@ ZEND_API zend_bool zend_is_executing(void) /* {{{ */
528528
}
529529
/* }}} */
530530

531-
ZEND_API void _zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ */
532-
{
533-
i_zval_ptr_dtor(zval_ptr ZEND_FILE_LINE_RELAY_CC);
534-
}
535-
/* }}} */
536-
537-
ZEND_API void _zval_internal_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ */
538-
{
539-
if (Z_REFCOUNTED_P(zval_ptr)) {
540-
Z_DELREF_P(zval_ptr);
541-
if (Z_REFCOUNT_P(zval_ptr) == 0) {
542-
_zval_internal_dtor_for_ptr(zval_ptr ZEND_FILE_LINE_CC);
543-
}
544-
}
545-
}
546-
/* }}} */
547-
548531
ZEND_API int zend_use_undefined_constant(zend_string *name, zend_ast_attr attr, zval *result) /* {{{ */
549532
{
550533
char *colon;

Diff for: Zend/zend_variables.c

+19-81
Original file line numberDiff line numberDiff line change
@@ -108,65 +108,32 @@ static void ZEND_FASTCALL zend_ast_ref_destroy_wrapper(zend_ast_ref *ast ZEND_FI
108108
}
109109
#endif
110110

111-
ZEND_API void _zval_internal_dtor(zval *zvalue ZEND_FILE_LINE_DC)
111+
ZEND_API void _zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ */
112112
{
113-
switch (Z_TYPE_P(zvalue)) {
114-
case IS_STRING:
115-
CHECK_ZVAL_STRING_REL(Z_STR_P(zvalue));
116-
zend_string_release_ex(Z_STR_P(zvalue), 1);
117-
break;
118-
case IS_ARRAY:
119-
case IS_CONSTANT_AST:
120-
case IS_OBJECT:
121-
case IS_RESOURCE:
122-
zend_error_noreturn(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources");
123-
break;
124-
case IS_REFERENCE: {
125-
zend_reference *ref = (zend_reference*)Z_REF_P(zvalue);
126-
127-
zval_internal_ptr_dtor(&ref->val);
128-
free(ref);
129-
break;
130-
}
131-
case IS_LONG:
132-
case IS_DOUBLE:
133-
case IS_FALSE:
134-
case IS_TRUE:
135-
case IS_NULL:
136-
default:
137-
break;
138-
}
113+
i_zval_ptr_dtor(zval_ptr ZEND_FILE_LINE_RELAY_CC);
139114
}
115+
/* }}} */
140116

141-
ZEND_API void _zval_internal_dtor_for_ptr(zval *zvalue ZEND_FILE_LINE_DC)
117+
ZEND_API void _zval_internal_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC) /* {{{ */
142118
{
143-
switch (Z_TYPE_P(zvalue)) {
144-
case IS_STRING:
145-
CHECK_ZVAL_STRING_REL(Z_STR_P(zvalue));
146-
zend_string_free(Z_STR_P(zvalue));
147-
break;
148-
case IS_ARRAY:
149-
case IS_CONSTANT_AST:
150-
case IS_OBJECT:
151-
case IS_RESOURCE:
152-
zend_error_noreturn(E_CORE_ERROR, "Internal zval's can't be arrays, objects or resources");
153-
break;
154-
case IS_REFERENCE: {
155-
zend_reference *ref = (zend_reference*)Z_REF_P(zvalue);
156-
157-
zval_internal_ptr_dtor(&ref->val);
158-
free(ref);
159-
break;
119+
if (Z_REFCOUNTED_P(zval_ptr)) {
120+
zend_refcounted *ref = Z_COUNTED_P(zval_ptr);
121+
122+
if (GC_DELREF(ref) == 0) {
123+
if (Z_TYPE_P(zval_ptr) == IS_STRING) {
124+
zend_string *str = (zend_string*)ref;
125+
126+
CHECK_ZVAL_STRING_REL(str);
127+
ZEND_ASSERT(!ZSTR_IS_INTERNED(str));
128+
ZEND_ASSERT((GC_FLAGS(str) & IS_STR_PERSISTENT));
129+
free(str);
130+
} else {
131+
zend_error_noreturn(E_CORE_ERROR, "Internal zval's can't be arrays, objects, resources or reference");
160132
}
161-
case IS_LONG:
162-
case IS_DOUBLE:
163-
case IS_FALSE:
164-
case IS_TRUE:
165-
case IS_NULL:
166-
default:
167-
break;
133+
}
168134
}
169135
}
136+
/* }}} */
170137

171138
/* This function should only be used as a copy constructor, i.e. it
172139
* should only be called AFTER a zval has been copied to another
@@ -183,17 +150,6 @@ ZEND_API void zval_add_ref(zval *p)
183150
}
184151
}
185152

186-
ZEND_API void zval_add_ref_unref(zval *p)
187-
{
188-
if (Z_REFCOUNTED_P(p)) {
189-
if (Z_ISREF_P(p)) {
190-
ZVAL_COPY(p, Z_REFVAL_P(p));
191-
} else {
192-
Z_ADDREF_P(p);
193-
}
194-
}
195-
}
196-
197153
ZEND_API void ZEND_FASTCALL _zval_copy_ctor_func(zval *zvalue ZEND_FILE_LINE_DC)
198154
{
199155
if (EXPECTED(Z_TYPE_P(zvalue) == IS_ARRAY)) {
@@ -206,25 +162,7 @@ ZEND_API void ZEND_FASTCALL _zval_copy_ctor_func(zval *zvalue ZEND_FILE_LINE_DC)
206162
}
207163

208164

209-
ZEND_API size_t zend_print_variable(zval *var)
210-
{
211-
return zend_print_zval(var, 0);
212-
}
213-
214-
215-
ZEND_API void _zval_dtor_wrapper(zval *zvalue)
216-
{
217-
zval_dtor(zvalue);
218-
}
219-
220-
221165
#if ZEND_DEBUG
222-
ZEND_API void _zval_internal_dtor_wrapper(zval *zvalue)
223-
{
224-
zval_internal_dtor(zvalue);
225-
}
226-
227-
228166
ZEND_API void _zval_ptr_dtor_wrapper(zval *zval_ptr)
229167
{
230168

Diff for: Zend/zend_variables.h

+4-13
Original file line numberDiff line numberDiff line change
@@ -71,42 +71,33 @@ static zend_always_inline void _zval_opt_copy_ctor(zval *zvalue ZEND_FILE_LINE_D
7171
}
7272
}
7373

74-
ZEND_API size_t zend_print_variable(zval *var);
7574
ZEND_API void _zval_ptr_dtor(zval *zval_ptr ZEND_FILE_LINE_DC);
76-
ZEND_API void _zval_internal_dtor_for_ptr(zval *zvalue ZEND_FILE_LINE_DC);
77-
ZEND_API void _zval_internal_dtor(zval *zvalue ZEND_FILE_LINE_DC);
7875
ZEND_API void _zval_internal_ptr_dtor(zval *zvalue ZEND_FILE_LINE_DC);
79-
ZEND_API void _zval_dtor_wrapper(zval *zvalue);
8076
#define zval_copy_ctor(zvalue) _zval_copy_ctor((zvalue) ZEND_FILE_LINE_CC)
8177
#define zval_opt_copy_ctor(zvalue) _zval_opt_copy_ctor((zvalue) ZEND_FILE_LINE_CC)
82-
#define zval_dtor(zvalue) zval_ptr_dtor_nogc(zvalue)
8378
#define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC)
8479
#define zval_ptr_dtor_nogc(zval_ptr) _zval_ptr_dtor_nogc((zval_ptr) ZEND_FILE_LINE_CC)
85-
#define zval_internal_dtor(zvalue) _zval_internal_dtor((zvalue) ZEND_FILE_LINE_CC)
8680
#define zval_internal_ptr_dtor(zvalue) _zval_internal_ptr_dtor((zvalue) ZEND_FILE_LINE_CC)
87-
#define zval_dtor_wrapper _zval_dtor_wrapper
81+
82+
/* Kept for compatibility */
83+
#define zval_dtor(zvalue) zval_ptr_dtor_nogc(zvalue)
84+
#define zval_internal_dtor(zvalue) _zval_internal_ptr_dtor((zvalue) ZEND_FILE_LINE_CC)
8885

8986
#if ZEND_DEBUG
9087
ZEND_API void _zval_ptr_dtor_wrapper(zval *zval_ptr);
91-
ZEND_API void _zval_internal_dtor_wrapper(zval *zvalue);
9288
ZEND_API void _zval_internal_ptr_dtor_wrapper(zval *zvalue);
9389
#define zval_ptr_dtor_wrapper _zval_ptr_dtor_wrapper
94-
#define zval_internal_dtor_wrapper _zval_internal_dtor_wrapper
9590
#define zval_internal_ptr_dtor_wrapper _zval_internal_ptr_dtor_wrapper
9691
#else
9792
#define zval_ptr_dtor_wrapper _zval_ptr_dtor
98-
#define zval_internal_dtor_wrapper _zval_internal_dtor
9993
#define zval_internal_ptr_dtor_wrapper _zval_internal_ptr_dtor
10094
#endif
10195

10296
ZEND_API void zval_add_ref(zval *p);
103-
ZEND_API void zval_add_ref_unref(zval *p);
10497

10598
END_EXTERN_C()
10699

107-
#define ZVAL_DESTRUCTOR zval_dtor_wrapper
108100
#define ZVAL_PTR_DTOR zval_ptr_dtor_wrapper
109-
#define ZVAL_INTERNAL_DTOR zval_internal_dtor_wrapper
110101
#define ZVAL_INTERNAL_PTR_DTOR zval_internal_ptr_dtor_wrapper
111102

112103
#endif

Diff for: Zend/zend_vm_def.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -6412,7 +6412,7 @@ ZEND_VM_COLD_HANDLER(79, ZEND_EXIT, CONST|TMPVAR|UNUSED|CV, ANY)
64126412
break;
64136413
}
64146414
}
6415-
zend_print_variable(ptr);
6415+
zend_print_zval(ptr, 0);
64166416
}
64176417
} while (0);
64186418
FREE_OP1();

Diff for: Zend/zend_vm_execute.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -3523,7 +3523,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_EXIT_SPEC_CONST_H
35233523
break;
35243524
}
35253525
}
3526-
zend_print_variable(ptr);
3526+
zend_print_zval(ptr, 0);
35273527
}
35283528
} while (0);
35293529

@@ -12727,7 +12727,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_EXIT_SPEC_TMPVAR_
1272712727
break;
1272812728
}
1272912729
}
12730-
zend_print_variable(ptr);
12730+
zend_print_zval(ptr, 0);
1273112731
}
1273212732
} while (0);
1273312733
zval_ptr_dtor_nogc(free_op1);
@@ -30417,7 +30417,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_EXIT_SPEC_UNUSED_
3041730417
break;
3041830418
}
3041930419
}
30420-
zend_print_variable(ptr);
30420+
zend_print_zval(ptr, 0);
3042130421
}
3042230422
} while (0);
3042330423

@@ -37487,7 +37487,7 @@ static ZEND_VM_COLD ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_EXIT_SPEC_CV_HAND
3748737487
break;
3748837488
}
3748937489
}
37490-
zend_print_variable(ptr);
37490+
zend_print_zval(ptr, 0);
3749137491
}
3749237492
} while (0);
3749337493

0 commit comments

Comments
 (0)