Skip to content

Commit f9b26bc

Browse files
committed
Cleanup (2-nd round)
1 parent 61e9b0d commit f9b26bc

32 files changed

+535
-2051
lines changed

Zend/zend_API.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -741,8 +741,8 @@ static const char *zend_parse_arg_impl(int arg_num, zval *arg, va_list *va, cons
741741
}
742742
break;
743743

744-
//??? 'Z' iz not supported anymore and should be replaced with 'z'
745744
case 'Z':
745+
/* 'Z' iz not supported anymore and should be replaced with 'z' */
746746
ZEND_ASSERT(c != 'Z');
747747
default:
748748
return "unknown";

Zend/zend_constants.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,28 +39,25 @@ void free_zend_constant(zval *zv)
3939
if (c->name) {
4040
STR_RELEASE(c->name);
4141
}
42-
free(c);
42+
pefree(c, c->flags & CONST_PERSISTENT);
4343
}
4444

4545

4646
static void copy_zend_constant(zval *zv)
4747
{
4848
zend_constant *c = Z_PTR_P(zv);
4949

50-
Z_PTR_P(zv) = malloc(sizeof(zend_constant)/*, c->flags & CONST_PERSISTENT*/);
50+
Z_PTR_P(zv) = pemalloc(sizeof(zend_constant), c->flags & CONST_PERSISTENT);
5151
memcpy(Z_PTR_P(zv), c, sizeof(zend_constant));
5252

5353
c = Z_PTR_P(zv);
54-
//??? c->name = STR_DUP(c->name, c->flags & CONST_PERSISTENT);
5554
c->name = STR_COPY(c->name);
5655
if (!(c->flags & CONST_PERSISTENT)) {
5756
zval_copy_ctor(&c->value);
5857
} else {
59-
//??? internal_copy_ctor needed
6058
if (Z_TYPE(c->value) == IS_STRING) {
6159
Z_STR(c->value) = STR_DUP(Z_STR(c->value), 1);
6260
}
63-
6461
}
6562
}
6663

@@ -213,7 +210,6 @@ ZEND_API void zend_register_stringl_constant(const char *name, uint name_len, ch
213210
{
214211
zend_constant c;
215212

216-
//??? ZVAL_STRINGL(&c.value, strval, strlen, 0);
217213
ZVAL_NEW_STR(&c.value, STR_INIT(strval, strlen, flags & CONST_PERSISTENT));
218214
c.flags = flags;
219215
c.name = STR_INIT(name, name_len, flags & CONST_PERSISTENT);
@@ -247,7 +243,7 @@ static zend_constant *zend_get_special_constant(const char *name, uint name_len
247243
memcpy(const_name->val, "\0__CLASS__", sizeof("\0__CLASS__")-1);
248244
zend_str_tolower_copy(const_name->val + sizeof("\0__CLASS__")-1, EG(scope)->name->val, EG(scope)->name->len);
249245
if ((c = zend_hash_find_ptr(EG(zend_constants), const_name)) == NULL) {
250-
c = malloc(sizeof(zend_constant));
246+
c = emalloc(sizeof(zend_constant));
251247
memset(c, 0, sizeof(zend_constant));
252248
ZVAL_STR(&c->value, STR_COPY(EG(scope)->name));
253249
zend_hash_add_ptr(EG(zend_constants), const_name, c);
@@ -256,7 +252,7 @@ static zend_constant *zend_get_special_constant(const char *name, uint name_len
256252
} else {
257253
zend_string *const_name = STR_INIT("\0__CLASS__", sizeof("\0__CLASS__")-1, 0);
258254
if ((c = zend_hash_find_ptr(EG(zend_constants), const_name)) == NULL) {
259-
c = malloc(sizeof(zend_constant));
255+
c = emalloc(sizeof(zend_constant));
260256
memset(c, 0, sizeof(zend_constant));
261257
ZVAL_EMPTY_STRING(&c->value);
262258
zend_hash_add_ptr(EG(zend_constants), const_name, c);
@@ -472,6 +468,19 @@ zend_constant *zend_quick_get_constant(const zend_literal *key, ulong flags TSRM
472468
return c;
473469
}
474470

471+
static void* zend_hash_add_constant(HashTable *ht, zend_string *key, zend_constant *c)
472+
{
473+
void *ret;
474+
zend_constant *copy = pemalloc(sizeof(zend_constant), c->flags & CONST_PERSISTENT);
475+
476+
memcpy(copy, c, sizeof(zend_constant));
477+
ret = zend_hash_add_ptr(ht, key, copy);
478+
if (!ret) {
479+
pefree(copy, c->flags & CONST_PERSISTENT);
480+
}
481+
return ret;
482+
}
483+
475484
ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC)
476485
{
477486
zend_string *lowercase_name = NULL;
@@ -502,7 +511,7 @@ ZEND_API int zend_register_constant(zend_constant *c TSRMLS_DC)
502511
/* Check if the user is trying to define the internal pseudo constant name __COMPILER_HALT_OFFSET__ */
503512
if ((c->name->len == sizeof("__COMPILER_HALT_OFFSET__")-1
504513
&& !memcmp(name->val, "__COMPILER_HALT_OFFSET__", sizeof("__COMPILER_HALT_OFFSET__")-1))
505-
|| zend_hash_add_mem(EG(zend_constants), name, c, sizeof(zend_constant)) == NULL) {
514+
|| zend_hash_add_constant(EG(zend_constants), name, c) == NULL) {
506515

507516
/* The internal __COMPILER_HALT_OFFSET__ is prefixed by NULL byte */
508517
if (c->name->val[0] == '\0' && c->name->len > sizeof("\0__COMPILER_HALT_OFFSET__")-1

Zend/zend_execute.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,11 +1155,6 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
11551155
if (!Z_OBJ_HT_P(container)->read_dimension) {
11561156
zend_error_noreturn(E_ERROR, "Cannot use object as array");
11571157
} else {
1158-
//??? if (dim_type == IS_TMP_VAR) {
1159-
//??? zval *orig = dim;
1160-
//??? MAKE_REAL_ZVAL_PTR(dim);
1161-
//??? ZVAL_NULL(orig);
1162-
//??? }
11631158
retval = Z_OBJ_HT_P(container)->read_dimension(container, dim, type, result TSRMLS_CC);
11641159

11651160
if (UNEXPECTED(retval == &EG(uninitialized_zval))) {
@@ -1182,9 +1177,6 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
11821177
zend_error(E_NOTICE, "Indirect modification of overloaded element of %s has no effect", ce->name->val);
11831178
}
11841179
}
1185-
//??? AI_SET_PTR(result, retval);
1186-
//??? PZVAL_LOCK(retval);
1187-
//??? ZVAL_COPY(result, retval);
11881180
if (result != retval) {
11891181
if (is_ref) {
11901182
SEPARATE_ZVAL_TO_MAKE_IS_REF(retval);
@@ -1196,9 +1188,6 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
11961188
} else {
11971189
ZVAL_INDIRECT(result, &EG(error_zval));
11981190
}
1199-
//??? if (dim_type == IS_TMP_VAR) {
1200-
//??? zval_ptr_dtor(dim);
1201-
//??? }
12021191
}
12031192
} else if (EXPECTED(Z_TYPE_P(container) == IS_NULL)) {
12041193
if (container == &EG(error_zval)) {
@@ -1302,11 +1291,6 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
13021291
if (!Z_OBJ_HT_P(container)->read_dimension) {
13031292
zend_error_noreturn(E_ERROR, "Cannot use object as array");
13041293
} else {
1305-
//??? if (dim_type == IS_TMP_VAR) {
1306-
//??? zval *orig = dim;
1307-
//??? MAKE_REAL_ZVAL_PTR(dim);
1308-
//??? ZVAL_NULL(orig);
1309-
//??? }
13101294
retval = Z_OBJ_HT_P(container)->read_dimension(container, dim, type, result TSRMLS_CC);
13111295

13121296
if (result) {
@@ -1318,9 +1302,6 @@ static zend_always_inline void zend_fetch_dimension_address_read(zval *result, z
13181302
ZVAL_NULL(result);
13191303
}
13201304
}
1321-
//??? if (dim_type == IS_TMP_VAR) {
1322-
//??? zval_ptr_dtor(dim);
1323-
//??? }
13241305
}
13251306
} else {
13261307
ZVAL_NULL(result);

Zend/zend_execute_API.c

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -483,15 +483,6 @@ ZEND_API int zend_is_true(zval *op TSRMLS_DC) /* {{{ */
483483
#define Z_REAL_TYPE_P(p) (Z_TYPE_P(p) & ~IS_VISITED_CONSTANT)
484484
#define MARK_CONSTANT_VISITED(p) Z_TYPE_INFO_P(p) |= IS_VISITED_CONSTANT
485485

486-
static void zval_deep_copy(zval *p)
487-
{
488-
//??? zval value;
489-
//???
490-
//??? ZVAL_DUP(&value, p);
491-
//??? ZVAL_COPY_VALUE(p, &value);
492-
zval_copy_ctor(p);
493-
}
494-
495486
ZEND_API int zval_update_constant_ex(zval *p, void *arg, zend_class_entry *scope TSRMLS_DC) /* {{{ */
496487
{
497488
zend_bool inline_change = (zend_bool) (zend_uintptr_t) arg;
@@ -502,15 +493,10 @@ ZEND_API int zval_update_constant_ex(zval *p, void *arg, zend_class_entry *scope
502493
zend_error(E_ERROR, "Cannot declare self-referencing constant '%s'", Z_STRVAL_P(p));
503494
} else if (Z_TYPE_P(p) == IS_CONSTANT) {
504495
int refcount;
505-
//??? zend_uchar is_ref;
506496

507497
SEPARATE_ZVAL_IF_NOT_REF(p);
508-
509498
MARK_CONSTANT_VISITED(p);
510-
511499
refcount = Z_REFCOUNTED_P(p) ? Z_REFCOUNT_P(p) : 1;
512-
//??? is_ref = Z_ISREF_P(p);
513-
514500
if (!zend_get_constant_ex(Z_STRVAL_P(p), Z_STRLEN_P(p), &const_value, scope, Z_CONST_FLAGS_P(p) TSRMLS_CC)) {
515501
char *actual = Z_STRVAL_P(p);
516502

@@ -524,7 +510,6 @@ ZEND_API int zval_update_constant_ex(zval *p, void *arg, zend_class_entry *scope
524510
STR_RELEASE(Z_STR_P(p));
525511
Z_STR_P(p) = tmp;
526512
} else {
527-
//??? Z_STRVAL_P(p) = colon + 1;
528513
Z_STR_P(p) = STR_INIT(colon + 1, len, 0);
529514
}
530515
Z_TYPE_FLAGS_P(p) = IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE;
@@ -581,7 +566,6 @@ ZEND_API int zval_update_constant_ex(zval *p, void *arg, zend_class_entry *scope
581566
}
582567

583568
if (Z_REFCOUNTED_P(p)) Z_SET_REFCOUNT_P(p, refcount);
584-
//??? Z_SET_ISREF_TO_P(p, is_ref);
585569
} else if (Z_TYPE_P(p) == IS_CONSTANT_ARRAY) {
586570
zval *element, new_val;
587571
zend_string *str_index;
@@ -595,7 +579,7 @@ ZEND_API int zval_update_constant_ex(zval *p, void *arg, zend_class_entry *scope
595579
HashTable *ht = Z_ARRVAL_P(p);
596580
ZVAL_NEW_ARR(p);
597581
zend_hash_init(Z_ARRVAL_P(p), zend_hash_num_elements(ht), NULL, ZVAL_PTR_DTOR, 0);
598-
zend_hash_copy(Z_ARRVAL_P(p), ht, zval_deep_copy);
582+
zend_hash_copy(Z_ARRVAL_P(p), ht, ZVAL_COPY_CTOR);
599583
}
600584

601585
/* First go over the array and see if there are any constant indices */
@@ -616,7 +600,6 @@ ZEND_API int zval_update_constant_ex(zval *p, void *arg, zend_class_entry *scope
616600
zend_ast_evaluate(&const_value, ast->ast, scope TSRMLS_CC);
617601
zend_ast_destroy(ast->ast);
618602
efree(ast);
619-
//???
620603
} else if (!zend_get_constant_ex(str_index->val, str_index->len, &const_value, scope, GC_FLAGS(str_index) & ~(IS_STR_PERSISTENT | IS_STR_INTERNED |IS_STR_PERMANENT) TSRMLS_CC)) {
621604
char *actual, *str;
622605
const char *save = str_index->val;
@@ -657,9 +640,6 @@ ZEND_API int zval_update_constant_ex(zval *p, void *arg, zend_class_entry *scope
657640

658641
if (Z_REFCOUNTED_P(element) && Z_REFCOUNT_P(element) > 1) {
659642
ZVAL_DUP(&new_val, element);
660-
661-
/* preserve this bit for inheritance */
662-
//??? Z_TYPE_P(element) |= IS_CONSTANT_INDEX;
663643
zval_ptr_dtor(element);
664644
ZVAL_COPY_VALUE(element, &new_val);
665645
}
@@ -990,7 +970,7 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
990970
fci_cache->initialized = 0;
991971
}
992972
} else { /* ZEND_OVERLOADED_FUNCTION */
993-
//??? ALLOC_INIT_ZVAL(*fci->retval_ptr_ptr);
973+
ZVAL_NULL(fci->retval);
994974

995975
/* Not sure what should be done here if it's a static method */
996976
if (fci->object) {

0 commit comments

Comments
 (0)