Skip to content

Commit be82a07

Browse files
committed
Use better data structures (incomplete)
1 parent 4e66aba commit be82a07

13 files changed

+128
-163
lines changed

Zend/zend_API.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ ZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module TS
18871887
{
18881888
int name_len;
18891889
zend_string *lcname;
1890-
//??? zend_module_entry *module_ptr;
1890+
zend_module_entry *module_ptr;
18911891

18921892
if (!module) {
18931893
return NULL;
@@ -1923,13 +1923,13 @@ ZEND_API zend_module_entry* zend_register_module_ex(zend_module_entry *module TS
19231923
lcname = STR_ALLOC(name_len, 1);
19241924
zend_str_tolower_copy(lcname->val, module->name, name_len);
19251925

1926-
if (zend_hash_add_mem(&module_registry, lcname, module, sizeof(zend_module_entry)) == NULL) {
1926+
if ((module_ptr = zend_hash_add_mem(&module_registry, lcname, module, sizeof(zend_module_entry))) == NULL) {
19271927
zend_error(E_CORE_WARNING, "Module '%s' already loaded", module->name);
19281928
STR_RELEASE(lcname);
19291929
return NULL;
19301930
}
19311931
STR_RELEASE(lcname);
1932-
//??? module = module_ptr;
1932+
module = module_ptr;
19331933
EG(current_module) = module;
19341934

19351935
if (module->functions && zend_register_functions(NULL, module->functions, NULL, module->type TSRMLS_CC)==FAILURE) {
@@ -2798,7 +2798,6 @@ static int zend_is_callable_check_func(int check_flags, zval *callable, zend_fca
27982798
EG(scope) = ce_org;
27992799
}
28002800

2801-
//??? if (!zend_is_callable_check_class(Z_STRVAL_P(callable), clen, fcc, &strict_class, error TSRMLS_CC)) {
28022801
if (!zend_is_callable_check_class(Z_STR_P(callable), fcc, &strict_class, error TSRMLS_CC)) {
28032802
EG(scope) = last_scope;
28042803
return 0;
@@ -3035,11 +3034,12 @@ ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval *object_ptr, uint ch
30353034
if (object_ptr && Z_TYPE_P(object_ptr) != IS_OBJECT) {
30363035
object_ptr = NULL;
30373036
}
3038-
//??? if (object_ptr &&
3039-
//??? (!EG(objects_store).object_buckets ||
3040-
//??? !EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(object_ptr)].valid)) {
3041-
//??? return 0;
3042-
//??? }
3037+
3038+
if (object_ptr &&
3039+
(!EG(objects_store).object_buckets ||
3040+
!IS_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(object_ptr)]))) {
3041+
return 0;
3042+
}
30433043

30443044
switch (Z_TYPE_P(callable)) {
30453045
case IS_STRING:
@@ -3117,10 +3117,10 @@ ZEND_API zend_bool zend_is_callable_ex(zval *callable, zval *object_ptr, uint ch
31173117
}
31183118

31193119
} else {
3120-
//??? if (!EG(objects_store).object_buckets ||
3121-
//??? !EG(objects_store).object_buckets[Z_OBJ_HANDLE_PP(obj)].valid) {
3122-
//??? return 0;
3123-
//??? }
3120+
if (!!EG(objects_store).object_buckets ||
3121+
!IS_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(obj)])) {
3122+
return 0;
3123+
}
31243124

31253125
fcc->calling_scope = Z_OBJCE_P(obj); /* TBFixed: what if it's overloaded? */
31263126

@@ -3711,7 +3711,7 @@ ZEND_API int zend_update_static_property(zend_class_entry *scope, const char *na
37113711
ZVAL_COPY_VALUE(property, value);
37123712
if (Z_REFCOUNT_P(value) > 0) {
37133713
zval_copy_ctor(property);
3714-
} else {
3714+
//??? } else {
37153715
//??? efree(value);
37163716
}
37173717
} else {
@@ -3849,12 +3849,12 @@ ZEND_API void zend_restore_error_handling(zend_error_handling *saved TSRMLS_DC)
38493849
{
38503850
EG(error_handling) = saved->handling;
38513851
EG(exception_class) = saved->handling == EH_THROW ? saved->exception : NULL;
3852-
if (Z_TYPE(saved->user_handler) != IS_UNDEF) {
3853-
//??? && saved->user_handler != EG(user_error_handler)) {
3852+
if (Z_TYPE(saved->user_handler) != IS_UNDEF
3853+
&& memcmp(&saved->user_handler, &EG(user_error_handler), sizeof(zval)) != 0) {
38543854
zval_ptr_dtor(&EG(user_error_handler));
38553855
ZVAL_COPY_VALUE(&EG(user_error_handler), &saved->user_handler);
3856-
//??? } else if (saved->user_handler) {
3857-
//??? zval_ptr_dtor(&saved->user_handler);
3856+
} else if (Z_TYPE(saved->user_handler)) {
3857+
zval_ptr_dtor(&saved->user_handler);
38583858
}
38593859
ZVAL_UNDEF(&saved->user_handler);
38603860
}

Zend/zend_execute_API.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -797,10 +797,11 @@ int zend_call_function(zend_fcall_info *fci, zend_fcall_info_cache *fci_cache TS
797797
called_scope = fci_cache->called_scope;
798798
fci->object_ptr = fci_cache->object_ptr;
799799
ZVAL_COPY_VALUE(&EX(object), fci->object_ptr);
800-
//??? if (fci->object_ptr && Z_TYPE_P(fci->object_ptr) == IS_OBJECT &&
801-
//??? (!EG(objects_store).object_buckets || !EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(fci->object_ptr)].valid)) {
802-
//??? return FAILURE;
803-
//??? }
800+
if (fci->object_ptr && Z_TYPE_P(fci->object_ptr) == IS_OBJECT &&
801+
(!EG(objects_store).object_buckets ||
802+
!IS_VALID(EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(fci->object_ptr)]))) {
803+
return FAILURE;
804+
}
804805

805806
if (EX(function_state).function->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED)) {
806807
if (EX(function_state).function->common.fn_flags & ZEND_ACC_ABSTRACT) {

Zend/zend_hash.c

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -510,9 +510,6 @@ static zend_always_inline void _zend_hash_del_el_ex(HashTable *ht, uint idx, Buc
510510
if (ht->pDestructor) {
511511
ht->pDestructor(&p->val);
512512
}
513-
//??? if (ht->flags & HASH_FLAG_BIG_DATA) {
514-
//??? pefree(p->xData, ht->flags & HASH_FLAG_PERSISTENT);
515-
//??? }
516513
if (p->key) {
517514
STR_RELEASE(p->key);
518515
}
@@ -665,9 +662,6 @@ ZEND_API void zend_hash_destroy(HashTable *ht)
665662
if (ht->pDestructor) {
666663
ht->pDestructor(&p->val);
667664
}
668-
//??? if (ht->flags & HASH_FLAG_BIG_DATA) {
669-
//??? pefree(p->xData, ht->flags & HASH_FLAG_PERSISTENT);
670-
//??? }
671665
if (p->key) {
672666
STR_RELEASE(p->key);
673667
}
@@ -696,9 +690,6 @@ ZEND_API void zend_hash_clean(HashTable *ht)
696690
if (ht->pDestructor) {
697691
ht->pDestructor(&p->val);
698692
}
699-
//??? if (ht->flags & HASH_FLAG_BIG_DATA) {
700-
//??? pefree(p->xData, ht->flags & HASH_FLAG_PERSISTENT);
701-
//??? }
702693
if (p->key) {
703694
STR_RELEASE(p->key);
704695
}

Zend/zend_iterators.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424

2525
static zend_class_entry zend_iterator_class_entry;
2626

27+
static void iter_wrapper_dtor(zend_object *object TSRMLS_DC);
28+
2729
static zend_object_handlers iterator_object_handlers = {
28-
ZEND_OBJECTS_STORE_HANDLERS,
30+
iter_wrapper_dtor,
31+
NULL,
32+
NULL,
2933
NULL, /* prop read */
3034
NULL, /* prop write */
3135
NULL, /* read dim */
@@ -61,20 +65,9 @@ static void iter_wrapper_dtor(zend_object *object TSRMLS_DC)
6165
iter->funcs->dtor(iter TSRMLS_CC);
6266
}
6367

64-
ZEND_API zval *zend_iterator_wrap(zend_object_iterator *iter TSRMLS_DC)
68+
ZEND_API void zend_iterator_wrap(zend_object_iterator *iter, zval *wrapped TSRMLS_DC)
6569
{
66-
//???
67-
return NULL;
68-
#if 0
69-
zval *wrapped;
70-
71-
MAKE_STD_ZVAL(wrapped);
72-
Z_TYPE_P(wrapped) = IS_OBJECT;
73-
Z_OBJ_HANDLE_P(wrapped) = zend_objects_store_put(iter, iter_wrapper_dtor, NULL, NULL TSRMLS_CC);
74-
Z_OBJ_HT_P(wrapped) = &iterator_object_handlers;
75-
76-
return wrapped;
77-
#endif
70+
ZVAL_OBJ(wrapped, &iter->std);
7871
}
7972

8073
ZEND_API enum zend_object_iterator_kind zend_iterator_unwrap(

Zend/zend_iterators.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ typedef struct _zend_object_iterator_funcs {
5555
} zend_object_iterator_funcs;
5656

5757
struct _zend_object_iterator {
58+
zend_object std;
5859
void *data;
5960
zend_object_iterator_funcs *funcs;
6061
ulong index; /* private to fe_reset/fe_fetch opcodes */
@@ -82,7 +83,7 @@ BEGIN_EXTERN_C()
8283
ZEND_API enum zend_object_iterator_kind zend_iterator_unwrap(zval *array_ptr, zend_object_iterator **iter TSRMLS_DC);
8384

8485
/* given an iterator, wrap it up as a zval for use by the engine opcodes */
85-
ZEND_API zval *zend_iterator_wrap(zend_object_iterator *iter TSRMLS_DC);
86+
ZEND_API void zend_iterator_wrap(zend_object_iterator *iter, zval *zv TSRMLS_DC);
8687

8788
ZEND_API void zend_register_iterator_wrapper(TSRMLS_D);
8889
END_EXTERN_C()

Zend/zend_object_handlers.c

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@
4141

4242
#define Z_OBJ_PROTECT_RECURSION(zval_p) \
4343
do { \
44-
if (EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(zval_p)].apply_count++ >= 3) { \
44+
if (Z_OBJ_APPLY_COUNT_P(zval_p) >= 3) { \
4545
zend_error(E_ERROR, "Nesting level too deep - recursive dependency?"); \
4646
} \
47+
Z_OBJ_INC_APPLY_COUNT_P(zval_p); \
4748
} while (0)
4849

4950

5051
#define Z_OBJ_UNPROTECT_RECURSION(zval_p) \
51-
EG(objects_store).object_buckets[Z_OBJ_HANDLE_P(zval_p)].apply_count--
52+
Z_OBJ_DEC_APPLY_COUNT_P(zval_p)
5253

5354
/*
5455
__X accessors explanation:
@@ -1010,8 +1011,6 @@ static union _zend_function *zend_std_get_method(zval *object, zend_string *meth
10101011
if (EXPECTED(key != NULL)) {
10111012
lc_method_name = Z_STR(key->constant);
10121013
} else {
1013-
/* Create a zend_copy_str_tolower(dest, src, src_length); */
1014-
//??? lc_method_name = do_alloca(method_len+1, use_heap);
10151014
lc_method_name = STR_ALLOC(method_name->len, 0);
10161015
zend_str_tolower_copy(lc_method_name->val, method_name->val, method_name->len);
10171016
}
@@ -1146,8 +1145,6 @@ ZEND_API zend_function *zend_std_get_static_method(zend_class_entry *ce, zend_st
11461145
if (EXPECTED(key != NULL)) {
11471146
lc_function_name = Z_STR(key->constant);
11481147
} else {
1149-
//???lc_function_name = do_alloca(function_name_strlen+1, use_heap);
1150-
/* Create a zend_copy_str_tolower(dest, src, src_length); */
11511148
lc_function_name = STR_ALLOC(function_name->len, 0);
11521149
zend_str_tolower_copy(lc_function_name->val, function_name->val, function_name->len);
11531150
}
@@ -1334,38 +1331,38 @@ static int zend_std_compare_objects(zval *o1, zval *o2 TSRMLS_DC) /* {{{ */
13341331
if (!zobj1->properties && !zobj2->properties) {
13351332
int i;
13361333

1337-
//??? Z_OBJ_PROTECT_RECURSION(o1);
1338-
//??? Z_OBJ_PROTECT_RECURSION(o2);
1334+
Z_OBJ_PROTECT_RECURSION(o1);
1335+
Z_OBJ_PROTECT_RECURSION(o2);
13391336
for (i = 0; i < zobj1->ce->default_properties_count; i++) {
13401337
if (Z_TYPE(zobj1->properties_table[i]) != IS_UNDEF) {
13411338
if (Z_TYPE(zobj2->properties_table[i]) != IS_UNDEF) {
13421339
zval result;
13431340

13441341
if (compare_function(&result, &zobj1->properties_table[i], &zobj2->properties_table[i] TSRMLS_CC)==FAILURE) {
1345-
//??? Z_OBJ_UNPROTECT_RECURSION(o1);
1346-
//??? Z_OBJ_UNPROTECT_RECURSION(o2);
1342+
Z_OBJ_UNPROTECT_RECURSION(o1);
1343+
Z_OBJ_UNPROTECT_RECURSION(o2);
13471344
return 1;
13481345
}
13491346
if (Z_LVAL(result) != 0) {
1350-
//??? Z_OBJ_UNPROTECT_RECURSION(o1);
1351-
//??? Z_OBJ_UNPROTECT_RECURSION(o2);
1347+
Z_OBJ_UNPROTECT_RECURSION(o1);
1348+
Z_OBJ_UNPROTECT_RECURSION(o2);
13521349
return Z_LVAL(result);
13531350
}
13541351
} else {
1355-
//??? Z_OBJ_UNPROTECT_RECURSION(o1);
1356-
//??? Z_OBJ_UNPROTECT_RECURSION(o2);
1352+
Z_OBJ_UNPROTECT_RECURSION(o1);
1353+
Z_OBJ_UNPROTECT_RECURSION(o2);
13571354
return 1;
13581355
}
13591356
} else {
13601357
if (Z_TYPE(zobj2->properties_table[i]) != IS_UNDEF) {
1361-
//??? Z_OBJ_UNPROTECT_RECURSION(o1);
1362-
//??? Z_OBJ_UNPROTECT_RECURSION(o2);
1358+
Z_OBJ_UNPROTECT_RECURSION(o1);
1359+
Z_OBJ_UNPROTECT_RECURSION(o2);
13631360
return 1;
13641361
}
13651362
}
13661363
}
1367-
//??? Z_OBJ_UNPROTECT_RECURSION(o1);
1368-
//??? Z_OBJ_UNPROTECT_RECURSION(o2);
1364+
Z_OBJ_UNPROTECT_RECURSION(o1);
1365+
Z_OBJ_UNPROTECT_RECURSION(o2);
13691366
return 0;
13701367
} else {
13711368
if (!zobj1->properties) {

0 commit comments

Comments
 (0)