Skip to content

Commit

Permalink
- make class tables contain class_entry *, not class_entry
Browse files Browse the repository at this point in the history
- fix isset($this)
  • Loading branch information
smalyshev committed Mar 12, 2002
1 parent bcdf9b3 commit 92dd5e6
Show file tree
Hide file tree
Showing 9 changed files with 196 additions and 148 deletions.
46 changes: 24 additions & 22 deletions Zend/zend.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ BOOL WINAPI IsDebuggerPresent(VOID);
#endif

/* true multithread-shared globals */
ZEND_API zend_class_entry zend_standard_class_def;
ZEND_API zend_class_entry *zend_standard_class_def = NULL;
ZEND_API int (*zend_printf)(const char *format, ...);
ZEND_API zend_write_func_t zend_write;
ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path);
Expand Down Expand Up @@ -148,7 +148,7 @@ ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_cop
break;
case IS_OBJECT:
expr_copy->value.str.val = (char *) emalloc(sizeof("Object id #")-1 + MAX_LENGTH_OF_LONG);
expr_copy->value.str.len = sprintf(expr_copy->value.str.val, "Object id #%ld", expr->value.obj.handle);
expr_copy->value.str.len = sprintf(expr_copy->value.str.val, "Object id #%ld", (long)expr->value.obj.handle);
#if 0
/* FIXME: This might break BC for some people */
expr_copy->value.str.len = sizeof("Object")-1;
Expand Down Expand Up @@ -246,26 +246,28 @@ static FILE *zend_fopen_wrapper(const char *filename, char **opened_path)

static void register_standard_class(void)
{
zend_standard_class_def.type = ZEND_INTERNAL_CLASS;
zend_standard_class_def.name_length = sizeof("stdClass") - 1;
zend_standard_class_def.name = zend_strndup("stdClass", zend_standard_class_def.name_length);
zend_standard_class_def.parent = NULL;
zend_hash_init_ex(&zend_standard_class_def.default_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
zend_hash_init_ex(&zend_standard_class_def.private_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
zend_standard_class_def.static_members = (HashTable *) malloc(sizeof(HashTable));
zend_hash_init_ex(zend_standard_class_def.static_members, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
zend_hash_init_ex(&zend_standard_class_def.constants_table, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
zend_hash_init_ex(&zend_standard_class_def.class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
zend_hash_init_ex(&zend_standard_class_def.function_table, 0, NULL, ZEND_FUNCTION_DTOR, 1, 0);
zend_standard_class_def.constructor = NULL;
zend_standard_class_def.destructor = NULL;
zend_standard_class_def.clone = NULL;
zend_standard_class_def.handle_function_call = NULL;
zend_standard_class_def.handle_property_get = NULL;
zend_standard_class_def.handle_property_set = NULL;
zend_standard_class_def.refcount = (int *) malloc(sizeof(int));
*zend_standard_class_def.refcount = 1;
zend_hash_add(GLOBAL_CLASS_TABLE, "stdclass", sizeof("stdclass"), &zend_standard_class_def, sizeof(zend_class_entry), NULL);
zend_standard_class_def = malloc(sizeof(zend_class_entry));

zend_standard_class_def->type = ZEND_INTERNAL_CLASS;
zend_standard_class_def->name_length = sizeof("stdClass") - 1;
zend_standard_class_def->name = zend_strndup("stdClass", zend_standard_class_def->name_length);
zend_standard_class_def->parent = NULL;
zend_hash_init_ex(&zend_standard_class_def->default_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
zend_hash_init_ex(&zend_standard_class_def->private_properties, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
zend_standard_class_def->static_members = (HashTable *) malloc(sizeof(HashTable));
zend_hash_init_ex(zend_standard_class_def->static_members, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
zend_hash_init_ex(&zend_standard_class_def->constants_table, 0, NULL, ZVAL_PTR_DTOR, 1, 0);
zend_hash_init_ex(&zend_standard_class_def->class_table, 10, NULL, ZEND_CLASS_DTOR, 1, 0);
zend_hash_init_ex(&zend_standard_class_def->function_table, 0, NULL, ZEND_FUNCTION_DTOR, 1, 0);
zend_standard_class_def->constructor = NULL;
zend_standard_class_def->destructor = NULL;
zend_standard_class_def->clone = NULL;
zend_standard_class_def->handle_function_call = NULL;
zend_standard_class_def->handle_property_get = NULL;
zend_standard_class_def->handle_property_set = NULL;
zend_standard_class_def->refcount = (int *) malloc(sizeof(int));
*zend_standard_class_def->refcount = 1;
zend_hash_add(GLOBAL_CLASS_TABLE, "stdclass", sizeof("stdclass"), &zend_standard_class_def, sizeof(zend_class_entry *), NULL);
}


Expand Down
2 changes: 1 addition & 1 deletion Zend/zend.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ ZEND_API void zend_error(int type, const char *format, ...);

void zenderror(char *error);

extern ZEND_API zend_class_entry zend_standard_class_def;
extern ZEND_API zend_class_entry *zend_standard_class_def;
extern zend_utility_values zend_uv;
extern ZEND_API zval zval_used_for_init;

Expand Down
27 changes: 17 additions & 10 deletions Zend/zend_API.c
Original file line number Diff line number Diff line change
Expand Up @@ -1202,9 +1202,12 @@ ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *cla
zend_class_entry *register_class;

if (!parent_ce && parent_name) {
if (zend_hash_find(CG(class_table), parent_name, strlen(parent_name)+1, (void **) &parent_ce)==FAILURE) {
return NULL;
}
zend_class_entry **pce;
if (zend_hash_find(CG(class_table), parent_name, strlen(parent_name)+1, (void **) &pce)==FAILURE) {
return NULL;
} else {
parent_ce = *pce;
}
}

register_class = zend_register_internal_class(class_entry TSRMLS_CC);
Expand All @@ -1215,10 +1218,11 @@ ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *cla
return register_class;
}

ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry TSRMLS_DC)
ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *orig_class_entry TSRMLS_DC)
{
zend_class_entry *register_class;
char *lowercase_name = zend_strndup(class_entry->name, class_entry->name_length);
zend_class_entry *class_entry = malloc(sizeof(zend_class_entry));
char *lowercase_name = zend_strndup(orig_class_entry->name, orig_class_entry->name_length);
*class_entry = *orig_class_entry;

zend_str_tolower(lowercase_name, class_entry->name_length);

Expand All @@ -1239,9 +1243,9 @@ ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_
zend_register_functions(class_entry->builtin_functions, &class_entry->function_table, MODULE_PERSISTENT TSRMLS_CC);
}

zend_hash_update(CG(class_table), lowercase_name, class_entry->name_length+1, class_entry, sizeof(zend_class_entry), (void **) &register_class);
zend_hash_update(CG(class_table), lowercase_name, class_entry->name_length+1, &class_entry, sizeof(zend_class_entry *), NULL);
free(lowercase_name);
return register_class;
return class_entry;
}


Expand Down Expand Up @@ -1327,7 +1331,7 @@ zend_bool zend_is_callable(zval *callable, zend_bool syntax_only, char **callabl
{
zval **method;
zval **obj;
zend_class_entry *ce = NULL;
zend_class_entry *ce = NULL, **pce;
char callable_name_len;

if (zend_hash_num_elements(Z_ARRVAL_P(callable)) == 2 &&
Expand All @@ -1354,7 +1358,10 @@ zend_bool zend_is_callable(zval *callable, zend_bool syntax_only, char **callabl

lcname = estrndup(Z_STRVAL_PP(obj), Z_STRLEN_PP(obj));
zend_str_tolower(lcname, Z_STRLEN_PP(obj));
zend_hash_find(EG(class_table), lcname, Z_STRLEN_PP(obj) + 1, (void**)&ce);
if(zend_hash_find(EG(class_table), lcname, Z_STRLEN_PP(obj) + 1, (void**)&pce) == SUCCESS) {
ce = *pce;
}

efree(lcname);
} else {
ce = Z_OBJCE_PP(obj); /* ??? */
Expand Down
20 changes: 14 additions & 6 deletions Zend/zend_builtin_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,9 +532,13 @@ ZEND_FUNCTION(get_parent_class)
}
RETURN_STRINGL(name, name_length, 1);
} else if (Z_TYPE_PP(arg) == IS_STRING) {
zend_class_entry **pce;

SEPARATE_ZVAL(arg);
zend_str_tolower(Z_STRVAL_PP(arg), Z_STRLEN_PP(arg));
zend_hash_find(EG(class_table), Z_STRVAL_PP(arg), Z_STRLEN_PP(arg)+1, (void **)&ce);
if(zend_hash_find(EG(class_table), Z_STRVAL_PP(arg), Z_STRLEN_PP(arg)+1, (void **)&pce) == SUCCESS) {
ce = *pce;
}
}

if (ce && ce->parent) {
Expand Down Expand Up @@ -609,7 +613,7 @@ ZEND_FUNCTION(get_class_vars)
{
zval **class_name;
char *lcname;
zend_class_entry *ce;
zend_class_entry *ce, **pce;
zval *tmp;

if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &class_name)==FAILURE) {
Expand All @@ -620,10 +624,11 @@ ZEND_FUNCTION(get_class_vars)
lcname = estrndup((*class_name)->value.str.val, (*class_name)->value.str.len);
zend_str_tolower(lcname, (*class_name)->value.str.len);

if (zend_hash_find(EG(class_table), lcname, (*class_name)->value.str.len+1, (void **)&ce)==FAILURE) {
if (zend_hash_find(EG(class_table), lcname, (*class_name)->value.str.len+1, (void **)&pce) == FAILURE) {
efree(lcname);
RETURN_FALSE;
} else {
ce = *pce;
efree(lcname);
array_init(return_value);
if (!ce->constants_updated) {
Expand Down Expand Up @@ -667,7 +672,7 @@ ZEND_FUNCTION(get_class_methods)
{
zval **class;
zval *method_name;
zend_class_entry *ce = NULL;
zend_class_entry *ce = NULL, **pce;
char *string_key;
ulong num_key;
int key_type;
Expand All @@ -685,7 +690,9 @@ ZEND_FUNCTION(get_class_methods)
} else if (Z_TYPE_PP(class) == IS_STRING) {
SEPARATE_ZVAL(class);
zend_str_tolower(Z_STRVAL_PP(class), Z_STRLEN_PP(class));
zend_hash_find(EG(class_table), Z_STRVAL_PP(class), Z_STRLEN_PP(class)+1, (void **)&ce);
if(zend_hash_find(EG(class_table), Z_STRVAL_PP(class), Z_STRLEN_PP(class)+1, (void **)&pce) == SUCCESS) {
ce = *pce;
}
}

if (!ce) {
Expand Down Expand Up @@ -926,9 +933,10 @@ ZEND_FUNCTION(restore_error_handler)
}


static int copy_class_name(zend_class_entry *ce, int num_args, va_list args, zend_hash_key *hash_key)
static int copy_class_name(zend_class_entry **pce, int num_args, va_list args, zend_hash_key *hash_key)
{
zval *array = va_arg(args, zval *);
zend_class_entry *ce = *pce;

if (hash_key->nKeyLength==0 || hash_key->arKey[0]!=0) {
add_next_index_stringl(array, ce->name, ce->name_length, 1);
Expand Down
Loading

0 comments on commit 92dd5e6

Please sign in to comment.