#if WIN32|WINNT
#include <winsock.h>
+#include <io.h>
#endif
#include <errno.h>
BEGIN(lex_state->state);
zend_restore_compiled_filename(lex_state->filename);
#else
- delete(CG(ZFL));
+ delete((ZendFlexLexer *) CG(ZFL));
CG(ZFL) = lex_state->ZFL;
#endif
}
BEGIN_EXTERN_C()
+ZEND_API void zend_close_file_handle(zend_file_handle *file_handle)
+{
+ switch (file_handle->type) {
+ case ZEND_HANDLE_FILENAME:
+ break;
+ case ZEND_HANDLE_FD:
+ close(file_handle->handle.fd);
+ break;
+ case ZEND_HANDLE_FP:
+ fclose(file_handle->handle.fp);
+ break;
+#ifdef ZTS
+ case ZEND_HANDLE_ISTREAM:
+ delete file_handle->handle.is;
+ break;
+#endif
+ }
+}
+
ZEND_API inline int open_file_for_scanning(zend_file_handle *file_handle CLS_DC)
{
#ifndef ZTS
- FILE *tmp;
YY_BUFFER_STATE buffer_state = YY_CURRENT_BUFFER;
switch (file_handle->type) {
case ZEND_HANDLE_FILENAME:
- tmp = zend_fopen(file_handle->filename);
+ file_handle->handle.fp = zend_fopen(file_handle->filename);
break;
case ZEND_HANDLE_FD:
- tmp = fdopen(file_handle->handle.fd, "r");
+ file_handle->handle.fp = fdopen(file_handle->handle.fd, "r");
break;
case ZEND_HANDLE_FP:
- tmp = file_handle->handle.fp;
+ file_handle->handle.fp = file_handle->handle.fp;
break;
}
- if (!tmp) {
+ if (!file_handle->handle.fp) {
return FAILURE;
}
+ file_handle->type = ZEND_HANDLE_FP;
/* Reset the scanner for scanning the new file */
- yyin = tmp;
+ yyin = file_handle->handle.fp;
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
BEGIN(INITIAL);
#else
- ifstream *input_file;
-
switch (file_handle->type) {
case ZEND_HANDLE_FD:
- input_file = new ifstream(file_handle->handle.fd);
+ file_handle->handle.is = new ifstream(file_handle->handle.fd);
break;
case ZEND_HANDLE_FILENAME:
- input_file = new ifstream(file_handle->filename);
+ file_handle->handle.is = new ifstream(file_handle->filename);
break;
case ZEND_HANDLE_FP:
if (file_handle->handle.fp==stdin) {
- input_file = (ifstream *) &cin;
+ file_handle->handle.is = (ifstream *) &cin;
} else {
- input_file = new ifstream(file_handle->filename);
+ fclose(file_handle->handle.fp);
+ file_handle->handle.is = new ifstream(file_handle->filename);
}
break;
}
- CG(ZFL) = new ZendFlexLexer;
+ file_handle->type = ZEND_HANDLE_ISTREAM;
- CG(ZFL)->switch_streams(input_file, &cout);
+ CG(ZFL) = new ZendFlexLexer;
+ CG(ZFL)->switch_streams(file_handle->handle.is, &cout);
#endif
zend_set_compiled_filename(file_handle->filename);
CG(zend_lineno) = 1;
retval = NULL;
break;
} else {
-#ifndef ZTS
- fclose(yyin);
-#endif
+ zend_close_file_handle(file_handle);
restore_lexical_state(&original_lex_state CLS_CC);
CG(active_op_array) = original_active_op_array;
retval = op_array;
return FAILURE;
}
zendparse(CLS_C);
-#ifndef ZTS
- fclose(yyin);
-#endif
+ zend_close_file_handle(file_handle);
restore_lexical_state(&original_lex_state CLS_CC);
return SUCCESS;
}
return FAILURE;
}
zend_highlight(syntax_highlighter_ini);
-#ifndef ZTS
- fclose(yyin);
-#endif
+ zend_close_file_handle(&file_handle);
restore_lexical_state(&original_lex_state CLS_CC);
return SUCCESS;
}
}
+ZendFlexLexer::~ZendFlexLexer()
+{
+ if (yy_start_stack) {
+ yy_flex_free(yy_start_stack);
+ }
+}
+
+
int yyFlexLexer::yylex()
{
fprintf(stderr, "Error: yyFlexLexer::yylex() called\n");
static void compiler_globals_dtor(zend_compiler_globals *compiler_globals)
{
- zend_hash_destroy(compiler_globals->function_table);
- free(compiler_globals->function_table);
- zend_hash_destroy(compiler_globals->class_table);
- free(compiler_globals->class_table);
+ if (compiler_globals->function_table != global_function_table) {
+ zend_hash_destroy(compiler_globals->function_table);
+ free(compiler_globals->function_table);
+ }
+ if (compiler_globals->class_table != global_class_table) {
+ zend_hash_destroy(compiler_globals->class_table);
+ free(compiler_globals->class_table);
+ }
}
executor_globals_id = ts_allocate_id(sizeof(zend_executor_globals), (void (*)(void *)) executor_globals_ctor, (void (*)(void *)) executor_globals_dtor);
compiler_globals = ts_resource(compiler_globals_id);
executor_globals = ts_resource(executor_globals_id);
- zend_hash_destroy(compiler_globals->function_table);
- zend_hash_destroy(compiler_globals->class_table);
+ compiler_globals_dtor(compiler_globals);
compiler_globals->function_table = GLOBAL_FUNCTION_TABLE;
compiler_globals->class_table = GLOBAL_CLASS_TABLE;
#endif