Skip to content

Commit 96ab56e

Browse files
author
Andi Gutmans
committed
- Roll back VM commit
1 parent bb8167c commit 96ab56e

13 files changed

+3854
-488
lines changed

Zend/ChangeLog

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,3 @@
1-
2004-09-08 Andi Gutmans <andi@zend.com>
2-
3-
* zend_builtin_functions.c:
4-
- Fix bug #28054 by preventing printing out bogus information in backtrace
5-
when in error handler (still doesn't know all information but at least
6-
it's not bogus)
7-
8-
* zend_compile.h
9-
zend_exceptions.c
10-
zend_execute.c
11-
zend_execute.h
12-
zend_execute_API.c
13-
zend_opcode.c
14-
zend_vm.h
15-
zend_vm_handlers.h
16-
zend_vm_spec.h:
17-
- Some architectural changes:
18-
a) We specialize opcodes according to op_type fields. Each opcode has to
19-
be marked with which op_type's it uses.
20-
b) We support different execution methods. Function handlers, switch()
21-
and goto dispatching. goto seems to be the fastest but it really
22-
depends on the compiler and how well it optimizes. I suggest playing
23-
around with optimization flags.
24-
25-
- Warning: Things might break so keep us posted on how things are going.
26-
(Dmitry, Andi)
27-
281
2004-09-06 Marcus Boerger <marcus.boerger@post.rwth-aachen.de>
292

303
* zend_objects.c:

Zend/zend.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ ZEND_INI_END()
8484
ZEND_API int compiler_globals_id;
8585
ZEND_API int executor_globals_id;
8686
ZEND_API int alloc_globals_id;
87+
zend_class_entry global_main_class;
8788
HashTable *global_function_table;
8889
HashTable *global_class_table;
8990
HashTable *global_constants_table;

Zend/zend_API.c

Lines changed: 14 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -316,13 +316,12 @@ static char *zend_parse_arg_impl(zval **arg, va_list *va, char **spec TSRMLS_DC)
316316
*pl = Z_STRLEN_PP(arg);
317317
break;
318318
case IS_OBJECT: {
319-
if (Z_OBJ_HANDLER_PP(arg, cast_object)) {
319+
if (Z_OBJ_HANDLER_PP(arg, cast_object)
320+
&& Z_OBJ_HANDLER_PP(arg, cast_object)(*arg, *arg, IS_STRING, 0 TSRMLS_CC) == SUCCESS) {
320321
SEPARATE_ZVAL_IF_NOT_REF(arg);
321-
if (Z_OBJ_HANDLER_PP(arg, cast_object)(*arg, *arg, IS_STRING, 0 TSRMLS_CC) == SUCCESS) {
322-
*pl = Z_STRLEN_PP(arg);
323-
*p = Z_STRVAL_PP(arg);
324-
break;
325-
}
322+
*pl = Z_STRLEN_PP(arg);
323+
*p = Z_STRVAL_PP(arg);
324+
break;
326325
}
327326
}
328327

@@ -1218,29 +1217,6 @@ ZEND_API int zend_startup_module(zend_module_entry *module)
12181217
return zend_register_module_ex(module TSRMLS_CC);
12191218
}
12201219

1221-
ZEND_API void zend_check_magic_method_implementation(zend_class_entry *ce, zend_function *fptr, int error_type TSRMLS_DC)
1222-
{
1223-
char lcname[16];
1224-
int name_len;
1225-
1226-
/* we don't care if the function name is longer, in fact lowercasing only
1227-
* the beginning of the name speeds up the check process */
1228-
name_len = strlen(fptr->common.function_name);
1229-
zend_str_tolower_copy(lcname, fptr->common.function_name, MIN(name_len, sizeof(lcname)-1));
1230-
lcname[sizeof(lcname)-1] = '\0'; /* zend_str_tolower_copy won't necessarily set the zero byte */
1231-
1232-
if (name_len == sizeof(ZEND_DESTRUCTOR_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_DESTRUCTOR_FUNC_NAME, sizeof(ZEND_DESTRUCTOR_FUNC_NAME)) && fptr->common.num_args != 0) {
1233-
zend_error(error_type, "Destuctor %s::%s() cannot take arguments", ce->name, ZEND_DESTRUCTOR_FUNC_NAME);
1234-
} else if (name_len == sizeof(ZEND_CLONE_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME)) && fptr->common.num_args != 0) {
1235-
zend_error(error_type, "Method %s::%s() cannot accept any arguments", ce->name, ZEND_CLONE_FUNC_NAME);
1236-
} else if (name_len == sizeof(ZEND_GET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME)) && fptr->common.num_args != 1) {
1237-
zend_error(error_type, "Method %s::%s() must take exactly 1 argument", ce->name, ZEND_GET_FUNC_NAME);
1238-
} else if (name_len == sizeof(ZEND_SET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME)) && fptr->common.num_args != 2) {
1239-
zend_error(error_type, "Method %s::%s() must take exactly 2 arguments", ce->name, ZEND_SET_FUNC_NAME);
1240-
} else if (name_len == sizeof(ZEND_CALL_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)) && fptr->common.num_args != 2) {
1241-
zend_error(error_type, "Method %s::%s() must take exactly 2 arguments", ce->name, ZEND_CALL_FUNC_NAME);
1242-
}
1243-
}
12441220

12451221
/* registers all functions in *library_functions in the function hash */
12461222
ZEND_API int zend_register_functions(zend_class_entry *scope, zend_function_entry *functions, HashTable *function_table, int type TSRMLS_DC)
@@ -1251,11 +1227,9 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, zend_function_entr
12511227
int count=0, unload=0;
12521228
HashTable *target_function_table = function_table;
12531229
int error_type;
1254-
zend_function *ctor = NULL, *dtor = NULL, *clone = NULL, *__get = NULL, *__set = NULL, *__call = NULL;
1230+
zend_function *ctor = NULL, *dtor = NULL, *clone = NULL;
12551231
char *lowercase_name;
12561232
int fname_len;
1257-
char *lc_class_name;
1258-
int class_name_len;
12591233

12601234
if (type==MODULE_PERSISTENT) {
12611235
error_type = E_CORE_WARNING;
@@ -1267,11 +1241,6 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, zend_function_entr
12671241
target_function_table = CG(function_table);
12681242
}
12691243
internal_function->type = ZEND_INTERNAL_FUNCTION;
1270-
1271-
if (scope) {
1272-
class_name_len = strlen(scope->name);
1273-
lc_class_name = zend_str_tolower_dup(scope->name, class_name_len);
1274-
}
12751244

12761245
while (ptr->fname) {
12771246
internal_function->handler = ptr->handler;
@@ -1341,38 +1310,25 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, zend_function_entr
13411310
* If it's an old-style constructor, store it only if we don't have
13421311
* a constructor already.
13431312
*/
1344-
if ((fname_len == class_name_len) && !memcmp(lowercase_name, lc_class_name, class_name_len+1) && !ctor) {
1313+
if (!strcmp(ptr->fname, scope->name) && !ctor) {
13451314
ctor = reg_function;
1346-
} else if ((fname_len == sizeof(ZEND_CONSTRUCTOR_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_CONSTRUCTOR_FUNC_NAME, sizeof(ZEND_CONSTRUCTOR_FUNC_NAME))) {
1315+
} else if (!strcmp(ptr->fname, ZEND_CONSTRUCTOR_FUNC_NAME)) {
13471316
ctor = reg_function;
1348-
} else if ((fname_len == sizeof(ZEND_DESTRUCTOR_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_DESTRUCTOR_FUNC_NAME, sizeof(ZEND_DESTRUCTOR_FUNC_NAME))) {
1317+
} else if (!strcmp(ptr->fname, ZEND_DESTRUCTOR_FUNC_NAME)) {
13491318
dtor = reg_function;
13501319
if (internal_function->num_args) {
13511320
zend_error(error_type, "Destructor %s::%s() cannot take arguments", scope->name, ptr->fname);
13521321
}
1353-
} else if ((fname_len == sizeof(ZEND_CLONE_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME))) {
1322+
1323+
} else if (!strcmp(ptr->fname, ZEND_CLONE_FUNC_NAME)) {
13541324
clone = reg_function;
1355-
} else if ((fname_len == sizeof(ZEND_CALL_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME))) {
1356-
__call = reg_function;
1357-
} else if ((fname_len == sizeof(ZEND_GET_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME))) {
1358-
__get = reg_function;
1359-
} else if ((fname_len == sizeof(ZEND_SET_FUNC_NAME)-1) && !memcmp(lowercase_name, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME))) {
1360-
__set = reg_function;
1361-
} else {
1362-
reg_function = NULL;
1363-
}
1364-
if (reg_function) {
1365-
zend_check_magic_method_implementation(scope, reg_function, error_type TSRMLS_CC);
13661325
}
13671326
}
13681327
ptr++;
13691328
count++;
13701329
free_alloca(lowercase_name);
13711330
}
13721331
if (unload) { /* before unloading, display all remaining bad function in the module */
1373-
if (scope) {
1374-
efree(lc_class_name);
1375-
}
13761332
while (ptr->fname) {
13771333
if (zend_hash_exists(target_function_table, ptr->fname, strlen(ptr->fname)+1)) {
13781334
zend_error(error_type, "Function registration failed - duplicate name - %s", ptr->fname);
@@ -1386,49 +1342,27 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, zend_function_entr
13861342
scope->constructor = ctor;
13871343
scope->destructor = dtor;
13881344
scope->clone = clone;
1389-
scope->__call = __call;
1390-
scope->__get = __get;
1391-
scope->__set = __set;
13921345
if (ctor) {
13931346
ctor->common.fn_flags |= ZEND_ACC_CTOR;
13941347
if (ctor->common.fn_flags & ZEND_ACC_STATIC) {
1395-
zend_error(error_type, "Constructor %s::%s() cannot be static", scope->name, ctor->common.function_name);
1348+
zend_error(error_type, "Constructor %s::%s() cannot be static", ctor->common.scope->name, ctor->common.function_name);
13961349
}
13971350
ctor->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
13981351
}
13991352
if (dtor) {
14001353
dtor->common.fn_flags |= ZEND_ACC_DTOR;
14011354
if (dtor->common.fn_flags & ZEND_ACC_STATIC) {
1402-
zend_error(error_type, "Destructor %s::%s() cannot be static", scope->name, dtor->common.function_name);
1355+
zend_error(error_type, "Destructor %s::%s() cannot be static", dtor->common.scope->name, dtor->common.function_name);
14031356
}
14041357
dtor->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
14051358
}
14061359
if (clone) {
14071360
clone->common.fn_flags |= ZEND_ACC_CLONE;
14081361
if (clone->common.fn_flags & ZEND_ACC_STATIC) {
1409-
zend_error(error_type, "Constructor %s::%s() cannot be static", scope->name, clone->common.function_name);
1362+
zend_error(error_type, "Constructor %s::%s() cannot be static", clone->common.scope->name, clone->common.function_name);
14101363
}
14111364
clone->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
14121365
}
1413-
if (__call) {
1414-
if (__call->common.fn_flags & ZEND_ACC_STATIC) {
1415-
zend_error(error_type, "Method %s::%s() cannot be static", scope->name, __call->common.function_name);
1416-
}
1417-
__call->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1418-
}
1419-
if (__get) {
1420-
if (__get->common.fn_flags & ZEND_ACC_STATIC) {
1421-
zend_error(error_type, "Method %s::%s() cannot be static", scope->name, __get->common.function_name);
1422-
}
1423-
__get->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1424-
}
1425-
if (__set) {
1426-
if (__set->common.fn_flags & ZEND_ACC_STATIC) {
1427-
zend_error(error_type, "Method %s::%s() cannot be static", scope->name, __set->common.function_name);
1428-
}
1429-
__set->common.fn_flags &= ~ZEND_ACC_ALLOW_STATIC;
1430-
}
1431-
efree(lc_class_name);
14321366
}
14331367
return SUCCESS;
14341368
}

Zend/zend_API.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,6 @@ ZEND_API int zend_register_functions(zend_class_entry *scope, zend_function_entr
168168
ZEND_API void zend_unregister_functions(zend_function_entry *functions, int count, HashTable *function_table TSRMLS_DC);
169169
ZEND_API int zend_register_module(zend_module_entry *module_entry);
170170
ZEND_API int zend_register_module_ex(zend_module_entry *module TSRMLS_DC);
171-
ZEND_API void zend_check_magic_method_implementation(zend_class_entry *ce, zend_function *fptr, int error_type TSRMLS_DC);
172171

173172
ZEND_API zend_class_entry *zend_register_internal_class(zend_class_entry *class_entry TSRMLS_DC);
174173
ZEND_API zend_class_entry *zend_register_internal_class_ex(zend_class_entry *class_entry, zend_class_entry *parent_ce, char *parent_name TSRMLS_DC);

Zend/zend_builtin_functions.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,7 +1621,7 @@ ZEND_FUNCTION(debug_print_backtrace)
16211621
zval_ptr_dtor(&arg_array);
16221622
}
16231623
zend_printf(") called at [%s:%d]\n", filename, lineno);
1624-
include_filename = function_name?NULL:filename;
1624+
include_filename = filename;
16251625
ptr = ptr->prev_execute_data;
16261626
++indent;
16271627
}
@@ -1766,7 +1766,7 @@ ZEND_API void zend_fetch_debug_backtrace(zval *return_value, int skip_last TSRML
17661766

17671767
add_next_index_zval(return_value, stack_frame);
17681768

1769-
include_filename = function_name?NULL:filename;
1769+
include_filename = filename;
17701770

17711771
ptr = ptr->prev_execute_data;
17721772
}

Zend/zend_compile.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,14 +1103,25 @@ void zend_do_end_function_declaration(znode *function_token TSRMLS_DC)
11031103

11041104
pass_two(CG(active_op_array) TSRMLS_CC);
11051105

1106+
/* we don't care if the function name is longer, in fact lowercasing only
1107+
* the beginning of the name speeds up the check process */
1108+
name_len = strlen(CG(active_op_array)->function_name);
1109+
zend_str_tolower_copy(lcname, CG(active_op_array)->function_name, MIN(name_len, sizeof(lcname)-1));
1110+
lcname[sizeof(lcname)-1] = '\0'; /* zend_str_tolower_copy won't necessarily set the zero byte */
1111+
11061112
if (CG(active_class_entry)) {
1107-
zend_check_magic_method_implementation(CG(active_class_entry), (zend_function*)CG(active_op_array), E_COMPILE_ERROR TSRMLS_CC);
1113+
if (name_len == sizeof(ZEND_DESTRUCTOR_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_DESTRUCTOR_FUNC_NAME, sizeof(ZEND_DESTRUCTOR_FUNC_NAME)) && CG(active_op_array)->num_args != 0) {
1114+
zend_error(E_COMPILE_ERROR, "Destuctor %s::%s() cannot take arguments", CG(active_class_entry)->name, ZEND_DESTRUCTOR_FUNC_NAME);
1115+
} else if (name_len == sizeof(ZEND_CLONE_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_CLONE_FUNC_NAME, sizeof(ZEND_CLONE_FUNC_NAME)) && CG(active_op_array)->num_args != 0) {
1116+
zend_error(E_COMPILE_ERROR, "Method %s::%s() cannot accept any arguments", CG(active_class_entry)->name, ZEND_CLONE_FUNC_NAME);
1117+
} else if (name_len == sizeof(ZEND_GET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_GET_FUNC_NAME, sizeof(ZEND_GET_FUNC_NAME)) && CG(active_op_array)->num_args != 1) {
1118+
zend_error(E_COMPILE_ERROR, "Method %s::%s() must take exactly 1 argument", CG(active_class_entry)->name, ZEND_GET_FUNC_NAME);
1119+
} else if (name_len == sizeof(ZEND_SET_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_SET_FUNC_NAME, sizeof(ZEND_SET_FUNC_NAME)) && CG(active_op_array)->num_args != 2) {
1120+
zend_error(E_COMPILE_ERROR, "Method %s::%s() must take exactly 2 arguments", CG(active_class_entry)->name, ZEND_SET_FUNC_NAME);
1121+
} else if (name_len == sizeof(ZEND_CALL_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_CALL_FUNC_NAME, sizeof(ZEND_CALL_FUNC_NAME)) && CG(active_op_array)->num_args != 2) {
1122+
zend_error(E_COMPILE_ERROR, "Method %s::%s() must take exactly 2 arguments", CG(active_class_entry)->name, ZEND_CALL_FUNC_NAME);
1123+
}
11081124
} else {
1109-
/* we don't care if the function name is longer, in fact lowercasing only
1110-
* the beginning of the name speeds up the check process */
1111-
name_len = strlen(CG(active_op_array)->function_name);
1112-
zend_str_tolower_copy(lcname, CG(active_op_array)->function_name, MIN(name_len, sizeof(lcname)-1));
1113-
lcname[sizeof(lcname)-1] = '\0'; /* zend_str_tolower_copy won't necessarily set the zero byte */
11141125
if (name_len == sizeof(ZEND_AUTOLOAD_FUNC_NAME) - 1 && !memcmp(lcname, ZEND_AUTOLOAD_FUNC_NAME, sizeof(ZEND_AUTOLOAD_FUNC_NAME)) && CG(active_op_array)->num_args != 1) {
11151126
zend_error(E_COMPILE_ERROR, "%s() must take exactly 1 argument", ZEND_AUTOLOAD_FUNC_NAME);
11161127
}

Zend/zend_compile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ typedef struct _zend_execute_data zend_execute_data;
7272

7373
typedef int (*opcode_handler_t) (ZEND_OPCODE_HANDLER_ARGS);
7474

75-
extern ZEND_API opcode_handler_t *zend_opcode_handlers;
75+
extern ZEND_API opcode_handler_t zend_opcode_handlers[512];
7676

7777
struct _zend_op {
7878
opcode_handler_t handler;

Zend/zend_exceptions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ ZEND_METHOD(error_exception, __construct)
175175
if (argc >= 4) {
176176
zend_update_property_string(default_exception_ce, object, "file", sizeof("file")-1, filename TSRMLS_CC);
177177
if (argc < 5) {
178-
lineno = 0; /* invalidate lineno */
178+
lineno = 0; // invalidate lineno
179179
}
180180
zend_update_property_long(default_exception_ce, object, "line", sizeof("line")-1, lineno TSRMLS_CC);
181181
}

0 commit comments

Comments
 (0)