- Quick way of supporting include_once().

Good enough for RC1.
This commit is contained in:
Andi Gutmans 2000-03-10 16:36:30 +00:00
parent b5de395367
commit 5951b166c8
5 changed files with 26 additions and 8 deletions

View File

@ -710,7 +710,7 @@ internal_functions_in_yacc:
T_ISSET '(' cvar ')' { do_isset_or_isempty(ZEND_ISSET, &$$, &$3 CLS_CC); }
| T_EMPTY '(' cvar ')' { do_isset_or_isempty(ZEND_ISEMPTY, &$$, &$3 CLS_CC); }
| T_INCLUDE expr { do_include_or_eval(ZEND_INCLUDE, &$$, &$2 CLS_CC); }
| T_INCLUDE_ONCE expr { do_include_or_eval(ZEND_INCLUDE, &$$, &$2 CLS_CC); }
| T_INCLUDE_ONCE expr { do_include_or_eval(ZEND_INCLUDE_ONCE, &$$, &$2 CLS_CC); }
| T_EVAL '(' expr ')' { do_include_or_eval(ZEND_EVAL, &$$, &$3 CLS_CC); }
;

View File

@ -49,7 +49,7 @@ static ZEND_FUNCTION(leak);
static ZEND_FUNCTION(crash);
#endif
static ZEND_FUNCTION(get_used_files);
static ZEND_FUNCTION(get_imported_files);
static ZEND_FUNCTION(get_included_files);
static ZEND_FUNCTION(is_subclass_of);
static ZEND_FUNCTION(get_class_vars);
static ZEND_FUNCTION(get_object_vars);
@ -79,7 +79,7 @@ static zend_function_entry builtin_functions[] = {
ZEND_FE(crash, NULL)
#endif
ZEND_FE(get_used_files, NULL)
ZEND_FE(get_imported_files, NULL)
ZEND_FE(get_included_files, NULL)
ZEND_FE(is_subclass_of, NULL)
ZEND_FE(get_class_vars, NULL)
ZEND_FE(get_object_vars, NULL)
@ -628,8 +628,8 @@ ZEND_FUNCTION(get_used_files)
}
ZEND_FUNCTION(get_imported_files)
ZEND_FUNCTION(get_included_files)
{
array_init(return_value);
zend_hash_apply_with_argument(&EG(imported_files), (int (*)(void *, void *)) copy_import_use_file, return_value);
zend_hash_apply_with_argument(&EG(included_files), (int (*)(void *, void *)) copy_import_use_file, return_value);
}

View File

@ -2055,6 +2055,24 @@ send_by_ref:
return_value_used = RETURN_VALUE_USED(opline);
switch (opline->op2.u.constant.value.lval) {
case ZEND_INCLUDE_ONCE:
{
FILE *inc_file;
char *opened_path;
int dummy = 0;
inc_file = zend_fopen(opline->op1.u.constant.value.str.val, &opened_path);
if (inc_file && opened_path) {
if (zend_hash_add(&EG(included_files), opened_path, strlen(opened_path)+1, (void *)&dummy, sizeof(int), NULL)==FAILURE) {
fclose(inc_file);
free(opened_path);
break;
}
fclose(inc_file);
free(opened_path);
}
}
case ZEND_INCLUDE:
case ZEND_REQUIRE:
new_op_array = compile_filename(opline->op2.u.constant.value.lval, get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R) CLS_CC ELS_CC);

View File

@ -115,7 +115,7 @@ void init_executor(CLS_D ELS_DC)
EG(opline_ptr) = NULL;
EG(garbage_ptr) = 0;
zend_hash_init(&EG(imported_files), 5, NULL, NULL, 0);
zend_hash_init(&EG(included_files), 5, NULL, NULL, 0);
EG(ticks_count) = 0;
}
@ -155,7 +155,7 @@ void shutdown_executor(ELS_D)
#endif
zend_hash_destroy(&EG(imported_files));
zend_hash_destroy(&EG(included_files));
}

View File

@ -147,7 +147,7 @@ struct _zend_executor_globals {
HashTable *active_symbol_table;
HashTable symbol_table; /* main symbol table */
HashTable imported_files; /* files already included using 'import' */
HashTable included_files; /* files already included */
jmp_buf bailout;