From ae2e5e64f4a1e355095e08365387d05fc19797ee Mon Sep 17 00:00:00 2001 From: SVN Migration Date: Thu, 17 Feb 2000 15:05:25 +0000 Subject: [PATCH] This commit was manufactured by cvs2svn to create tag 'BEFORE_SAPI_POST_PATCH_17_FEB_2000'. --- TSRM/Makefile.am | 4 - TSRM/TSRM.c | 456 ------- TSRM/TSRM.dsp | 125 -- TSRM/TSRM.h | 110 -- TSRM/acconfig.h | 1 - TSRM/acinclude.m4 | 5 - TSRM/build.mk | 43 - TSRM/buildconf | 33 - TSRM/configure.in | 21 - TSRM/tsrm.m4 | 113 -- Zend/FlexLexer.h | 186 --- Zend/LICENSE | 116 -- Zend/Makefile.am | 41 - Zend/ZEND_CHANGES | 111 -- Zend/Zend.dsp | 432 ------ Zend/Zend.m4 | 223 ---- Zend/ZendCore.dep | 258 ---- Zend/ZendTS.dsp | 440 ------ Zend/acconfig.h | 66 - Zend/acinclude.m4 | 29 - Zend/build.mk | 43 - Zend/buildconf | 33 - Zend/configure.in | 45 - Zend/flex.skl | 1541 --------------------- Zend/zend-parser.y | 717 ---------- Zend/zend-scanner.h | 58 - Zend/zend-scanner.l | 1656 ----------------------- Zend/zend.c | 466 ------- Zend/zend.h | 379 ------ Zend/zend.ico | Bin 1382 -> 0 bytes Zend/zend_API.c | 947 ------------- Zend/zend_API.h | 377 ------ Zend/zend_alloc.c | 622 --------- Zend/zend_alloc.h | 134 -- Zend/zend_builtin_functions.c | 585 -------- Zend/zend_builtin_functions.h | 26 - Zend/zend_compile.c | 2303 -------------------------------- Zend/zend_compile.h | 610 --------- Zend/zend_config.w32.h | 67 - Zend/zend_constants.c | 254 ---- Zend/zend_constants.h | 64 - Zend/zend_errors.h | 37 - Zend/zend_execute.c | 2350 --------------------------------- Zend/zend_execute.h | 79 -- Zend/zend_execute_API.c | 592 --------- Zend/zend_execute_locks.h | 22 - Zend/zend_extensions.c | 157 --- Zend/zend_extensions.h | 96 -- Zend/zend_fast_cache.h | 116 -- Zend/zend_globals.h | 210 --- Zend/zend_globals_macros.h | 89 -- Zend/zend_hash.c | 1117 ---------------- Zend/zend_hash.h | 177 --- Zend/zend_highlight.c | 178 --- Zend/zend_highlight.h | 49 - Zend/zend_indent.c | 152 --- Zend/zend_indent.h | 26 - Zend/zend_list.c | 289 ---- Zend/zend_list.h | 87 -- Zend/zend_llist.c | 217 --- Zend/zend_llist.h | 61 - Zend/zend_modules.h | 64 - Zend/zend_opcode.c | 417 ------ Zend/zend_operators.c | 1463 -------------------- Zend/zend_operators.h | 136 -- Zend/zend_ptr_stack.c | 114 -- Zend/zend_ptr_stack.h | 42 - Zend/zend_sprintf.c | 40 - Zend/zend_stack.c | 164 --- Zend/zend_stack.h | 47 - Zend/zend_variables.c | 190 --- Zend/zend_variables.h | 61 - ext/pcre/config0.m4 | 64 - strtok_r.c | 113 -- 74 files changed, 22756 deletions(-) delete mode 100644 TSRM/Makefile.am delete mode 100644 TSRM/TSRM.c delete mode 100644 TSRM/TSRM.dsp delete mode 100644 TSRM/TSRM.h delete mode 100644 TSRM/acconfig.h delete mode 100644 TSRM/acinclude.m4 delete mode 100644 TSRM/build.mk delete mode 100755 TSRM/buildconf delete mode 100644 TSRM/configure.in delete mode 100644 TSRM/tsrm.m4 delete mode 100644 Zend/FlexLexer.h delete mode 100644 Zend/LICENSE delete mode 100644 Zend/Makefile.am delete mode 100644 Zend/ZEND_CHANGES delete mode 100644 Zend/Zend.dsp delete mode 100644 Zend/Zend.m4 delete mode 100644 Zend/ZendCore.dep delete mode 100644 Zend/ZendTS.dsp delete mode 100644 Zend/acconfig.h delete mode 100644 Zend/acinclude.m4 delete mode 100644 Zend/build.mk delete mode 100755 Zend/buildconf delete mode 100644 Zend/configure.in delete mode 100644 Zend/flex.skl delete mode 100644 Zend/zend-parser.y delete mode 100644 Zend/zend-scanner.h delete mode 100644 Zend/zend-scanner.l delete mode 100644 Zend/zend.c delete mode 100644 Zend/zend.h delete mode 100644 Zend/zend.ico delete mode 100644 Zend/zend_API.c delete mode 100644 Zend/zend_API.h delete mode 100644 Zend/zend_alloc.c delete mode 100644 Zend/zend_alloc.h delete mode 100644 Zend/zend_builtin_functions.c delete mode 100644 Zend/zend_builtin_functions.h delete mode 100644 Zend/zend_compile.c delete mode 100644 Zend/zend_compile.h delete mode 100644 Zend/zend_config.w32.h delete mode 100644 Zend/zend_constants.c delete mode 100644 Zend/zend_constants.h delete mode 100644 Zend/zend_errors.h delete mode 100644 Zend/zend_execute.c delete mode 100644 Zend/zend_execute.h delete mode 100644 Zend/zend_execute_API.c delete mode 100644 Zend/zend_execute_locks.h delete mode 100644 Zend/zend_extensions.c delete mode 100644 Zend/zend_extensions.h delete mode 100644 Zend/zend_fast_cache.h delete mode 100644 Zend/zend_globals.h delete mode 100644 Zend/zend_globals_macros.h delete mode 100644 Zend/zend_hash.c delete mode 100644 Zend/zend_hash.h delete mode 100644 Zend/zend_highlight.c delete mode 100644 Zend/zend_highlight.h delete mode 100644 Zend/zend_indent.c delete mode 100644 Zend/zend_indent.h delete mode 100644 Zend/zend_list.c delete mode 100644 Zend/zend_list.h delete mode 100644 Zend/zend_llist.c delete mode 100644 Zend/zend_llist.h delete mode 100644 Zend/zend_modules.h delete mode 100644 Zend/zend_opcode.c delete mode 100644 Zend/zend_operators.c delete mode 100644 Zend/zend_operators.h delete mode 100644 Zend/zend_ptr_stack.c delete mode 100644 Zend/zend_ptr_stack.h delete mode 100644 Zend/zend_sprintf.c delete mode 100644 Zend/zend_stack.c delete mode 100644 Zend/zend_stack.h delete mode 100644 Zend/zend_variables.c delete mode 100644 Zend/zend_variables.h delete mode 100644 ext/pcre/config0.m4 delete mode 100644 strtok_r.c diff --git a/TSRM/Makefile.am b/TSRM/Makefile.am deleted file mode 100644 index a779ca8552..0000000000 --- a/TSRM/Makefile.am +++ /dev/null @@ -1,4 +0,0 @@ -## process this file with automake to produce Makefile.am -AUTOMAKE_OPTIONS=foreign -noinst_LTLIBRARIES=libtsrm.la -libtsrm_la_SOURCES = TSRM.c diff --git a/TSRM/TSRM.c b/TSRM/TSRM.c deleted file mode 100644 index 1f7da18d88..0000000000 --- a/TSRM/TSRM.c +++ /dev/null @@ -1,456 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Thread Safe Resource Manager | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to the Zend license, that is bundled | - | with this package in the file LICENSE. If you did not receive a | - | copy of the Zend license, please mail us at zend@zend.com so we can | - | send you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include "TSRM.h" -#include -#include - -#if HAVE_STDARG_H -#include -#endif - -typedef struct _tsrm_tls_entry tsrm_tls_entry; - -struct _tsrm_tls_entry { - void **storage; - int count; - THREAD_T thread_id; - tsrm_tls_entry *next; -}; - - -typedef struct { - size_t size; - ts_allocate_ctor ctor; - ts_allocate_dtor dtor; -} tsrm_resource_type; - - -/* The memory manager table */ -static tsrm_tls_entry **tsrm_tls_table; -static int tsrm_tls_table_size; -static ts_rsrc_id id_count; - -/* The resource sizes table */ -static tsrm_resource_type *resource_types_table; -static int resource_types_table_size; - - -static MUTEX_T tsmm_mutex; /* thread-safe memory manager mutex */ - -/* New thread handlers */ -static void (*tsrm_new_thread_begin_handler)(); -static void (*tsrm_new_thread_end_handler)(); - -/* Debug support */ -static int tsrm_debug(const char *format, ...); -static int tsrm_debug_status; - - -/* Startup TSRM (call once for the entire process) */ -TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_status) -{ -#if defined(GNUPTH) - pth_init(); -#endif - - tsrm_tls_table_size = expected_threads; - tsrm_tls_table = (tsrm_tls_entry **) calloc(tsrm_tls_table_size, sizeof(tsrm_tls_entry *)); - if (!tsrm_tls_table) { - return 0; - } - id_count=0; - - resource_types_table_size = expected_resources; - resource_types_table = (tsrm_resource_type *) calloc(resource_types_table_size, sizeof(tsrm_resource_type)); - if (!resource_types_table) { - free(tsrm_tls_table); - return 0; - } - - tsmm_mutex = tsrm_mutex_alloc(); - - tsrm_new_thread_begin_handler = tsrm_new_thread_end_handler = NULL; - - tsrm_debug_status = debug_status; - - tsrm_debug("Started up TSRM, %d expected threads, %d expected resources\n", expected_threads, expected_resources); - return 1; -} - - -/* Shutdown TSRM (call once for the entire process) */ -TSRM_API void tsrm_shutdown(void) -{ - int i; - - if (tsrm_tls_table) { - for (i=0; inext; - for (j=0; jstorage[j]); - } - free(p->storage); - free(p); - p = next_p; - } - } - free(tsrm_tls_table); - } - if (resource_types_table) { - free(resource_types_table); - } - tsrm_mutex_free(tsmm_mutex); - tsrm_debug("Shutdown TSRM\n"); -#if defined(GNUPTH) - pth_kill(); -#endif -} - - -/* allocates a new thread-safe-resource id */ -TSRM_API ts_rsrc_id ts_allocate_id(size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor) -{ - ts_rsrc_id new_id; - int i; - - tsrm_debug("Obtaining a new resource id, %d bytes\n", size); - - tsrm_mutex_lock(tsmm_mutex); - - /* obtain a resource id */ - new_id = id_count++; - tsrm_debug("Obtained resource id %d\n", new_id); - - /* store the new resource type in the resource sizes table */ - if (resource_types_table_size < id_count) { - resource_types_table = (tsrm_resource_type *) realloc(resource_types_table, sizeof(tsrm_resource_type)*id_count); - if (!resource_types_table) { - return -1; - } - resource_types_table_size = id_count; - } - resource_types_table[new_id].size = size; - resource_types_table[new_id].ctor = ctor; - resource_types_table[new_id].dtor = dtor; - - /* enlarge the arrays for the already active threads */ - for (i=0; icount < id_count) { - int j; - - p->storage = (void *) realloc(p->storage, sizeof(void *)*id_count); - for (j=p->count; jstorage[j] = (void *) malloc(resource_types_table[j].size); - if (resource_types_table[j].ctor) { - resource_types_table[j].ctor(p->storage[j]); - } - } - p->count = id_count; - } - p = p->next; - } - } - tsrm_mutex_unlock(tsmm_mutex); - - tsrm_debug("Successfully allocated new resource id %d\n", new_id); - return new_id; -} - - -static void allocate_new_resource(tsrm_tls_entry **thread_resources_ptr, THREAD_T thread_id) -{ - int i; - - (*thread_resources_ptr) = (tsrm_tls_entry *) malloc(sizeof(tsrm_tls_entry)); - (*thread_resources_ptr)->storage = (void **) malloc(sizeof(void *)*id_count); - (*thread_resources_ptr)->count = id_count; - (*thread_resources_ptr)->thread_id = thread_id; - (*thread_resources_ptr)->next = NULL; - - tsrm_mutex_unlock(tsmm_mutex); - - if (tsrm_new_thread_begin_handler) { - tsrm_new_thread_begin_handler(thread_id); - } - for (i=0; istorage[i] = (void *) malloc(resource_types_table[i].size); - if (resource_types_table[i].ctor) { - resource_types_table[i].ctor((*thread_resources_ptr)->storage[i]); - } - } - if (tsrm_new_thread_end_handler) { - tsrm_new_thread_end_handler(thread_id); - } -} - - -/* fetches the requested resource for the current thread */ -void *ts_resource(ts_rsrc_id id) -{ - THREAD_T thread_id = tsrm_thread_id(); - int hash_value; - tsrm_tls_entry *thread_resources; - void *resource; - - tsrm_debug("Fetching resource id %d for thread %ld\n", id, (long) thread_id); - tsrm_mutex_lock(tsmm_mutex); - - hash_value = THREAD_HASH_OF(thread_id, tsrm_tls_table_size); - thread_resources = tsrm_tls_table[hash_value]; - - if (!thread_resources) { - allocate_new_resource(&tsrm_tls_table[hash_value], thread_id); - return ts_resource(id); - /* thread_resources = tsrm_tls_table[hash_value]; */ - } else { - do { - if (thread_resources->thread_id == thread_id) { - break; - } - if (thread_resources->next) { - thread_resources = thread_resources->next; - } else { - allocate_new_resource(&thread_resources->next, thread_id); - return ts_resource(id); - /* - * thread_resources = thread_resources->next; - * break; - */ - } - } while (thread_resources); - } - - resource = thread_resources->storage[id]; - - tsrm_mutex_unlock(tsmm_mutex); - - tsrm_debug("Successfully fetched resource id %d for thread id %ld - %x\n", id, (long) thread_id, (long) resource); - return resource; -} - - -/* frees all resources allocated for the current thread */ -void ts_free_thread(void) -{ - THREAD_T thread_id = tsrm_thread_id(); - int hash_value; - tsrm_tls_entry *thread_resources; - tsrm_tls_entry *last=NULL; - - tsrm_mutex_lock(tsmm_mutex); - hash_value = THREAD_HASH_OF(thread_id, tsrm_tls_table_size); - thread_resources = tsrm_tls_table[hash_value]; - - while (thread_resources) { - if (thread_resources->thread_id == thread_id) { - int i; - - for (i=0; icount; i++) { - if (resource_types_table[i].dtor) { - resource_types_table[i].dtor(thread_resources->storage[i]); - } - free(thread_resources->storage[i]); - } - free(thread_resources->storage); - if (last) { - last->next = thread_resources->next; - } else { - tsrm_tls_table[hash_value]=NULL; - } - free(thread_resources); - break; - } - if (thread_resources->next) { - last = thread_resources; - } - thread_resources = thread_resources->next; - } - tsrm_mutex_unlock(tsmm_mutex); -} - - -/* deallocates all occurrences of a given id */ -void ts_free_id(ts_rsrc_id id) -{ -} - - - - -/* - * Utility Functions - */ - -/* Obtain the current thread id */ -TSRM_API THREAD_T tsrm_thread_id(void) -{ -#ifdef WIN32 - return GetCurrentThreadId(); -#elif defined(GNUPTH) - return pth_self(); -#elif defined(PTHREADS) - return pthread_self(); -#elif defined(NSAPI) - return systhread_current(); -#elif defined(PI3WEB) - return PIThread_getCurrent(); -#endif -} - - -/* Allocate a mutex */ -TSRM_API MUTEX_T tsrm_mutex_alloc( void ) -{ - MUTEX_T mutexp; - -#ifdef WIN32 - mutexp = malloc(sizeof(CRITICAL_SECTION)); - InitializeCriticalSection(mutexp); -#elif defined(GNUPTH) - mutexp = (MUTEX_T) malloc(sizeof(*mutexp)); - pth_mutex_init(mutexp); -#elif defined(PTHREADS) - mutexp = (pthread_mutex_t *)malloc(sizeof(pthread_mutex_t)); - pthread_mutex_init(mutexp,NULL); -#elif defined(NSAPI) - mutexp = crit_init(); -#elif defined(PI3WEB) - mutexp = PIPlatform_allocLocalMutex(); -#endif -#ifdef THR_DEBUG - printf("Mutex created thread: %d\n",mythreadid()); -#endif - return( mutexp ); -} - - -/* Free a mutex */ -TSRM_API void tsrm_mutex_free( MUTEX_T mutexp ) -{ - if (mutexp) { -#ifdef WIN32 - DeleteCriticalSection(mutexp); -#elif defined(GNUPTH) - free(mutexp); -#elif defined(PTHREADS) - pthread_mutex_destroy(mutexp); - free(mutexp); -#elif defined(NSAPI) - crit_terminate(mutexp); -#elif defined(PI3WEB) - PISync_delete(mutexp) -#endif - } -#ifdef THR_DEBUG - printf("Mutex freed thread: %d\n",mythreadid()); -#endif -} - - -/* Lock a mutex */ -TSRM_API int tsrm_mutex_lock( MUTEX_T mutexp ) -{ -#if 0 - tsrm_debug("Mutex locked thread: %ld\n",tsrm_thread_id()); -#endif -#ifdef WIN32 - EnterCriticalSection(mutexp); - return 1; -#elif defined(GNUPTH) - return pth_mutex_acquire(mutexp, 0, NULL); -#elif defined(PTHREADS) - return pthread_mutex_lock(mutexp); -#elif defined(NSAPI) - return crit_enter(mutexp); -#elif defined(PI3WEB) - return PISync_lock(mutexp); -#endif -} - - -/* Unlock a mutex */ -TSRM_API int tsrm_mutex_unlock( MUTEX_T mutexp ) -{ -#if 0 - tsrm_debug("Mutex unlocked thread: %ld\n",tsrm_thread_id()); -#endif -#ifdef WIN32 - LeaveCriticalSection(mutexp); - return 1; -#elif defined(GNUPTH) - return pth_mutex_release(mutexp); -#elif defined(PTHREADS) - return pthread_mutex_unlock(mutexp); -#elif defined(NSAPI) - return crit_exit(mutexp); -#elif defined(PI3WEB) - return PISync_unlock(mutexp); -#endif -} - - -TSRM_API void *tsrm_set_new_thread_begin_handler(void (*new_thread_begin_handler)(THREAD_T thread_id)) -{ - void *retval = (void *) tsrm_new_thread_begin_handler; - - tsrm_new_thread_begin_handler = new_thread_begin_handler; - return retval; -} - - -TSRM_API void *tsrm_set_new_thread_end_handler(void (*new_thread_end_handler)(THREAD_T thread_id)) -{ - void *retval = (void *) tsrm_new_thread_end_handler; - - tsrm_new_thread_end_handler = new_thread_end_handler; - return retval; -} - - - -/* - * Debug support - */ - -static int tsrm_debug(const char *format, ...) -{ - if (tsrm_debug_status) { - va_list args; - int size; - - va_start(args, format); - size = vprintf(format, args); - va_end(args); - return size; - } else { - return 0; - } -} - - -void tsrm_debug_set(int status) -{ - tsrm_debug_status = status; -} diff --git a/TSRM/TSRM.dsp b/TSRM/TSRM.dsp deleted file mode 100644 index 185887f9be..0000000000 --- a/TSRM/TSRM.dsp +++ /dev/null @@ -1,125 +0,0 @@ -# Microsoft Developer Studio Project File - Name="TSRM" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Static Library" 0x0104 - -CFG=TSRM - Win32 Debug_TS -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "TSRM.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "TSRM.mak" CFG="TSRM - Win32 Debug_TS" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "TSRM - Win32 Debug_TS" (based on "Win32 (x86) Static Library") -!MESSAGE "TSRM - Win32 Release_TS" (based on "Win32 (x86) Static Library") -!MESSAGE "TSRM - Win32 Release_TS_inline" (based on "Win32 (x86) Static Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "TSRM - Win32 Debug_TS" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 1 -# PROP BASE Output_Dir "TSRM___Win32_Debug_TS" -# PROP BASE Intermediate_Dir "TSRM___Win32_Debug_TS" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 1 -# PROP Output_Dir "Debug_TS" -# PROP Intermediate_Dir "Debug_TS" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /I "C:\Projects\TSRM" /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "." /D "_DEBUG" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD BASE RSC /l 0x40d /d "_DEBUG" -# ADD RSC /l 0x40d /d "_DEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo - -!ELSEIF "$(CFG)" == "TSRM - Win32 Release_TS" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "TSRM___Win32_Release_TS" -# PROP BASE Intermediate_Dir "TSRM___Win32_Release_TS" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release_TS" -# PROP Intermediate_Dir "Release_TS" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "TSRM_EXPORTS" /YX /FD /c -# ADD BASE RSC /l 0x40d /d "NDEBUG" -# ADD RSC /l 0x40d /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo - -!ELSEIF "$(CFG)" == "TSRM - Win32 Release_TS_inline" - -# PROP BASE Use_MFC 0 -# PROP BASE Use_Debug_Libraries 0 -# PROP BASE Output_Dir "TSRM___Win32_Release_TS_inline" -# PROP BASE Intermediate_Dir "TSRM___Win32_Release_TS_inline" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Use_Debug_Libraries 0 -# PROP Output_Dir "Release_TS_inline" -# PROP Intermediate_Dir "Release_TS_inline" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "TSRM_EXPORTS" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDEBUG" /D "WIN32" /D "_MBCS" /D "_LIB" /D "TSRM_EXPORTS" /YX /FD /c -# ADD BASE RSC /l 0x40d /d "NDEBUG" -# ADD RSC /l 0x40d /d "NDEBUG" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo - -!ENDIF - -# Begin Target - -# Name "TSRM - Win32 Debug_TS" -# Name "TSRM - Win32 Release_TS" -# Name "TSRM - Win32 Release_TS_inline" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=.\TSRM.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\TSRM.h -# End Source File -# End Group -# End Target -# End Project diff --git a/TSRM/TSRM.h b/TSRM/TSRM.h deleted file mode 100644 index 4d2a2c2595..0000000000 --- a/TSRM/TSRM.h +++ /dev/null @@ -1,110 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Thread Safe Resource Manager | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to the Zend license, that is bundled | - | with this package in the file LICENSE. If you did not receive a | - | copy of the Zend license, please mail us at zend@zend.com so we can | - | send you a copy immediately. | - +----------------------------------------------------------------------+ - | Author: Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _TSRM_H -#define _TSRM_H - -#ifdef HAVE_CONFIG_H -# undef PACKAGE -# undef VERSION -# include "tsrm_config.h" -# undef PACKAGE -# undef VERSION -#endif - -#if WIN32||WINNT -# include -#elif defined(GNUPTH) -# include -#elif defined(PTHREADS) -# include -#endif - -typedef int ts_rsrc_id; - -#if WIN32||WINNT -# ifdef TSRM_EXPORTS -# define TSRM_API __declspec(dllexport) -# else -# define TSRM_API __declspec(dllimport) -# endif -#else -# define TSRM_API -#endif - - -/* Define THREAD_T and MUTEX_T */ -#if defined(WIN32) -# define THREAD_T DWORD -# define MUTEX_T CRITICAL_SECTION * -#elif defined(GNUPTH) -# define THREAD_T pth_t -# define MUTEX_T pth_mutex_t * -#elif defined(PTHREADS) -# define THREAD_T pthread_t -# define MUTEX_T pthread_mutex_t * -#elif defined(NSAPI) -# define THREAD_T SYS_THREAD -# define MUTEX_T CRITICAL -#elif defined(PI3WEB) -# define THREAD_T PIThread * -# define MUTEX_T PISync * -#endif - -typedef void (*ts_allocate_ctor)(void *); -typedef void (*ts_allocate_dtor)(void *); - -#define THREAD_HASH_OF(thr,ts) (unsigned long)thr%(unsigned long)ts - -#ifdef __cplusplus -extern "C" { -#endif - -/* startup/shutdown */ -TSRM_API int tsrm_startup(int expected_threads, int expected_resources, int debug_status); -TSRM_API void tsrm_shutdown(void); - -/* allocates a new thread-safe-resource id */ -TSRM_API ts_rsrc_id ts_allocate_id(size_t size, ts_allocate_ctor ctor, ts_allocate_dtor dtor); - -/* fetches the requested resource for the current thread */ -TSRM_API void *ts_resource(ts_rsrc_id id); - -/* frees all resources allocated for the current thread */ -TSRM_API void ts_free_thread(void); - -/* deallocates all occurrences of a given id */ -TSRM_API void ts_free_id(ts_rsrc_id id); - - -/* Debug support */ -TSRM_API void tsrm_debug_set(int status); - -/* utility functions */ -TSRM_API THREAD_T tsrm_thread_id(void); -TSRM_API MUTEX_T tsrm_mutex_alloc(void); -TSRM_API void tsrm_mutex_free(MUTEX_T mutexp); -TSRM_API int tsrm_mutex_lock(MUTEX_T mutexp); -TSRM_API int tsrm_mutex_unlock(MUTEX_T mutexp); - -TSRM_API void *tsrm_set_new_thread_begin_handler(void (*new_thread_begin_handler)(THREAD_T thread_id)); -TSRM_API void *tsrm_set_new_thread_end_handler(void (*new_thread_end_handler)(THREAD_T thread_id)); - -#ifdef __cplusplus -} -#endif - -#endif /* _TSRM_H */ diff --git a/TSRM/acconfig.h b/TSRM/acconfig.h deleted file mode 100644 index 2b94cf35e7..0000000000 --- a/TSRM/acconfig.h +++ /dev/null @@ -1 +0,0 @@ -#undef PTHREADS diff --git a/TSRM/acinclude.m4 b/TSRM/acinclude.m4 deleted file mode 100644 index 1953172aef..0000000000 --- a/TSRM/acinclude.m4 +++ /dev/null @@ -1,5 +0,0 @@ - -AC_DEFUN(AM_SET_LIBTOOL_VARIABLE,[ - LIBTOOL='$(SHELL) $(top_builddir)/libtool $1' -]) - diff --git a/TSRM/build.mk b/TSRM/build.mk deleted file mode 100644 index aac1a8b982..0000000000 --- a/TSRM/build.mk +++ /dev/null @@ -1,43 +0,0 @@ -# Makefile to generate build tools -# -# Standard usage: -# make -f build.mk -# -# Written by Sascha Schumann -# -# $Id$ - - -LT_TARGETS = ltmain.sh ltconfig - -config_h_in = tsrm_config.h.in - -makefile_am_files = Makefile.am -makefile_in_files = $(makefile_am_files:.am=.in) -makefile_files = $(makefile_am_files:e.am=e) - -targets = $(makefile_in_files) $(LT_TARGETS) configure $(config_h_in) - -all: $(targets) - -clean: - rm -f $(targets) - -$(LT_TARGETS): - rm -f $(LT_TARGETS) - libtoolize --automake $(AMFLAGS) -f - -$(makefile_in_files): $(makefile_am_files) - automake -a -i $(AMFLAGS) $(makefile_files) - -aclocal.m4: configure.in acinclude.m4 - aclocal - -$(config_h_in): configure.in acconfig.h -# explicitly remove target since autoheader does not seem to work -# correctly otherwise (timestamps are not updated) - @rm -f $@ - autoheader - -configure: aclocal.m4 configure.in - autoconf diff --git a/TSRM/buildconf b/TSRM/buildconf deleted file mode 100755 index fe8dee6f76..0000000000 --- a/TSRM/buildconf +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh - -case "$1" in ---copy) - automake_flags=--copy - shift -;; -esac - -libtoolize --force --automake $automake_flags - -mv aclocal.m4 aclocal.m4.old 2>/dev/null -aclocal -if cmp aclocal.m4.old aclocal.m4 > /dev/null 2>&1; then - echo "buildconf: keeping ${1}aclocal.m4" - mv aclocal.m4.old aclocal.m4 -else - echo "buildconf: created or modified ${1}aclocal.m4" -fi - -autoheader - -automake --add-missing --include-deps $automake_flags - -mv configure configure.old 2>/dev/null -autoconf -if cmp configure.old configure > /dev/null 2>&1; then - echo "buildconf: keeping ${1}configure" - mv configure.old configure -else - echo "buildconf: created or modified ${1}configure" -fi - diff --git a/TSRM/configure.in b/TSRM/configure.in deleted file mode 100644 index 43171d8f5d..0000000000 --- a/TSRM/configure.in +++ /dev/null @@ -1,21 +0,0 @@ -dnl $Id$ -dnl -dnl Minimalistic configure.in for TSRM. -dnl - -AC_INIT(TSRM.c) -AM_INIT_AUTOMAKE(TSRM, 1.0) -AM_CONFIG_HEADER(tsrm_config.h) - -sinclude(tsrm.m4) - -TSRM_BASIC_CHECKS - -AM_PROG_LIBTOOL -if test "$enable_debug" != "yes"; then - AM_SET_LIBTOOL_VARIABLE([--silent]) -fi - -TSRM_PTHREAD - -AC_OUTPUT(Makefile) diff --git a/TSRM/tsrm.m4 b/TSRM/tsrm.m4 deleted file mode 100644 index 23cd49ffd9..0000000000 --- a/TSRM/tsrm.m4 +++ /dev/null @@ -1,113 +0,0 @@ - -dnl TSRM_CHECK_GCC_ARG(ARG, ACTION-IF-FOUND, ACTION-IF-NOT_FOUND) -AC_DEFUN(TSRM_CHECK_GCC_ARG,[ - gcc_arg_name=[ac_cv_gcc_arg]translit($1,A-Z-,a-z_) - AC_CACHE_CHECK([whether $CC supports $1], [ac_cv_gcc_arg]translit($1,A-Z-,a-z_), [ - echo 'void somefunc() { };' > conftest.c - cmd='$CC $1 -c conftest.c' - if eval $cmd 2>&1 | egrep -e $1 >/dev/null ; then - ac_result=no - else - ac_result=yes - fi - eval $gcc_arg_name=$ac_result - rm -f conftest.* - ]) - if eval test "\$$gcc_arg_name" = "yes"; then - $2 - else - : - $3 - fi -]) - -AC_DEFUN(TSRM_BASIC_CHECKS,[ - -AC_REQUIRE([AC_PROG_CC])dnl -dnl AC_REQUIRE([AM_PROG_CC_STDC])dnl -AC_REQUIRE([AC_PROG_CC_C_O])dnl -AC_REQUIRE([AC_PROG_RANLIB])dnl - -AC_CHECK_HEADERS(stdarg.h) - -]) - - -AC_DEFUN(TSRM_CHECK_PTH,[ - -AC_MSG_CHECKING(for GNU Pth) -PTH_PREFIX="`$1 --prefix`" -if test -z "$PTH_PREFIX"; then - AC_MSG_RESULT(Please check your Pth installation) -fi - -CPPFLAGS="$CPPFLAGS `$1 --cflags`" -LDFLAGS="$LDFLAGS `$1 --ldflags`" -LIBS="$LIBS `$1 --libs`" - -AC_DEFINE(GNUPTH, 1, [Whether you use GNU Pth]) -AC_MSG_RESULT(yes - installed in $PTH_PREFIX) - -]) - - -AC_DEFUN(TSRM_CHECK_PTHREADS,[ - -old_CFLAGS="$CFLAGS" - -if test -n "$GCC"; then - TSRM_CHECK_GCC_ARG(-pthread, [ - CFLAGS="$CFLAGS -pthread" - ],[ - TSRM_CHECK_GCC_ARG(-pthreads, [ - CFLAGS="$CFLAGS -pthreads" - ])]) -fi - -AC_CHECK_FUNCS(pthread_kill) - -if test "$ac_cv_func_pthread_kill" != "yes"; then - CFLAGS="$old_CFLAGS" - AC_CHECK_LIB(pthread, pthread_kill) - unset ac_cv_func_pthread_kill - AC_CHECK_FUNCS(pthread_kill) - if test "$ac_cv_func_pthread_kill" != "yes"; then - AC_MSG_ERROR(Your system seems to lack POSIX threads.) - fi -fi - -AC_DEFINE(PTHREADS, 1, Whether to use Pthreads) - -AC_MSG_CHECKING(for POSIX threads) -AC_MSG_RESULT(yes) -]) - - -AC_DEFUN(TSRM_OTHER_CHECKS,[ - -dnl For the thread implementations, we always use --with-* -dnl to maintain consistency - -AC_ARG_WITH(tsrm-pth, -[ --with-tsrm-pth[=pth-config] Use GNU Pth.],[ - TSRM_PTH=$withval -],[ - TSRM_PTH=no -]) - -AC_ARG_WITH(tsrm-pthreads, -[ --with-tsrm-pthreads Use POSIX threads (default)],[ - TSRM_PTHREADS=$withval -],[ - TSRM_PTHREADS=yes -]) - -test "$TSRM_PTH" = "yes" && TSRM_PTH=pth-config - -if test "$TSRM_PTH" != "no"; then - TSRM_CHECK_PTH($TSRM_PTH) -elif test "$TSRM_PTHREADS" != "no"; then - TSRM_CHECK_PTHREADS -fi - -]) diff --git a/Zend/FlexLexer.h b/Zend/FlexLexer.h deleted file mode 100644 index 549177b8b9..0000000000 --- a/Zend/FlexLexer.h +++ /dev/null @@ -1,186 +0,0 @@ -// $Header$ - -// FlexLexer.h -- define interfaces for lexical analyzer classes generated -// by flex - -// Copyright (c) 1993 The Regents of the University of California. -// All rights reserved. -// -// This code is derived from software contributed to Berkeley by -// Kent Williams and Tom Epperly. -// -// Redistribution and use in source and binary forms with or without -// modification are permitted provided that: (1) source distributions retain -// this entire copyright notice and comment, and (2) distributions including -// binaries display the following acknowledgement: ``This product includes -// software developed by the University of California, Berkeley and its -// contributors'' in the documentation or other materials provided with the -// distribution and in all advertising materials mentioning features or use -// of this software. Neither the name of the University nor the names of -// its contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. - -// THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED -// WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF -// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. - -// This file defines FlexLexer, an abstract class which specifies the -// external interface provided to flex C++ lexer objects, and yyFlexLexer, -// which defines a particular lexer class. -// -// If you want to create multiple lexer classes, you use the -P flag -// to rename each yyFlexLexer to some other xxFlexLexer. You then -// include in your other sources once per lexer class: -// -// #undef yyFlexLexer -// #define yyFlexLexer xxFlexLexer -// #include -// -// #undef yyFlexLexer -// #define yyFlexLexer zzFlexLexer -// #include -// ... - -#ifndef __FLEX_LEXER_H -// Never included before - need to define base class. -#define __FLEX_LEXER_H -#include - -extern "C++" { - -struct yy_buffer_state; -typedef int yy_state_type; - -class FlexLexer { -public: - virtual ~FlexLexer() { } - - const char* YYText() { return yytext; } - int YYLeng() { return yyleng; } - - virtual void - yy_switch_to_buffer( struct yy_buffer_state* new_buffer ) = 0; - virtual struct yy_buffer_state* - yy_create_buffer( istream* s, int size ) = 0; - virtual void yy_delete_buffer( struct yy_buffer_state* b ) = 0; - virtual void yyrestart( istream* s ) = 0; - - virtual int yylex() = 0; - - // Call yylex with new input/output sources. - int yylex( istream* new_in, ostream* new_out = 0 ) - { - switch_streams( new_in, new_out ); - return yylex(); - } - - // Switch to new input/output streams. A nil stream pointer - // indicates "keep the current one". - virtual void switch_streams( istream* new_in = 0, - ostream* new_out = 0 ) = 0; - - int lineno() const { return yylineno; } - - int debug() const { return yy_flex_debug; } - void set_debug( int flag ) { yy_flex_debug = flag; } - -protected: - char* yytext; - int yyleng; - int yylineno; // only maintained if you use %option yylineno - int yy_flex_debug; // only has effect with -d or "%option debug" -}; - -} -#endif - -#if defined(yyFlexLexer) || ! defined(yyFlexLexerOnce) -// Either this is the first time through (yyFlexLexerOnce not defined), -// or this is a repeated include to define a different flavor of -// yyFlexLexer, as discussed in the flex man page. -#define yyFlexLexerOnce - -class yyFlexLexer : public FlexLexer { -public: - // arg_yyin and arg_yyout default to the cin and cout, but we - // only make that assignment when initializing in yylex(). - yyFlexLexer( istream* arg_yyin = 0, ostream* arg_yyout = 0 ); - - virtual ~yyFlexLexer(); - - void yy_switch_to_buffer( struct yy_buffer_state* new_buffer ); - struct yy_buffer_state* yy_create_buffer( istream* s, int size ); - void yy_delete_buffer( struct yy_buffer_state* b ); - void yyrestart( istream* s ); - - virtual int yylex(); - virtual void switch_streams( istream* new_in, ostream* new_out ); - -protected: - virtual int LexerInput( char* buf, int max_size ); - virtual void LexerOutput( const char* buf, int size ); - virtual void LexerError( const char* msg ); - - void yyunput( int c, char* buf_ptr ); - int yyinput(); - - void yy_load_buffer_state(); - void yy_init_buffer( struct yy_buffer_state* b, istream* s ); - void yy_flush_buffer( struct yy_buffer_state* b ); - - int yy_start_stack_ptr; - int yy_start_stack_depth; - int* yy_start_stack; - - void yy_push_state( int new_state ); - void yy_pop_state(); - int yy_top_state(); - - yy_state_type yy_get_previous_state(); - yy_state_type yy_try_NUL_trans( yy_state_type current_state ); - int yy_get_next_buffer(); - - istream* yyin; // input source for default LexerInput - ostream* yyout; // output sink for default LexerOutput - - struct yy_buffer_state* yy_current_buffer; - - // yy_hold_char holds the character lost when yytext is formed. - char yy_hold_char; - - // Number of characters read into yy_ch_buf. - int yy_n_chars; - - // Points to current character in buffer. - char* yy_c_buf_p; - - int yy_init; // whether we need to initialize - int yy_start; // start state number - - // Flag which is used to allow yywrap()'s to do buffer switches - // instead of setting up a fresh yyin. A bit of a hack ... - int yy_did_buffer_switch_on_eof; - - // The following are not always needed, but may be depending - // on use of certain flex features (like REJECT or yymore()). - - yy_state_type yy_last_accepting_state; - char* yy_last_accepting_cpos; - - yy_state_type* yy_state_buf; - yy_state_type* yy_state_ptr; - - char* yy_full_match; - int* yy_full_state; - int yy_full_lp; - - int yy_lp; - int yy_looking_for_trail_begin; - - int yy_more_flag; - int yy_more_len; - int yy_more_offset; - int yy_prev_more_offset; -}; - -#endif diff --git a/Zend/LICENSE b/Zend/LICENSE deleted file mode 100644 index 1dd42f1ff3..0000000000 --- a/Zend/LICENSE +++ /dev/null @@ -1,116 +0,0 @@ ---------------------------------------------------------------------------- - The Zend License, version 0.91 - Copyright (C) 1999 Andi Gutmans & Zeev Suraski ---------------------------------------------------------------------------- - -The Zend scripting engine library is a product of Andi Gutmans and -Zeev Suraski. It may be used and/or distributed under the terms of the -Q Public License (QPL) version 1.0, enclosed below. - -For more information about Zend please visit http://www.zend.com/ -For license related questions please mail license@zend.com - -=========================================================================== - - THE Q PUBLIC LICENSE - version 1.0 - - Copyright (C) 1999 Troll Tech AS, Norway. - Everyone is permitted to copy and - distribute this license document. - -The intent of this license is to establish freedom to share and change the -software regulated by this license under the open source model. - -This license applies to any software containing a notice placed by the -copyright holder saying that it may be distributed under the terms of -the Q Public License version 1.0. Such software is herein referred to as -the Software. This license covers modification and distribution of the -Software, use of third-party application programs based on the Software, -and development of free software which uses the Software. - - Granted Rights - -1. You are granted the non-exclusive rights set forth in this license - provided you agree to and comply with any and all conditions in this - license. Whole or partial distribution of the Software, or software - items that link with the Software, in any form signifies acceptance of - this license. - -2. You may copy and distribute the Software in unmodified form provided - that the entire package, including - but not restricted to - copyright, - trademark notices and disclaimers, as released by the initial developer - of the Software, is distributed. - -3. You may make modifications to the Software and distribute your - modifications, in a form that is separate from the Software, such as - patches. The following restrictions apply to modifications: - - a. Modifications must not alter or remove any copyright notices in - the Software. - - b. When modifications to the Software are released under this - license, a non-exclusive royalty-free right is granted to the - initial developer of the Software to distribute your modification - in future versions of the Software provided such versions remain - available under these terms in addition to any other license(s) of - the initial developer. - -4. You may distribute machine-executable forms of the Software or - machine-executable forms of modified versions of the Software, provided - that you meet these restrictions: - - a. You must include this license document in the distribution. - - b. You must ensure that all recipients of the machine-executable forms - are also able to receive the complete machine-readable source code - to the distributed Software, including all modifications, without - any charge beyond the costs of data transfer, and place prominent - notices in the distribution explaining this. - - c. You must ensure that all modifications included in the - machine-executable forms are available under the terms of this - license. - -5. You may use the original or modified versions of the Software to - compile, link and run application programs legally developed by you - or by others. - -6. You may develop application programs, reusable components and other - software items that link with the original or modified versions of the - Software. These items, when distributed, are subject to the following - requirements: - - a. You must ensure that all recipients of machine-executable forms of - these items are also able to receive and use the complete - machine-readable source code to the items without any charge - beyond the costs of data transfer. - - b. You must explicitly license all recipients of your items to use - and re-distribute original and modified versions of the items in - both machine-executable and source code forms. The recipients must - be able to do so without any charges whatsoever, and they must be - able to re-distribute to anyone they choose. - - - c. If the items are not available to the general public, and the - initial developer of the Software requests a copy of the items, - then you must supply one. - - Limitations of Liability - -In no event shall the initial developers or copyright holders be liable -for any damages whatsoever, including - but not restricted to - lost -revenue or profits or other direct, indirect, special, incidental or -consequential damages, even if they have been advised of the possibility -of such damages, except to the extent invariable law, if any, provides -otherwise. - - No Warranty - -The Software and this license document are provided AS IS with NO WARRANTY -OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS -FOR A PARTICULAR PURPOSE. - - -=========================================================================== \ No newline at end of file diff --git a/Zend/Makefile.am b/Zend/Makefile.am deleted file mode 100644 index e06d89f6d6..0000000000 --- a/Zend/Makefile.am +++ /dev/null @@ -1,41 +0,0 @@ -## Process this file with automake to produce Makefile.in -*- makefile -*- - -#CLEANFILES = zend-parser.c zend-parser.h zend-scanner.c zend-parser.output - -AUTOMAKE_OPTIONS=foreign -EXTRA_LTLIBRARIES=libZend_cc.la libZend_c.la -noinst_LTLIBRARIES=$(ZEND_SCANNER) libZend.la - -libZend_cc_la_SOURCES=zend-scanner-cc.cc -libZend_c_la_SOURCES=zend-scanner.c - -libZend_la_SOURCES=\ - zend-parser.y \ - zend_alloc.c zend_compile.c zend_constants.c \ - zend_execute.c zend_execute_API.c zend_highlight.c zend_llist.c \ - zend_opcode.c zend_operators.c zend_ptr_stack.c zend_stack.c \ - zend_variables.c zend.c zend_API.c zend_extensions.c zend_hash.c \ - zend_list.c zend_indent.c zend_builtin_functions.c zend_sprintf.c - -libZend_la_LIBADD = $(ZEND_SCANNER) -libZend_la_LDFLAGS = @EXTRA_LIBS@ -libZend_la_DEPENDENCIES = $(ZEND_SCANNER) - -# automake isn't too clever about "non-standard" use of lex and yacc - -zend-scanner.l: zend-parser.h - -zend-scanner.c: zend-scanner.l - $(LEX) -Pzend -o$@ -i $(srcdir)/zend-scanner.l - -zend-scanner-cc.cc: zend-scanner.l - $(LEX) -+ -B -i -S$(srcdir)/flex.skl -Pzend -o$@ $(srcdir)/zend-scanner.l - -zend-parser.h: zend-parser.c -zend-parser.c: zend-parser.y - $(YACC) -p zend -v -d $(srcdir)/zend-parser.y -o zend-parser.c - -depend: - -zend_execute.lo: $(srcdir)/zend_execute.c - $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(CPPFLAGS) $(INLINE_CFLAGS) -c $(srcdir)/zend_execute.c diff --git a/Zend/ZEND_CHANGES b/Zend/ZEND_CHANGES deleted file mode 100644 index 0c144e2d5c..0000000000 --- a/Zend/ZEND_CHANGES +++ /dev/null @@ -1,111 +0,0 @@ -Improvements ------------- - -Zend was designed from the ground up for increased speed, -reduced memory consumption and more reliable execution. We dare -say it meets all of these goals and does so pretty well. Beyond -that, there are several improvements in the language engine -features: - -* References support. $foo = &$a; would make $foo and $a be two - names to the same variable. This works with arrays as well, - on either side; e.g., $foo = &$a[7]; would make $foo and $a[7] - be two names to the same variable. Changing one would change - the other and vice versa. -* Object overloading support. This feature allows various OO - libraries to use the OO notation of PHP to access their - functionality. Right now, no use is made of that feature, - but we'd have a COM module ready by the time PHP 4.0 is released. - A CORBA module would probably follow. -* include() and eval() are now functions, and not statements. - That means they return a value. The default return value from - include() and eval() is 1, so that you can do if (include()) - without further coding. The return value may be changed by - returning a value from the global scope of the included file - or the evaluated string. For example, if 'return 7;' is executed - in the global scope of foo.inc, include("foo.inc") would evaluate - to 7. -* Automatic resource deallocation. Several people have been bitten - by the fact that PHP 3.0 had no concept of reference counting. - Zend adds full reference counting for every value in the system, - including resources. As soon as a resource is no longer referenced - from any variable, it is automatically destroyed to save memory - and resources. The most obvious example for the advantage in this - is a loop that has an SQL query inside it, something like - '$result = sql_query(...);'. In PHP 3.0, every iteration resulted - in another SQL result-set allocated in the memory, and all of the - result sets weren't destroyed until the end of the script's execution. - In Zend, as soon as we overwrite an old result set with a new one, - the old result set which is no longer referenced, is destroyed. -* Full support for nesting arrays and objects within each other, in - as many levels as you want. -* Boolean type. true and false are now constants of type boolean. - Comparing any other value to them would convert that value to a - boolean first, and conduct the comparison later. That means, for - example, that 5==true would evaluate to true (in PHP 3.0, true - was nothing but a constant for the integer value of 1, so 5==true - was identical to 5==1, which was false). -* Runtime binding of function names. This complex name has a simple - explanation - you can now call functions before they're declared! -* Added here-docs support. -* Added foreach. Two syntaxes supported: - foreach(array_expr as $val) statement - foreach(array_expr as $key => $val) statement -* A true unset() implementation. A variable or element that is unset(), is now - sent to oblivion in its entirely, no trace remains from it. -* Output buffering support! Use ob_start() to begin output buffering, ob_end_flush() - to end buffering and send out the buffered contents, ob_end_clean() to end buffering - without sending the buffered contents, and ob_get_contents() to retreive the current - contents of the output buffer. - Header information (header(), content type, cookies) are not buffered. By turning - on output buffering, you can effectively send header information all throughout your - file, regardless of whether you've emitted body output or not. -* Full variable reference within quoted strings: - ${expr} - full indirect reference support for scalar variables - {variable} - full variable support - For example: - $foo[5]["bar"] = "foobar"; - print "{$foo[5]["bar"]}"; // would print "foobar" -* Ability to call member functions of other classes from within member functions or from - the global scope. You can now, for example, override a parent function with a child function, - and call the parent function from it. -* Runtime information for classes (class name, parent, available functions, etc.). -* Much more efficient syntax highlighter - runs much quicker, performs more reliably, and - generates much tighter HTML. -* A full-featured debugger has been integrated with the language (supports breakpoints, - expression evaluation, step-in/over, function call backtrace, and more). - - -Incompatabilities ------------------ - -Zend claims 100% compatability with the engine of PHP 3.0, and is -shamelessly lying about it. Here's why: - -* static variable initializers only accept scalar values - (in PHP 3.0 they accepted any valid expression). The impact - should be somewhere in between void and non existant, since - initializing a static variable with anything but a simple - static value makes no sense at all. - -* The scope of break and continue is local to that of an - include()'d file or an eval()'d string. The impact should - be somewhat smaller of the one above. - -* return statement from a require()'d file no longer works. It - hardly worked in PHP 3.0, so the impact should be fairly small. - If you want this functionality - use include() instead. - -* unset() is no longer a function, but a statement. It was never - documented as a function so the impact should be no bigger than - nada. - -* The following letter combination is not supported within encapsulated - strings: "{$". If you have a string that includes this letter - combination, for example, print "{$somevar"; (which printed the - letter { and the contents of the variable $somevar in PHP 3.0), - it will result in a parse error under Zend. In this case, you - would have to change the code to print "\{$somevar"; - This incompatability is due to the full variable reference - within quoted strings feature added in Zend. - diff --git a/Zend/Zend.dsp b/Zend/Zend.dsp deleted file mode 100644 index 6ea8958480..0000000000 --- a/Zend/Zend.dsp +++ /dev/null @@ -1,432 +0,0 @@ -# Microsoft Developer Studio Project File - Name="Zend" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Static Library" 0x0104 - -CFG=Zend - Win32 Release_inline -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "Zend.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "Zend.mak" CFG="Zend - Win32 Release_inline" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "Zend - Win32 Release" (based on "Win32 (x86) Static Library") -!MESSAGE "Zend - Win32 Debug" (based on "Win32 (x86) Static Library") -!MESSAGE "Zend - Win32 Release_inline" (based on "Win32 (x86) Static Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "Zend - Win32 Release" - -# PROP BASE Use_MFC 0 -# PROP BASE Output_Dir "Release" -# PROP BASE Intermediate_Dir "Release" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Output_Dir "Release" -# PROP Intermediate_Dir "Release" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDebug" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDebug" /D "_LIB" /D "Zend_EXPORTS" /D ZEND_DEBUG=0 /D "LIBZEND_EXPORTS" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /D "ZEND_WIN32" /FR /FD /c -# SUBTRACT CPP /YX -# ADD BASE RSC /l 0x40d /d "NDebug" -# ADD RSC /l 0x40d /d "NDebug" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo - -!ELSEIF "$(CFG)" == "Zend - Win32 Debug" - -# PROP BASE Use_MFC 0 -# PROP BASE Output_Dir "Debug" -# PROP BASE Intermediate_Dir "Debug" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Output_Dir "Debug" -# PROP Intermediate_Dir "Debug" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_Debug" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "." /D "_Debug" /D "_LIB" /D "LIBZEND_EXPORTS" /D "TSRM_EXPORTS" /D ZEND_DEBUG=1 /D "ZEND_WIN32" /D "WIN32" /D "_MBCS" /FR /YX /FD /GZ /c -# ADD BASE RSC /l 0x40d /d "_Debug" -# ADD RSC /l 0x40d /d "_Debug" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo - -!ELSEIF "$(CFG)" == "Zend - Win32 Release_inline" - -# PROP BASE Use_MFC 0 -# PROP BASE Output_Dir "Zend___Win32_Release_inline" -# PROP BASE Intermediate_Dir "Zend___Win32_Release_inline" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Output_Dir "Release_inline" -# PROP Intermediate_Dir "Release_inline" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDebug" /D "_LIB" /D "Zend_EXPORTS" /D ZEND_DEBUG=0 /D "LIBZEND_EXPORTS" /D "TSRM_EXPORTS" /D "WIN32" /D "_MBCS" /FR /FD /c -# SUBTRACT BASE CPP /YX -# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDebug" /D "_LIB" /D "Zend_EXPORTS" /D "LIBZEND_EXPORTS" /D "TSRM_EXPORTS" /D ZEND_DEBUG=0 /D "ZEND_WIN32_FORCE_INLINE" /D "WIN32" /D "_MBCS" /D "ZEND_WIN32" /FR /FD /c -# SUBTRACT CPP /YX -# ADD BASE RSC /l 0x40d /d "NDebug" -# ADD RSC /l 0x40d /d "NDebug" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo - -!ENDIF - -# Begin Target - -# Name "Zend - Win32 Release" -# Name "Zend - Win32 Debug" -# Name "Zend - Win32 Release_inline" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=".\zend-parser.c" -# End Source File -# Begin Source File - -SOURCE=".\zend-scanner.c" -# End Source File -# Begin Source File - -SOURCE=.\zend.c -# End Source File -# Begin Source File - -SOURCE=.\zend_alloc.c -# End Source File -# Begin Source File - -SOURCE=.\zend_API.c -# End Source File -# Begin Source File - -SOURCE=.\zend_builtin_functions.c -# End Source File -# Begin Source File - -SOURCE=.\zend_compile.c -# End Source File -# Begin Source File - -SOURCE=.\zend_constants.c -# End Source File -# Begin Source File - -SOURCE=.\zend_execute.c -# End Source File -# Begin Source File - -SOURCE=.\zend_execute_API.c -# End Source File -# Begin Source File - -SOURCE=.\zend_extensions.c -# End Source File -# Begin Source File - -SOURCE=.\zend_hash.c -# End Source File -# Begin Source File - -SOURCE=.\zend_highlight.c -# End Source File -# Begin Source File - -SOURCE=.\zend_indent.c -# End Source File -# Begin Source File - -SOURCE=.\zend_list.c -# End Source File -# Begin Source File - -SOURCE=.\zend_llist.c -# End Source File -# Begin Source File - -SOURCE=.\zend_opcode.c -# End Source File -# Begin Source File - -SOURCE=.\zend_operators.c -# End Source File -# Begin Source File - -SOURCE=.\zend_ptr_stack.c -# End Source File -# Begin Source File - -SOURCE=.\zend_sprintf.c -# End Source File -# Begin Source File - -SOURCE=.\zend_stack.c -# End Source File -# Begin Source File - -SOURCE=.\zend_variables.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\FlexLexer.h -# End Source File -# Begin Source File - -SOURCE=.\modules.h -# End Source File -# Begin Source File - -SOURCE=".\zend-parser.h" -# End Source File -# Begin Source File - -SOURCE=".\zend-scanner.h" -# End Source File -# Begin Source File - -SOURCE=.\zend.h -# End Source File -# Begin Source File - -SOURCE=.\zend_alloc.h -# End Source File -# Begin Source File - -SOURCE=.\zend_API.h -# End Source File -# Begin Source File - -SOURCE=.\zend_builtin_functions.h -# End Source File -# Begin Source File - -SOURCE=.\zend_compile.h -# End Source File -# Begin Source File - -SOURCE=.\zend_config.w32.h -# End Source File -# Begin Source File - -SOURCE=.\zend_constants.h -# End Source File -# Begin Source File - -SOURCE=.\zend_errors.h -# End Source File -# Begin Source File - -SOURCE=.\zend_execute.h -# End Source File -# Begin Source File - -SOURCE=.\zend_extensions.h -# End Source File -# Begin Source File - -SOURCE=.\zend_fast_cache.h -# End Source File -# Begin Source File - -SOURCE=.\zend_globals.h -# End Source File -# Begin Source File - -SOURCE=.\zend_hash.h -# End Source File -# Begin Source File - -SOURCE=.\zend_highlight.h -# End Source File -# Begin Source File - -SOURCE=.\zend_indent.h -# End Source File -# Begin Source File - -SOURCE=.\zend_list.h -# End Source File -# Begin Source File - -SOURCE=.\zend_llist.h -# End Source File -# Begin Source File - -SOURCE=.\zend_operators.h -# End Source File -# Begin Source File - -SOURCE=.\zend_ptr_stack.h -# End Source File -# Begin Source File - -SOURCE=.\zend_stack.h -# End Source File -# Begin Source File - -SOURCE=.\zend_variables.h -# End Source File -# End Group -# Begin Group "Parsers" - -# PROP Default_Filter "y" -# Begin Source File - -SOURCE=".\zend-parser.y" - -!IF "$(CFG)" == "Zend - Win32 Release" - -# Begin Custom Build -InputDir=. -InputPath=".\zend-parser.y" - -BuildCmds= \ - if not "X%CYGWIN%"=="X" bison --output=zend-parser.c -v -d -S "%CYGWIN%\share\bison.simple" -p zend zend-parser.y \ - if "X%CYGWIN%"=="X" bison --output=zend-parser.c -v -d -S "C:\Program Files\Cygnus\share\bison.simple" -p zend zend-parser.y \ - - -"$(InputDir)\zend-parser.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - $(BuildCmds) - -"$(InputDir)\zend-parser.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - $(BuildCmds) -# End Custom Build - -!ELSEIF "$(CFG)" == "Zend - Win32 Debug" - -# Begin Custom Build -InputDir=. -InputPath=".\zend-parser.y" - -BuildCmds= \ - if not "X%CYGWIN%"=="X" bison --output=zend-parser.c -v -d -S "%CYGWIN%\share\bison.simple" -p zend zend-parser.y \ - if "X%CYGWIN%"=="X" bison --output=zend-parser.c -v -d -S "C:\Program Files\Cygnus\share\bison.simple" -p zend zend-parser.y \ - - -"$(InputDir)\zend-parser.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - $(BuildCmds) - -"$(InputDir)\zend-parser.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - $(BuildCmds) -# End Custom Build - -!ELSEIF "$(CFG)" == "Zend - Win32 Release_inline" - -# Begin Custom Build -InputDir=. -InputPath=".\zend-parser.y" - -BuildCmds= \ - if not "X%CYGWIN%"=="X" bison --output=zend-parser.c -v -d -S "%CYGWIN%\share\bison.simple" -p zend zend-parser.y \ - if "X%CYGWIN%"=="X" bison --output=zend-parser.c -v -d -S "C:\Program Files\Cygnus\share\bison.simple" -p zend zend-parser.y \ - - -"$(InputDir)\zend-parser.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - $(BuildCmds) - -"$(InputDir)\zend-parser.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - $(BuildCmds) -# End Custom Build - -!ENDIF - -# End Source File -# End Group -# Begin Group "Scanners" - -# PROP Default_Filter "l" -# Begin Source File - -SOURCE=".\zend-scanner.l" - -!IF "$(CFG)" == "Zend - Win32 Release" - -# Begin Custom Build -InputPath=".\zend-scanner.l" - -"zend-scanner.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - flex -i -Pzend -ozend-scanner.c zend-scanner.l - -# End Custom Build - -!ELSEIF "$(CFG)" == "Zend - Win32 Debug" - -# Begin Custom Build -InputPath=".\zend-scanner.l" - -"zend-scanner.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - flex -i -Pzend -ozend-scanner.c zend-scanner.l - -# End Custom Build - -!ELSEIF "$(CFG)" == "Zend - Win32 Release_inline" - -# Begin Custom Build -InputPath=".\zend-scanner.l" - -"zend-scanner.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - flex -i -Pzend -ozend-scanner.c zend-scanner.l - -# End Custom Build - -!ENDIF - -# End Source File -# End Group -# Begin Group "Text Files" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=.\ZEND_BUGS -# End Source File -# Begin Source File - -SOURCE=.\ZEND_CHANGES -# End Source File -# Begin Source File - -SOURCE=.\ZEND_TODO -# End Source File -# End Group -# Begin Group "Resources" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=.\zend.ico -# End Source File -# End Group -# End Target -# End Project diff --git a/Zend/Zend.m4 b/Zend/Zend.m4 deleted file mode 100644 index 5acdf7c3fa..0000000000 --- a/Zend/Zend.m4 +++ /dev/null @@ -1,223 +0,0 @@ - -AC_DEFUN(LIBZEND_BISON_CHECK,[ - -if test "$YACC" != "bison -y"; then - AC_MSG_WARN(You will need bison if you want to regenerate the Zend parser.) -else - AC_MSG_CHECKING(bison version) - set `bison --version| sed -e 's/^GNU Bison version //' -e 's/\./ /'` - if test "${1}" = "1" -a "${2}" -lt "25"; then - AC_MSG_WARN(You will need bison 1.25 if you want to regenerate the Zend parser (found ${1}.${2}).) - fi - AC_MSG_RESULT(${1}.${2} (ok)) -fi - -]) - -AC_DEFUN(LIBZEND_BASIC_CHECKS,[ - -AC_REQUIRE([AC_PROG_YACC]) -AC_REQUIRE([AC_PROG_CC]) -AC_REQUIRE([AC_PROG_CC_C_O]) -AC_REQUIRE([AM_PROG_LEX]) -AC_REQUIRE([AC_HEADER_STDC]) - -LIBZEND_BISON_CHECK - -dnl Ugly hack to get around a problem with gcc on AIX. -if test "$CC" = "gcc" -a "$ac_cv_prog_cc_g" = "yes" -a \ - "`uname -sv`" = "AIX 4"; then - CFLAGS=`echo $CFLAGS | sed -e 's/-g//'` -fi - -dnl Hack to work around a Mac OS X cpp problem -dnl Known versions needing this workaround are 5.3 and 5.4 -if test "$ac_cv_prog_gcc" = "yes" -a "`uname -s`" = "Rhapsody"; then - CPPFLAGS="$CPPFLAGS -traditional-cpp" -fi - -AC_CHECK_HEADERS( -limits.h \ -malloc.h \ -string.h \ -unistd.h \ -stdarg.h \ -sys/types.h \ -signal.h \ -unix.h \ -dlfcn.h) - -AC_TYPE_SIZE_T -AC_TYPE_SIGNAL - -AC_CHECK_LIB(c, dlopen, [ - # fake it - AC_DEFINE(HAVE_LIBDL) ], [ - AC_CHECK_LIB(dl, dlopen, [ - LIBS="-ldl $LIBS" - AC_DEFINE(HAVE_LIBDL) ], []) ]) - - -dnl This is required for QNX and may be some BSD derived systems -AC_CHECK_TYPE( uint, unsigned int ) -AC_CHECK_TYPE( ulong, unsigned long ) - - -dnl Checks for library functions. -AC_FUNC_VPRINTF -AC_FUNC_MEMCMP -AC_FUNC_ALLOCA -AC_CHECK_FUNCS(memcpy strdup getpid kill strtod strtol) -AC_ZEND_BROKEN_SPRINTF - -AC_SUBST(ZEND_SCANNER) - -]) - - - - - -AC_DEFUN(LIBZEND_ENABLE_DEBUG,[ - -AC_ARG_ENABLE(debug, -[ --disable-debug Compile without debugging symbols],[ - ZEND_DEBUG=$enableval -],[ - ZEND_DEBUG=yes -]) - -]) - - - - - - - - - - - - - - - -AC_DEFUN(LIBZEND_OTHER_CHECKS,[ - -AC_ARG_ENABLE(experimental-zts, -[ --enable-experimental-zts This will most likely break your build],[ - ZEND_EXPERIMENTAL_ZTS=$enableval -],[ - ZEND_EXPERIMENTAL_ZTS=no -]) - -AC_ARG_ENABLE(inline-optimization, -[ --enable-inline-optimization If you have much memory and are using - gcc, you might try this.],[ - ZEND_INLINE_OPTIMIZATION=$enableval -],[ - ZEND_INLINE_OPTIMIZATION=no -]) - -AC_ARG_ENABLE(memory-limit, -[ --enable-memory-limit Compile with memory limit support. ], [ - ZEND_MEMORY_LIMIT=$enableval -],[ - ZEND_MEMORY_LIMIT=no -]) - -AC_MSG_CHECKING(whether to enable experimental ZTS) -AC_MSG_RESULT($ZEND_EXPERIMENTAL_ZTS) - -AC_MSG_CHECKING(whether to enable inline optimization for GCC) -AC_MSG_RESULT($ZEND_INLINE_OPTIMIZATION) - -AC_MSG_CHECKING(whether to enable a memory limit) -AC_MSG_RESULT($ZEND_MEMORY_LIMIT) - -AC_MSG_CHECKING(whether to enable Zend debugging) -AC_MSG_RESULT($ZEND_DEBUG) - -if test "$ZEND_DEBUG" = "yes"; then - AC_DEFINE(ZEND_DEBUG,1) - echo " $CFLAGS" | grep ' -g' >/dev/null || DEBUG_CFLAGS="-g" - test -n "$GCC" && DEBUG_CFLAGS="$DEBUG_CFLAGS -Wall" - test -n "$GCC" && test "$USE_MAINTAINER_MODE" = "yes" && \ - DEBUG_CFLAGS="$DEBUG_CFLAGS -Wmissing-prototypes -Wstrict-prototypes -Wmissing-declarations" -else - AC_DEFINE(ZEND_DEBUG,0) -fi - -test -n "$DEBUG_CFLAGS" && CFLAGS="$CFLAGS $DEBUG_CFLAGS" - -if test "$ZEND_EXPERIMENTAL_ZTS" = "yes"; then - AC_DEFINE(ZTS) - ZEND_SCANNER_TYPE=cc - CPPFLAGS="$CPPFLAGS -I../TSRM" - LIBZEND_CPLUSPLUS_CHECKS -else - ZEND_SCANNER_TYPE=c -fi - -ZEND_SCANNER="libZend_${ZEND_SCANNER_TYPE}.la" - -if test "$ZEND_MEMORY_LIMIT" = "yes"; then - AC_DEFINE(MEMORY_LIMIT, 1, [Memory limit]) -else - AC_DEFINE(MEMORY_LIMIT, 0, [Memory limit]) -fi - -changequote({,}) -if test -n "$GCC" && test "$ZEND_INLINE_OPTIMIZATION" != "yes"; then - INLINE_CFLAGS=`echo $ac_n "$CFLAGS $ac_c" | sed s/-O[0-9]*//` -else - INLINE_CFLAGS="$CFLAGS" -fi -changequote([,]) - -AC_C_INLINE - -AC_SUBST(INLINE_CFLAGS) - -]) - - -AC_DEFUN(LIBZEND_CPLUSPLUS_CHECKS,[ - -dnl extra check to avoid C++ preprocessor testing if in non-ZTS mode - -if test "$ZEND_EXPERIMENTAL_ZTS" = "yes"; then -AC_PROG_CXX -AC_PROG_CXXCPP -AC_LANG_CPLUSPLUS -AC_CHECK_HEADER(stdiostream.h, [ AC_DEFINE(HAVE_STDIOSTREAM_H, [], Whether you have stdiostream.h) ]) - -AC_CHECK_LIB(C, cin) -AC_CHECK_LIB(g++, cin) -AC_CHECK_LIB(stdc++, cin) -dnl Digital Unix 4.0 -AC_CHECK_LIB(cxx, cin) -AC_CHECK_LIB(cxxstd, __array_delete) - -AC_CACHE_CHECK(for class istdiostream,ac_cv_class_istdiostream,[ -AC_TRY_COMPILE([ -#include -#include -#include -#include -],[ -istdiostream *foo = new istdiostream((FILE *) 0); -],[ - ac_cv_class_istdiostream=yes -],[ - ac_cv_class_istdiostream=no -]) -]) - if test "$ac_cv_class_istdiostream" = "yes"; then - AC_DEFINE(HAVE_CLASS_ISTDIOSTREAM, 1, [Whether you have class istdiostream]) - fi -AC_LANG_C -fi -]) - diff --git a/Zend/ZendCore.dep b/Zend/ZendCore.dep deleted file mode 100644 index 5320a0b674..0000000000 --- a/Zend/ZendCore.dep +++ /dev/null @@ -1,258 +0,0 @@ -# Microsoft Developer Studio Generated Dependency File, included by ZendCore.mak - -.\zend_alloc.c : \ - "..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ - ".\zend_alloc.h"\ - ".\zend_compile.h"\ - ".\zend_config.w32.h"\ - ".\zend_execute.h"\ - ".\zend_llist.h"\ - ".\zend_ptr_stack.h"\ - ".\zend_stack.h"\ - ".\zend.h"\ - ".\zend_errors.h"\ - ".\zend_globals.h"\ - ".\zend_hash.h"\ - - -.\alloca.c : \ - "..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ - ".\zend_config.w32.h"\ - ".\zend.h"\ - ".\zend_errors.h"\ - ".\zend_hash.h"\ - - -.\zend_compile.c : \ - "..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ - ".\zend_alloc.h"\ - ".\zend_compile.h"\ - ".\zend_config.w32.h"\ - ".\zend_execute.h"\ - ".\zend_llist.h"\ - ".\modules.h"\ - ".\zend_operators.h"\ - ".\zend_ptr_stack.h"\ - ".\zend_stack.h"\ - ".\zend_variables.h"\ - ".\zend.h"\ - ".\zend_API.h"\ - ".\zend_errors.h"\ - ".\zend_globals.h"\ - ".\zend_hash.h"\ - ".\zend_ini.h"\ - - -.\zend_constants.c : \ - "..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ - ".\zend_alloc.h"\ - ".\zend_config.w32.h"\ - ".\zend_constants.h"\ - ".\zend_operators.h"\ - ".\zend_variables.h"\ - ".\zend.h"\ - ".\zend_errors.h"\ - ".\zend_hash.h"\ - - -.\zend_execute.c : \ - "..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ - ".\zend_alloc.h"\ - ".\zend_compile.h"\ - ".\zend_config.w32.h"\ - ".\zend_constants.h"\ - ".\zend_execute.h"\ - ".\zend_llist.h"\ - ".\modules.h"\ - ".\zend_operators.h"\ - ".\zend_ptr_stack.h"\ - ".\zend_stack.h"\ - ".\zend_variables.h"\ - ".\zend.h"\ - ".\zend_API.h"\ - ".\zend_errors.h"\ - ".\zend_globals.h"\ - ".\zend_hash.h"\ - ".\zend_ini.h"\ - - -.\zend_highlight.c : \ - "..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ - ".\zend_alloc.h"\ - ".\zend_compile.h"\ - ".\zend_config.w32.h"\ - ".\zend_execute.h"\ - ".\zend_highlight.h"\ - ".\zend_llist.h"\ - ".\zend_ptr_stack.h"\ - ".\zend_stack.h"\ - ".\zend-parser.tab.h"\ - ".\zend.h"\ - ".\zend_errors.h"\ - ".\zend_globals.h"\ - ".\zend_hash.h"\ - - -.\zend_llist.c : \ - "..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ - ".\zend_alloc.h"\ - ".\zend_config.w32.h"\ - ".\zend_llist.h"\ - ".\zend.h"\ - ".\zend_errors.h"\ - ".\zend_hash.h"\ - - -.\zend_opcode.c : \ - "..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ - ".\zend_alloc.h"\ - ".\zend_compile.h"\ - ".\zend_config.w32.h"\ - ".\zend_execute.h"\ - ".\zend_llist.h"\ - ".\modules.h"\ - ".\zend_operators.h"\ - ".\zend_ptr_stack.h"\ - ".\zend_stack.h"\ - ".\zend_variables.h"\ - ".\zend.h"\ - ".\zend_API.h"\ - ".\zend_errors.h"\ - ".\zend_globals.h"\ - ".\zend_hash.h"\ - ".\zend_ini.h"\ - - -.\zend_operators.c : \ - "..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ - ".\zend_alloc.h"\ - ".\zend_compile.h"\ - ".\zend_config.w32.h"\ - ".\zend_execute.h"\ - ".\zend_llist.h"\ - ".\zend_operators.h"\ - ".\zend_ptr_stack.h"\ - ".\zend_stack.h"\ - ".\zend_variables.h"\ - ".\zend.h"\ - ".\zend_errors.h"\ - ".\zend_globals.h"\ - ".\zend_hash.h"\ - - -.\zend_ptr_stack.c : \ - "..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ - ".\zend_alloc.h"\ - ".\zend_config.w32.h"\ - ".\zend_ptr_stack.h"\ - ".\zend.h"\ - ".\zend_errors.h"\ - ".\zend_hash.h"\ - - -.\zend_stack.c : \ - "..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ - ".\zend_alloc.h"\ - ".\zend_config.w32.h"\ - ".\zend_stack.h"\ - ".\zend.h"\ - ".\zend_errors.h"\ - ".\zend_hash.h"\ - - -.\zend_variables.c : \ - "..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ - ".\zend_alloc.h"\ - ".\zend_compile.h"\ - ".\zend_config.w32.h"\ - ".\zend_constants.h"\ - ".\zend_execute.h"\ - ".\zend_llist.h"\ - ".\modules.h"\ - ".\zend_ptr_stack.h"\ - ".\zend_stack.h"\ - ".\zend_variables.h"\ - ".\zend.h"\ - ".\zend_API.h"\ - ".\zend_errors.h"\ - ".\zend_globals.h"\ - ".\zend_hash.h"\ - ".\zend_ini.h"\ - ".\zend_list.h"\ - - -.\zend.c : \ - "..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ - ".\zend_alloc.h"\ - ".\zend_config.w32.h"\ - ".\zend_operators.h"\ - ".\zend_variables.h"\ - ".\zend.h"\ - ".\zend_errors.h"\ - ".\zend_hash.h"\ - - -.\zend_API.c : \ - "..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ - ".\zend_alloc.h"\ - ".\zend_compile.h"\ - ".\zend_config.w32.h"\ - ".\zend_constants.h"\ - ".\zend_execute.h"\ - ".\zend_llist.h"\ - ".\modules.h"\ - ".\zend_operators.h"\ - ".\zend_ptr_stack.h"\ - ".\zend_stack.h"\ - ".\zend_variables.h"\ - ".\zend.h"\ - ".\zend_API.h"\ - ".\zend_errors.h"\ - ".\zend_globals.h"\ - ".\zend_hash.h"\ - ".\zend_ini.h"\ - ".\zend_list.h"\ - - -.\zend_hash.c : \ - "..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ - ".\zend_config.w32.h"\ - ".\zend.h"\ - ".\zend_errors.h"\ - ".\zend_hash.h"\ - - -.\zend_ini.c : \ - "..\..\..\program files\microsoft visual studio\vc98\include\basetsd.h"\ - ".\zend_alloc.h"\ - ".\zend_config.w32.h"\ - ".\zend.h"\ - ".\zend_errors.h"\ - ".\zend_hash.h"\ - ".\zend_ini.h"\ - - -!IF "$(CFG)" == "ZendCore - Win32 Release" - -!ELSEIF "$(CFG)" == "ZendCore - Win32 Debug" - -!ENDIF - -!IF "$(CFG)" == "ZendCore - Win32 Release" - -!ELSEIF "$(CFG)" == "ZendCore - Win32 Debug" - -!ENDIF - -!IF "$(CFG)" == "ZendCore - Win32 Release" - -!ELSEIF "$(CFG)" == "ZendCore - Win32 Debug" - -!ENDIF - -!IF "$(CFG)" == "ZendCore - Win32 Release" - -!ELSEIF "$(CFG)" == "ZendCore - Win32 Debug" - -!ENDIF - diff --git a/Zend/ZendTS.dsp b/Zend/ZendTS.dsp deleted file mode 100644 index 4976e6a712..0000000000 --- a/Zend/ZendTS.dsp +++ /dev/null @@ -1,440 +0,0 @@ -# Microsoft Developer Studio Project File - Name="ZendTS" - Package Owner=<4> -# Microsoft Developer Studio Generated Build File, Format Version 6.00 -# ** DO NOT EDIT ** - -# TARGTYPE "Win32 (x86) Static Library" 0x0104 - -CFG=ZendTS - Win32 Release_TS_inline -!MESSAGE This is not a valid makefile. To build this project using NMAKE, -!MESSAGE use the Export Makefile command and run -!MESSAGE -!MESSAGE NMAKE /f "ZendTS.mak". -!MESSAGE -!MESSAGE You can specify a configuration when running NMAKE -!MESSAGE by defining the macro CFG on the command line. For example: -!MESSAGE -!MESSAGE NMAKE /f "ZendTS.mak" CFG="ZendTS - Win32 Release_TS_inline" -!MESSAGE -!MESSAGE Possible choices for configuration are: -!MESSAGE -!MESSAGE "ZendTS - Win32 Release_TS" (based on "Win32 (x86) Static Library") -!MESSAGE "ZendTS - Win32 Debug_TS" (based on "Win32 (x86) Static Library") -!MESSAGE "ZendTS - Win32 Release_TS_inline" (based on "Win32 (x86) Static Library") -!MESSAGE - -# Begin Project -# PROP AllowPerConfigDependencies 0 -# PROP Scc_ProjName "" -# PROP Scc_LocalPath "" -CPP=cl.exe -RSC=rc.exe - -!IF "$(CFG)" == "ZendTS - Win32 Release_TS" - -# PROP BASE Use_MFC 0 -# PROP BASE Output_Dir "Release_TS" -# PROP BASE Intermediate_Dir "Release_TS" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Output_Dir "Release_TS" -# PROP Intermediate_Dir "Release_TS" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDebug_TS" /D "_MBCS" /D "_LIB" /YX /FD /c -# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDebug_TS" /D "_LIB" /D "TSRM_EXPORTS" /D "LIBZEND_EXPORTS" /D ZEND_DEBUG=0 /D "ZTS" /D "WIN32" /D "_MBCS" /D "ZEND_WIN32" /FR /FD /c -# SUBTRACT CPP /YX -# ADD BASE RSC /l 0x40d /d "NDebug_TS" -# ADD RSC /l 0x40d /d "NDebug_TS" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo - -!ELSEIF "$(CFG)" == "ZendTS - Win32 Debug_TS" - -# PROP BASE Use_MFC 0 -# PROP BASE Output_Dir "Debug_TS" -# PROP BASE Intermediate_Dir "Debug_TS" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Output_Dir "Debug_TS" -# PROP Intermediate_Dir "Debug_TS" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_Debug_TS" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c -# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "." /D "_Debug_TS" /D "_LIB" /D "LIBZEND_EXPORTS" /D "TSRM_EXPORTS" /D ZEND_DEBUG=1 /D "ZEND_WIN32" /D "ZTS" /D "WIN32" /D "_MBCS" /FR /YX /FD /GZ /c -# ADD BASE RSC /l 0x40d /d "_Debug_TS" -# ADD RSC /l 0x40d /d "_Debug_TS" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo - -!ELSEIF "$(CFG)" == "ZendTS - Win32 Release_TS_inline" - -# PROP BASE Use_MFC 0 -# PROP BASE Output_Dir "ZendTS___Win32_Release_TS_inline" -# PROP BASE Intermediate_Dir "ZendTS___Win32_Release_TS_inline" -# PROP BASE Target_Dir "" -# PROP Use_MFC 0 -# PROP Output_Dir "Release_TS_inline" -# PROP Intermediate_Dir "Release_TS_inline" -# PROP Target_Dir "" -# ADD BASE CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDebug_TS" /D "_LIB" /D "TSRM_EXPORTS" /D "LIBZEND_EXPORTS" /D "ZTS" /D "WIN32" /D "_MBCS" /D ZEND_DEBUG=0 /FR /FD /c -# SUBTRACT BASE CPP /YX -# ADD CPP /nologo /MD /W3 /GX /O2 /I "." /D "NDebug_TS" /D "_LIB" /D "TSRM_EXPORTS" /D "LIBZEND_EXPORTS" /D ZEND_DEBUG=0 /D "ZTS" /D "ZEND_WIN32" /D "WIN32" /D "_MBCS" /D "ZEND_WIN32_FORCE_INLINE" /FR /FD /c -# SUBTRACT CPP /YX -# ADD BASE RSC /l 0x40d /d "NDebug_TS" -# ADD RSC /l 0x40d /d "NDebug_TS" -BSC32=bscmake.exe -# ADD BASE BSC32 /nologo -# ADD BSC32 /nologo -LIB32=link.exe -lib -# ADD BASE LIB32 /nologo -# ADD LIB32 /nologo - -!ENDIF - -# Begin Target - -# Name "ZendTS - Win32 Release_TS" -# Name "ZendTS - Win32 Debug_TS" -# Name "ZendTS - Win32 Release_TS_inline" -# Begin Group "Source Files" - -# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" -# Begin Source File - -SOURCE=".\zend-parser.c" -# End Source File -# Begin Source File - -SOURCE=".\zend-scanner.cpp" -# End Source File -# Begin Source File - -SOURCE=.\zend.c -# End Source File -# Begin Source File - -SOURCE=.\zend_alloc.c -# End Source File -# Begin Source File - -SOURCE=.\zend_API.c -# End Source File -# Begin Source File - -SOURCE=.\zend_builtin_functions.c -# End Source File -# Begin Source File - -SOURCE=.\zend_compile.c -# End Source File -# Begin Source File - -SOURCE=.\zend_constants.c -# End Source File -# Begin Source File - -SOURCE=.\zend_execute.c -# End Source File -# Begin Source File - -SOURCE=.\zend_execute_API.c -# End Source File -# Begin Source File - -SOURCE=.\zend_extensions.c -# End Source File -# Begin Source File - -SOURCE=.\zend_hash.c -# End Source File -# Begin Source File - -SOURCE=.\zend_highlight.c -# End Source File -# Begin Source File - -SOURCE=.\zend_indent.c -# End Source File -# Begin Source File - -SOURCE=.\zend_list.c -# End Source File -# Begin Source File - -SOURCE=.\zend_llist.c -# End Source File -# Begin Source File - -SOURCE=.\zend_opcode.c -# End Source File -# Begin Source File - -SOURCE=.\zend_operators.c -# End Source File -# Begin Source File - -SOURCE=.\zend_ptr_stack.c -# End Source File -# Begin Source File - -SOURCE=.\zend_sprintf.c -# End Source File -# Begin Source File - -SOURCE=.\zend_stack.c -# End Source File -# Begin Source File - -SOURCE=.\zend_variables.c -# End Source File -# End Group -# Begin Group "Header Files" - -# PROP Default_Filter "h;hpp;hxx;hm;inl" -# Begin Source File - -SOURCE=.\FlexLexer.h -# End Source File -# Begin Source File - -SOURCE=.\modules.h -# End Source File -# Begin Source File - -SOURCE=".\zend-parser.h" -# End Source File -# Begin Source File - -SOURCE=".\zend-scanner.h" -# End Source File -# Begin Source File - -SOURCE=.\zend.h -# End Source File -# Begin Source File - -SOURCE=.\zend_alloc.h -# End Source File -# Begin Source File - -SOURCE=.\zend_API.h -# End Source File -# Begin Source File - -SOURCE=.\zend_builtin_functions.h -# End Source File -# Begin Source File - -SOURCE=.\zend_compile.h -# End Source File -# Begin Source File - -SOURCE=.\zend_config.w32.h -# End Source File -# Begin Source File - -SOURCE=.\zend_constants.h -# End Source File -# Begin Source File - -SOURCE=.\zend_errors.h -# End Source File -# Begin Source File - -SOURCE=.\zend_execute.h -# End Source File -# Begin Source File - -SOURCE=.\zend_execute_locks.h -# End Source File -# Begin Source File - -SOURCE=.\zend_extensions.h -# End Source File -# Begin Source File - -SOURCE=.\zend_fast_cache.h -# End Source File -# Begin Source File - -SOURCE=.\zend_globals.h -# End Source File -# Begin Source File - -SOURCE=.\zend_globals_macros.h -# End Source File -# Begin Source File - -SOURCE=.\zend_hash.h -# End Source File -# Begin Source File - -SOURCE=.\zend_highlight.h -# End Source File -# Begin Source File - -SOURCE=.\zend_indent.h -# End Source File -# Begin Source File - -SOURCE=.\zend_list.h -# End Source File -# Begin Source File - -SOURCE=.\zend_llist.h -# End Source File -# Begin Source File - -SOURCE=.\zend_operators.h -# End Source File -# Begin Source File - -SOURCE=.\zend_ptr_stack.h -# End Source File -# Begin Source File - -SOURCE=.\zend_stack.h -# End Source File -# Begin Source File - -SOURCE=.\zend_variables.h -# End Source File -# End Group -# Begin Group "Parsers" - -# PROP Default_Filter "y" -# Begin Source File - -SOURCE=".\zend-parser.y" - -!IF "$(CFG)" == "ZendTS - Win32 Release_TS" - -# Begin Custom Build -InputDir=. -InputPath=".\zend-parser.y" - -BuildCmds= \ - if not "X%CYGWIN%"=="X" bison --output=zend-parser.c -v -d -S "%CYGWIN%\share\bison.simple" -p zend zend-parser.y \ - if "X%CYGWIN%"=="X" bison --output=zend-parser.c -v -d -S "C:\Program Files\Cygnus\share\bison.simple" -p zend zend-parser.y \ - - -"$(InputDir)\zend-parser.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - $(BuildCmds) - -"$(InputDir)\zend-parser.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - $(BuildCmds) -# End Custom Build - -!ELSEIF "$(CFG)" == "ZendTS - Win32 Debug_TS" - -# Begin Custom Build -InputDir=. -InputPath=".\zend-parser.y" - -BuildCmds= \ - if not "X%CYGWIN%"=="X" bison --output=zend-parser.c -v -d -S "%CYGWIN%\share\bison.simple" -p zend zend-parser.y \ - if "X%CYGWIN%"=="X" bison --output=zend-parser.c -v -d -S "C:\Program Files\Cygnus\share\bison.simple" -p zend zend-parser.y \ - - -"$(InputDir)\zend-parser.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - $(BuildCmds) - -"$(InputDir)\zend-parser.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - $(BuildCmds) -# End Custom Build - -!ELSEIF "$(CFG)" == "ZendTS - Win32 Release_TS_inline" - -# Begin Custom Build -InputDir=. -InputPath=".\zend-parser.y" - -BuildCmds= \ - if not "X%CYGWIN%"=="X" bison --output=zend-parser.c -v -d -S "%CYGWIN%\share\bison.simple" -p zend zend-parser.y \ - if "X%CYGWIN%"=="X" bison --output=zend-parser.c -v -d -S "C:\Program Files\Cygnus\share\bison.simple" -p zend zend-parser.y \ - - -"$(InputDir)\zend-parser.c" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - $(BuildCmds) - -"$(InputDir)\zend-parser.h" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - $(BuildCmds) -# End Custom Build - -!ENDIF - -# End Source File -# End Group -# Begin Group "Scanners" - -# PROP Default_Filter "l" -# Begin Source File - -SOURCE=".\zend-scanner.l" - -!IF "$(CFG)" == "ZendTS - Win32 Release_TS" - -# Begin Custom Build -InputPath=".\zend-scanner.l" - -"zend-scanner.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - flex -+ -i -Sflex.skl -Pzend -ozend-scanner.cpp zend-scanner.l - -# End Custom Build - -!ELSEIF "$(CFG)" == "ZendTS - Win32 Debug_TS" - -# Begin Custom Build -InputPath=".\zend-scanner.l" - -"zend-scanner.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - flex -+ -B -i -Sflex.skl -Pzend -ozend-scanner.cpp zend-scanner.l - -# End Custom Build - -!ELSEIF "$(CFG)" == "ZendTS - Win32 Release_TS_inline" - -# Begin Custom Build -InputPath=".\zend-scanner.l" - -"zend-scanner.cpp" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)" - flex -+ -i -Sflex.skl -Pzend -ozend-scanner.cpp zend-scanner.l - -# End Custom Build - -!ENDIF - -# End Source File -# End Group -# Begin Group "Text Files" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=.\LICENSE -# End Source File -# Begin Source File - -SOURCE=.\ZEND_BUGS -# End Source File -# Begin Source File - -SOURCE=.\ZEND_CHANGES -# End Source File -# End Group -# Begin Group "Resources" - -# PROP Default_Filter "" -# Begin Source File - -SOURCE=.\zend.ico -# End Source File -# End Group -# End Target -# End Project diff --git a/Zend/acconfig.h b/Zend/acconfig.h deleted file mode 100644 index a6de7d427c..0000000000 --- a/Zend/acconfig.h +++ /dev/null @@ -1,66 +0,0 @@ -#define ZEND_API - -@TOP@ - -/* This is the default configuration file to read */ -#define USE_CONFIG_FILE 1 - -/* these are defined by automake */ -#undef PACKAGE -#undef VERSION - -/* define uint by configure if it is missed (QNX and BSD derived) */ -#undef uint - -/* define ulong by configure if it is missed (most probably is) */ -#undef ulong - -/* Undefine if you want stricter XML/SGML compliance by default */ -/* (this disables "" by default) */ -#define T_DEFAULT_SHORT_OPEN_TAG 1 - -/* Define both of these if you want the bundled REGEX library */ -#define REGEX 0 -#define HSREGEX 0 - -#undef ZEND_DEBUG - -/* Define if you want to enable memory limit support */ -#define MEMORY_LIMIT 0 - -/* Define to compile Zend thread safe */ -#undef ZTS - -#undef HAVE_LIBDL - -@BOTTOM@ - -#ifdef HAVE_STDLIB_H -# include -#endif - -#ifdef HAVE_SYS_TYPES_H -# include -#endif - -#ifdef HAVE_STRING_H -# include -#else -# include -#endif - -/* Define if you have stdiostream.h */ -#undef HAVE_STDIOSTREAM_H - -#if ZEND_BROKEN_SPRINTF -int zend_sprintf(char *buffer, const char *format, ...); -#else -# define zend_sprintf sprintf -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/Zend/acinclude.m4 b/Zend/acinclude.m4 deleted file mode 100644 index 7ec914d407..0000000000 --- a/Zend/acinclude.m4 +++ /dev/null @@ -1,29 +0,0 @@ -dnl $Id$ -dnl -dnl This file contains local autoconf functions. - -dnl -dnl Check for broken sprintf() -dnl -AC_DEFUN(AC_ZEND_BROKEN_SPRINTF,[ - AC_CACHE_CHECK(whether sprintf is broken, ac_cv_broken_sprintf,[ - AC_TRY_RUN([main() {char buf[20];exit(sprintf(buf,"testing 123")!=11); }],[ - ac_cv_broken_sprintf=no - ],[ - ac_cv_broken_sprintf=yes - ],[ - ac_cv_broken_sprintf=no - ]) - ]) - if test "$ac_cv_broken_sprintf" = "yes"; then - ac_result=1 - else - ac_result=0 - fi - AC_DEFINE_UNQUOTED(ZEND_BROKEN_SPRINTF, $ac_result, [Whether sprintf is broken]) -]) - -AC_DEFUN(AM_SET_LIBTOOL_VARIABLE,[ - LIBTOOL='$(SHELL) $(top_builddir)/libtool $1' -]) - diff --git a/Zend/build.mk b/Zend/build.mk deleted file mode 100644 index 6105ff12c4..0000000000 --- a/Zend/build.mk +++ /dev/null @@ -1,43 +0,0 @@ -# Makefile to generate build tools -# -# Standard usage: -# make -f build.mk -# -# Written by Sascha Schumann -# -# $Id$ - - -LT_TARGETS = ltmain.sh ltconfig - -config_h_in = zend_config.h.in - -makefile_am_files = Makefile.am -makefile_in_files = $(makefile_am_files:.am=.in) -makefile_files = $(makefile_am_files:e.am=e) - -targets = $(makefile_in_files) $(LT_TARGETS) configure $(config_h_in) - -all: $(targets) - -clean: - rm -f $(targets) - -$(LT_TARGETS): - rm -f $(LT_TARGETS) - libtoolize --automake $(AMFLAGS) -f - -$(makefile_in_files): $(makefile_am_files) - automake -a -i $(AMFLAGS) $(makefile_files) - -aclocal.m4: configure.in acinclude.m4 - aclocal - -$(config_h_in): configure.in acconfig.h -# explicitly remove target since autoheader does not seem to work -# correctly otherwise (timestamps are not updated) - @rm -f $@ - autoheader - -configure: aclocal.m4 configure.in - autoconf diff --git a/Zend/buildconf b/Zend/buildconf deleted file mode 100755 index fe8dee6f76..0000000000 --- a/Zend/buildconf +++ /dev/null @@ -1,33 +0,0 @@ -#!/bin/sh - -case "$1" in ---copy) - automake_flags=--copy - shift -;; -esac - -libtoolize --force --automake $automake_flags - -mv aclocal.m4 aclocal.m4.old 2>/dev/null -aclocal -if cmp aclocal.m4.old aclocal.m4 > /dev/null 2>&1; then - echo "buildconf: keeping ${1}aclocal.m4" - mv aclocal.m4.old aclocal.m4 -else - echo "buildconf: created or modified ${1}aclocal.m4" -fi - -autoheader - -automake --add-missing --include-deps $automake_flags - -mv configure configure.old 2>/dev/null -autoconf -if cmp configure.old configure > /dev/null 2>&1; then - echo "buildconf: keeping ${1}configure" - mv configure.old configure -else - echo "buildconf: created or modified ${1}configure" -fi - diff --git a/Zend/configure.in b/Zend/configure.in deleted file mode 100644 index 50ead57d93..0000000000 --- a/Zend/configure.in +++ /dev/null @@ -1,45 +0,0 @@ -dnl $Id$ -dnl Process this file with autoconf to produce a configure script. - -AC_INIT(zend.c) -AM_INIT_AUTOMAKE(zend, 0.80A) -AM_CONFIG_HEADER(zend_config.h) -AM_SANITY_CHECK -AM_MAINTAINER_MODE -AC_PROG_CC -AM_PROG_LEX -AM_PROG_CC_STDC -ZEND_VERSION=$VERSION - -dnl We want this one before the checks, so the checks can modify CFLAGS. -test -z "$CFLAGS" && auto_cflags=1 - -sinclude(Zend.m4) - -LIBZEND_BASIC_CHECKS - -AM_PROG_LIBTOOL -if test "$enable_debug" != "yes"; then - AM_SET_LIBTOOL_VARIABLE([--silent]) -fi - -dnl -dnl Check for /usr/pkg/{lib,include} which is where NetBSD puts binary -dnl and source packages. This should be harmless on other OSs. -dnl -if test -d /usr/pkg/include -a -d /usr/pkg/lib ; then - CFLAGS="$CFLAGS -I/usr/pkg/include" - LDFLAGS="$LDFLAGS -L/usr/pkg/lib" -fi - -LIBZEND_ENABLE_DEBUG -LIBZEND_OTHER_CHECKS - -EXTRA_LIBS="$LIBS" -LIBS="" -AC_SUBST(EXTRA_LIBS) -AC_OUTPUT(Makefile) - -# Local Variables: -# tab-width: 4 -# End: diff --git a/Zend/flex.skl b/Zend/flex.skl deleted file mode 100644 index 7c87706948..0000000000 --- a/Zend/flex.skl +++ /dev/null @@ -1,1541 +0,0 @@ -/* A lexical scanner generated by flex */ - -/* Scanner skeleton version: - * $Header$ - */ - -#define FLEX_SCANNER -#define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 5 - -%- -#include -%* - - -/* cfront 1.2 defines "c_plusplus" instead of "__cplusplus" */ -#ifdef c_plusplus -#ifndef __cplusplus -#define __cplusplus -#endif -#endif - - -#ifdef __cplusplus - -#include -%+ -class istream; -%* -#if HAVE_UNISTD_H -#include -#endif - -/* Use prototypes in function declarations. */ -#define YY_USE_PROTOS - -/* The "const" storage-class-modifier is valid. */ -#define YY_USE_CONST - -#else /* ! __cplusplus */ - -#if __STDC__ - -#define YY_USE_PROTOS -#define YY_USE_CONST - -#endif /* __STDC__ */ -#endif /* ! __cplusplus */ - -#ifdef __TURBOC__ - #pragma warn -rch - #pragma warn -use -#include -#include -#define YY_USE_CONST -#define YY_USE_PROTOS -#endif - -#ifdef YY_USE_CONST -#define yyconst const -#else -#define yyconst -#endif - - -#ifdef YY_USE_PROTOS -#define YY_PROTO(proto) proto -#else -#define YY_PROTO(proto) () -#endif - -/* Returned upon end-of-file. */ -#define YY_NULL 0 - -/* Promotes a possibly negative, possibly signed char to an unsigned - * integer for use as an array index. If the signed char is negative, - * we want to instead treat it as an 8-bit unsigned char, hence the - * double cast. - */ -#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) - -/* Enter a start condition. This macro really ought to take a parameter, - * but we do it the disgusting crufty way forced on us by the ()-less - * definition of BEGIN. - */ -#define BEGIN yy_start = 1 + 2 * - -/* Translate the current start state into a value that can be later handed - * to BEGIN to return to the state. The YYSTATE alias is for lex - * compatibility. - */ -#define YY_START ((yy_start - 1) / 2) -#define YYSTATE YY_START - -/* Action number for EOF rule of a given start state. */ -#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) - -/* Special action meaning "start processing a new file". */ -#define YY_NEW_FILE yyrestart( yyin ) - -#define YY_END_OF_BUFFER_CHAR 0 - -/* Size of default input buffer. */ -#define YY_BUF_SIZE 16384 - -typedef struct yy_buffer_state *YY_BUFFER_STATE; - -extern int yyleng; -%- -extern FILE *yyin, *yyout; -%* - -#define EOB_ACT_CONTINUE_SCAN 0 -#define EOB_ACT_END_OF_FILE 1 -#define EOB_ACT_LAST_MATCH 2 - -/* The funky do-while in the following #define is used to turn the definition - * int a single C statement (which needs a semi-colon terminator). This - * avoids problems with code like: - * - * if ( condition_holds ) - * yyless( 5 ); - * else - * do_something_else(); - * - * Prior to using the do-while the compiler would get upset at the - * "else" because it interpreted the "if" statement as being all - * done when it reached the ';' after the yyless() call. - */ - -/* Return all but the first 'n' matched characters back to the input stream. */ - -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - *yy_cp = yy_hold_char; \ - yy_c_buf_p = yy_cp = yy_bp + n - YY_MORE_ADJ; \ - YY_DO_BEFORE_ACTION; /* set up yytext again */ \ - } \ - while ( 0 ) - -#define unput(c) yyunput( c, yytext_ptr ) - -/* The following is because we cannot portably get our hands on size_t - * (without autoconf's help, which isn't available because we want - * flex-generated scanners to compile on their own). - */ -typedef unsigned int yy_size_t; - - -struct yy_buffer_state - { -%- - FILE *yy_input_file; -%+ - istream* yy_input_file; -%* - - char *yy_ch_buf; /* input buffer */ - char *yy_buf_pos; /* current position in input buffer */ - - /* Size of input buffer in bytes, not including room for EOB - * characters. - */ - yy_size_t yy_buf_size; - - /* Number of characters read into yy_ch_buf, not including EOB - * characters. - */ - int yy_n_chars; - - /* Whether we "own" the buffer - i.e., we know we created it, - * and can realloc() it to grow it, and should free() it to - * delete it. - */ - int yy_is_our_buffer; - - /* Whether this is an "interactive" input source; if so, and - * if we're using stdio for input, then we want to use getc() - * instead of fread(), to make sure we stop fetching input after - * each newline. - */ - int yy_is_interactive; - - /* Whether we're considered to be at the beginning of a line. - * If so, '^' rules will be active on the next match, otherwise - * not. - */ - int yy_at_bol; - - /* Whether to try to fill the input buffer when we reach the - * end of it. - */ - int yy_fill_buffer; - - int yy_buffer_status; -#define YY_BUFFER_NEW 0 -#define YY_BUFFER_NORMAL 1 - /* When an EOF's been seen but there's still some text to process - * then we mark the buffer as YY_EOF_PENDING, to indicate that we - * shouldn't try reading from the input source any more. We might - * still have a bunch of tokens to match, though, because of - * possible backing-up. - * - * When we actually see the EOF, we change the status to "new" - * (via yyrestart()), so that the user can continue scanning by - * just pointing yyin at a new input file. - */ -#define YY_BUFFER_EOF_PENDING 2 - }; - -%- Standard (non-C++) definition -static YY_BUFFER_STATE yy_current_buffer = 0; -%* - -/* We provide macros for accessing buffer states in case in the - * future we want to put the buffer states in a more general - * "scanner state". - */ -#define YY_CURRENT_BUFFER yy_current_buffer - - -%- Standard (non-C++) definition -/* yy_hold_char holds the character lost when yytext is formed. */ -static char yy_hold_char; - -static int yy_n_chars; /* number of characters read into yy_ch_buf */ - - -int yyleng; - -/* Points to current character in buffer. */ -static char *yy_c_buf_p = (char *) 0; -static int yy_init = 1; /* whether we need to initialize */ -static int yy_start = 0; /* start state number */ - -/* Flag which is used to allow yywrap()'s to do buffer switches - * instead of setting up a fresh yyin. A bit of a hack ... - */ -static int yy_did_buffer_switch_on_eof; - -void yyrestart YY_PROTO(( FILE *input_file )); - -void yy_switch_to_buffer YY_PROTO(( YY_BUFFER_STATE new_buffer )); -void yy_load_buffer_state YY_PROTO(( void )); -YY_BUFFER_STATE yy_create_buffer YY_PROTO(( FILE *file, int size )); -void yy_delete_buffer YY_PROTO(( YY_BUFFER_STATE b )); -void yy_init_buffer YY_PROTO(( YY_BUFFER_STATE b, FILE *file )); -void yy_flush_buffer YY_PROTO(( YY_BUFFER_STATE b )); -#define YY_FLUSH_BUFFER yy_flush_buffer( yy_current_buffer ) - -YY_BUFFER_STATE yy_scan_buffer YY_PROTO(( char *base, yy_size_t size )); -YY_BUFFER_STATE yy_scan_string YY_PROTO(( yyconst char *yy_str )); -YY_BUFFER_STATE yy_scan_bytes YY_PROTO(( yyconst char *bytes, int len )); -%* - -static void *yy_flex_alloc YY_PROTO(( yy_size_t )); -static void *yy_flex_realloc YY_PROTO(( void *, yy_size_t )); -static void yy_flex_free YY_PROTO(( void * )); - -#define yy_new_buffer yy_create_buffer - -#define yy_set_interactive(is_interactive) \ - { \ - if ( ! yy_current_buffer ) \ - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ - yy_current_buffer->yy_is_interactive = is_interactive; \ - } - -#define yy_set_bol(at_bol) \ - { \ - if ( ! yy_current_buffer ) \ - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); \ - yy_current_buffer->yy_at_bol = at_bol; \ - } - -#define YY_AT_BOL() (yy_current_buffer->yy_at_bol) - -%% yytext/yyin/yyout/yy_state_type/yylineno etc. def's & init go here - -%- Standard (non-C++) definition -static yy_state_type yy_get_previous_state YY_PROTO(( void )); -static yy_state_type yy_try_NUL_trans YY_PROTO(( yy_state_type current_state )); -static int yy_get_next_buffer YY_PROTO(( void )); -static void yy_fatal_error YY_PROTO(( yyconst char msg[] )); -%* - -/* Done after the current pattern has been matched and before the - * corresponding action - sets up yytext. - */ -#define YY_DO_BEFORE_ACTION \ - yytext_ptr = yy_bp; \ -%% code to fiddle yytext and yyleng for yymore() goes here - yy_hold_char = *yy_cp; \ - *yy_cp = '\0'; \ -%% code to copy yytext_ptr to yytext[] goes here, if %array - yy_c_buf_p = yy_cp; - -%% data tables for the DFA and the user's section 1 definitions go here - -/* Macros after this point can all be overridden by user definitions in - * section 1. - */ - -#ifndef YY_SKIP_YYWRAP -#ifdef __cplusplus -extern "C" int yywrap YY_PROTO(( void )); -#else -extern int yywrap YY_PROTO(( void )); -#endif -#endif - -%- -#ifndef YY_NO_UNPUT -static void yyunput YY_PROTO(( int c, char *buf_ptr )); -#endif -%* - -#ifndef yytext_ptr -static void yy_flex_strncpy YY_PROTO(( char *, yyconst char *, int )); -#endif - -#ifdef YY_NEED_STRLEN -static int yy_flex_strlen YY_PROTO(( yyconst char * )); -#endif - -#ifndef YY_NO_INPUT -%- Standard (non-C++) definition -#ifdef __cplusplus -static int yyinput YY_PROTO(( void )); -#else -static int input YY_PROTO(( void )); -#endif -%* -#endif - -#if YY_STACK_USED -static int yy_start_stack_ptr = 0; -static int yy_start_stack_depth = 0; -static int *yy_start_stack = 0; -#ifndef YY_NO_PUSH_STATE -static void yy_push_state YY_PROTO(( int new_state )); -#endif -#ifndef YY_NO_POP_STATE -static void yy_pop_state YY_PROTO(( void )); -#endif -#ifndef YY_NO_TOP_STATE -static int yy_top_state YY_PROTO(( void )); -#endif - -#else -#define YY_NO_PUSH_STATE 1 -#define YY_NO_POP_STATE 1 -#define YY_NO_TOP_STATE 1 -#endif - -#ifdef YY_MALLOC_DECL -YY_MALLOC_DECL -#else -#if __STDC__ -#ifndef __cplusplus -#include -#endif -#else -/* Just try to get by without declaring the routines. This will fail - * miserably on non-ANSI systems for which sizeof(size_t) != sizeof(int) - * or sizeof(void*) != sizeof(int). - */ -#endif -#endif - -/* Amount of stuff to slurp up with each read. */ -#ifndef YY_READ_BUF_SIZE -#define YY_READ_BUF_SIZE 8192 -#endif - -/* Copy whatever the last rule matched to the standard output. */ - -#ifndef ECHO -%- Standard (non-C++) definition -/* This used to be an fputs(), but since the string might contain NUL's, - * we now use fwrite(). - */ -#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) -%+ C++ definition -#define ECHO LexerOutput( yytext, yyleng ) -%* -#endif - -/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, - * is returned in "result". - */ -#ifndef YY_INPUT -#define YY_INPUT(buf,result,max_size) \ -%% fread()/read() definition of YY_INPUT goes here unless we're doing C++ -%+ C++ definition - if ( (result = LexerInput( (char *) buf, max_size )) < 0 ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); -%* -#endif - -/* No semi-colon after return; correct usage is to write "yyterminate();" - - * we don't want an extra ';' after the "return" because that will cause - * some compilers to complain about unreachable statements. - */ -#ifndef yyterminate -#define yyterminate() return YY_NULL -#endif - -/* Number of entries by which start-condition stack grows. */ -#ifndef YY_START_STACK_INCR -#define YY_START_STACK_INCR 25 -#endif - -/* Report a fatal error. */ -#ifndef YY_FATAL_ERROR -%- -#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) -%+ -#define YY_FATAL_ERROR(msg) LexerError( msg ) -%* -#endif - -/* Default declaration of generated scanner - a define so the user can - * easily add parameters. - */ -#ifndef YY_DECL -%- Standard (non-C++) definition -#define YY_DECL int yylex YY_PROTO(( void )) -%+ C++ definition -#define YY_DECL int yyFlexLexer::yylex() -%* -#endif - -/* Code executed at the beginning of each rule, after yytext and yyleng - * have been set up. - */ -#ifndef YY_USER_ACTION -#define YY_USER_ACTION -#endif - -/* Code executed at the end of each rule. */ -#ifndef YY_BREAK -#define YY_BREAK break; -#endif - -%% YY_RULE_SETUP definition goes here - -YY_DECL - { - register yy_state_type yy_current_state; - register char *yy_cp, *yy_bp; - register int yy_act; - -%% user's declarations go here - - if ( yy_init ) - { - yy_init = 0; - -#ifdef YY_USER_INIT - YY_USER_INIT; -#endif - - if ( ! yy_start ) - yy_start = 1; /* first start state */ - - if ( ! yyin ) -%- - yyin = stdin; -%+ - yyin = &cin; -%* - - if ( ! yyout ) -%- - yyout = stdout; -%+ - yyout = &cout; -%* - - if ( ! yy_current_buffer ) - yy_current_buffer = - yy_create_buffer( yyin, YY_BUF_SIZE ); - - yy_load_buffer_state(); - } - - while ( 1 ) /* loops until end-of-file is reached */ - { -%% yymore()-related code goes here - yy_cp = yy_c_buf_p; - - /* Support of yytext. */ - *yy_cp = yy_hold_char; - - /* yy_bp points to the position in yy_ch_buf of the start of - * the current run. - */ - yy_bp = yy_cp; - -%% code to set up and find next match goes here - -yy_find_action: -%% code to find the action number goes here - - YY_DO_BEFORE_ACTION; - -%% code for yylineno update goes here - -do_action: /* This label is used only to access EOF actions. */ - -%% debug code goes here - - switch ( yy_act ) - { /* beginning of action switch */ -%% actions go here - - case YY_END_OF_BUFFER: - { - /* Amount of text matched not including the EOB char. */ - int yy_amount_of_matched_text = (int) (yy_cp - yytext_ptr) - 1; - - /* Undo the effects of YY_DO_BEFORE_ACTION. */ - *yy_cp = yy_hold_char; - - if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_NEW ) - { - /* We're scanning a new file or input source. It's - * possible that this happened because the user - * just pointed yyin at a new source and called - * yylex(). If so, then we have to assure - * consistency between yy_current_buffer and our - * globals. Here is the right place to do so, because - * this is the first action (other than possibly a - * back-up) that will match for the new input source. - */ - yy_n_chars = yy_current_buffer->yy_n_chars; - yy_current_buffer->yy_input_file = yyin; - yy_current_buffer->yy_buffer_status = YY_BUFFER_NORMAL; - } - - /* Note that here we test for yy_c_buf_p "<=" to the position - * of the first EOB in the buffer, since yy_c_buf_p will - * already have been incremented past the NUL character - * (since all states make transitions on EOB to the - * end-of-buffer state). Contrast this with the test - * in input(). - */ - if ( yy_c_buf_p <= &yy_current_buffer->yy_ch_buf[yy_n_chars] ) - { /* This was really a NUL. */ - yy_state_type yy_next_state; - - yy_c_buf_p = yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state(); - - /* Okay, we're now positioned to make the NUL - * transition. We couldn't have - * yy_get_previous_state() go ahead and do it - * for us because it doesn't know how to deal - * with the possibility of jamming (and we don't - * want to build jamming into it because then it - * will run more slowly). - */ - - yy_next_state = yy_try_NUL_trans( yy_current_state ); - - yy_bp = yytext_ptr + YY_MORE_ADJ; - - if ( yy_next_state ) - { - /* Consume the NUL. */ - yy_cp = ++yy_c_buf_p; - yy_current_state = yy_next_state; - goto yy_match; - } - - else - { -%% code to do back-up for compressed tables and set up yy_cp goes here - goto yy_find_action; - } - } - - else switch ( yy_get_next_buffer() ) - { - case EOB_ACT_END_OF_FILE: - { - yy_did_buffer_switch_on_eof = 0; - - if ( yywrap() ) - { - /* Note: because we've taken care in - * yy_get_next_buffer() to have set up - * yytext, we can now set up - * yy_c_buf_p so that if some total - * hoser (like flex itself) wants to - * call the scanner after we return the - * YY_NULL, it'll still work - another - * YY_NULL will get returned. - */ - yy_c_buf_p = yytext_ptr + YY_MORE_ADJ; - - yy_act = YY_STATE_EOF(YY_START); - goto do_action; - } - - else - { - if ( ! yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; - } - break; - } - - case EOB_ACT_CONTINUE_SCAN: - yy_c_buf_p = - yytext_ptr + yy_amount_of_matched_text; - - yy_current_state = yy_get_previous_state(); - - yy_cp = yy_c_buf_p; - yy_bp = yytext_ptr + YY_MORE_ADJ; - goto yy_match; - - case EOB_ACT_LAST_MATCH: - yy_c_buf_p = - &yy_current_buffer->yy_ch_buf[yy_n_chars]; - - yy_current_state = yy_get_previous_state(); - - yy_cp = yy_c_buf_p; - yy_bp = yytext_ptr + YY_MORE_ADJ; - goto yy_find_action; - } - break; - } - - default: - YY_FATAL_ERROR( - "fatal flex scanner internal error--no action found" ); - } /* end of action switch */ - } /* end of scanning one token */ - } /* end of yylex */ - -%+ -yyFlexLexer::yyFlexLexer( istream* arg_yyin, ostream* arg_yyout ) - { - yyin = arg_yyin; - yyout = arg_yyout; - yy_c_buf_p = 0; - yy_init = 1; - yy_start = 0; - yy_flex_debug = 0; - yylineno = 1; // this will only get updated if %option yylineno - - yy_did_buffer_switch_on_eof = 0; - - yy_looking_for_trail_begin = 0; - yy_more_flag = 0; - yy_more_len = 0; - yy_more_offset = yy_prev_more_offset = 0; - - yy_start_stack_ptr = yy_start_stack_depth = 0; - yy_start_stack = 0; - - yy_current_buffer = 0; - -#ifdef YY_USES_REJECT - yy_state_buf = new yy_state_type[YY_BUF_SIZE + 2]; -#else - yy_state_buf = 0; -#endif - } - -yyFlexLexer::~yyFlexLexer() - { - delete yy_state_buf; - yy_delete_buffer( yy_current_buffer ); - } - -void yyFlexLexer::switch_streams( istream* new_in, ostream* new_out ) - { - if ( new_in ) - { - yy_delete_buffer( yy_current_buffer ); - yy_switch_to_buffer( yy_create_buffer( new_in, YY_BUF_SIZE ) ); - } - - if ( new_out ) - yyout = new_out; - } - -#ifdef YY_INTERACTIVE -int yyFlexLexer::LexerInput( char* buf, int /* max_size */ ) -#else -int yyFlexLexer::LexerInput( char* buf, int max_size ) -#endif - { - if ( yyin->eof() || yyin->fail() ) - return 0; - -#ifdef YY_INTERACTIVE - yyin->get( buf[0] ); - - if ( yyin->eof() ) - return 0; - - if ( yyin->bad() ) - return -1; - - return 1; - -#else - (void) yyin->read( buf, max_size ); - - if ( yyin->bad() ) - return -1; - else - return yyin->gcount(); -#endif - } - -void yyFlexLexer::LexerOutput( const char* buf, int size ) - { - (void) yyout->write( buf, size ); - } -%* - -/* yy_get_next_buffer - try to read in a new buffer - * - * Returns a code representing an action: - * EOB_ACT_LAST_MATCH - - * EOB_ACT_CONTINUE_SCAN - continue scanning from current position - * EOB_ACT_END_OF_FILE - end of file - */ - -%- -static int yy_get_next_buffer() -%+ -int yyFlexLexer::yy_get_next_buffer() -%* - { - register char *dest = yy_current_buffer->yy_ch_buf; - register char *source = yytext_ptr; - register int number_to_move, i; - int ret_val; - - if ( yy_c_buf_p > &yy_current_buffer->yy_ch_buf[yy_n_chars + 1] ) - YY_FATAL_ERROR( - "fatal flex scanner internal error--end of buffer missed" ); - - if ( yy_current_buffer->yy_fill_buffer == 0 ) - { /* Don't try to fill the buffer, so this is an EOF. */ - if ( yy_c_buf_p - yytext_ptr - YY_MORE_ADJ == 1 ) - { - /* We matched a single character, the EOB, so - * treat this as a final EOF. - */ - return EOB_ACT_END_OF_FILE; - } - - else - { - /* We matched some text prior to the EOB, first - * process it. - */ - return EOB_ACT_LAST_MATCH; - } - } - - /* Try to read more data. */ - - /* First move last chars to start of buffer. */ - number_to_move = (int) (yy_c_buf_p - yytext_ptr) - 1; - - for ( i = 0; i < number_to_move; ++i ) - *(dest++) = *(source++); - - if ( yy_current_buffer->yy_buffer_status == YY_BUFFER_EOF_PENDING ) - /* don't do the read, it's not guaranteed to return an EOF, - * just force an EOF - */ - yy_current_buffer->yy_n_chars = yy_n_chars = 0; - - else - { - int num_to_read = - yy_current_buffer->yy_buf_size - number_to_move - 1; - - while ( num_to_read <= 0 ) - { /* Not enough room in the buffer - grow it. */ -#ifdef YY_USES_REJECT - YY_FATAL_ERROR( -"input buffer overflow, can't enlarge buffer because scanner uses REJECT" ); -#else - - /* just a shorter name for the current buffer */ - YY_BUFFER_STATE b = yy_current_buffer; - - int yy_c_buf_p_offset = - (int) (yy_c_buf_p - b->yy_ch_buf); - - if ( b->yy_is_our_buffer ) - { - int new_size = b->yy_buf_size * 2; - - if ( new_size <= 0 ) - b->yy_buf_size += b->yy_buf_size / 8; - else - b->yy_buf_size *= 2; - - b->yy_ch_buf = (char *) - /* Include room in for 2 EOB chars. */ - yy_flex_realloc( (void *) b->yy_ch_buf, - b->yy_buf_size + 2 ); - } - else - /* Can't grow it, we don't own it. */ - b->yy_ch_buf = 0; - - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( - "fatal error - scanner input buffer overflow" ); - - yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset]; - - num_to_read = yy_current_buffer->yy_buf_size - - number_to_move - 1; -#endif - } - - if ( num_to_read > YY_READ_BUF_SIZE ) - num_to_read = YY_READ_BUF_SIZE; - - /* Read in more data. */ - YY_INPUT( (&yy_current_buffer->yy_ch_buf[number_to_move]), - yy_n_chars, num_to_read ); - - yy_current_buffer->yy_n_chars = yy_n_chars; - } - - if ( yy_n_chars == 0 ) - { - if ( number_to_move == YY_MORE_ADJ ) - { - ret_val = EOB_ACT_END_OF_FILE; - yyrestart( yyin ); - } - - else - { - ret_val = EOB_ACT_LAST_MATCH; - yy_current_buffer->yy_buffer_status = - YY_BUFFER_EOF_PENDING; - } - } - - else - ret_val = EOB_ACT_CONTINUE_SCAN; - - yy_n_chars += number_to_move; - yy_current_buffer->yy_ch_buf[yy_n_chars] = YY_END_OF_BUFFER_CHAR; - yy_current_buffer->yy_ch_buf[yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR; - - yytext_ptr = &yy_current_buffer->yy_ch_buf[0]; - - return ret_val; - } - - -/* yy_get_previous_state - get the state just before the EOB char was reached */ - -%- -static yy_state_type yy_get_previous_state() -%+ -yy_state_type yyFlexLexer::yy_get_previous_state() -%* - { - register yy_state_type yy_current_state; - register char *yy_cp; - -%% code to get the start state into yy_current_state goes here - - for ( yy_cp = yytext_ptr + YY_MORE_ADJ; yy_cp < yy_c_buf_p; ++yy_cp ) - { -%% code to find the next state goes here - } - - return yy_current_state; - } - - -/* yy_try_NUL_trans - try to make a transition on the NUL character - * - * synopsis - * next_state = yy_try_NUL_trans( current_state ); - */ - -%- -#ifdef YY_USE_PROTOS -static yy_state_type yy_try_NUL_trans( yy_state_type yy_current_state ) -#else -static yy_state_type yy_try_NUL_trans( yy_current_state ) -yy_state_type yy_current_state; -#endif -%+ -yy_state_type yyFlexLexer::yy_try_NUL_trans( yy_state_type yy_current_state ) -%* - { - register int yy_is_jam; -%% code to find the next state, and perhaps do backing up, goes here - - return yy_is_jam ? 0 : yy_current_state; - } - - -%- -#ifndef YY_NO_UNPUT -#ifdef YY_USE_PROTOS -static void yyunput( int c, register char *yy_bp ) -#else -static void yyunput( c, yy_bp ) -int c; -register char *yy_bp; -#endif -%+ -void yyFlexLexer::yyunput( int c, register char* yy_bp ) -%* - { - register char *yy_cp = yy_c_buf_p; - - /* undo effects of setting up yytext */ - *yy_cp = yy_hold_char; - - if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) - { /* need to shift things up to make room */ - /* +2 for EOB chars. */ - register int number_to_move = yy_n_chars + 2; - register char *dest = &yy_current_buffer->yy_ch_buf[ - yy_current_buffer->yy_buf_size + 2]; - register char *source = - &yy_current_buffer->yy_ch_buf[number_to_move]; - - while ( source > yy_current_buffer->yy_ch_buf ) - *--dest = *--source; - - yy_cp += (int) (dest - source); - yy_bp += (int) (dest - source); - yy_current_buffer->yy_n_chars = - yy_n_chars = yy_current_buffer->yy_buf_size; - - if ( yy_cp < yy_current_buffer->yy_ch_buf + 2 ) - YY_FATAL_ERROR( "flex scanner push-back overflow" ); - } - - *--yy_cp = (char) c; - -%% update yylineno here - - yytext_ptr = yy_bp; - yy_hold_char = *yy_cp; - yy_c_buf_p = yy_cp; - } -%- -#endif /* ifndef YY_NO_UNPUT */ -%* - - -%- -#ifdef __cplusplus -static int yyinput() -#else -static int input() -#endif -%+ -int yyFlexLexer::yyinput() -%* - { - int c; - - *yy_c_buf_p = yy_hold_char; - - if ( *yy_c_buf_p == YY_END_OF_BUFFER_CHAR ) - { - /* yy_c_buf_p now points to the character we want to return. - * If this occurs *before* the EOB characters, then it's a - * valid NUL; if not, then we've hit the end of the buffer. - */ - if ( yy_c_buf_p < &yy_current_buffer->yy_ch_buf[yy_n_chars] ) - /* This was really a NUL. */ - *yy_c_buf_p = '\0'; - - else - { /* need more input */ - int offset = yy_c_buf_p - yytext_ptr; - ++yy_c_buf_p; - - switch ( yy_get_next_buffer() ) - { - case EOB_ACT_LAST_MATCH: - /* This happens because yy_g_n_b() - * sees that we've accumulated a - * token and flags that we need to - * try matching the token before - * proceeding. But for input(), - * there's no matching to consider. - * So convert the EOB_ACT_LAST_MATCH - * to EOB_ACT_END_OF_FILE. - */ - - /* Reset buffer status. */ - yyrestart( yyin ); - - /* fall through */ - - case EOB_ACT_END_OF_FILE: - { - if ( yywrap() ) - return EOF; - - if ( ! yy_did_buffer_switch_on_eof ) - YY_NEW_FILE; -#ifdef __cplusplus - return yyinput(); -#else - return input(); -#endif - } - - case EOB_ACT_CONTINUE_SCAN: - yy_c_buf_p = yytext_ptr + offset; - break; - } - } - } - - c = *(unsigned char *) yy_c_buf_p; /* cast for 8-bit char's */ - *yy_c_buf_p = '\0'; /* preserve yytext */ - yy_hold_char = *++yy_c_buf_p; - -%% update BOL and yylineno - - return c; - } - - -%- -#ifdef YY_USE_PROTOS -void yyrestart( FILE *input_file ) -#else -void yyrestart( input_file ) -FILE *input_file; -#endif -%+ -void yyFlexLexer::yyrestart( istream* input_file ) -%* - { - if ( ! yy_current_buffer ) - yy_current_buffer = yy_create_buffer( yyin, YY_BUF_SIZE ); - - yy_init_buffer( yy_current_buffer, input_file ); - yy_load_buffer_state(); - } - - -%- -#ifdef YY_USE_PROTOS -void yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) -#else -void yy_switch_to_buffer( new_buffer ) -YY_BUFFER_STATE new_buffer; -#endif -%+ -void yyFlexLexer::yy_switch_to_buffer( YY_BUFFER_STATE new_buffer ) -%* - { - if ( yy_current_buffer == new_buffer ) - return; - - if ( yy_current_buffer ) - { - /* Flush out information for old buffer. */ - *yy_c_buf_p = yy_hold_char; - yy_current_buffer->yy_buf_pos = yy_c_buf_p; - yy_current_buffer->yy_n_chars = yy_n_chars; - } - - yy_current_buffer = new_buffer; - yy_load_buffer_state(); - - /* We don't actually know whether we did this switch during - * EOF (yywrap()) processing, but the only time this flag - * is looked at is after yywrap() is called, so it's safe - * to go ahead and always set it. - */ - yy_did_buffer_switch_on_eof = 1; - } - - -%- -#ifdef YY_USE_PROTOS -void yy_load_buffer_state( void ) -#else -void yy_load_buffer_state() -#endif -%+ -void yyFlexLexer::yy_load_buffer_state() -%* - { - yy_n_chars = yy_current_buffer->yy_n_chars; - yytext_ptr = yy_c_buf_p = yy_current_buffer->yy_buf_pos; - yyin = yy_current_buffer->yy_input_file; - yy_hold_char = *yy_c_buf_p; - } - - -%- -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_create_buffer( FILE *file, int size ) -#else -YY_BUFFER_STATE yy_create_buffer( file, size ) -FILE *file; -int size; -#endif -%+ -YY_BUFFER_STATE yyFlexLexer::yy_create_buffer( istream* file, int size ) -%* - { - YY_BUFFER_STATE b; - - b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_buf_size = size; - - /* yy_ch_buf has to be 2 characters longer than the size given because - * we need to put in 2 end-of-buffer characters. - */ - b->yy_ch_buf = (char *) yy_flex_alloc( b->yy_buf_size + 2 ); - if ( ! b->yy_ch_buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - - b->yy_is_our_buffer = 1; - - yy_init_buffer( b, file ); - - return b; - } - - -%- -#ifdef YY_USE_PROTOS -void yy_delete_buffer( YY_BUFFER_STATE b ) -#else -void yy_delete_buffer( b ) -YY_BUFFER_STATE b; -#endif -%+ -void yyFlexLexer::yy_delete_buffer( YY_BUFFER_STATE b ) -%* - { - if ( ! b ) - return; - - if ( b == yy_current_buffer ) - yy_current_buffer = (YY_BUFFER_STATE) 0; - - if ( b->yy_is_our_buffer ) - yy_flex_free( (void *) b->yy_ch_buf ); - - yy_flex_free( (void *) b ); - } - - -%- -#ifndef YY_ALWAYS_INTERACTIVE -#ifndef YY_NEVER_INTERACTIVE -extern int isatty YY_PROTO(( int )); -#endif -#endif - -#ifdef YY_USE_PROTOS -void yy_init_buffer( YY_BUFFER_STATE b, FILE *file ) -#else -void yy_init_buffer( b, file ) -YY_BUFFER_STATE b; -FILE *file; -#endif - -%+ -extern "C" int isatty YY_PROTO(( int )); -void yyFlexLexer::yy_init_buffer( YY_BUFFER_STATE b, istream* file ) -%* - - { - yy_flush_buffer( b ); - - b->yy_input_file = file; - b->yy_fill_buffer = 1; - -%- -#if YY_ALWAYS_INTERACTIVE - b->yy_is_interactive = 1; -#else -#if YY_NEVER_INTERACTIVE - b->yy_is_interactive = 0; -#else - b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; -#endif -#endif -%+ - b->yy_is_interactive = 0; -%* - } - - -%- -#ifdef YY_USE_PROTOS -void yy_flush_buffer( YY_BUFFER_STATE b ) -#else -void yy_flush_buffer( b ) -YY_BUFFER_STATE b; -#endif - -%+ -void yyFlexLexer::yy_flush_buffer( YY_BUFFER_STATE b ) -%* - { - if ( ! b ) - return; - - b->yy_n_chars = 0; - - /* We always need two end-of-buffer characters. The first causes - * a transition to the end-of-buffer state. The second causes - * a jam in that state. - */ - b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; - b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; - - b->yy_buf_pos = &b->yy_ch_buf[0]; - - b->yy_at_bol = 1; - b->yy_buffer_status = YY_BUFFER_NEW; - - if ( b == yy_current_buffer ) - yy_load_buffer_state(); - } -%* - - -#ifndef YY_NO_SCAN_BUFFER -%- -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_buffer( char *base, yy_size_t size ) -#else -YY_BUFFER_STATE yy_scan_buffer( base, size ) -char *base; -yy_size_t size; -#endif - { - YY_BUFFER_STATE b; - - if ( size < 2 || - base[size-2] != YY_END_OF_BUFFER_CHAR || - base[size-1] != YY_END_OF_BUFFER_CHAR ) - /* They forgot to leave room for the EOB's. */ - return 0; - - b = (YY_BUFFER_STATE) yy_flex_alloc( sizeof( struct yy_buffer_state ) ); - if ( ! b ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); - - b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ - b->yy_buf_pos = b->yy_ch_buf = base; - b->yy_is_our_buffer = 0; - b->yy_input_file = 0; - b->yy_n_chars = b->yy_buf_size; - b->yy_is_interactive = 0; - b->yy_at_bol = 1; - b->yy_fill_buffer = 0; - b->yy_buffer_status = YY_BUFFER_NEW; - - yy_switch_to_buffer( b ); - - return b; - } -%* -#endif - - -#ifndef YY_NO_SCAN_STRING -%- -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_string( yyconst char *yy_str ) -#else -YY_BUFFER_STATE yy_scan_string( yy_str ) -yyconst char *yy_str; -#endif - { - int len; - for ( len = 0; yy_str[len]; ++len ) - ; - - return yy_scan_bytes( yy_str, len ); - } -%* -#endif - - -#ifndef YY_NO_SCAN_BYTES -%- -#ifdef YY_USE_PROTOS -YY_BUFFER_STATE yy_scan_bytes( yyconst char *bytes, int len ) -#else -YY_BUFFER_STATE yy_scan_bytes( bytes, len ) -yyconst char *bytes; -int len; -#endif - { - YY_BUFFER_STATE b; - char *buf; - yy_size_t n; - int i; - - /* Get memory for full buffer, including space for trailing EOB's. */ - n = len + 2; - buf = (char *) yy_flex_alloc( n ); - if ( ! buf ) - YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); - - for ( i = 0; i < len; ++i ) - buf[i] = bytes[i]; - - buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; - - b = yy_scan_buffer( buf, n ); - if ( ! b ) - YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); - - /* It's okay to grow etc. this buffer, and we should throw it - * away when we're done. - */ - b->yy_is_our_buffer = 1; - - return b; - } -%* -#endif - - -#ifndef YY_NO_PUSH_STATE -%- -#ifdef YY_USE_PROTOS -static void yy_push_state( int new_state ) -#else -static void yy_push_state( new_state ) -int new_state; -#endif -%+ -void yyFlexLexer::yy_push_state( int new_state ) -%* - { - if ( yy_start_stack_ptr >= yy_start_stack_depth ) - { - yy_size_t new_size; - - yy_start_stack_depth += YY_START_STACK_INCR; - new_size = yy_start_stack_depth * sizeof( int ); - - if ( ! yy_start_stack ) - yy_start_stack = (int *) yy_flex_alloc( new_size ); - - else - yy_start_stack = (int *) yy_flex_realloc( - (void *) yy_start_stack, new_size ); - - if ( ! yy_start_stack ) - YY_FATAL_ERROR( - "out of memory expanding start-condition stack" ); - } - - yy_start_stack[yy_start_stack_ptr++] = YY_START; - - BEGIN(new_state); - } -#endif - - -#ifndef YY_NO_POP_STATE -%- -static void yy_pop_state() -%+ -void yyFlexLexer::yy_pop_state() -%* - { - if ( --yy_start_stack_ptr < 0 ) - YY_FATAL_ERROR( "start-condition stack underflow" ); - - BEGIN(yy_start_stack[yy_start_stack_ptr]); - } -#endif - - -#ifndef YY_NO_TOP_STATE -%- -static int yy_top_state() -%+ -int yyFlexLexer::yy_top_state() -%* - { - return yy_start_stack[yy_start_stack_ptr - 1]; - } -#endif - -#ifndef YY_EXIT_FAILURE -#define YY_EXIT_FAILURE 2 -#endif - -%- -#ifdef YY_USE_PROTOS -static void yy_fatal_error( yyconst char msg[] ) -#else -static void yy_fatal_error( msg ) -char msg[]; -#endif - { - (void) fprintf( stderr, "%s\n", msg ); - exit( YY_EXIT_FAILURE ); - } - -%+ - -void yyFlexLexer::LexerError( yyconst char msg[] ) - { - cerr << msg << '\n'; - exit( YY_EXIT_FAILURE ); - } -%* - - -/* Redefine yyless() so it works in section 3 code. */ - -#undef yyless -#define yyless(n) \ - do \ - { \ - /* Undo effects of setting up yytext. */ \ - yytext[yyleng] = yy_hold_char; \ - yy_c_buf_p = yytext + n; \ - yy_hold_char = *yy_c_buf_p; \ - *yy_c_buf_p = '\0'; \ - yyleng = n; \ - } \ - while ( 0 ) - - -/* Internal utility routines. */ - -#ifndef yytext_ptr -#ifdef YY_USE_PROTOS -static void yy_flex_strncpy( char *s1, yyconst char *s2, int n ) -#else -static void yy_flex_strncpy( s1, s2, n ) -char *s1; -yyconst char *s2; -int n; -#endif - { - register int i; - for ( i = 0; i < n; ++i ) - s1[i] = s2[i]; - } -#endif - -#ifdef YY_NEED_STRLEN -#ifdef YY_USE_PROTOS -static int yy_flex_strlen( yyconst char *s ) -#else -static int yy_flex_strlen( s ) -yyconst char *s; -#endif - { - register int n; - for ( n = 0; s[n]; ++n ) - ; - - return n; - } -#endif - - -#ifdef YY_USE_PROTOS -static void *yy_flex_alloc( yy_size_t size ) -#else -static void *yy_flex_alloc( size ) -yy_size_t size; -#endif - { - return (void *) malloc( size ); - } - -#ifdef YY_USE_PROTOS -static void *yy_flex_realloc( void *ptr, yy_size_t size ) -#else -static void *yy_flex_realloc( ptr, size ) -void *ptr; -yy_size_t size; -#endif - { - /* The cast to (char *) in the following accommodates both - * implementations that use char* generic pointers, and those - * that use void* generic pointers. It works with the latter - * because both ANSI C and C++ allow castless assignment from - * any pointer type to void*, and deal with argument conversions - * as though doing an assignment. - */ - return (void *) realloc( (char *) ptr, size ); - } - -#ifdef YY_USE_PROTOS -static void yy_flex_free( void *ptr ) -#else -static void yy_flex_free( ptr ) -void *ptr; -#endif - { - free( ptr ); - } - -#if YY_MAIN -int main() - { - yylex(); - return 0; - } -#endif diff --git a/Zend/zend-parser.y b/Zend/zend-parser.y deleted file mode 100644 index 0d1d911dac..0000000000 --- a/Zend/zend-parser.y +++ /dev/null @@ -1,717 +0,0 @@ -%{ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - -/* - * LALR shift/reduce conflicts and how they are resolved: - * - * - 2 shift/reduce conflicts due to the dangeling elseif/else ambiguity. Solved by shift. - * - 1 shift/reduce conflict due to arrays within encapsulated strings. Solved by shift. - * - 1 shift/reduce conflict due to objects within encapsulated strings. Solved by shift. - * - */ - - -#include "zend_compile.h" -#include "zend.h" -#include "zend_list.h" -#include "zend_globals.h" -#include "zend_API.h" -#include "zend_variables.h" -#include "zend_operators.h" - -#define YYERROR_VERBOSE -#define YYSTYPE znode -#ifdef ZTS -# define YYPARSE_PARAM compiler_globals -# define YYLEX_PARAM compiler_globals -#endif - - -%} - -%pure_parser -%expect 7 - -%left T_INCLUDE T_EVAL T_IMPORT -%left ',' -%left T_LOGICAL_OR -%left T_LOGICAL_XOR -%left T_LOGICAL_AND -%right T_PRINT -%left '=' T_PLUS_EQUAL T_MINUS_EQUAL T_MUL_EQUAL T_DIV_EQUAL T_CONCAT_EQUAL T_MOD_EQUAL T_AND_EQUAL T_OR_EQUAL XT_OR_EQUAL T_SL_EQUAL T_SR_EQUAL -%left '?' ':' -%left T_BOOLEAN_OR -%left T_BOOLEAN_AND -%left '|' -%left '^' -%left '&' -%nonassoc T_IS_EQUAL T_IS_NOT_EQUAL T_IS_IDENTICAL -%nonassoc '<' T_IS_SMALLER_OR_EQUAL '>' T_IS_GREATER_OR_EQUAL -%left T_SL T_SR -%left '+' '-' '.' -%left '*' '/' '%' -%right '!' '~' T_INC T_DEC T_INT_CAST T_DOUBLE_CAST T_STRING_CAST T_ARRAY_CAST T_OBJECT_CAST T_BOOL_CAST T_UNSET_CAST '@' -%right '[' -%nonassoc T_NEW -%token T_EXIT -%token T_IF -%left T_ELSEIF -%left T_ELSE -%left T_ENDIF -%token T_LNUMBER -%token T_DNUMBER -%token T_STRING -%token T_STRING_VARNAME -%token T_VARIABLE -%token T_NUM_STRING -%token T_INLINE_HTML -%token T_CHARACTER -%token T_BAD_CHARACTER -%token T_ENCAPSED_AND_WHITESPACE -%token T_CONSTANT_ENCAPSED_STRING -%token T_ECHO -%token T_DO -%token T_WHILE -%token T_ENDWHILE -%token T_FOR -%token T_ENDFOR -%token T_FOREACH -%token T_ENDFOREACH -%token T_DECLARE -%token T_ENDDECLARE -%token T_AS -%token T_SWITCH -%token T_ENDSWITCH -%token T_CASE -%token T_DEFAULT -%token T_BREAK -%token T_CONTINUE -%token T_OLD_FUNCTION -%token T_FUNCTION -%token T_CONST -%token T_RETURN -%token T_REQUIRE -%token T_USE -%token T_GLOBAL -%token T_STATIC -%token T_VAR -%token T_UNSET -%token T_ISSET -%token T_EMPTY -%token T_CLASS -%token T_EXTENDS -%token T_OBJECT_OPERATOR -%token T_DOUBLE_ARROW -%token T_LIST -%token T_ARRAY -%token T_LINE -%token T_FILE -%token T_COMMENT -%token T_ML_COMMENT -%token T_OPEN_TAG -%token T_OPEN_TAG_WITH_ECHO -%token T_CLOSE_TAG -%token T_WHITESPACE -%token T_START_HEREDOC -%token T_END_HEREDOC -%token T_DOLLAR_OPEN_CURLY_BRACES -%token T_CURLY_OPEN -%token T_PAAMAYIM_NEKUDOTAYIM -%token T_PHP_TRACK_VARS - -%% /* Rules */ - -start: - top_statement_list -; - -top_statement_list: - top_statement_list { do_extended_info(CLS_C); } top_statement { HANDLE_INTERACTIVE(); } - | /* empty */ -; - - -top_statement: - statement - | declaration_statement { do_early_binding(CLS_C); } -; - - -inner_statement_list: - inner_statement_list { do_extended_info(CLS_C); } inner_statement { HANDLE_INTERACTIVE(); } - | /* empty */ -; - - -inner_statement: - statement - | declaration_statement -; - - -statement: - unticked_statement { do_ticks(CLS_C); } -; - - -unticked_statement: - '{' inner_statement_list '}' - | T_IF '(' expr ')' { do_if_cond(&$3, &$4 CLS_CC); } statement { do_if_after_statement(&$4, 1 CLS_CC); } elseif_list else_single { do_if_end(CLS_C); } - | T_IF '(' expr ')' ':' { do_if_cond(&$3, &$4 CLS_CC); } inner_statement_list { do_if_after_statement(&$4, 1 CLS_CC); } new_elseif_list new_else_single T_ENDIF ';' { do_if_end(CLS_C); } - | T_WHILE '(' { $1.u.opline_num = get_next_op_number(CG(active_op_array)); } expr ')' { do_while_cond(&$4, &$5 CLS_CC); } while_statement { do_while_end(&$1, &$5 CLS_CC); } - | T_DO { $1.u.opline_num = get_next_op_number(CG(active_op_array)); do_do_while_begin(CLS_C); } statement T_WHILE '(' { $5.u.opline_num = get_next_op_number(CG(active_op_array)); } expr ')' ';' { do_do_while_end(&$1, &$5, &$7 CLS_CC); } - | T_FOR - '(' - for_expr - ';' { do_free(&$3 CLS_CC); $4.u.opline_num = get_next_op_number(CG(active_op_array)); } - for_expr - ';' { do_for_cond(&$6, &$7 CLS_CC); } - for_expr - ')' { do_free(&$9 CLS_CC); do_for_before_statement(&$4, &$7 CLS_CC); } - for_statement { do_for_end(&$7 CLS_CC); } - | T_SWITCH '(' expr ')' { do_switch_cond(&$3 CLS_CC); } switch_case_list { do_switch_end(&$6 CLS_CC); } - | T_BREAK ';' { do_brk_cont(ZEND_BRK, NULL CLS_CC); } - | T_BREAK expr ';' { do_brk_cont(ZEND_BRK, &$2 CLS_CC); } - | T_CONTINUE ';' { do_brk_cont(ZEND_CONT, NULL CLS_CC); } - | T_CONTINUE expr ';' { do_brk_cont(ZEND_CONT, &$2 CLS_CC); } - | T_RETURN ';' { do_return(NULL, 0 CLS_CC); } - | T_RETURN expr_without_variable ';' { do_return(&$2, 0 CLS_CC); } - | T_RETURN cvar ';' { do_return(&$2, 1 CLS_CC); } - | T_GLOBAL global_var_list - | T_STATIC static_var_list - | T_ECHO echo_expr_list ';' - | T_INLINE_HTML { do_echo(&$1 CLS_CC); } - | expr ';' { do_free(&$1 CLS_CC); } - | T_REQUIRE expr ';' { do_require(&$2 CLS_CC); } - | T_USE use_filename ';' { use_filename($2.u.constant.value.str.val, $2.u.constant.value.str.len CLS_CC); zval_dtor(&$2.u.constant); } - | T_UNSET '(' cvar ')' ';' { do_end_variable_parse(BP_VAR_UNSET, 0 CLS_CC); do_unset(&$3 CLS_CC); } - | T_FOREACH '(' expr T_AS { do_foreach_begin(&$1, &$3, &$2, &$4 CLS_CC); } w_cvar foreach_optional_arg ')' { do_foreach_cont(&$6, &$7, &$4 CLS_CC); } foreach_statement { do_foreach_end(&$1, &$2 CLS_CC); } - | T_DECLARE { do_declare_begin(CLS_C); } '(' declare_list ')' declare_statement { do_declare_end(CLS_C); } - | ';' /* empty statement */ -; - - -use_filename: - T_CONSTANT_ENCAPSED_STRING { $$ = $1; } - | '(' T_CONSTANT_ENCAPSED_STRING ')' { $$ = $2; } -; - - -declaration_statement: - unticked_declaration_statement { do_ticks(CLS_C); } -; - - -unticked_declaration_statement: - T_FUNCTION { $1.u.opline_num = CG(zend_lineno); } is_reference T_STRING { do_begin_function_declaration(&$1, &$4, 0, $3.op_type CLS_CC); } - '(' parameter_list ')' '{' inner_statement_list '}' { do_end_function_declaration(&$1 CLS_CC); } - | T_OLD_FUNCTION { $1.u.opline_num = CG(zend_lineno); } is_reference T_STRING { do_begin_function_declaration(&$1, &$4, 0, $3.op_type CLS_CC); } - parameter_list '(' inner_statement_list ')' ';' { do_end_function_declaration(&$1 CLS_CC); } - | T_CLASS T_STRING { do_begin_class_declaration(&$2, NULL CLS_CC); } '{' class_statement_list '}' { do_end_class_declaration(CLS_C); } - | T_CLASS T_STRING T_EXTENDS T_STRING { do_begin_class_declaration(&$2, &$4 CLS_CC); } '{' class_statement_list '}' { do_end_class_declaration(CLS_C); } -; - - -foreach_optional_arg: - /* empty */ { $$.op_type = IS_UNUSED; } - | T_DOUBLE_ARROW w_cvar { $$ = $2; } -; - - -for_statement: - statement - | ':' inner_statement_list T_ENDFOR ';' -; - - -foreach_statement: - statement - | ':' inner_statement_list T_ENDFOREACH ';' -; - - -declare_statement: - statement - | ':' inner_statement_list T_ENDDECLARE ';' -; - - -declare_list: - T_STRING '=' static_scalar { do_declare_stmt(&$1, &$3 CLS_CC); } - | declare_list ',' T_STRING '=' static_scalar { do_declare_stmt(&$3, &$5 CLS_CC); } -; - - -switch_case_list: - '{' case_list '}' { $$ = $2; } - | '{' ';' case_list '}' { $$ = $3; } - | ':' case_list T_ENDSWITCH ';' { $$ = $2; } - | ':' ';' case_list T_ENDSWITCH ';' { $$ = $3; } -; - - -case_list: - /* empty */ { $$.u.opline_num = -1; } - | case_list T_CASE expr case_separator { do_case_before_statement(&$1, &$2, &$3 CLS_CC); } inner_statement_list { do_case_after_statement(&$$, &$2 CLS_CC); } - | case_list T_DEFAULT case_separator { do_default_before_statement(&$1, &$2 CLS_CC); } inner_statement_list { do_case_after_statement(&$$, &$2 CLS_CC); } -; - - -case_separator: - ':' - | ';' -; - - -while_statement: - statement - | ':' inner_statement_list T_ENDWHILE ';' -; - - - -elseif_list: - /* empty */ - | elseif_list T_ELSEIF '(' expr ')' { do_if_cond(&$4, &$5 CLS_CC); } statement { do_if_after_statement(&$5, 0 CLS_CC); } -; - - -new_elseif_list: - /* empty */ - | new_elseif_list T_ELSEIF '(' expr ')' ':' { do_if_cond(&$4, &$5 CLS_CC); } inner_statement_list { do_if_after_statement(&$5, 0 CLS_CC); } -; - - -else_single: - /* empty */ - | T_ELSE statement -; - - -new_else_single: - /* empty */ - | T_ELSE ':' inner_statement_list -; - - - - -parameter_list: - non_empty_parameter_list - | /* empty */ -; - - -non_empty_parameter_list: - T_VARIABLE { znode tmp; fetch_simple_variable(&tmp, &$1, 0 CLS_CC); $$.op_type = IS_CONST; $$.u.constant.value.lval=1; $$.u.constant.type=IS_LONG; INIT_PZVAL(&$$.u.constant); do_receive_arg(ZEND_RECV, &tmp, &$$, NULL, BYREF_NONE CLS_CC); } - | '&' T_VARIABLE { znode tmp; fetch_simple_variable(&tmp, &$2, 0 CLS_CC); $$.op_type = IS_CONST; $$.u.constant.value.lval=1; $$.u.constant.type=IS_LONG; INIT_PZVAL(&$$.u.constant); do_receive_arg(ZEND_RECV, &tmp, &$$, NULL, BYREF_FORCE CLS_CC); } - | T_CONST T_VARIABLE { znode tmp; fetch_simple_variable(&tmp, &$2, 0 CLS_CC); $$.op_type = IS_CONST; $$.u.constant.value.lval=1; $$.u.constant.type=IS_LONG; INIT_PZVAL(&$$.u.constant); do_receive_arg(ZEND_RECV, &tmp, &$$, NULL, BYREF_NONE CLS_CC); } - | T_VARIABLE '=' static_scalar { znode tmp; fetch_simple_variable(&tmp, &$1, 0 CLS_CC); $$.op_type = IS_CONST; $$.u.constant.value.lval=1; $$.u.constant.type=IS_LONG; INIT_PZVAL(&$$.u.constant); do_receive_arg(ZEND_RECV_INIT, &tmp, &$$, &$3, BYREF_NONE CLS_CC); } - | non_empty_parameter_list ',' T_VARIABLE { znode tmp; fetch_simple_variable(&tmp, &$3, 0 CLS_CC); $$=$1; $$.u.constant.value.lval++; do_receive_arg(ZEND_RECV, &tmp, &$$, NULL, BYREF_NONE CLS_CC); } - | non_empty_parameter_list ',' '&' T_VARIABLE { znode tmp; fetch_simple_variable(&tmp, &$4, 0 CLS_CC); $$=$1; $$.u.constant.value.lval++; do_receive_arg(ZEND_RECV, &tmp, &$$, NULL, BYREF_FORCE CLS_CC); } - | non_empty_parameter_list ',' T_CONST T_VARIABLE { znode tmp; fetch_simple_variable(&tmp, &$4, 0 CLS_CC); $$=$1; $$.u.constant.value.lval++; do_receive_arg(ZEND_RECV, &tmp, &$$, NULL, BYREF_NONE CLS_CC); } - | non_empty_parameter_list ',' T_VARIABLE '=' static_scalar { znode tmp; fetch_simple_variable(&tmp, &$3, 0 CLS_CC); $$=$1; $$.u.constant.value.lval++; do_receive_arg(ZEND_RECV_INIT, &tmp, &$$, &$5, BYREF_NONE CLS_CC); } -; - - -function_call_parameter_list: - non_empty_function_call_parameter_list { $$ = $1; } - | /* empty */ { $$.u.constant.value.lval = 0; } -; - - -non_empty_function_call_parameter_list: - expr_without_variable { $$.u.constant.value.lval = 1; do_pass_param(&$1, ZEND_SEND_VAL, $$.u.constant.value.lval CLS_CC); } - | cvar { $$.u.constant.value.lval = 1; do_pass_param(&$1, ZEND_SEND_VAR, $$.u.constant.value.lval CLS_CC); } - | '&' w_cvar { $$.u.constant.value.lval = 1; do_pass_param(&$2, ZEND_SEND_REF, $$.u.constant.value.lval CLS_CC); } - | non_empty_function_call_parameter_list ',' expr_without_variable { $$.u.constant.value.lval=$1.u.constant.value.lval+1; do_pass_param(&$3, ZEND_SEND_VAL, $$.u.constant.value.lval CLS_CC); } - | non_empty_function_call_parameter_list ',' cvar { $$.u.constant.value.lval=$1.u.constant.value.lval+1; do_pass_param(&$3, ZEND_SEND_VAR, $$.u.constant.value.lval CLS_CC); } - | non_empty_function_call_parameter_list ',' '&' w_cvar { $$.u.constant.value.lval=$1.u.constant.value.lval+1; do_pass_param(&$4, ZEND_SEND_REF, $$.u.constant.value.lval CLS_CC); } -; - -global_var_list: - global_var_list ',' global_var { do_fetch_global_or_static_variable(&$3, NULL, ZEND_FETCH_GLOBAL CLS_CC); } - | global_var { do_fetch_global_or_static_variable(&$1, NULL, ZEND_FETCH_GLOBAL CLS_CC); } -; - - -global_var: - T_VARIABLE { $$ = $1; } - | '$' r_cvar { $$ = $2; } - | '$' '{' expr '}' { $$ = $3; } -; - - -static_var_list: - static_var_list ',' T_VARIABLE { do_fetch_global_or_static_variable(&$3, NULL, ZEND_FETCH_STATIC CLS_CC); } - | static_var_list ',' T_VARIABLE '=' static_scalar { do_fetch_global_or_static_variable(&$3, &$5, ZEND_FETCH_STATIC CLS_CC); } - | T_VARIABLE { do_fetch_global_or_static_variable(&$1, NULL, ZEND_FETCH_STATIC CLS_CC); } - | T_VARIABLE '=' static_scalar { do_fetch_global_or_static_variable(&$1, &$3, ZEND_FETCH_STATIC CLS_CC); } - -; - - -class_statement_list: - class_statement_list class_statement - | /* empty */ -; - - -class_statement: - T_VAR class_variable_decleration ';' - | T_FUNCTION { $1.u.opline_num = CG(zend_lineno); } is_reference T_STRING { do_begin_function_declaration(&$1, &$4, 1, $3.op_type CLS_CC); } '(' - parameter_list ')' '{' inner_statement_list '}' { do_end_function_declaration(&$1 CLS_CC); } - | T_OLD_FUNCTION { $1.u.opline_num = CG(zend_lineno); } is_reference T_STRING { do_begin_function_declaration(&$1, &$4, 1, $3.op_type CLS_CC); } - parameter_list '(' inner_statement_list ')' ';' { do_end_function_declaration(&$1 CLS_CC); } - -; - -is_reference: - /* empty */ { $$.op_type = ZEND_RETURN_VAL; } - | '&' { $$.op_type = ZEND_RETURN_REF; } - -class_variable_decleration: - class_variable_decleration ',' T_VARIABLE { do_declare_property(&$3, NULL CLS_CC); } - | class_variable_decleration ',' T_VARIABLE '=' static_scalar { do_declare_property(&$3, &$5 CLS_CC); } - | T_VARIABLE { do_declare_property(&$1, NULL CLS_CC); } - | T_VARIABLE '=' static_scalar { do_declare_property(&$1, &$3 CLS_CC); } -; - - -echo_expr_list: - | echo_expr_list ',' expr { do_echo(&$3 CLS_CC); } - | expr { do_echo(&$1 CLS_CC); } -; - - -for_expr: - /* empty */ { $$.op_type = IS_CONST; $$.u.constant.type = IS_BOOL; $$.u.constant.value.lval = 1; } - | non_empty_for_expr { $$ = $1; } -; - -non_empty_for_expr: - non_empty_for_expr ',' { do_free(&$1 CLS_CC); } expr { $$ = $4; } - | expr { $$ = $1; } -; - - -expr_without_variable: - T_LIST '(' { do_list_init(CLS_C); } assignment_list ')' '=' expr { do_list_end(&$$, &$7 CLS_CC); } - | cvar '=' expr { do_end_variable_parse(BP_VAR_W, 0 CLS_CC); do_assign(&$$, &$1, &$3 CLS_CC); } - | cvar '=' '&' w_cvar { do_end_variable_parse(BP_VAR_W, 0 CLS_CC); do_assign_ref(&$$, &$1, &$4 CLS_CC); } - | cvar '=' '&' function_call { do_end_variable_parse(BP_VAR_W, 0 CLS_CC); do_assign_ref(&$$, &$1, &$4 CLS_CC); } - | T_NEW class_name { do_extended_fcall_begin(CLS_C); do_begin_new_object(&$1, &$2 CLS_CC); } ctor_arguments { do_end_new_object(&$$, &$2, &$1, &$4 CLS_CC); do_extended_fcall_end(CLS_C);} - | cvar T_PLUS_EQUAL expr { do_end_variable_parse(BP_VAR_RW, 0 CLS_CC); do_binary_assign_op(ZEND_ASSIGN_ADD, &$$, &$1, &$3 CLS_CC); } - | cvar T_MINUS_EQUAL expr { do_end_variable_parse(BP_VAR_RW, 0 CLS_CC); do_binary_assign_op(ZEND_ASSIGN_SUB, &$$, &$1, &$3 CLS_CC); } - | cvar T_MUL_EQUAL expr { do_end_variable_parse(BP_VAR_RW, 0 CLS_CC); do_binary_assign_op(ZEND_ASSIGN_MUL, &$$, &$1, &$3 CLS_CC); } - | cvar T_DIV_EQUAL expr { do_end_variable_parse(BP_VAR_RW, 0 CLS_CC); do_binary_assign_op(ZEND_ASSIGN_DIV, &$$, &$1, &$3 CLS_CC); } - | cvar T_CONCAT_EQUAL expr { do_end_variable_parse(BP_VAR_RW, 0 CLS_CC); do_binary_assign_op(ZEND_ASSIGN_CONCAT, &$$, &$1, &$3 CLS_CC); } - | cvar T_MOD_EQUAL expr { do_end_variable_parse(BP_VAR_RW, 0 CLS_CC); do_binary_assign_op(ZEND_ASSIGN_MOD, &$$, &$1, &$3 CLS_CC); } - | cvar T_AND_EQUAL expr { do_end_variable_parse(BP_VAR_RW, 0 CLS_CC); do_binary_assign_op(ZEND_ASSIGN_BW_AND, &$$, &$1, &$3 CLS_CC); } - | cvar T_OR_EQUAL expr { do_end_variable_parse(BP_VAR_RW, 0 CLS_CC); do_binary_assign_op(ZEND_ASSIGN_BW_OR, &$$, &$1, &$3 CLS_CC); } - | cvar XT_OR_EQUAL expr { do_end_variable_parse(BP_VAR_RW, 0 CLS_CC); do_binary_assign_op(ZEND_ASSIGN_BW_XOR, &$$, &$1, &$3 CLS_CC); } - | cvar T_SL_EQUAL expr { do_end_variable_parse(BP_VAR_RW, 0 CLS_CC); do_binary_assign_op(ZEND_ASSIGN_SL, &$$, &$1, &$3 CLS_CC); } - | cvar T_SR_EQUAL expr { do_end_variable_parse(BP_VAR_RW, 0 CLS_CC); do_binary_assign_op(ZEND_ASSIGN_SR, &$$, &$1, &$3 CLS_CC); } - | rw_cvar T_INC { do_post_incdec(&$$, &$1, ZEND_POST_INC CLS_CC); } - | T_INC rw_cvar { do_pre_incdec(&$$, &$2, ZEND_PRE_INC CLS_CC); } - | rw_cvar T_DEC { do_post_incdec(&$$, &$1, ZEND_POST_DEC CLS_CC); } - | T_DEC rw_cvar { do_pre_incdec(&$$, &$2, ZEND_PRE_DEC CLS_CC); } - | expr T_BOOLEAN_OR { do_boolean_or_begin(&$1, &$2 CLS_CC); } expr { do_boolean_or_end(&$$, &$1, &$4, &$2 CLS_CC); } - | expr T_BOOLEAN_AND { do_boolean_and_begin(&$1, &$2 CLS_CC); } expr { do_boolean_and_end(&$$, &$1, &$4, &$2 CLS_CC); } - | expr T_LOGICAL_OR { do_boolean_or_begin(&$1, &$2 CLS_CC); } expr { do_boolean_or_end(&$$, &$1, &$4, &$2 CLS_CC); } - | expr T_LOGICAL_AND { do_boolean_and_begin(&$1, &$2 CLS_CC); } expr { do_boolean_and_end(&$$, &$1, &$4, &$2 CLS_CC); } - | expr T_LOGICAL_XOR expr { do_binary_op(ZEND_BOOL_XOR, &$$, &$1, &$3 CLS_CC); } - | expr '|' expr { do_binary_op(ZEND_BW_OR, &$$, &$1, &$3 CLS_CC); } - | expr '&' expr { do_binary_op(ZEND_BW_AND, &$$, &$1, &$3 CLS_CC); } - | expr '^' expr { do_binary_op(ZEND_BW_XOR, &$$, &$1, &$3 CLS_CC); } - | expr '.' expr { do_binary_op(ZEND_CONCAT,&$$,&$1,&$3 CLS_CC); } - | expr '+' expr { do_binary_op(ZEND_ADD,&$$,&$1,&$3 CLS_CC); } - | expr '-' expr { do_binary_op(ZEND_SUB,&$$,&$1,&$3 CLS_CC); } - | expr '*' expr { do_binary_op(ZEND_MUL,&$$,&$1,&$3 CLS_CC); } - | expr '/' expr { do_binary_op(ZEND_DIV,&$$,&$1,&$3 CLS_CC); } - | expr '%' expr { do_binary_op(ZEND_MOD,&$$,&$1,&$3 CLS_CC); } - | expr T_SL expr { do_binary_op(ZEND_SL, &$$, &$1, &$3 CLS_CC); } - | expr T_SR expr { do_binary_op(ZEND_SR, &$$, &$1, &$3 CLS_CC); } - | '+' expr { $1.u.constant.value.lval=0; $1.u.constant.type=IS_LONG; $1.op_type = IS_CONST; INIT_PZVAL(&$1.u.constant); do_binary_op(ZEND_ADD, &$$, &$1, &$2 CLS_CC); } - | '-' expr { $1.u.constant.value.lval=0; $1.u.constant.type=IS_LONG; $1.op_type = IS_CONST; INIT_PZVAL(&$1.u.constant); do_binary_op(ZEND_SUB, &$$, &$1, &$2 CLS_CC); } - | '!' expr { do_unary_op(ZEND_BOOL_NOT, &$$, &$2 CLS_CC); } - | '~' expr { do_unary_op(ZEND_BW_NOT, &$$, &$2 CLS_CC); } - | expr T_IS_IDENTICAL expr { do_binary_op(ZEND_IS_IDENTICAL, &$$, &$1, &$3 CLS_CC); } - | expr T_IS_EQUAL expr { do_binary_op(ZEND_IS_EQUAL, &$$, &$1, &$3 CLS_CC); } - | expr T_IS_NOT_EQUAL expr { do_binary_op(ZEND_IS_NOT_EQUAL, &$$, &$1, &$3 CLS_CC); } - | expr '<' expr { do_binary_op(ZEND_IS_SMALLER, &$$, &$1, &$3 CLS_CC); } - | expr T_IS_SMALLER_OR_EQUAL expr { do_binary_op(ZEND_IS_SMALLER_OR_EQUAL, &$$, &$1, &$3 CLS_CC); } - | expr '>' expr { do_binary_op(ZEND_IS_SMALLER, &$$, &$3, &$1 CLS_CC); } - | expr T_IS_GREATER_OR_EQUAL expr { do_binary_op(ZEND_IS_SMALLER_OR_EQUAL, &$$, &$3, &$1 CLS_CC); } - | '(' expr ')' { $$ = $2; } - | expr '?' { do_begin_qm_op(&$1, &$2 CLS_CC); } - expr ':' { do_qm_true(&$4, &$2, &$5 CLS_CC); } - expr { do_qm_false(&$$, &$7, &$2, &$5 CLS_CC); } - | function_call { $$ = $1; } - | internal_functions_in_yacc { $$ = $1; } - | T_INT_CAST expr { do_cast(&$$, &$2, IS_LONG CLS_CC); } - | T_DOUBLE_CAST expr { do_cast(&$$, &$2, IS_DOUBLE CLS_CC); } - | T_STRING_CAST expr { do_cast(&$$, &$2, IS_STRING CLS_CC); } - | T_ARRAY_CAST expr { do_cast(&$$, &$2, IS_ARRAY CLS_CC); } - | T_OBJECT_CAST expr { do_cast(&$$, &$2, IS_OBJECT CLS_CC); } - | T_BOOL_CAST expr { do_cast(&$$, &$2, IS_BOOL CLS_CC); } - | T_UNSET_CAST expr { do_cast(&$$, &$2, IS_NULL CLS_CC); } - | T_EXIT exit_expr { do_exit(&$$, &$2 CLS_CC); } - | '@' { do_begin_silence(&$1 CLS_CC); } expr { do_end_silence(&$1 CLS_CC); $$ = $3; } - | scalar { $$ = $1; } - | T_ARRAY '(' array_pair_list ')' { $$ = $3; } - | '`' encaps_list '`' { do_shell_exec(&$$, &$2 CLS_CC); } - | T_PRINT expr { do_print(&$$, &$2 CLS_CC); } -; - - -function_call: - T_STRING '(' { do_extended_fcall_begin(CLS_C); $2.u.opline_num = do_begin_function_call(&$1 CLS_CC); } - function_call_parameter_list - ')' { do_end_function_call(&$1, &$$, &$4, 0, $2.u.opline_num CLS_CC); do_extended_fcall_end(CLS_C); } - | r_cvar '(' { do_extended_fcall_begin(CLS_C); do_begin_dynamic_function_call(&$1 CLS_CC); } - function_call_parameter_list - ')' { do_end_function_call(&$1, &$$, &$4, 0, 1 CLS_CC); do_extended_fcall_end(CLS_C);} - | T_STRING T_PAAMAYIM_NEKUDOTAYIM T_STRING '(' { do_extended_fcall_begin(CLS_C); do_begin_class_member_function_call(&$1, &$3 CLS_CC); } - function_call_parameter_list - ')' { do_end_function_call(&$3, &$$, &$6, 1, 1 CLS_CC); do_extended_fcall_end(CLS_C);} -; - - -exit_expr: - /* empty */ { $$.op_type = IS_UNUSED; } - | '(' ')' { $$.op_type = IS_UNUSED; } - | '(' expr ')' { $$ = $2; } -; - - -ctor_arguments: - /* empty */ { $$.u.constant.value.lval=0; } - | '(' function_call_parameter_list ')' { $$ = $2; } -; - - -class_name: - T_STRING { $$ = $1; } - | r_cvar { $$ = $1; } -; - - - -common_scalar: - T_LNUMBER { $$=$1; } - | T_DNUMBER { $$=$1; } - | T_CONSTANT_ENCAPSED_STRING { $$ = $1; } - | T_LINE { $$ = $1; } - | T_FILE { $$ = $1; } -; - - -static_scalar: /* compile-time evaluated scalars */ - common_scalar { $$ = $1; } - | T_STRING { do_fetch_constant(&$$, &$1, ZEND_CT CLS_CC); } - | '+' static_scalar { $$ = $1; } - | '-' static_scalar { zval minus_one; minus_one.type = IS_LONG; minus_one.value.lval = -1; mul_function(&$2.u.constant, &$2.u.constant, &minus_one); $$ = $2; } - | T_ARRAY '(' static_array_pair_list ')' { $$ = $3; } -; - - -scalar: - T_STRING { do_fetch_constant(&$$, &$1, ZEND_RT CLS_CC); } - | T_STRING_VARNAME { $$ = $1; } - | common_scalar { $$ = $1; } - | '"' encaps_list '"' { $$ = $2; } - | '\'' encaps_list '\'' { $$ = $2; } - | T_START_HEREDOC encaps_list T_END_HEREDOC { $$ = $2; do_end_heredoc(CLS_C); } -; - - -static_array_pair_list: - /* empty */ { $$.op_type = IS_CONST; INIT_PZVAL(&$$.u.constant); array_init(&$$.u.constant); } - | non_empty_static_array_pair_list { $$ = $1; } -; - - -non_empty_static_array_pair_list: - non_empty_static_array_pair_list ',' static_scalar T_DOUBLE_ARROW static_scalar { do_add_static_array_element(&$$, &$3, &$5); } - | non_empty_static_array_pair_list ',' static_scalar { do_add_static_array_element(&$$, NULL, &$3); } - | static_scalar T_DOUBLE_ARROW static_scalar { $$.op_type = IS_CONST; INIT_PZVAL(&$$.u.constant); array_init(&$$.u.constant); do_add_static_array_element(&$$, &$1, &$3); } - | static_scalar { $$.op_type = IS_CONST; INIT_PZVAL(&$$.u.constant); array_init(&$$.u.constant); do_add_static_array_element(&$$, NULL, &$1); } -; - -expr: - r_cvar { $$ = $1; } - | expr_without_variable { $$ = $1; } -; - -/* -w_expr: - w_cvar { $$ = $1; } - | expr_without_variable { $$ = $1; } -; -*/ - - -r_cvar: - cvar { do_end_variable_parse(BP_VAR_R, 0 CLS_CC); $$ = $1; } -; - - -w_cvar: - cvar { do_end_variable_parse(BP_VAR_W, 0 CLS_CC); $$ = $1; } -; - - -rw_cvar: - cvar { do_end_variable_parse(BP_VAR_RW, 0 CLS_CC); $$ = $1; } -; - - -cvar: - cvar_without_objects { $$ = $1; } - | cvar_without_objects T_OBJECT_OPERATOR { do_push_object(&$1 CLS_CC); } ref_list { $$ = $4; } -; - - -cvar_without_objects: - reference_variable { $$ = $1; } - | simple_indirect_reference reference_variable { do_indirect_references(&$$, &$1, &$2 CLS_CC); } -; - - -reference_variable: - reference_variable '[' dim_offset ']' { fetch_array_dim(&$$, &$1, &$3 CLS_CC); } - | reference_variable '{' expr '}' { fetch_string_offset(&$$, &$1, &$3 CLS_CC); } - | compound_variable { do_fetch_globals(&$1 CLS_CC); do_begin_variable_parse(CLS_C); fetch_simple_variable(&$$, &$1, 1 CLS_CC); } -; - - -compound_variable: - T_VARIABLE { $$ = $1; } - | '$' '{' expr '}' { $$ = $3; } -; - -dim_offset: - /* empty */ { $$.op_type = IS_UNUSED; } - | expr { $$ = $1; } -; - -ref_list: - object_property { $$ = $1; } - | ref_list T_OBJECT_OPERATOR { do_push_object(&$1 CLS_CC); } object_property { $$ = $4; } -; - -object_property: - object_dim_list { $$ = $1; } - | cvar_without_objects { do_end_variable_parse(BP_VAR_R, 0 CLS_CC); } { znode tmp_znode; do_pop_object(&tmp_znode CLS_CC); do_fetch_property(&$$, &tmp_znode, &$1 CLS_CC);} -; - -object_dim_list: - object_dim_list '[' dim_offset ']' { fetch_array_dim(&$$, &$1, &$3 CLS_CC); } - | object_dim_list '{' expr '}' { fetch_string_offset(&$$, &$1, &$3 CLS_CC); } - | variable_name { znode tmp_znode; do_pop_object(&tmp_znode CLS_CC); do_fetch_property(&$$, &tmp_znode, &$1 CLS_CC);} -; - -variable_name: - T_STRING { $$ = $1; } - | '{' expr '}' { $$ = $2; } -; - - -simple_indirect_reference: - '$' { $$.u.constant.value.lval = 1; } - | simple_indirect_reference '$' { $$.u.constant.value.lval++; } -; - -assignment_list: - assignment_list ',' assignment_list_element - | assignment_list_element -; - - -assignment_list_element: - cvar { do_add_list_element(&$1 CLS_CC); } - | T_LIST '(' { do_new_list_begin(CLS_C); } assignment_list ')' { do_new_list_end(CLS_C); } - | /* empty */ { do_add_list_element(NULL CLS_CC); } -; - - -array_pair_list: - /* empty */ { do_init_array(&$$, NULL, NULL, 0 CLS_CC); } - | non_empty_array_pair_list { $$ = $1; } -; - -non_empty_array_pair_list: - non_empty_array_pair_list ',' expr T_DOUBLE_ARROW expr { do_add_array_element(&$$, &$5, &$3, 0 CLS_CC); } - | non_empty_array_pair_list ',' expr { do_add_array_element(&$$, &$3, NULL, 0 CLS_CC); } - | expr T_DOUBLE_ARROW expr { do_init_array(&$$, &$3, &$1, 0 CLS_CC); } - | expr { do_init_array(&$$, &$1, NULL, 0 CLS_CC); } - | non_empty_array_pair_list ',' expr T_DOUBLE_ARROW '&' w_cvar { do_add_array_element(&$$, &$6, &$3, 1 CLS_CC); } - | non_empty_array_pair_list ',' '&' w_cvar { do_add_array_element(&$$, &$4, NULL, 1 CLS_CC); } - | expr T_DOUBLE_ARROW '&' w_cvar { do_init_array(&$$, &$4, &$1, 1 CLS_CC); } - | '&' w_cvar { do_init_array(&$$, &$2, NULL, 1 CLS_CC); } -; - -encaps_list: - encaps_list encaps_var { do_end_variable_parse(BP_VAR_R, 0 CLS_CC); do_add_variable(&$$, &$1, &$2 CLS_CC); } - | encaps_list T_STRING { do_add_string(&$$, &$1, &$2 CLS_CC); } - | encaps_list T_NUM_STRING { do_add_string(&$$, &$1, &$2 CLS_CC); } - | encaps_list T_ENCAPSED_AND_WHITESPACE { do_add_string(&$$, &$1, &$2 CLS_CC); } - | encaps_list T_CHARACTER { do_add_char(&$$, &$1, &$2 CLS_CC); } - | encaps_list T_BAD_CHARACTER { do_add_string(&$$, &$1, &$2 CLS_CC); } - | encaps_list '[' { $2.u.constant.value.chval = '['; do_add_char(&$$, &$1, &$2 CLS_CC); } - | encaps_list ']' { $2.u.constant.value.chval = ']'; do_add_char(&$$, &$1, &$2 CLS_CC); } - | encaps_list '{' { $2.u.constant.value.chval = '{'; do_add_char(&$$, &$1, &$2 CLS_CC); } - | encaps_list '}' { $2.u.constant.value.chval = '}'; do_add_char(&$$, &$1, &$2 CLS_CC); } - | encaps_list T_OBJECT_OPERATOR { znode tmp; $2.u.constant.value.chval = '-'; do_add_char(&tmp, &$1, &$2 CLS_CC); $2.u.constant.value.chval = '>'; do_add_char(&$$, &tmp, &$2 CLS_CC); } - | /* empty */ { do_init_string(&$$ CLS_CC); } - -; - - - -encaps_var: - T_VARIABLE { do_fetch_globals(&$1 CLS_CC); do_begin_variable_parse(CLS_C); fetch_simple_variable(&$$, &$1, 1 CLS_CC); } - | T_VARIABLE '[' { do_begin_variable_parse(CLS_C); } encaps_var_offset ']' { do_fetch_globals(&$1 CLS_CC); fetch_array_begin(&$$, &$1, &$4 CLS_CC); } - | T_VARIABLE T_OBJECT_OPERATOR T_STRING { do_begin_variable_parse(CLS_C); fetch_simple_variable(&$2, &$1, 1 CLS_CC); do_fetch_property(&$$, &$2, &$3 CLS_CC); } - | T_DOLLAR_OPEN_CURLY_BRACES expr '}' { do_begin_variable_parse(CLS_C); fetch_simple_variable(&$$, &$2, 1 CLS_CC); } - | T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}' { do_begin_variable_parse(CLS_C); fetch_array_begin(&$$, &$2, &$4 CLS_CC); } - | T_CURLY_OPEN cvar '}' { $$ = $2; } -; - - -encaps_var_offset: - T_STRING { $$ = $1; } - | T_NUM_STRING { $$ = $1; } - | T_VARIABLE { fetch_simple_variable(&$$, &$1, 1 CLS_CC); } -; - - -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_EVAL '(' expr ')' { do_include_or_eval(ZEND_EVAL, &$$, &$3 CLS_CC); } - | T_IMPORT '(' expr ')' { do_include_or_eval(ZEND_IMPORT, &$$, &$3 CLS_CC); } -; - - -%% - diff --git a/Zend/zend-scanner.h b/Zend/zend-scanner.h deleted file mode 100644 index 7a77986cc9..0000000000 --- a/Zend/zend-scanner.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _LANGUAGE_SCANNER_H -#define _LANGUAGE_SCANNER_H - -#ifdef ZTS -class ZendFlexLexer : public yyFlexLexer -{ -public: - virtual ~ZendFlexLexer(); - int lex_scan(zval *zendlval CLS_DC); - void BeginState(int state); -}; - -#endif /* ZTS */ - - -#ifndef ZTS -typedef struct _zend_lex_state { - YY_BUFFER_STATE buffer_state; - int state; - uint return_offset; - uint lineno; - FILE *in; - char *filename; -} zend_lex_state; -#else -typedef struct _zend_lex_state { - ZendFlexLexer *ZFL; - istream *input_file; -} zend_lex_state; -#endif - -void zend_fatal_scanner_error(char *); -inline void restore_lexical_state(zend_lex_state * CLS_DC); -BEGIN_EXTERN_C() -int zend_compare_file_handles(zend_file_handle *fh1, zend_file_handle *fh2); -END_EXTERN_C() - -#endif diff --git a/Zend/zend-scanner.l b/Zend/zend-scanner.l deleted file mode 100644 index 02ea8f54f9..0000000000 --- a/Zend/zend-scanner.l +++ /dev/null @@ -1,1656 +0,0 @@ -%{ - -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - -%} - -%x ST_IN_SCRIPTING -%x ST_DOUBLE_QUOTES -%x ST_SINGLE_QUOTE -%x ST_BACKQUOTE -%x ST_HEREDOC -%x ST_LOOKING_FOR_PROPERTY -%x ST_LOOKING_FOR_VARNAME -%x ST_COMMENT -%option stack - -%{ - -#ifdef ZEND_WIN32 -#include -#include -#endif - -#include -#include "zend.h" -#include "zend_alloc.h" -#include "zend-parser.h" -#include "zend_compile.h" -#include "zend-scanner.h" -#include "zend_highlight.h" -#include "zend_constants.h" -#include "zend_variables.h" -#include "zend_operators.h" - -#ifdef ZTS -# include -# ifdef HAVE_STDIOSTR_H -# include -# endif -# ifdef HAVE_STDIOSTREAM_H -# include -# endif -# ifdef ZEND_WIN32 -# include -# else -# include -# endif -#endif - -#ifdef HAVE_STDARG_H -# include -#endif - -#ifdef HAVE_UNISTD_H -# include -#endif - -#ifdef ZTS -#define YY_DECL int ZendFlexLexer::lex_scan(zval *zendlval CLS_DC) -#else -#define YY_DECL int lex_scan(zval *zendlval CLS_DC) -#endif -#define ECHO { ZEND_WRITE( yytext, yyleng ); } - -#ifdef ZTS -# define MY_INPUT yyinput -#else -# define MY_INPUT input -#endif - -#if defined(ZTS) && !defined(HAVE_CLASS_ISTDIOSTREAM) -class istdiostream : public istream -{ -private: - stdiobuf _file; -public: - istdiostream (FILE* __f) : istream(), _file(__f) { init(&_file); } -}; -#endif - -#define YY_FATAL_ERROR zend_fatal_scanner_error - -#define HANDLE_NEWLINES(s,l) \ -do { \ - char *p = (s),*boundary = p+(l); \ -\ - while(p='0' && (c)<'8') -#define ZEND_IS_HEX(c) (((c)>='0' && (c)<='9') || ((c)>='a' && (c)<='f') || ((c)>='A' && (c)<='F')) - - -void zend_fatal_scanner_error(char *message) -{ - zend_error(E_COMPILE_ERROR, message); -} - -BEGIN_EXTERN_C() -void startup_scanner(CLS_D) -{ - CG(heredoc) = NULL; - CG(heredoc_len)=0; -} - - -void shutdown_scanner(CLS_D) -{ - if (CG(heredoc)) { - efree(CG(heredoc)); - CG(heredoc_len)=0; - } -} -END_EXTERN_C() - - -static inline void save_lexical_state(zend_lex_state *lex_state CLS_DC) -{ -#ifndef ZTS - memcpy(&lex_state->buffer_state,&YY_CURRENT_BUFFER,sizeof(YY_BUFFER_STATE)); - lex_state->in = yyin; - lex_state->lineno = CG(zend_lineno); - lex_state->state = YYSTATE; - lex_state->filename = zend_get_compiled_filename(CLS_C); -#else - lex_state->ZFL = CG(ZFL); -#endif -} - - -inline void restore_lexical_state(zend_lex_state *lex_state CLS_DC) -{ -#ifndef ZTS - YY_BUFFER_STATE original_buffer_state = YY_CURRENT_BUFFER; - - if (lex_state->buffer_state) { - yy_switch_to_buffer(lex_state->buffer_state); - } else { - YY_CURRENT_BUFFER = NULL; - } - - yy_delete_buffer(original_buffer_state); - yyin = lex_state->in; - CG(zend_lineno) = lex_state->lineno; - BEGIN(lex_state->state); - zend_restore_compiled_filename(lex_state->filename); -#else - delete((ZendFlexLexer *) CG(ZFL)); - CG(ZFL) = lex_state->ZFL; -#endif -} - - -BEGIN_EXTERN_C() - - -ZEND_API void zend_open_file_dtor(zend_file_handle *fh) -{ - switch (fh->type) { - case ZEND_HANDLE_FP: - fclose(fh->handle.fp); - break; - case ZEND_HANDLE_FILENAME: - /* We're only supposed to get here when destructing the used_files hash, - * which doesn't really contain open files, but references to their names/paths - */ - break; -#ifdef ZTS - case ZEND_HANDLE_FSTREAM: - delete ((ifstream *) fh->handle.is); - break; - case ZEND_HANDLE_STDIOSTREAM: - istdiostream *pstdiostream = (istdiostream *) fh->handle.is; - - fclose(pstdiostream->rdbuf()->stdiofile()); - delete pstdiostream; - break; -#endif - } - if (fh->opened_path) { - free(fh->opened_path); - } - if (fh->free_filename && fh->filename) { - efree(fh->filename); - } -} - - -int zend_compare_file_handles(zend_file_handle *fh1, zend_file_handle *fh2) -{ - if (fh1->type != fh2->type) { - return 0; - } - switch (fh1->type) { - case ZEND_HANDLE_FP: - return fh1->handle.fp==fh2->handle.fp; - break; -#ifdef ZTS - case ZEND_HANDLE_FSTREAM: - case ZEND_HANDLE_STDIOSTREAM: - return fh1->handle.is==fh2->handle.is; - break; -#endif - } - return 0; -} - - -ZEND_API void zend_close_file_handle(zend_file_handle *file_handle CLS_DC) -{ - zend_llist_del_element(&CG(open_files), file_handle, (int (*)(void *, void *)) zend_compare_file_handles); -} - - -ZEND_API int open_file_for_scanning(zend_file_handle *file_handle CLS_DC) -{ -#ifndef ZTS - switch (file_handle->type) { - case ZEND_HANDLE_FILENAME: - file_handle->handle.fp = zend_fopen(file_handle->filename, &file_handle->opened_path); - break; - case ZEND_HANDLE_FD: - file_handle->opened_path = NULL; - file_handle->handle.fp = fdopen(file_handle->handle.fd, "r"); - break; - case ZEND_HANDLE_FP: - file_handle->opened_path = NULL; - file_handle->handle.fp = file_handle->handle.fp; - break; - } - if (!file_handle->handle.fp) { - return FAILURE; - } - file_handle->type = ZEND_HANDLE_FP; - if (file_handle->handle.fp != stdin) { - zend_llist_add_element(&CG(open_files), file_handle); - } - /* Reset the scanner for scanning the new file */ - yyin = file_handle->handle.fp; - yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); - BEGIN(INITIAL); -#else - switch (file_handle->type) { - case ZEND_HANDLE_FD: - file_handle->opened_path = NULL; - file_handle->handle.is = new ifstream(file_handle->handle.fd); - file_handle->type = ZEND_HANDLE_FSTREAM; - break; - case ZEND_HANDLE_FILENAME: - { - file_handle->handle.fp = zend_fopen(file_handle->filename, &file_handle->opened_path); - if (!file_handle->handle.fp) { - return FAILURE; - } - file_handle->handle.is = new istdiostream(file_handle->handle.fp); - file_handle->type = ZEND_HANDLE_STDIOSTREAM; - break; - } - case ZEND_HANDLE_FP: - file_handle->opened_path = NULL; - if (file_handle->handle.fp==stdin) { - file_handle->handle.is = &cin; - } else { - if (!file_handle->handle.fp) { - return FAILURE; - } - file_handle->handle.is = new istdiostream(file_handle->handle.fp); - file_handle->type = ZEND_HANDLE_STDIOSTREAM; - } - break; - } - if (file_handle->handle.is->fail()) { - delete file_handle->handle.is; - return FAILURE; - } - if (file_handle->handle.is != &cin) { - zend_llist_add_element(&CG(open_files), file_handle); - } - - 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; - return SUCCESS; -} -END_EXTERN_C() - - -ZEND_API zend_op_array *compile_files(int mark_as_ref CLS_DC, int file_count, ...) -{ - va_list files; - zend_op_array *op_array; - - va_start(files, file_count); - op_array = v_compile_files(mark_as_ref CLS_CC, file_count, files); - va_end(files); - return op_array; -} - - -ZEND_API zend_op_array *v_compile_files(int mark_as_ref CLS_DC, int file_count, va_list files) -{ - zend_lex_state original_lex_state; - zend_op_array *op_array = (zend_op_array *) emalloc(sizeof(zend_op_array)); - zend_op_array *original_active_op_array = CG(active_op_array); - zend_op_array *retval=NULL; - zend_file_handle *file_handle; - int i; - int compiler_result; - int compiled_files=0; - zend_bool original_in_compilation = CG(in_compilation); - - CG(in_compilation) = 1; - init_op_array(op_array, INITIAL_OP_ARRAY_SIZE); - save_lexical_state(&original_lex_state CLS_CC); - - retval = op_array; /* success oriented */ - for (i=0; ifilename); - } else { - CG(active_op_array) = op_array; - compiler_result = zendparse(CLS_C); - zend_close_file_handle(file_handle CLS_CC); - restore_lexical_state(&original_lex_state CLS_CC); - if (compiler_result==1) { /* parser error */ - CG(unclean_shutdown) = 1; - retval = NULL; - break; - } - compiled_files++; - } - } - - if (retval) { - if (compiled_files>0) { - do_return(NULL, 0 CLS_CC); - CG(active_op_array) = original_active_op_array; - pass_two(op_array); - if (mark_as_ref) { - pass_include_eval(op_array); - } - } else { - CG(active_op_array) = original_active_op_array; - destroy_op_array(op_array); - efree(op_array); - retval = NULL; - } - } - CG(in_compilation) = original_in_compilation; - return retval; -} - - -zend_op_array *compile_filename(int mode, zval *filename CLS_DC ELS_DC) -{ - zend_file_handle file_handle; - zval tmp; - zend_op_array *retval; - int error_reporting=0; - - if (filename->type != IS_STRING) { - tmp = *filename; - zval_copy_ctor(&tmp); - convert_to_string(&tmp); - filename = &tmp; - } - file_handle.filename = filename->value.str.val; - file_handle.free_filename = 0; - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.opened_path = NULL; - - - if (mode==ZEND_REQUIRE) { - /* We don't want to hear about inclusion failures; If we fail, - * we'll generate a require failure - */ - error_reporting = EG(error_reporting); - EG(error_reporting) = 0; - } - retval = zend_compile_files(1 CLS_CC, 1, &file_handle); - - if (mode==ZEND_REQUIRE) { - EG(error_reporting) = error_reporting; - if (!retval) { - zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, filename->value.str.val); - zend_bailout(); - } - } - - if (filename==&tmp) { - zval_dtor(&tmp); - } - return retval; -} - - -static inline int prepare_string_for_scanning(zval *str CLS_DC) -{ -#ifndef ZTS - /* enforce two trailing NULLs for flex... */ - STR_REALLOC(str->value.str.val, str->value.str.len+2); - - str->value.str.val[str->value.str.len+1]=0; - - yyin=NULL; - yy_scan_buffer(str->value.str.val, str->value.str.len+2); -#else - istrstream *input_stream = new istrstream(str->value.str.val, str->value.str.len); - CG(ZFL) = new ZendFlexLexer; - - CG(ZFL)->switch_streams(input_stream, &cout); -#endif - return SUCCESS; -} - - -zend_op_array *compile_string(zval *source_string CLS_DC) -{ - zend_lex_state original_lex_state; - zend_op_array *op_array = (zend_op_array *) emalloc(sizeof(zend_op_array)); - zend_op_array *original_active_op_array = CG(active_op_array); - zend_op_array *retval; - zval tmp; - int compiler_result; - zend_bool original_in_compilation = CG(in_compilation); - - if (source_string->value.str.len==0) { - efree(op_array); - return NULL; - } - - CG(in_compilation) = 1; - - tmp = *source_string; - zval_copy_ctor(&tmp); - convert_to_string(&tmp); - source_string = &tmp; - - init_op_array(op_array, INITIAL_OP_ARRAY_SIZE); - op_array->type = ZEND_EVAL_CODE; - save_lexical_state(&original_lex_state CLS_CC); - if (prepare_string_for_scanning(source_string CLS_CC)==FAILURE) { - destroy_op_array(op_array); - efree(op_array); - retval = NULL; - } else { - CG(active_op_array) = op_array; -#ifndef ZTS - BEGIN(ST_IN_SCRIPTING); -#else - CG(ZFL)->BeginState(ST_IN_SCRIPTING); -#endif - compiler_result = zendparse(CLS_C); - restore_lexical_state(&original_lex_state CLS_CC); - - if (compiler_result==1) { - CG(active_op_array) = original_active_op_array; - CG(unclean_shutdown)=1; - retval = NULL; - } else { - do_return(NULL, 0 CLS_CC); - CG(active_op_array) = original_active_op_array; - pass_two(op_array); - pass_include_eval(op_array); - retval = op_array; - } - } - zval_dtor(&tmp); - CG(in_compilation) = original_in_compilation; - return retval; -} - - -BEGIN_EXTERN_C() -int require_filename(char *filename CLS_DC) -{ - zend_file_handle file_handle; - - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = filename; - file_handle.free_filename = 0; - if (require_file(&file_handle, 0 CLS_CC)==FAILURE) { - zend_bailout(); - return FAILURE; /* will never get here */ - } - return SUCCESS; -} - - -int use_filename(char *filename, uint filename_length CLS_DC) -{ - zend_file_handle file_handle; - - file_handle.filename = (char *) emalloc(filename_length + zend_uv.import_use_extension_length); - memcpy(file_handle.filename, filename, filename_length); - memcpy(file_handle.filename+filename_length, zend_uv.import_use_extension, zend_uv.import_use_extension_length); - file_handle.filename[filename_length+zend_uv.import_use_extension_length] = 0; - file_handle.free_filename = 1; - - file_handle.type = ZEND_HANDLE_FILENAME; - if (require_file(&file_handle, 1 CLS_CC)==FAILURE) { - efree(file_handle.filename); - zend_bailout(); - return FAILURE; /* will never get here */ - } - return SUCCESS; -} - - -int require_file(zend_file_handle *file_handle, zend_bool unique CLS_DC) -{ - zend_lex_state original_lex_state; - int compiler_result; - - save_lexical_state(&original_lex_state CLS_CC); - if (open_file_for_scanning(file_handle CLS_CC)==FAILURE) { - zend_message_dispatcher(ZMSG_FAILED_REQUIRE_FOPEN, file_handle->filename); - return FAILURE; - } - if (file_handle->opened_path) { - if (unique) { - zend_file_handle *pfh; - - if (zend_hash_add(&CG(used_files), file_handle->opened_path, strlen(file_handle->opened_path)+1, file_handle, sizeof(zend_file_handle), (void **) &pfh)==FAILURE) { - zend_close_file_handle(file_handle CLS_CC); - restore_lexical_state(&original_lex_state CLS_CC); - return SUCCESS; - } else { - /* pfh is a copy we only save for get_used_files() */ - pfh->type = ZEND_HANDLE_FILENAME; - if (pfh->filename) { - pfh->filename = estrdup(pfh->filename); - } - if (pfh->opened_path) { - pfh->opened_path = strdup(pfh->opened_path); - } - } - } - } - compiler_result = zendparse(CLS_C); - zend_close_file_handle(file_handle CLS_CC); - restore_lexical_state(&original_lex_state CLS_CC); - if (compiler_result==1) { - zend_bailout(); - } - return SUCCESS; -} - - -int highlight_file(char *filename, zend_syntax_highlighter_ini *syntax_highlighter_ini) -{ - zend_lex_state original_lex_state; - zend_file_handle file_handle; - CLS_FETCH(); - - file_handle.type = ZEND_HANDLE_FILENAME; - file_handle.filename = filename; - file_handle.free_filename = 0; - file_handle.opened_path = NULL; - save_lexical_state(&original_lex_state CLS_CC); - if (open_file_for_scanning(&file_handle CLS_CC)==FAILURE) { - zend_message_dispatcher(ZMSG_FAILED_HIGHLIGHT_FOPEN, filename); - return FAILURE; - } - zend_highlight(syntax_highlighter_ini); - zend_close_file_handle(&file_handle CLS_CC); - restore_lexical_state(&original_lex_state CLS_CC); - return SUCCESS; -} - - -int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_ini) -{ - zend_lex_state original_lex_state; - zval tmp = *str; - CLS_FETCH(); - - str = &tmp; - zval_copy_ctor(str); - save_lexical_state(&original_lex_state CLS_CC); - if (prepare_string_for_scanning(str CLS_CC)==FAILURE) { - return FAILURE; - } - zend_highlight(syntax_highlighter_ini); - restore_lexical_state(&original_lex_state CLS_CC); - zval_dtor(str); - return SUCCESS; -} -END_EXTERN_C() - -#ifdef ZTS -BEGIN_EXTERN_C() -int lex_scan(zval *zendlval CLS_DC) -{ - return CG(ZFL)->lex_scan(zendlval CLS_CC); -} - - -const char *zend_get_zendtext(CLS_D) -{ - return CG(ZFL)->YYText(); -} - - -int zend_get_zendleng(CLS_D) -{ - return CG(ZFL)->YYLeng(); -} -END_EXTERN_C() - - -void ZendFlexLexer::BeginState(int state) -{ - BEGIN(state); -} - - -ZendFlexLexer::~ZendFlexLexer() -{ - if (yy_start_stack) { - yy_flex_free(yy_start_stack); - } -} - - -int yyFlexLexer::yylex() -{ - fprintf(stderr, "Error: yyFlexLexer::yylex() called\n"); - return -1; -} - -#endif - - -/* redefine YY_INPUT to handle urls for win32*/ -#if 0 /*defined(ZEND_WIN32)*/ -#define YY_INPUT(buf,result,max_size) \ - if ( yyin->_tmpfname != "url" ){ \ - if ( yy_current_buffer->yy_is_interactive ) \ - { \ - int c = '*', n; \ - for ( n = 0; n < max_size && \ - (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( c == EOF && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - result = n; \ - } \ - else if ( ((result = fread( buf, 1, max_size, yyin )) == 0) \ - && ferror( yyin ) ) \ - YY_FATAL_ERROR( "input in flex scanner failed" ); \ - }else{ /* this is a url */ \ - int recv_char=0,socketd=0; \ - /*memset(buf,0,max_size);*/ \ - socketd=yyin->_file; \ - if ( yy_current_buffer->yy_is_interactive ) \ - { \ - int c = '*', n; \ - for ( n = 0; n < max_size && \ - ( (recv_char=recv( socketd,(char *)&c,1,0 ))) >0 && c != '\n'; ++n ) \ - buf[n] = (char) c; \ - if ( c == '\n' ) \ - buf[n++] = (char) c; \ - if ( recv_char == SOCKET_ERROR ) \ - YY_FATAL_ERROR( "input from url in flex scanner failed" ); \ - result = n; \ - } \ - else if ((result = recv( socketd, (char *)buf, max_size, 0)) == SOCKET_ERROR) \ - YY_FATAL_ERROR( "input from url read in flex scanner failed" ); \ - } -#endif - -%} - -LNUM [0-9]+ -DNUM ([0-9]*[\.][0-9]+)|([0-9]+[\.][0-9]*) -EXPONENT_DNUM (({LNUM}|{DNUM})[eE][+-]?{LNUM}) -HNUM "0x"[0-9a-fA-F]+ -LABEL [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]* -WHITESPACE [ \n\r\t]+ -TABS_AND_SPACES [ \t]* -TOKENS [;:,.\[\]()|^&+-/*=%!~$<>?@] -ENCAPSED_TOKENS [\[\]{}$] -ESCAPED_AND_WHITESPACE [\n\t\r #'.:;,()|^&+-/*=%!~<>?@]+ - -%option noyylineno -%option noyywrap -%% - -"exit" { - return T_EXIT; -} - -"die" { - return T_EXIT; -} - -"old_function" { - return T_OLD_FUNCTION; -} - -"function"|"cfunction" { - return T_FUNCTION; -} - -"const" { - return T_CONST; -} - -"return" { - return T_RETURN; -} - -"if" { - return T_IF; -} - -"elseif" { - return T_ELSEIF; -} - -"endif" { - return T_ENDIF; -} - -"else" { - return T_ELSE; -} - -"while" { - return T_WHILE; -} - -"endwhile" { - return T_ENDWHILE; -} - -"do" { - return T_DO; -} - -"for" { - return T_FOR; -} - -"endfor" { - return T_ENDFOR; -} - -"foreach" { - return T_FOREACH; -} - -"endforeach" { - return T_ENDFOREACH; -} - -"declare" { - return T_DECLARE; -} - -"enddeclare" { - return T_ENDDECLARE; -} - -"as" { - return T_AS; -} - -"switch" { - return T_SWITCH; -} - -"endswitch" { - return T_ENDSWITCH; -} - -"case" { - return T_CASE; -} - -"default" { - return T_DEFAULT; -} - -"break" { - return T_BREAK; -} - -"continue" { - return T_CONTINUE; -} - -"echo" { - return T_ECHO; -} - -"print" { - return T_PRINT; -} - -"class" { - return T_CLASS; -} - -"extends" { - return T_EXTENDS; -} - -"->" { - yy_push_state(ST_LOOKING_FOR_PROPERTY); - return T_OBJECT_OPERATOR; -} - -{LABEL} { - yy_pop_state(); - zendlval->value.str.val = (char *)estrndup(yytext, yyleng); - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - return T_STRING; -} - -. { - /*unput(yytext[0]);*/ - yyless(0); - yy_pop_state(); -} - -"::" { - return T_PAAMAYIM_NEKUDOTAYIM; -} - -"new" { - return T_NEW; -} - -"var" { - return T_VAR; -} - -"("{TABS_AND_SPACES}("int"|"integer"){TABS_AND_SPACES}")" { - return T_INT_CAST; -} - -"("{TABS_AND_SPACES}("real"|"double"|"float"){TABS_AND_SPACES}")" { - return T_DOUBLE_CAST; -} - -"("{TABS_AND_SPACES}"string"{TABS_AND_SPACES}")" { - return T_STRING_CAST; -} - -"("{TABS_AND_SPACES}"array"{TABS_AND_SPACES}")" { - return T_ARRAY_CAST; -} - -"("{TABS_AND_SPACES}"object"{TABS_AND_SPACES}")" { - return T_OBJECT_CAST; -} - -"("{TABS_AND_SPACES}("bool"|"boolean"){TABS_AND_SPACES}")" { - return T_BOOL_CAST; -} - -"("{TABS_AND_SPACES}("unset"){TABS_AND_SPACES}")" { - return T_UNSET_CAST; -} - -"eval" { - return T_EVAL; -} - -"include" { - return T_INCLUDE; -} - -"import" { - return T_IMPORT; -} - -"require" { - return T_REQUIRE; -} - -"use" { - return T_USE; -} - -"global" { - return T_GLOBAL; -} - -"isset" { - return T_ISSET; -} - -"empty" { - return T_EMPTY; -} - -"static" { - return T_STATIC; -} - -"unset" { - return T_UNSET; -} - -"=>" { - return T_DOUBLE_ARROW; -} - -"list" { - return T_LIST; -} - -"array" { - return T_ARRAY; -} - -"++" { - return T_INC; -} - -"--" { - return T_DEC; -} - -"===" { - return T_IS_IDENTICAL; -} - -"==" { - return T_IS_EQUAL; -} - -"!="|"<>" { - return T_IS_NOT_EQUAL; -} - -"<=" { - return T_IS_SMALLER_OR_EQUAL; -} - -">=" { - return T_IS_GREATER_OR_EQUAL; -} - -"+=" { - return T_PLUS_EQUAL; -} - -"-=" { - return T_MINUS_EQUAL; -} - -"*=" { - return T_MUL_EQUAL; -} - -"/=" { - return T_DIV_EQUAL; -} - -".=" { - return T_CONCAT_EQUAL; -} - - -"%=" { - return T_MOD_EQUAL; -} - -"<<=" { - return T_SL_EQUAL; -} - -">>=" { - return T_SR_EQUAL; -} - -"&=" { - return T_AND_EQUAL; -} - -"|=" { - return T_OR_EQUAL; -} - -"^=" { - return XT_OR_EQUAL; -} - -"||" { - return T_BOOLEAN_OR; -} - -"&&" { - return T_BOOLEAN_AND; -} - -"OR" { - return T_LOGICAL_OR; -} - -"AND" { - return T_LOGICAL_AND; -} - -"XOR" { - return T_LOGICAL_XOR; -} - -"<<" { - return T_SL; -} - -">>" { - return T_SR; -} - -{TOKENS} { - return yytext[0]; -} - - -"{" { - yy_push_state(ST_IN_SCRIPTING); - return '{'; -} - - -"${" { - yy_push_state(ST_LOOKING_FOR_VARNAME); - return T_DOLLAR_OPEN_CURLY_BRACES; -} - - -"}" { - /* This is a temporary fix which is dependant on flex and it's implementation */ - if (yy_start_stack_ptr) { - yy_pop_state(); - } - return '}'; -} - - -{LABEL} { - zendlval->value.str.val = (char *) estrndup(yytext, yyleng); - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - yy_pop_state(); - yy_push_state(ST_IN_SCRIPTING); - return T_STRING_VARNAME; -} - - -. { - /*unput(yytext[0]);*/ - yyless(0); - yy_pop_state(); - yy_push_state(ST_IN_SCRIPTING); -} - - -{LNUM}|{HNUM} { - errno = 0; - zendlval->value.lval = strtol(yytext, NULL, 0); - if (errno == ERANGE) { /* overflow */ - zendlval->value.dval = strtod(yytext,NULL); - zendlval->type = IS_DOUBLE; - return T_DNUMBER; - } else { - zendlval->type = IS_LONG; - return T_LNUMBER; - } -} - -{LNUM}|{HNUM} { /* treat numbers (almost) as strings inside encapsulated strings */ - zendlval->value.str.val = (char *)estrndup(yytext, yyleng); - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - return T_NUM_STRING; -} - -{DNUM}|{EXPONENT_DNUM} { - zendlval->value.dval = strtod(yytext,NULL); - zendlval->type = IS_DOUBLE; - return T_DNUMBER; -} - -"__LINE__" { - zendlval->value.lval = CG(zend_lineno); - zendlval->type = IS_LONG; - return T_LINE; -} - -"__FILE__" { - char *filename = zend_get_compiled_filename(CLS_C); - - if (!filename) { - filename = ""; - } - zendlval->value.str.len = strlen(filename); - zendlval->value.str.val = estrndup(filename,zendlval->value.str.len); - zendlval->type = IS_STRING; - return T_FILE; -} - - -(([^<]|"<"[^?%s<]){1,400})|"value.str.val = (char *) estrndup(yytext, yyleng); - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - HANDLE_NEWLINES(yytext,yyleng); - return T_INLINE_HTML; -} - -"" { - HANDLE_NEWLINES(yytext,yyleng); - if (CG(short_tags) || yyleng>2) { /* yyleng>2 means it's not */ - zendlval->value.str.val = yytext; /* no copying - intentional */ - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - BEGIN(ST_IN_SCRIPTING); - return T_OPEN_TAG; - } else { - zendlval->value.str.val = (char *) estrndup(yytext, yyleng); - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - return T_INLINE_HTML; - } -} - - -"<%="|"value.str.val = yytext; /* no copying - intentional */ - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - BEGIN(ST_IN_SCRIPTING); - return T_OPEN_TAG_WITH_ECHO; - } else { - zendlval->value.str.val = (char *) estrndup(yytext, yyleng); - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - return T_INLINE_HTML; - } -} - - -"<%" { - if (CG(asp_tags)) { - zendlval->value.str.val = yytext; /* no copying - intentional */ - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - BEGIN(ST_IN_SCRIPTING); - } else { - zendlval->value.str.val = (char *) estrndup(yytext, yyleng); - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - return T_INLINE_HTML; - } -} - - -"value.str.val = yytext; /* no copying - intentional */ - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - HANDLE_NEWLINE(yytext[yyleng-1]); - BEGIN(ST_IN_SCRIPTING); - return T_OPEN_TAG; -} - - -""([\n]|"\r\n")? { - zend_message_dispatcher(ZMSG_ENABLE_TRACK_VARS, NULL); - HANDLE_NEWLINE(yytext[yyleng-1]); - return T_PHP_TRACK_VARS; -} - -"$"{LABEL} { - zendlval->value.str.val = (char *)estrndup(yytext+1, yyleng-1); - zendlval->value.str.len = yyleng-1; - zendlval->type = IS_STRING; - return T_VARIABLE; -} - - -{LABEL} { - zendlval->value.str.val = (char *)estrndup(yytext, yyleng); - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - return T_STRING; -} - - -{LABEL} { - zendlval->value.str.val = (char *)estrndup(yytext, yyleng); - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - return T_STRING; -} - - -{WHITESPACE} { - zendlval->value.str.val = yytext; /* no copying - intentional */ - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - HANDLE_NEWLINES(yytext,yyleng); - return T_WHITESPACE; -} - - -([#]|"//")([^\n\r?]|"?"[^>\n\r])*("?\n"|"?\r\n")? { /* eat one line comments */ - HANDLE_NEWLINE(yytext[yyleng-1]); - return T_COMMENT; -} - -"/*" { - CG(comment_start_line) = CG(zend_lineno); - BEGIN(ST_COMMENT); - yymore(); -} - - -[^*]+ { - yymore(); -} - -"*/" { - HANDLE_NEWLINES(yytext, yyleng); - BEGIN(ST_IN_SCRIPTING); - return T_COMMENT; -} - -"*" { - yymore(); -} - -("?>"|"")([\n]|"\r\n")? { - zendlval->value.str.val = yytext; /* no copying - intentional */ - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - HANDLE_NEWLINES(yytext, yyleng); - BEGIN(INITIAL); - return T_CLOSE_TAG; /* implicit ';' at php-end tag */ -} - - -"%>"([\n]|"\r\n")? { - zendlval->value.str.val = yytext; /* no copying - intentional */ - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - HANDLE_NEWLINES(yytext,yyleng); - if (CG(asp_tags)) { - BEGIN(INITIAL); - return T_CLOSE_TAG; /* implicit ';' at php-end tag */ - } else { - return T_INLINE_HTML; - } -} - - -(["]([^$"\\]|("\\".))*["]) { - register char *s, *t; - char *end; - - zendlval->value.str.val = estrndup(yytext+1, yyleng-2); - zendlval->value.str.len = yyleng-2; - zendlval->type = IS_STRING; - HANDLE_NEWLINES(yytext,yyleng); - - /* convert escape sequences */ - s = t = zendlval->value.str.val; - end = s+zendlval->value.str.len; - while (s=end) { - continue; - } - switch(*s) { - case 'n': - *t++ = '\n'; - zendlval->value.str.len--; - break; - case 'r': - *t++ = '\r'; - zendlval->value.str.len--; - break; - case 't': - *t++ = '\t'; - zendlval->value.str.len--; - break; - case '\\': - case '$': - case '"': - *t++ = *s; - zendlval->value.str.len--; - break; - default: - /* check for an octal */ - if (ZEND_IS_OCT(*s)) { - char octal_buf[4] = { 0, 0, 0, 0 }; - - octal_buf[0] = *s; - zendlval->value.str.len--; - if ((s+1)value.str.len--; - if ((s+1)value.str.len--; - } - } - *t++ = (char) strtol(octal_buf, NULL, 8); - } else if (*s=='x' && (s+1)value.str.len--; /* for the 'x' */ - - hex_buf[0] = *(++s); - zendlval->value.str.len--; - if ((s+1)value.str.len--; - } - *t++ = (char) strtol(hex_buf, NULL, 16); - } else { - *t++ = '\\'; - *t++ = *s; - } - break; - } - s++; - } else { - *t++ = *s++; - } - } - *t = 0; - - return T_CONSTANT_ENCAPSED_STRING; -} - - -([']([^'\\]|("\\".))*[']) { - register char *s, *t; - char *end; - - zendlval->value.str.val = estrndup(yytext+1, yyleng-2); - zendlval->value.str.len = yyleng-2; - zendlval->type = IS_STRING; - HANDLE_NEWLINES(yytext,yyleng); - - /* convert escape sequences */ - s = t = zendlval->value.str.val; - end = s+zendlval->value.str.len; - while (s=end) { - continue; - } - switch(*s) { - case '\\': - case '\'': - *t++ = *s; - zendlval->value.str.len--; - break; - default: - *t++ = '\\'; - *t++ = *s; - break; - } - s++; - } else { - *t++ = *s++; - } - } - *t = 0; - - return T_CONSTANT_ENCAPSED_STRING; -} - - -["] { - BEGIN(ST_DOUBLE_QUOTES); - return '\"'; -} - - -"<<<"{TABS_AND_SPACES}{LABEL}("\r")?"\n" { - char *s; - CG(zend_lineno)++; - CG(heredoc_len) = yyleng-3-1-(yytext[yyleng-2]=='\r'?1:0); - s = yytext+3; - while ((*s == ' ') || (*s == '\t')) { - s++; - CG(heredoc_len)--; - } - CG(heredoc) = estrndup(s, CG(heredoc_len)); - BEGIN(ST_HEREDOC); - return T_START_HEREDOC; -} - - -[`] { - BEGIN(ST_BACKQUOTE); - return '`'; -} - - -['] { - BEGIN(ST_SINGLE_QUOTE); - return '\''; -} - - -^{LABEL}(";")?("\r")?"\n" { - int label_len; - unsigned char unput_semicolon; - - CG(zend_lineno)++; - if (yytext[yyleng-2]=='\r') { - label_len = yyleng-2; - } else { - label_len = yyleng-1; - } - - if (yytext[label_len-1]==';') { - label_len--; - unput_semicolon=1; - } else{ - unput_semicolon=0; - } - - if (label_len==CG(heredoc_len) && !memcmp(yytext, CG(heredoc), label_len)) { - zendlval->value.str.val = estrndup(yytext, yyleng); /* unput destroys yytext */ - zendlval->value.str.len = yyleng; - if (unput_semicolon) { - unput(';'); - } - efree(CG(heredoc)); - CG(heredoc)=NULL; - CG(heredoc_len)=0; - BEGIN(ST_IN_SCRIPTING); - return T_END_HEREDOC; - } else { - zendlval->value.str.val = (char *)estrndup(yytext, yyleng); - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - return T_STRING; - } -} - - -{ESCAPED_AND_WHITESPACE} { - HANDLE_NEWLINES(yytext,yyleng); - zendlval->value.str.val = (char *) estrndup(yytext, yyleng); - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - return T_ENCAPSED_AND_WHITESPACE; -} - -([^'\\]|\\[^'\\])+ { - HANDLE_NEWLINES(yytext,yyleng); - zendlval->value.str.val = (char *) estrndup(yytext, yyleng); - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - return T_ENCAPSED_AND_WHITESPACE; -} - - -[`]+ { - zendlval->value.str.val = (char *) estrndup(yytext, yyleng); - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - return T_ENCAPSED_AND_WHITESPACE; -} - - -["]+ { - zendlval->value.str.val = (char *) estrndup(yytext, yyleng); - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - return T_ENCAPSED_AND_WHITESPACE; -} - - -"$"[^a-zA-Z_\x7f-\xff{] { - zendlval->value.chval = yytext[0]; - if (yyleng == 2) { - yyless(1); - /*unput(yytext[1]); - yytext[1] = 0; - yyleng--;*/ - } - return T_CHARACTER; -} - - -{ENCAPSED_TOKENS} { - zendlval->value.chval = yytext[0]; - return yytext[0]; -} - -"{$" { - zendlval->value.chval = yytext[0]; - yy_push_state(ST_IN_SCRIPTING); - /*unput('$');*/ - yyless(1); - return T_CURLY_OPEN; -} - - -"\\'" { - zendlval->value.chval='\''; - return T_CHARACTER; -} - -"\\\\" { - zendlval->value.chval='\\'; - return T_CHARACTER; -} - -"\\\"" { - zendlval->value.chval='"'; - return T_CHARACTER; -} - -"\\`" { - zendlval->value.chval='`'; - return T_CHARACTER; -} - -"\\"[0-7]{1,3} { - zendlval->value.chval = (char) strtol (yytext+1, NULL, 8); - return T_CHARACTER; -} - -"\\x"[0-9A-Fa-f]{1,2} { - zendlval->value.chval = (char) strtol (yytext+2, NULL, 16); - return T_CHARACTER; -} - -"\\". { - switch (yytext[1]) { - case 'n': - zendlval->value.chval='\n'; - break; - case 't': - zendlval->value.chval='\t'; - break; - case 'r': - zendlval->value.chval='\r'; - break; - case '\\': - zendlval->value.chval='\\'; - break; - case '$': - zendlval->value.chval=yytext[1]; - break; - case '{': - zendlval->value.chval=yytext[1]; - break; - default: - zendlval->value.str.val = estrndup(yytext,yyleng); - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - return T_BAD_CHARACTER; - break; - } - return T_CHARACTER; -} - - -["'`]+ { - zendlval->value.str.val = (char *) estrndup(yytext, yyleng); - zendlval->value.str.len = yyleng; - zendlval->type = IS_STRING; - return T_ENCAPSED_AND_WHITESPACE; -} - - -["] { - BEGIN(ST_IN_SCRIPTING); - return '\"'; -} - - -[`] { - BEGIN(ST_IN_SCRIPTING); - return '`'; -} - - -['] { - BEGIN(ST_IN_SCRIPTING); - return '\''; -} - - -<> { - return 0; -} - -<> { - zend_error(E_COMPILE_WARNING,"Unterminated comment starting line %d", CG(comment_start_line)); - return 0; -} - - - -. { - zend_error(E_COMPILE_WARNING,"Unexpected character in input: '%c' (ASCII=%d) state=%d",yytext[0],yytext[0],YYSTATE); -} diff --git a/Zend/zend.c b/Zend/zend.c deleted file mode 100644 index 611ee6b4f1..0000000000 --- a/Zend/zend.c +++ /dev/null @@ -1,466 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include "zend.h" -#include "zend_operators.h" -#include "zend_variables.h" -#include "zend_extensions.h" -#include "modules.h" -#include "zend_constants.h" -#include "zend_list.h" -#include "zend_API.h" -#include "zend_builtin_functions.h" - -#ifdef ZTS -# define GLOBAL_FUNCTION_TABLE global_function_table -# define GLOBAL_CLASS_TABLE global_class_table -# define GLOBAL_CONSTANTS_TABLE global_constants_table -#else -# define GLOBAL_FUNCTION_TABLE CG(function_table) -# define GLOBAL_CLASS_TABLE CG(class_table) -# define GLOBAL_CONSTANTS_TABLE CG(zend_constants) -#endif - -/* true multithread-shared globals */ -ZEND_API zend_class_entry zend_standard_class_def; -ZEND_API int (*zend_printf)(const char *format, ...); -ZEND_API int (*zend_write)(const char *str, uint str_length); -ZEND_API void (*zend_error)(int type, const char *format, ...); -ZEND_API void (*zend_message_dispatcher)(long message, void *data); -ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path); -ZEND_API void (*zend_block_interruptions)(void); -ZEND_API void (*zend_unblock_interruptions)(void); -ZEND_API int (*zend_get_ini_entry)(char *name, uint name_length, zval *contents); -ZEND_API void (*zend_ticks_function)(int ticks); - -#ifdef ZTS -ZEND_API int compiler_globals_id; -ZEND_API int executor_globals_id; -ZEND_API int alloc_globals_id; -HashTable *global_function_table; -HashTable *global_class_table; -HashTable *global_constants_table; -#endif - -zend_utility_values zend_uv; - -ZEND_API zval zval_used_for_init; /* True global variable */ - -/* version information */ -static char *zend_version_info; -static uint zend_version_info_length; -#define ZEND_CORE_VERSION_INFO "Zend Engine v" ZEND_VERSION ", Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski\n" - - -#define PRINT_ZVAL_INDENT 4 - -static void print_hash(HashTable *ht, int indent) -{ - zval **tmp; - char *string_key; - unsigned long num_key; - int i; - - for (i=0; i "); - zend_print_zval_r(*tmp, indent+PRINT_ZVAL_INDENT); - ZEND_PUTS("\n"); - zend_hash_move_forward(ht); - } - indent -= PRINT_ZVAL_INDENT; - for (i=0; itype==IS_STRING) { - *use_copy = 0; - return; - } - switch (expr->type) { - case IS_NULL: - expr_copy->value.str.len = 0; - expr_copy->value.str.val = empty_string; - break; - case IS_BOOL: -#if 1 - if (expr->value.lval) { - expr_copy->value.str.len = 1; - expr_copy->value.str.val = estrndup("1", 1); - } else { - expr_copy->value.str.len = 0; - expr_copy->value.str.val = empty_string; - } -#else - if (expr->value.lval) { - expr_copy->value.str.len = sizeof("true")-1; - expr_copy->value.str.val = estrndup("true", expr_copy->value.str.len); - } else { - expr_copy->value.str.len = sizeof("false")-1; - expr_copy->value.str.val = estrndup("false", expr_copy->value.str.len); - } -#endif - break; - case IS_RESOURCE: - expr_copy->value.str.val = (char *) emalloc(sizeof("Resource id #")-1 + MAX_LENGTH_OF_LONG); - expr_copy->value.str.len = sprintf(expr_copy->value.str.val, "Resource id #%ld", expr->value.lval); - break; - case IS_ARRAY: - expr_copy->value.str.len = sizeof("Array")-1; - expr_copy->value.str.val = estrndup("Array", expr_copy->value.str.len); - break; - case IS_OBJECT: { - zval function_name; - - function_name.value.str.len = sizeof("to_string")-1; - function_name.value.str.val = estrndup("to_string", function_name.value.str.len); - function_name.type = IS_STRING; - - if (call_user_function(NULL, expr, &function_name, expr_copy, 0, NULL)==FAILURE) { - expr_copy->value.str.len = sizeof("Object")-1; - expr_copy->value.str.val = estrndup("Object", expr_copy->value.str.len); - } - efree(function_name.value.str.val); - } - break; - default: - *expr_copy = *expr; - zval_copy_ctor(expr_copy); - convert_to_string(expr_copy); - break; - } - expr_copy->type = IS_STRING; - *use_copy = 1; -} - - -ZEND_API int zend_print_zval(zval *expr, int indent) -{ - zval expr_copy; - int use_copy; - - zend_make_printable_zval(expr, &expr_copy, &use_copy); - if (use_copy) { - expr = &expr_copy; - } - if (expr->value.str.len==0) { /* optimize away empty strings */ - if (use_copy) { - zval_dtor(expr); - } - return 0; - } - ZEND_WRITE(expr->value.str.val,expr->value.str.len); - if (use_copy) { - zval_dtor(expr); - } - return expr->value.str.len; -} - - -ZEND_API void zend_print_zval_r(zval *expr, int indent) -{ - switch(expr->type) { - case IS_ARRAY: - ZEND_PUTS("Array\n"); - print_hash(expr->value.ht,indent); - break; - case IS_OBJECT: - zend_printf("%s Object\n", expr->value.obj.ce->name); - print_hash(expr->value.obj.properties, indent); - break; - default: - zend_print_variable(expr); - break; - } -} - - -static FILE *zend_fopen_wrapper(const char *filename, char **opened_path) -{ - if (opened_path) { - *opened_path = strdup(filename); - } - return fopen(filename, "r"); -} - - -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(&zend_standard_class_def.default_properties, 0, NULL, ZVAL_PTR_DTOR, 1); - zend_hash_init(&zend_standard_class_def.function_table, 0, NULL, ZEND_FUNCTION_DTOR, 1); - 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); -} - - -#ifdef ZTS -static void compiler_globals_ctor(zend_compiler_globals *compiler_globals) -{ - zend_function tmp_func; - zend_class_entry tmp_class; - - compiler_globals->function_table = (HashTable *) malloc(sizeof(HashTable)); - zend_hash_init(compiler_globals->function_table, 100, NULL, ZEND_FUNCTION_DTOR, 1); - zend_hash_copy(compiler_globals->function_table, global_function_table, NULL, &tmp_func, sizeof(zend_function)); - - compiler_globals->class_table = (HashTable *) malloc(sizeof(HashTable)); - zend_hash_init(compiler_globals->class_table, 10, NULL, ZEND_CLASS_DTOR, 1); - zend_hash_copy(compiler_globals->class_table, global_class_table, (copy_ctor_func_t) zend_class_add_ref, &tmp_class, sizeof(zend_class_entry)); - - compiler_globals->extended_info = 0; -} - - -static void compiler_globals_dtor(zend_compiler_globals *compiler_globals) -{ - 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); - } -} - - -static void executor_globals_ctor(zend_executor_globals *executor_globals) -{ - if (global_constants_table) { - zend_startup_constants(ELS_C); - zend_copy_constants(executor_globals->zend_constants, global_constants_table); - } - init_resource_plist(ELS_C); -} - - -static void executor_globals_dtor(zend_executor_globals *executor_globals) -{ - zend_shutdown_constants(ELS_C); - destroy_resource_plist(ELS_C); -} - - -static void alloc_globals_ctor(zend_alloc_globals *alloc_globals) -{ - start_memory_manager(ALS_C); -} - -#endif - - -int zend_startup(zend_utility_functions *utility_functions, char **extensions) -{ -#ifdef ZTS - zend_compiler_globals *compiler_globals; - zend_executor_globals *executor_globals; - - alloc_globals_id = ts_allocate_id(sizeof(zend_alloc_globals), (ts_allocate_ctor) alloc_globals_ctor, NULL); -#else - start_memory_manager(ALS_C); -#endif - - /* Set up utility functions and values */ - zend_error = utility_functions->error_function; - zend_printf = utility_functions->printf_function; - zend_write = utility_functions->write_function; - zend_fopen = utility_functions->fopen_function; - if (!zend_fopen) { - zend_fopen = zend_fopen_wrapper; - } - zend_message_dispatcher = utility_functions->message_handler; - zend_block_interruptions = utility_functions->block_interruptions; - zend_unblock_interruptions = utility_functions->unblock_interruptions; - zend_get_ini_entry = utility_functions->get_ini_entry; - zend_ticks_function = utility_functions->ticks_function; - - zend_compile_files = compile_files; - zend_execute = execute; - - zend_llist_init(&zend_extensions, sizeof(zend_extension), (void (*)(void *)) zend_extension_dtor, 1); - - /* set up version */ - zend_version_info = strdup(ZEND_CORE_VERSION_INFO); - zend_version_info_length = sizeof(ZEND_CORE_VERSION_INFO)-1; - - GLOBAL_FUNCTION_TABLE = (HashTable *) malloc(sizeof(HashTable)); - GLOBAL_CLASS_TABLE = (HashTable *) malloc(sizeof(HashTable)); - zend_hash_init(GLOBAL_FUNCTION_TABLE, 100, NULL, ZEND_FUNCTION_DTOR, 1); - zend_hash_init(GLOBAL_CLASS_TABLE, 10, NULL, ZEND_CLASS_DTOR, 1); - register_standard_class(); - zend_hash_init(&module_registry, 50, NULL, ZEND_MODULE_DTOR, 1); - zend_hash_init(&list_destructors, 50, NULL, NULL, 1); - - /* This zval can be used to initialize allocate zval's to an uninit'ed value */ - zval_used_for_init.is_ref = 0; - zval_used_for_init.refcount = 1; - zval_used_for_init.type = IS_NULL; - -#ifdef ZTS - global_constants_table = NULL; - compiler_globals_id = ts_allocate_id(sizeof(zend_compiler_globals), (void (*)(void *)) compiler_globals_ctor, (void (*)(void *)) compiler_globals_dtor); - 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); - compiler_globals_dtor(compiler_globals); - compiler_globals->function_table = GLOBAL_FUNCTION_TABLE; - compiler_globals->class_table = GLOBAL_CLASS_TABLE; - zend_startup_constants(executor_globals); - GLOBAL_CONSTANTS_TABLE = EG(zend_constants); -#else - zend_startup_constants(); -#endif - zend_register_standard_constants(ELS_C); - -#ifndef ZTS - init_resource_plist(ELS_C); -#endif - - zend_startup_builtin_functions(); - - return SUCCESS; -} - - -void zend_shutdown() -{ -#ifndef ZTS - destroy_resource_plist(); -#endif - zend_hash_destroy(&list_destructors); - zend_hash_destroy(&module_registry); - zend_hash_destroy(GLOBAL_FUNCTION_TABLE); - free(GLOBAL_FUNCTION_TABLE); - zend_hash_destroy(GLOBAL_CLASS_TABLE); - free(GLOBAL_CLASS_TABLE); - zend_shutdown_extensions(); - free(zend_version_info); -#ifndef ZTS - zend_shutdown_constants(); -#endif -} - - -void zend_set_utility_values(zend_utility_values *utility_values) -{ - zend_uv = *utility_values; - zend_uv.import_use_extension_length = strlen(zend_uv.import_use_extension); -} - - -/* this should be compatible with the standard zenderror */ -void zenderror(char *error) -{ - zend_error(E_PARSE, error); -} - - -BEGIN_EXTERN_C() -ZEND_API void zend_bailout() -{ - CLS_FETCH(); - ELS_FETCH(); - - CG(unclean_shutdown) = 1; - longjmp(EG(bailout), FAILURE); -} -END_EXTERN_C() - - -void zend_append_version_info(zend_extension *extension) -{ - char *new_info; - uint new_info_length; - - new_info_length = sizeof(" with v, by \n") - + strlen(extension->name) - + strlen(extension->version) - + strlen(extension->copyright) - + strlen(extension->author); - - new_info = (char *) malloc(new_info_length+1); - - sprintf(new_info, " with %s v%s, %s, by %s\n", extension->name, extension->version, extension->copyright, extension->author); - - zend_version_info = (char *) realloc(zend_version_info, zend_version_info_length+new_info_length+1); - strcat(zend_version_info, new_info); - zend_version_info_length += new_info_length; - free(new_info); -} - - -ZEND_API char *get_zend_version() -{ - return zend_version_info; -} - - -void zend_activate(CLS_D ELS_DC) -{ - init_compiler(CLS_C ELS_CC); - init_executor(CLS_C ELS_CC); - startup_scanner(CLS_C); -} - - -void zend_activate_modules() -{ - zend_hash_apply(&module_registry, (int (*)(void *)) module_registry_request_startup); -} - - -void zend_deactivate(CLS_D ELS_DC) -{ - zend_hash_apply(&module_registry, (int (*)(void *)) module_registry_cleanup); - shutdown_scanner(CLS_C); - shutdown_executor(ELS_C); - shutdown_compiler(CLS_C); -} diff --git a/Zend/zend.h b/Zend/zend.h deleted file mode 100644 index 60b88f11e9..0000000000 --- a/Zend/zend.h +++ /dev/null @@ -1,379 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _ZEND_H -#define _ZEND_H - -#define ZEND_VERSION "0.90" - -#ifdef __cplusplus -#define BEGIN_EXTERN_C() extern "C" { -#define END_EXTERN_C() } -#else -#define BEGIN_EXTERN_C() -#define END_EXTERN_C() -#endif - -#include - -/* - * general definitions - */ - -#ifdef ZEND_WIN32 -# include "zend_config.w32.h" -#else -# include "zend_config.h" -#endif - -/* all HAVE_XXX test have to be after the include of zend_config above */ - -#ifdef HAVE_UNIX_H -# include -#endif - -#ifdef HAVE_STDARG_H -# include -#endif - -#ifdef HAVE_DLFCN_H -# include -#endif - -#if defined(HAVE_LIBDL) && defined(RTLD_NOW) -# define DL_LOAD(libname) dlopen(libname, RTLD_NOW) -# define DL_UNLOAD dlclose -# define DL_FETCH_SYMBOL dlsym -# define DL_HANDLE void * -# define ZEND_EXTENSIONS_SUPPORT 1 -#elif defined(ZEND_WIN32) -# define DL_LOAD(libname) LoadLibrary(libname) -# define DL_FETCH_SYMBOL GetProcAddress -# define DL_UNLOAD FreeLibrary -# define DL_HANDLE HMODULE -# define ZEND_EXTENSIONS_SUPPORT 1 -#else -# define DL_HANDLE void * -# define ZEND_EXTENSIONS_SUPPORT 0 -#endif - -#if ZEND_DEBUG -#define ZEND_FILE_LINE_D char *__zend_filename, uint __zend_lineno -#define ZEND_FILE_LINE_DC , ZEND_FILE_LINE_D -#define ZEND_FILE_LINE_ORIG_D char *__zend_orig_filename, uint __zend_orig_lineno -#define ZEND_FILE_LINE_ORIG_DC , ZEND_FILE_LINE_ORIG_D -#define ZEND_FILE_LINE_RELAY_C __zend_filename, __zend_lineno -#define ZEND_FILE_LINE_RELAY_CC , ZEND_FILE_LINE_RELAY_C -#define ZEND_FILE_LINE_C __FILE__, __LINE__ -#define ZEND_FILE_LINE_CC , ZEND_FILE_LINE_C -#define ZEND_FILE_LINE_EMPTY_C NULL, 0 -#define ZEND_FILE_LINE_EMPTY_CC , ZEND_FILE_LINE_EMPTY_C -#define ZEND_FILE_LINE_ORIG_RELAY_C __zend_orig_filename, __zend_orig_lineno -#define ZEND_FILE_LINE_ORIG_RELAY_CC , ZEND_FILE_LINE_ORIG_RELAY_C -#else -#define ZEND_FILE_LINE_D -#define ZEND_FILE_LINE_DC -#define ZEND_FILE_LINE_ORIG_D -#define ZEND_FILE_LINE_ORIG_DC -#define ZEND_FILE_LINE_RELAY_C -#define ZEND_FILE_LINE_RELAY_CC -#define ZEND_FILE_LINE_C -#define ZEND_FILE_LINE_CC -#define ZEND_FILE_LINE_EMPTY_C -#define ZEND_FILE_LINE_EMPTY_CC -#define ZEND_FILE_LINE_ORIG_RELAY_C -#define ZEND_FILE_LINE_ORIG_RELAY_CC -#endif /* ZEND_DEBUG */ - - -#include "zend_errors.h" -#include "zend_alloc.h" - -typedef unsigned char zend_bool; - -#undef SUCCESS -#undef FAILURE -#define SUCCESS 0 -#define FAILURE -1 /* this MUST stay a negative number, or it may affect functions! */ - - -#include "zend_hash.h" -#include "zend_llist.h" - -#define INTERNAL_FUNCTION_PARAMETERS int ht, zval *return_value, zval *this_ptr, int return_value_used ELS_DC -#define INTERNAL_FUNCTION_PARAM_PASSTHRU ht, return_value, this_ptr, return_value_used ELS_CC - -/* - * zval - */ -typedef struct _zval_struct zval; -typedef struct _zend_class_entry zend_class_entry; - -typedef union _zvalue_value { - long lval; /* long value */ - double dval; /* double value */ - struct { - char *val; - int len; - } str; - char chval; /* char value */ - HashTable *ht; /* hash table value */ - struct { - zend_class_entry *ce; - HashTable *properties; - } obj; -} zvalue_value; - - -struct _zval_struct { - /* Variable information */ - zvalue_value value; /* value */ - unsigned char type; /* active type */ - unsigned char is_ref; - short refcount; -}; - - - -typedef struct _zend_function_entry { - char *fname; - void (*handler)(INTERNAL_FUNCTION_PARAMETERS); - unsigned char *func_arg_types; -} zend_function_entry; - - -typedef struct _zend_property_reference { - int type; /* read, write or r/w */ - zval *object; - zend_llist elements_list; -} zend_property_reference; - - - -typedef struct _zend_overloaded_element { - int type; /* array offset or object proprety */ - zval element; -} zend_overloaded_element; - -/* excpt.h on Digital Unix 4.0 defines function_table */ -#undef function_table - -struct _zend_class_entry { - char type; - char *name; - uint name_length; - struct _zend_class_entry *parent; - int *refcount; - zend_bool constants_updated; - - HashTable function_table; - HashTable default_properties; - zend_function_entry *builtin_functions; - - /* handlers */ - void (*handle_function_call)(INTERNAL_FUNCTION_PARAMETERS, zend_property_reference *property_reference); - zval (*handle_property_get)(zend_property_reference *property_reference); - int (*handle_property_set)(zend_property_reference *property_reference, zval *value); -}; - - - -typedef struct _zend_utility_functions { - void (*error_function)(int type, const char *format, ...); - int (*printf_function)(const char *format, ...); - int (*write_function)(const char *str, uint str_length); - FILE *(*fopen_function)(const char *filename, char **opened_path); - void (*message_handler)(long message, void *data); - void (*block_interruptions)(void); - void (*unblock_interruptions)(void); - int (*get_ini_entry)(char *name, uint name_length, zval *contents); - void (*ticks_function)(int ticks); -} zend_utility_functions; - - -typedef struct _zend_utility_values { - zend_bool short_tags; - zend_bool asp_tags; - zend_bool allow_call_time_pass_reference; - char *import_use_extension; - uint import_use_extension_length; -} zend_utility_values; - - -#undef MIN -#undef MAX -#define MAX(a,b) (((a)>(b))?(a):(b)) -#define MIN(a,b) (((a)<(b))?(a):(b)) -#define ZEND_STRL(str) (str), (sizeof(str)-1) -#define ZEND_STRS(str) (str), (sizeof(str) - - -/* data types */ -#define IS_NULL 0 -#define IS_LONG 1 -#define IS_DOUBLE 2 -#define IS_STRING 3 -#define IS_ARRAY 4 -#define IS_OBJECT 5 -#define IS_BOOL 6 -#define IS_RESOURCE 7 -#define IS_CONSTANT 8 - -/* Special data type to temporarily mark large numbers */ -#define FLAG_IS_BC 9 /* for parser internal use only */ - -/* overloaded elements data types */ -#define OE_IS_ARRAY (1<<0) -#define OE_IS_OBJECT (1<<1) -#define OE_IS_METHOD (1<<2) - -int zend_startup(zend_utility_functions *utility_functions, char **extensions); -void zend_shutdown(void); - -void zend_set_utility_values(zend_utility_values *utility_values); -BEGIN_EXTERN_C() -ZEND_API void zend_bailout(void); -END_EXTERN_C() -ZEND_API char *get_zend_version(void); - -ZEND_API void zend_make_printable_zval(zval *expr, zval *expr_copy, int *use_copy); -ZEND_API int zend_print_zval(zval *expr, int indent); -ZEND_API void zend_print_zval_r(zval *expr, int indent); - -ZEND_API extern char *empty_string; - -#define STR_FREE(ptr) if (ptr && ptr!=empty_string) { efree(ptr); } -#define STR_FREE_REL(ptr) if (ptr && ptr!=empty_string) { efree_rel(ptr); } - -#define STR_REALLOC(ptr, size) \ - if (ptr!=empty_string) { \ - ptr = (char *) erealloc(ptr, size); \ - } else { \ - ptr = (char *) emalloc(size); \ - memset(ptr, 0, size); \ - } - -/* output support */ -#define ZEND_WRITE(str, str_len) zend_write((str), (str_len)) -#define ZEND_PUTS(str) zend_write((str), strlen((str))) -#define ZEND_PUTC(c) zend_write(&(c), 1), (c) - -BEGIN_EXTERN_C() -extern ZEND_API int (*zend_printf)(const char *format, ...); -extern ZEND_API int (*zend_write)(const char *str, uint str_length); -extern ZEND_API void (*zend_error)(int type, const char *format, ...); -extern ZEND_API FILE *(*zend_fopen)(const char *filename, char **opened_path); -extern ZEND_API void (*zend_block_interruptions)(void); -extern ZEND_API void (*zend_unblock_interruptions)(void); -extern ZEND_API void (*zend_message_dispatcher)(long message, void *data); -extern ZEND_API int (*zend_get_ini_entry)(char *name, uint name_length, zval *contents); -extern ZEND_API void (*zend_ticks_function)(int ticks); - -void zenderror(char *error); - -extern ZEND_API zend_class_entry zend_standard_class_def; -extern zend_utility_values zend_uv; -extern ZEND_API zval zval_used_for_init; - -END_EXTERN_C() - -#define ZEND_UV(name) (zend_uv.name) - - -#define HANDLE_BLOCK_INTERRUPTIONS() if (zend_block_interruptions) { zend_block_interruptions(); } -#define HANDLE_UNBLOCK_INTERRUPTIONS() if (zend_unblock_interruptions) { zend_unblock_interruptions(); } - - -/* Messages for applications of Zend */ -#define ZMSG_ENABLE_TRACK_VARS 1L -#define ZMSG_FAILED_INCLUDE_FOPEN 2L -#define ZMSG_FAILED_REQUIRE_FOPEN 3L -#define ZMSG_FAILED_HIGHLIGHT_FOPEN 4L -#define ZMSG_MEMORY_LEAK_DETECTED 5L -#define ZMSG_MEMORY_LEAK_REPEATED 6L -#define ZMSG_LOG_SCRIPT_NAME 7L - -#define INIT_PZVAL(z) \ - (z)->refcount = 1; \ - (z)->is_ref = 0; - -#define INIT_ZVAL(z) z = zval_used_for_init; - -#define ALLOC_INIT_ZVAL(zp) \ - ALLOC_ZVAL(zp); \ - INIT_ZVAL(*zp); - -#define MAKE_STD_ZVAL(zv) \ - ALLOC_ZVAL(zv); \ - INIT_PZVAL(zv); - -#define PZVAL_IS_REF(z) ((z)->is_ref) - -#define SEPARATE_ZVAL(ppzv) \ - { \ - zval *orig_ptr = *(ppzv); \ - \ - if (orig_ptr->refcount>1) { \ - orig_ptr->refcount--; \ - ALLOC_ZVAL(*(ppzv)); \ - **(ppzv) = *orig_ptr; \ - zval_copy_ctor(*(ppzv)); \ - (*(ppzv))->refcount=1; \ - (*(ppzv))->is_ref = 0; \ - } \ - } - -#define SEPARATE_ZVAL_IF_NOT_REF(ppzv) \ - if (!PZVAL_IS_REF(*ppzv)) { \ - SEPARATE_ZVAL(ppzv); \ - } - - -#define COPY_PZVAL_TO_ZVAL(zv, pzv) \ - (zv) = *(pzv); \ - if ((pzv)->refcount>1) { \ - zval_copy_ctor(&(zv)); \ - (pzv)->refcount--; \ - } else { \ - FREE_ZVAL(pzv); \ - } \ - INIT_PZVAL(&(zv)); - -#define ZEND_MAX_RESERVED_RESOURCES 1 - -#ifdef ZEND_WIN32 -/* Only use this macro if you know for sure that all of the switches values - are covered by its case statements */ -#define EMPTY_SWITCH_DEFAULT_CASE() \ - default: \ - __assume(0); \ - break; -#else -#define EMPTY_SWITCH_DEFAULT_CASE() -#endif - -#endif /* _ZEND_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/Zend/zend.ico b/Zend/zend.ico deleted file mode 100644 index 80978a6c7eb9797674ed75679fced786ad6f47a3..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1382 zcmbW$F>KmE7>41m6)kkj%9h1ZSG*H3pvo{Yl(2iMgoGk_h{X~QY0Lx?L&l6%WhR!0 zEEUQCQin`dhlmNJsH2sIE!X!p6bIZ zsmI*m;qLnPm(sV__S|aeb4mL0hWi*>aY)$pY?te^b8O$0!zL&1Xc^{tny=={zJ5}g8BNzl!_=s|F!E+bPC}k+j8{_sR`Rc;W+1sO zr5pSbKf#ai0ltH66AgS7U%@;0GM;s(Q~VI$#d~-Mt7if)yzs)Sr44?GpWsLM0N=s4 z*~13Dim%`ud>NnN*Z35_z|ZgrKEaRieY}rv;$6JK8@$0Ayulm%Gj&D1rCw13YAg2{ zevMD@3;YakS5MGmbRX@bn`oEyH~1xff*;`nd~3HXCHKN;WHG(;=H>e1>1+Q~Uxy!zcIzKgRd*KE8=}?N^C6 zc!M{1gEu@6+qGi5ZrQFYwku$}S}iHVukk5Vp7i+msE3CK-QVBq?(R-EH#bU>MAz5X8jr`iyu4Ju-&e2KlkfXFIXO|Y+0^mz Mv0T^H(b1890N*_06aWAK diff --git a/Zend/zend_API.c b/Zend/zend_API.c deleted file mode 100644 index 4cf4eb6e22..0000000000 --- a/Zend/zend_API.c +++ /dev/null @@ -1,947 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include "zend.h" -#include "zend_variables.h" -#include "zend_execute.h" -#include "zend_API.h" -#include "modules.h" -#include "zend_constants.h" -#include "zend_operators.h" - -#ifdef HAVE_STDARG_H -# include -#endif - -/* these variables are true statics/globals, and have to be mutex'ed on every access */ -static int module_count=0; -HashTable list_destructors, module_registry; - -/* this function doesn't check for too many parameters */ -ZEND_API int zend_get_parameters(int ht, int param_count,...) -{ - void **p; - int arg_count; - va_list ptr; - zval **param, *param_ptr; - ELS_FETCH(); - - p = EG(argument_stack).top_element-1; - arg_count = (ulong) *p; - - if (param_count>arg_count) { - return FAILURE; - } - - va_start(ptr, param_count); - - while (param_count>0) { - param = va_arg(ptr, zval **); - param_ptr = *(p-param_count); - if (!PZVAL_IS_REF(param_ptr) && param_ptr->refcount>1) { - zval *new_tmp; - - ALLOC_ZVAL(new_tmp); - *new_tmp = *param_ptr; - zval_copy_ctor(new_tmp); - INIT_PZVAL(new_tmp); - param_ptr = new_tmp; - ((zval *) *(p-param_count))->refcount--; - *(p-param_count) = param_ptr; - } - *param = param_ptr; - param_count--; - } - va_end(ptr); - - return SUCCESS; -} - - -ZEND_API int zend_get_parameters_array(int ht, int param_count, zval **argument_array) -{ - void **p; - int arg_count; - zval *param_ptr; - ELS_FETCH(); - - p = EG(argument_stack).top_element-1; - arg_count = (ulong) *p; - - if (param_count>arg_count) { - return FAILURE; - } - - - while (param_count>0) { - param_ptr = *(p-param_count); - if (!PZVAL_IS_REF(param_ptr) && param_ptr->refcount>1) { - zval *new_tmp; - - ALLOC_ZVAL(new_tmp); - *new_tmp = *param_ptr; - zval_copy_ctor(new_tmp); - INIT_PZVAL(new_tmp); - param_ptr = new_tmp; - ((zval *) *(p-param_count))->refcount--; - *(p-param_count) = param_ptr; - } - *(argument_array++) = param_ptr; - param_count--; - } - - return SUCCESS; -} - - - - -/* Zend-optimized Extended functions */ -/* this function doesn't check for too many parameters */ -ZEND_API int zend_get_parameters_ex(int param_count,...) -{ - void **p; - int arg_count; - va_list ptr; - zval ***param; - ELS_FETCH(); - - p = EG(argument_stack).top_element-1; - arg_count = (ulong) *p; - - if (param_count>arg_count) { - return FAILURE; - } - - va_start(ptr, param_count); - while (param_count>0) { - param = va_arg(ptr, zval ***); - *param = (zval **) p-(param_count--); - } - va_end(ptr); - - return SUCCESS; -} - - -ZEND_API int zend_get_parameters_array_ex(int param_count, zval ***argument_array) -{ - void **p; - int arg_count; - ELS_FETCH(); - - p = EG(argument_stack).top_element-1; - arg_count = (ulong) *p; - - if (param_count>arg_count) { - return FAILURE; - } - - while (param_count>0) { - *(argument_array++) = (zval **) p-(param_count--); - } - - return SUCCESS; -} - - -ZEND_API int ParameterPassedByReference(int ht, uint n) -{ - void **p; - ulong arg_count; - zval *arg; - ELS_FETCH(); - - p = EG(argument_stack).elements+EG(argument_stack).top-1; - arg_count = (ulong) *p; - - if (n>arg_count) { - return FAILURE; - } - arg = (zval *) *(p-arg_count+n-1); - return PZVAL_IS_REF(arg); -} - - -ZEND_API void wrong_param_count() -{ - zend_error(E_WARNING,"Wrong parameter count for %s()",get_active_function_name()); -} - - -ZEND_API inline int array_init(zval *arg) -{ - ALLOC_HASHTABLE(arg->value.ht); - - if (!arg->value.ht || zend_hash_init(arg->value.ht, 0, NULL, ZVAL_PTR_DTOR, 0)) { - zend_error(E_CORE_ERROR, "Cannot allocate memory for array"); - return FAILURE; - } - arg->type = IS_ARRAY; - return SUCCESS; -} - - -ZEND_API inline int object_init_ex(zval *arg, zend_class_entry *class_type) -{ - zval *tmp; - - if (!class_type->constants_updated) { - zend_hash_apply(&class_type->default_properties, (int (*)(void *)) zval_update_constant); - class_type->constants_updated = 1; - } - - ALLOC_HASHTABLE(arg->value.obj.properties); - zend_hash_init(arg->value.obj.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(arg->value.obj.properties, &class_type->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - arg->type = IS_OBJECT; - arg->value.obj.ce = class_type; - return SUCCESS; -} - - -ZEND_API inline int object_init(zval *arg) -{ - return object_init_ex(arg, &zend_standard_class_def); -} - - -ZEND_API inline int add_assoc_function(zval *arg, char *key,void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS)) -{ - zend_error(E_WARNING, "add_assoc_function() is no longer supported"); - return FAILURE; -} - - -ZEND_API inline int add_assoc_long(zval *arg, char *key, long n) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_LONG; - tmp->value.lval = n; - INIT_PZVAL(tmp); - return zend_hash_update(arg->value.ht, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), NULL); -} - - -ZEND_API inline int add_assoc_unset(zval *arg, char *key) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_NULL; - INIT_PZVAL(tmp); - return zend_hash_update(arg->value.ht, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), NULL); -} - -ZEND_API inline int add_assoc_bool(zval *arg, char *key, int b) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_BOOL; - tmp->value.lval = b; - INIT_PZVAL(tmp); - return zend_hash_update(arg->value.ht, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), NULL); -} - - -ZEND_API inline int add_assoc_resource(zval *arg, char *key, int r) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_RESOURCE; - tmp->value.lval = r; - INIT_PZVAL(tmp); - return zend_hash_update(arg->value.ht, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), NULL); -} - - -ZEND_API inline int add_assoc_double(zval *arg, char *key, double d) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_DOUBLE; - tmp->value.dval = d; - INIT_PZVAL(tmp); - return zend_hash_update(arg->value.ht, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), NULL); -} - - -ZEND_API inline int add_assoc_string(zval *arg, char *key, char *str, int duplicate) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_STRING; - tmp->value.str.len = strlen(str); - if (duplicate) { - tmp->value.str.val = estrndup(str,tmp->value.str.len); - } else { - tmp->value.str.val = str; - } - INIT_PZVAL(tmp); - return zend_hash_update(arg->value.ht, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), NULL); -} - - -ZEND_API inline int add_assoc_stringl(zval *arg, char *key, char *str, uint length, int duplicate) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_STRING; - tmp->value.str.len = length; - if (duplicate) { - tmp->value.str.val = estrndup(str,tmp->value.str.len); - } else { - tmp->value.str.val = str; - } - INIT_PZVAL(tmp); - return zend_hash_update(arg->value.ht, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), NULL); -} - - -ZEND_API inline int add_index_long(zval *arg, uint index, long n) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_LONG; - tmp->value.lval = n; - INIT_PZVAL(tmp); - return zend_hash_index_update(arg->value.ht, index, (void *) &tmp, sizeof(zval *),NULL); -} - - -ZEND_API inline int add_index_unset(zval *arg, uint index) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_NULL; - INIT_PZVAL(tmp); - return zend_hash_index_update(arg->value.ht, index, (void *) &tmp, sizeof(zval *), NULL); -} - - -ZEND_API inline int add_index_bool(zval *arg, uint index, int b) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_BOOL; - tmp->value.lval = b; - INIT_PZVAL(tmp); - return zend_hash_index_update(arg->value.ht, index, (void *) &tmp, sizeof(zval *),NULL); -} - - -ZEND_API inline int add_index_resource(zval *arg, uint index, int r) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_RESOURCE; - tmp->value.lval = r; - INIT_PZVAL(tmp); - return zend_hash_index_update(arg->value.ht, index, (void *) &tmp, sizeof(zval *),NULL); -} - - -ZEND_API inline int add_index_double(zval *arg, uint index, double d) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_DOUBLE; - tmp->value.dval = d; - INIT_PZVAL(tmp); - return zend_hash_index_update(arg->value.ht, index, (void *) &tmp, sizeof(zval *),NULL); -} - - -ZEND_API inline int add_index_string(zval *arg, uint index, char *str, int duplicate) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_STRING; - tmp->value.str.len = strlen(str); - if (duplicate) { - tmp->value.str.val = estrndup(str,tmp->value.str.len); - } else { - tmp->value.str.val = str; - } - INIT_PZVAL(tmp); - return zend_hash_index_update(arg->value.ht, index, (void *) &tmp, sizeof(zval *), NULL); -} - - -ZEND_API inline int add_index_stringl(zval *arg, uint index, char *str, uint length, int duplicate) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_STRING; - tmp->value.str.len = length; - if (duplicate) { - tmp->value.str.val = estrndup(str,tmp->value.str.len); - } else { - tmp->value.str.val = str; - } - INIT_PZVAL(tmp); - return zend_hash_index_update(arg->value.ht, index, (void *) &tmp, sizeof(zval *),NULL); -} - - -ZEND_API inline int add_next_index_long(zval *arg, long n) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_LONG; - tmp->value.lval = n; - INIT_PZVAL(tmp); - return zend_hash_next_index_insert(arg->value.ht, &tmp, sizeof(zval *), NULL); -} - - -ZEND_API inline int add_next_index_unset(zval *arg) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_NULL; - INIT_PZVAL(tmp); - return zend_hash_next_index_insert(arg->value.ht, &tmp, sizeof(zval *), NULL); -} - - -ZEND_API inline int add_next_index_bool(zval *arg, int b) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_BOOL; - tmp->value.lval = b; - INIT_PZVAL(tmp); - return zend_hash_next_index_insert(arg->value.ht, &tmp, sizeof(zval *), NULL); -} - - -ZEND_API inline int add_next_index_resource(zval *arg, int r) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_RESOURCE; - tmp->value.lval = r; - INIT_PZVAL(tmp); - return zend_hash_next_index_insert(arg->value.ht, &tmp, sizeof(zval *), NULL); -} - - -ZEND_API inline int add_next_index_double(zval *arg, double d) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_DOUBLE; - tmp->value.dval = d; - INIT_PZVAL(tmp); - return zend_hash_next_index_insert(arg->value.ht, &tmp, sizeof(zval *), NULL); -} - - -ZEND_API inline int add_next_index_string(zval *arg, char *str, int duplicate) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_STRING; - tmp->value.str.len = strlen(str); - if (duplicate) { - tmp->value.str.val = estrndup(str,tmp->value.str.len); - } else { - tmp->value.str.val = str; - } - INIT_PZVAL(tmp); - return zend_hash_next_index_insert(arg->value.ht, &tmp, sizeof(zval *),NULL); -} - - -ZEND_API inline int add_next_index_stringl(zval *arg, char *str, uint length, int duplicate) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_STRING; - tmp->value.str.len = length; - if (duplicate) { - tmp->value.str.val = estrndup(str,tmp->value.str.len); - } else { - tmp->value.str.val = str; - } - INIT_PZVAL(tmp); - return zend_hash_next_index_insert(arg->value.ht, &tmp, sizeof(zval *),NULL); -} - - -ZEND_API inline int add_get_assoc_string(zval *arg, char *key, char *str, void **dest, int duplicate) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_STRING; - tmp->value.str.len = strlen(str); - if (duplicate) { - tmp->value.str.val = estrndup(str,tmp->value.str.len); - } else { - tmp->value.str.val = str; - } - INIT_PZVAL(tmp); - return zend_hash_update(arg->value.ht, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), dest); -} - - -ZEND_API inline int add_get_assoc_stringl(zval *arg, char *key, char *str, uint length, void **dest, int duplicate) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_STRING; - tmp->value.str.len = length; - if (duplicate) { - tmp->value.str.val = estrndup(str,tmp->value.str.len); - } else { - tmp->value.str.val = str; - } - INIT_PZVAL(tmp); - return zend_hash_update(arg->value.ht, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), dest); -} - - -ZEND_API inline int add_get_index_long(zval *arg, uint index, long l, void **dest) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_LONG; - tmp->value.lval = l; - INIT_PZVAL(tmp); - return zend_hash_index_update(arg->value.ht, index, (void *) &tmp, sizeof(zval *),dest); -} - - -ZEND_API inline int add_get_index_double(zval *arg, uint index, double d, void **dest) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_DOUBLE; - tmp->value.dval= d; - INIT_PZVAL(tmp); - return zend_hash_index_update(arg->value.ht, index, (void *) &tmp, sizeof(zval *),dest); -} - - -ZEND_API inline int add_get_index_string(zval *arg, uint index, char *str, void **dest, int duplicate) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_STRING; - tmp->value.str.len = strlen(str); - if (duplicate) { - tmp->value.str.val = estrndup(str,tmp->value.str.len); - } else { - tmp->value.str.val = str; - } - INIT_PZVAL(tmp); - return zend_hash_index_update(arg->value.ht, index, (void *) &tmp, sizeof(zval *),dest); -} - - -ZEND_API inline int add_get_index_stringl(zval *arg, uint index, char *str, uint length, void **dest, int duplicate) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_STRING; - tmp->value.str.len = length; - if (duplicate) { - tmp->value.str.val = estrndup(str,tmp->value.str.len); - } else { - tmp->value.str.val = str; - } - INIT_PZVAL(tmp); - return zend_hash_index_update(arg->value.ht, index, (void *) &tmp, sizeof(zval *),dest); -} - - -ZEND_API inline int add_property_long(zval *arg, char *key, long n) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_LONG; - tmp->value.lval = n; - INIT_PZVAL(tmp); - return zend_hash_update(arg->value.obj.properties, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), NULL); -} - -ZEND_API inline int add_property_bool(zval *arg, char *key, int b) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_BOOL; - tmp->value.lval = b; - INIT_PZVAL(tmp); - return zend_hash_update(arg->value.obj.properties, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), NULL); -} - -ZEND_API inline int add_property_unset(zval *arg, char *key) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_NULL; - INIT_PZVAL(tmp); - return zend_hash_update(arg->value.obj.properties, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), NULL); -} - -ZEND_API inline int add_property_resource(zval *arg, char *key, long n) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_RESOURCE; - tmp->value.lval = n; - INIT_PZVAL(tmp); - return zend_hash_update(arg->value.obj.properties, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), NULL); -} - - -ZEND_API inline int add_property_double(zval *arg, char *key, double d) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_DOUBLE; - tmp->value.dval = d; - INIT_PZVAL(tmp); - return zend_hash_update(arg->value.obj.properties, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), NULL); -} - - -ZEND_API inline int add_property_string(zval *arg, char *key, char *str, int duplicate) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_STRING; - tmp->value.str.len = strlen(str); - if (duplicate) { - tmp->value.str.val = estrndup(str,tmp->value.str.len); - } else { - tmp->value.str.val = str; - } - INIT_PZVAL(tmp); - return zend_hash_update(arg->value.obj.properties, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), NULL); -} - - -ZEND_API inline int add_property_stringl(zval *arg, char *key, char *str, uint length, int duplicate) -{ - zval *tmp; - - ALLOC_ZVAL(tmp); - tmp->type = IS_STRING; - tmp->value.str.len = length; - if (duplicate) { - tmp->value.str.val = estrndup(str,tmp->value.str.len); - } else { - tmp->value.str.val = str; - } - INIT_PZVAL(tmp); - return zend_hash_update(arg->value.obj.properties, key, strlen(key)+1, (void *) &tmp, sizeof(zval *), NULL); -} - - -ZEND_API int zend_startup_module(zend_module_entry *module) -{ - if (module) { - module->module_number = zend_next_free_module(); - if (module->module_startup_func) { - ELS_FETCH(); - - if (module->module_startup_func(MODULE_PERSISTENT, module->module_number ELS_CC)==FAILURE) { - zend_error(E_CORE_ERROR,"Unable to start %s module",module->name); - return FAILURE; - } - } - module->type = MODULE_PERSISTENT; - zend_register_module(module); - } - return SUCCESS; -} - - -ZEND_API int _register_list_destructors(void (*list_destructor)(void *), void (*plist_destructor)(void *), int module_number) -{ - list_destructors_entry ld; - -#if 0 - printf("Registering destructors %d for module %d\n", list_destructors.nNextFreeElement, module_number); -#endif - - ld.list_destructor=(void (*)(void *)) list_destructor; - ld.plist_destructor=(void (*)(void *)) plist_destructor; - ld.module_number = module_number; - ld.resource_id = list_destructors.nNextFreeElement; - - if (zend_hash_next_index_insert(&list_destructors,(void *) &ld,sizeof(list_destructors_entry),NULL)==FAILURE) { - return FAILURE; - } - return list_destructors.nNextFreeElement-1; -} - - -/* registers all functions in *library_functions in the function hash */ -int zend_register_functions(zend_function_entry *functions, HashTable *function_table) -{ - zend_function_entry *ptr = functions; - zend_function function; - zend_internal_function *internal_function = (zend_internal_function *)&function; - int count=0,unload=0; - HashTable *target_function_table = function_table; - CLS_FETCH(); - - if (!target_function_table) { - target_function_table = CG(function_table); - } - internal_function->type = ZEND_INTERNAL_FUNCTION; - - while (ptr->fname) { - internal_function->handler = ptr->handler; - internal_function->arg_types = ptr->func_arg_types; - internal_function->function_name = ptr->fname; - if (!internal_function->handler) { - zend_error(E_CORE_WARNING,"Null function defined as active function"); - zend_unregister_functions(functions, count, target_function_table); - return FAILURE; - } - if (zend_hash_add(target_function_table, ptr->fname, strlen(ptr->fname)+1, &function, sizeof(zend_function), NULL) == FAILURE) { - unload=1; - break; - } - ptr++; - count++; - } - if (unload) { /* before unloading, display all remaining bad function in the module */ - while (ptr->fname) { - if (zend_hash_exists(target_function_table, ptr->fname, strlen(ptr->fname)+1)) { - zend_error(E_CORE_WARNING, "Function registration failed - duplicate name - %s",ptr->fname); - } - ptr++; - } - zend_unregister_functions(functions, count, target_function_table); - return FAILURE; - } - return SUCCESS; -} - -/* count=-1 means erase all functions, otherwise, - * erase the first count functions - */ -void zend_unregister_functions(zend_function_entry *functions, int count, HashTable *function_table) -{ - zend_function_entry *ptr = functions; - int i=0; - HashTable *target_function_table = function_table; - CLS_FETCH(); - - if (!target_function_table) { - target_function_table = CG(function_table); - } - while (ptr->fname) { - if (count!=-1 && i>=count) { - break; - } -#if 0 - zend_printf("Unregistering %s()\n", ptr->fname); -#endif - zend_hash_del(target_function_table, ptr->fname, strlen(ptr->fname)+1); - ptr++; - i++; - } -} - - -ZEND_API int zend_register_module(zend_module_entry *module) -{ -#if 0 - zend_printf("%s: Registering module %d\n",module->name, module->module_number); -#endif - if (module->functions && zend_register_functions(module->functions, NULL)==FAILURE) { - zend_error(E_CORE_WARNING,"%s: Unable to register functions, unable to load",module->name); - return FAILURE; - } - module->module_started=1; - return zend_hash_add(&module_registry, module->name,strlen(module->name)+1,(void *)module,sizeof(zend_module_entry),NULL); -} - - -void module_destructor(zend_module_entry *module) -{ - if (module->type == MODULE_TEMPORARY) { - zend_hash_apply_with_argument(&list_destructors, (int (*)(void *,void *)) clean_module_resource_destructors, (void *) &(module->module_number)); - clean_module_constants(module->module_number); - } - - if (module->module_started && module->module_shutdown_func) { -#if 0 - zend_printf("%s: Module shutdown\n",module->name); -#endif - module->module_shutdown_func(module->type, module->module_number); - } - module->module_started=0; - if (module->functions) { - zend_unregister_functions(module->functions, -1, NULL); - } - -#if HAVE_LIBDL - if (module->handle) { - dlclose(module->handle); - } -#endif -} - - -/* call request startup for all modules */ -int module_registry_request_startup(zend_module_entry *module) -{ - if (module->request_startup_func) { - ELS_FETCH(); - -#if 0 - zend_printf("%s: Request startup\n",module->name); -#endif - if (module->request_startup_func(module->type, module->module_number ELS_CC)==FAILURE) { - zend_error(E_WARNING, "request_startup() for %s module failed", module->name); - exit(1); - } - } - return 0; -} - - -/* for persistent modules - call request shutdown and flag NOT to erase - * for temporary modules - do nothing, and flag to erase - */ -int module_registry_cleanup(zend_module_entry *module) -{ - switch(module->type) { - case MODULE_PERSISTENT: - if (module->request_shutdown_func) { -#if 0 - zend_printf("%s: Request shutdown\n",module->name); -#endif - module->request_shutdown_func(module->type, module->module_number); - } - return 0; - break; - case MODULE_TEMPORARY: - return 1; - break; - } - return 0; -} - - -/* return the next free module number */ -int zend_next_free_module(void) -{ - return ++module_count; -} - - -ZEND_API zend_class_entry *register_internal_class(zend_class_entry *class_entry) -{ - zend_class_entry *register_class; - char *lowercase_name = zend_strndup(class_entry->name, class_entry->name_length); - CLS_FETCH(); - - zend_str_tolower(lowercase_name, class_entry->name_length); - - class_entry->type = ZEND_INTERNAL_CLASS; - class_entry->parent = NULL; - class_entry->refcount = (int *) malloc(sizeof(int)); - *class_entry->refcount = 1; - class_entry->constants_updated = 0; - zend_hash_init(&class_entry->default_properties, 0, NULL, ZVAL_PTR_DTOR, 1); - zend_hash_init(&class_entry->function_table, 0, NULL, ZEND_FUNCTION_DTOR, 1); - - - if (class_entry->builtin_functions) { - zend_register_functions(class_entry->builtin_functions, &class_entry->function_table); - } - - zend_hash_update(CG(class_table), lowercase_name, class_entry->name_length+1, class_entry, sizeof(zend_class_entry), (void **) ®ister_class); - free(lowercase_name); - return register_class; -} - - -ZEND_API zend_module_entry *zend_get_module(int module_number) -{ - zend_module_entry *module; - - if (zend_hash_index_find(&module_registry, module_number, (void **) &module)==SUCCESS) { - return module; - } else { - return NULL; - } -} - -ZEND_API int zend_set_hash_symbol(zval *symbol, char *name, int name_length, - int is_ref, int num_symbol_tables, ...) -{ - HashTable *symbol_table; - va_list symbol_table_list; - - if (num_symbol_tables <= 0) return FAILURE; - - symbol->is_ref = is_ref; - - va_start(symbol_table_list, num_symbol_tables); - while(num_symbol_tables-- > 0) { - symbol_table = va_arg(symbol_table_list, HashTable *); - zend_hash_update_ptr(symbol_table, name, name_length + 1, symbol, sizeof(zval *), NULL); - zval_add_ref(&symbol); - } - va_end(symbol_table_list); - return SUCCESS; -} diff --git a/Zend/zend_API.h b/Zend/zend_API.h deleted file mode 100644 index cdd464248f..0000000000 --- a/Zend/zend_API.h +++ /dev/null @@ -1,377 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _ZEND_API_H -#define _ZEND_API_H - -#include "modules.h" -#include "zend_list.h" -#include "zend_fast_cache.h" - - -#define ZEND_NAMED_FUNCTION(name) void name(INTERNAL_FUNCTION_PARAMETERS) -#define ZEND_FUNCTION(name) ZEND_NAMED_FUNCTION(zend_if_##name) - -#define ZEND_NAMED_FE(runtime_name, name, arg_types) { #runtime_name, name, arg_types }, -#define ZEND_FE(name, arg_types) ZEND_NAMED_FE(name, zend_if_##name, arg_types) - - -#define INIT_CLASS_ENTRY(class_container, class_name, functions) \ - { \ - class_container.name = strdup(class_name); \ - class_container.name_length = sizeof(class_name)-1; \ - class_container.builtin_functions = functions; \ - class_container.handle_function_call = NULL; \ - class_container.handle_property_get = NULL; \ - class_container.handle_property_set = NULL; \ - } - -#define INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset) \ - { \ - class_container.name = strdup(class_name); \ - class_container.name_length = sizeof(class_name)-1; \ - class_container.builtin_functions = functions; \ - class_container.handle_function_call = handle_fcall; \ - class_container.handle_property_get = handle_propget; \ - class_container.handle_property_set = handle_propset; \ - } - - - -int zend_next_free_module(void); - -ZEND_API int zend_get_parameters(int ht, int param_count,...); -ZEND_API int zend_get_parameters_array(int ht, int param_count, zval **argument_array); -ZEND_API int zend_get_parameters_ex(int param_count,...); -ZEND_API int zend_get_parameters_array_ex(int param_count, zval ***argument_array); - -ZEND_API int ParameterPassedByReference(int ht, uint n); - -int zend_register_functions(zend_function_entry *functions, HashTable *function_table); -void zend_unregister_functions(zend_function_entry *functions, int count, HashTable *function_table); -ZEND_API int zend_register_module(zend_module_entry *module_entry); -ZEND_API zend_class_entry *register_internal_class(zend_class_entry *class_entry); -ZEND_API zend_module_entry *zend_get_module(int module_number); - -ZEND_API void wrong_param_count(void); - -#define getThis() (this_ptr) - -#define WRONG_PARAM_COUNT { wrong_param_count(); return; } -#define WRONG_PARAM_COUNT_WITH_RETVAL(ret) { wrong_param_count(); return ret; } -#define ARG_COUNT(dummy) (ht) -#define ZEND_NUM_ARGS() (ht) - -#define BYREF_NONE 0 -#define BYREF_FORCE 1 -#define BYREF_ALLOW 2 -#define BYREF_FORCE_REST 3 - -#ifndef ZEND_WIN32 -#define DLEXPORT -#endif - -ZEND_API int zend_startup_module(zend_module_entry *module); - -ZEND_API int array_init(zval *arg); -ZEND_API int object_init(zval *arg); -ZEND_API int object_init_ex(zval *arg, zend_class_entry *ce); - -/* no longer supported */ -ZEND_API int add_assoc_function(zval *arg, char *key,void (*function_ptr)(INTERNAL_FUNCTION_PARAMETERS)); - -ZEND_API int add_assoc_long(zval *arg, char *key, long n); -ZEND_API int add_assoc_unset(zval *arg, char *key); -ZEND_API int add_assoc_bool(zval *arg, char *key, int b); -ZEND_API int add_assoc_resource(zval *arg, char *key, int r); -ZEND_API int add_assoc_double(zval *arg, char *key, double d); -ZEND_API int add_assoc_string(zval *arg, char *key, char *str, int duplicate); -ZEND_API int add_assoc_stringl(zval *arg, char *key, char *str, uint length, int duplicate); - -ZEND_API int add_index_long(zval *arg, uint idx, long n); -ZEND_API int add_index_unset(zval *arg, uint idx); -ZEND_API int add_index_bool(zval *arg, uint idx, int b); -ZEND_API int add_index_resource(zval *arg, uint idx, int r); -ZEND_API int add_index_double(zval *arg, uint idx, double d); -ZEND_API int add_index_string(zval *arg, uint idx, char *str, int duplicate); -ZEND_API int add_index_stringl(zval *arg, uint idx, char *str, uint length, int duplicate); - -ZEND_API int add_next_index_long(zval *arg, long n); -ZEND_API int add_next_index_unset(zval *arg); -ZEND_API int add_next_index_bool(zval *arg, int b); -ZEND_API int add_next_index_resource(zval *arg, int r); -ZEND_API int add_next_index_double(zval *arg, double d); -ZEND_API int add_next_index_string(zval *arg, char *str, int duplicate); -ZEND_API int add_next_index_stringl(zval *arg, char *str, uint length, int duplicate); - -ZEND_API int add_get_index_long(zval *arg, uint idx, long l, void **dest); -ZEND_API int add_get_index_double(zval *arg, uint idx, double d, void **dest); -ZEND_API int add_get_assoc_string(zval *arg, char *key, char *str, void **dest, int duplicate); -ZEND_API int add_get_assoc_stringl(zval *arg, char *key, char *str, uint length, void **dest, int duplicate); -ZEND_API int add_get_index_string(zval *arg, uint idx, char *str, void **dest, int duplicate); -ZEND_API int add_get_index_stringl(zval *arg, uint idx, char *str, uint length, void **dest, int duplicate); - -ZEND_API int call_user_function(HashTable *function_table, zval *object, zval *function_name, zval *retval_ptr, int param_count, zval *params[]); -ZEND_API int call_user_function_ex(HashTable *function_table, zval *object, zval *function_name, zval **retval_ptr_ptr, int param_count, zval **params[], int no_separation); - -ZEND_API int add_property_long(zval *arg, char *key, long l); -ZEND_API int add_property_unset(zval *arg, char *key); -ZEND_API int add_property_bool(zval *arg, char *key, int b); -ZEND_API int add_property_resource(zval *arg, char *key, long r); -ZEND_API int add_property_double(zval *arg, char *key, double d); -ZEND_API int add_property_string(zval *arg, char *key, char *str, int duplicate); -ZEND_API int add_property_stringl(zval *arg, char *key, char *str, uint length, int duplicate); - -ZEND_API int zend_set_hash_symbol(zval *symbol, char *name, int name_length, - int is_ref, int num_symbol_tables, ...); - -#define add_method(arg,key,method) add_assoc_function((arg),(key),(method)) - -#define ZVAL_RESOURCE(z,l) { \ - (z)->type = IS_RESOURCE; \ - (z)->value.lval = l; \ - } -#define ZVAL_BOOL(z,b) { \ - (z)->type = IS_BOOL; \ - (z)->value.lval = b; \ - } -#define ZVAL_NULL(z) { \ - (z)->type = IS_NULL; \ - } -#define ZVAL_LONG(z,l) { \ - (z)->type = IS_LONG; \ - (z)->value.lval = l; \ - } -#define ZVAL_DOUBLE(z,d) { \ - (z)->type = IS_DOUBLE; \ - (z)->value.dval = d; \ - } -#define ZVAL_STRING(z,s,duplicate) { \ - char *__s=(s); \ - (z)->value.str.len = strlen(__s); \ - (z)->value.str.val = (duplicate?estrndup(__s,(z)->value.str.len):__s); \ - (z)->type = IS_STRING; \ - } -#define ZVAL_STRINGL(z,s,l,duplicate) { \ - char *__s=(s); int __l=l; \ - (z)->value.str.len = __l; \ - (z)->value.str.val = (duplicate?estrndup(__s,__l):__s); \ - (z)->type = IS_STRING; \ - } - -#define ZVAL_EMPTY_STRING(z) { \ - (z)->value.str.len = 0; \ - (z)->value.str.val = empty_string \ - (z)->type = IS_STRING; \ - } - -#define ZVAL_FALSE { (z)->value.lval = 0; (z)->type = IS_BOOL; } -#define ZVAL_TRUE { (z)->value.lval = 1; (z)->type = IS_BOOL; } - -#define RETVAL_RESOURCE(l) { \ - return_value->type = IS_RESOURCE;\ - return_value->value.lval = l; \ - } -#define RETVAL_BOOL(b) { \ - return_value->type = IS_BOOL; \ - return_value->value.lval = b; \ - } -#define RETVAL_NULL() { \ - return_value->type = IS_NULL; \ - } -#define RETVAL_LONG(l) { \ - return_value->type = IS_LONG; \ - return_value->value.lval = l; \ - } -#define RETVAL_DOUBLE(d) { \ - return_value->type = IS_DOUBLE; \ - return_value->value.dval = d; \ - } -#define RETVAL_STRING(s,duplicate) { \ - char *__s=(s); \ - return_value->value.str.len = strlen(__s); \ - return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s); \ - return_value->type = IS_STRING; \ - } -#define RETVAL_STRINGL(s,l,duplicate) { \ - char *__s=(s); int __l=l; \ - return_value->value.str.len = __l; \ - return_value->value.str.val = (duplicate?estrndup(__s,__l):__s); \ - return_value->type = IS_STRING; \ - } - -#define RETVAL_EMPTY_STRING() { \ - return_value->value.str.len = 0; \ - return_value->value.str.val = empty_string \ - return_value->type = IS_STRING; \ - } - -#define RETVAL_FALSE { return_value->value.lval = 0; return_value->type = IS_BOOL; } -#define RETVAL_TRUE { return_value->value.lval = 1; return_value->type = IS_BOOL; } - -#define RETURN_RESOURCE(l) { \ - return_value->type = IS_RESOURCE;\ - return_value->value.lval = l; \ - return; \ - } - -#define RETURN_BOOL(b) { \ - return_value->type = IS_BOOL; \ - return_value->value.lval = b; \ - return; \ - } - -#define RETURN_NULL() { \ - return_value->type = IS_NULL; \ - return; \ - } - -#define RETURN_LONG(l) { \ - return_value->type = IS_LONG; \ - return_value->value.lval = l; \ - return; \ - } -#define RETURN_DOUBLE(d) { \ - return_value->type = IS_DOUBLE; \ - return_value->value.dval = d; \ - return; \ - } -#define RETURN_STRING(s,duplicate) { \ - char *__s=(s); \ - return_value->value.str.len = strlen(__s); \ - return_value->value.str.val = (duplicate?estrndup(__s,return_value->value.str.len):__s); \ - return_value->type = IS_STRING; \ - return; \ - } -#define RETURN_STRINGL(s,l,duplicate) { \ - char *__s=(s); int __l=l; \ - return_value->value.str.len = __l; \ - return_value->value.str.val = (duplicate?estrndup(__s,__l):__s); \ - return_value->type = IS_STRING; \ - return; \ - } - -#define RETURN_EMPTY_STRING() { \ - return_value->value.str.len = 0; \ - return_value->value.str.val = empty_string \ - return_value->type = IS_STRING; \ - return; \ - } - -#define RETURN_FALSE { RETVAL_FALSE; return; } -#define RETURN_TRUE { RETVAL_TRUE; return; } - -#define SET_VAR_STRING(n,v) { \ - { \ - zval *var; \ - char *str=(v); /* prevent 'v' from being evaluated more than once */ \ - \ - ALLOC_ZVAL(var); \ - var->value.str.val = (str); \ - var->value.str.len = strlen((str)); \ - var->type = IS_STRING; \ - ZEND_SET_GLOBAL_VAR(n, var); \ - } \ - } - -#define SET_VAR_STRINGL(n,v,l) { \ - { \ - zval *var; \ - \ - ALLOC_ZVAL(var); \ - var->value.str.val = (v); \ - var->value.str.len = (l); \ - var->type = IS_STRING; \ - ZEND_SET_GLOBAL_VAR(n, var); \ - } \ - } - -#define SET_VAR_LONG(n,v) { \ - { \ - zval *var; \ - \ - ALLOC_ZVAL(var); \ - var->value.lval = (v); \ - var->type = IS_LONG; \ - ZEND_SET_GLOBAL_VAR(n, var); \ - } \ - } - -#define SET_VAR_DOUBLE(n,v) { \ - { \ - zval *var; \ - \ - ALLOC_ZVAL(var); \ - var->value.dval = (v); \ - var->type = IS_DOUBLE; \ - ZEND_SET_GLOBAL_VAR(n, var); \ - } \ - } - - -#define ZEND_SET_SYMBOL(symtable, name, var) \ - { \ - char *_name = (name); \ - \ - ZEND_SET_SYMBOL_WITH_LENGTH(symtable, _name, strlen(_name)+1, var, 1, 0); \ - } - -#define ZEND_SET_SYMBOL_WITH_LENGTH(symtable, name, name_length, var, _refcount, _is_ref) \ - { \ - zval **orig_var; \ - \ - if (zend_hash_find(symtable, (name), (name_length), (void **) &orig_var)==SUCCESS \ - && PZVAL_IS_REF(*orig_var)) { \ - (var)->refcount = (*orig_var)->refcount; \ - (var)->is_ref = 1; \ - \ - if (_refcount) { \ - (var)->refcount += _refcount-1; \ - } \ - zval_dtor(*orig_var); \ - **orig_var = *(var); \ - FREE_ZVAL(var); \ - } else { \ - (var)->is_ref = _is_ref; \ - if (_refcount) { \ - (var)->refcount = _refcount; \ - } \ - zend_hash_update(symtable, (name), (name_length), &(var), sizeof(zval *), NULL); \ - } \ - } - - -#define ZEND_SET_GLOBAL_VAR(name, var) \ - ZEND_SET_SYMBOL(&EG(symbol_table), name, var) - -#define ZEND_SET_GLOBAL_VAR_WITH_LENGTH(name, name_length, var, _refcount, _is_ref) \ - ZEND_SET_SYMBOL_WITH_LENGTH(&EG(symbol_table), name, name_length, var, _refcount, _is_ref) - -#define HASH_OF(p) ((p)->type==IS_ARRAY ? (p)->value.ht : (((p)->type==IS_OBJECT ? (p)->value.obj.properties : NULL))) -#define ZVAL_IS_NULL(z) ((z)->type==IS_NULL) - -#endif /* _ZEND_API_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c deleted file mode 100644 index d220694f02..0000000000 --- a/Zend/zend_alloc.c +++ /dev/null @@ -1,622 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include - -#include "zend.h" -#include "zend_alloc.h" -#include "zend_globals.h" -#include "zend_fast_cache.h" -#ifdef HAVE_SIGNAL_H -# include -#endif -#ifdef HAVE_UNISTD_H -# include -#endif - -#ifndef ZTS -ZEND_API zend_alloc_globals alloc_globals; -#endif - - -#define ZEND_DISABLE_MEMORY_CACHE 0 - - -#if ZEND_DEBUG -# define END_MAGIC_SIZE sizeof(long) -# define END_ALIGNMENT(size) (((size)%PLATFORM_ALIGNMENT)?(PLATFORM_ALIGNMENT-((size)%PLATFORM_ALIGNMENT)):0) -#else -# define END_MAGIC_SIZE 0 -# define END_ALIGNMENT(size) 0 -#endif - - -# if MEMORY_LIMIT -# if ZEND_DEBUG -#define CHECK_MEMORY_LIMIT(s) _CHECK_MEMORY_LIMIT(s, __zend_filename, __zend_lineno) -# else -#define CHECK_MEMORY_LIMIT(s) _CHECK_MEMORY_LIMIT(s,NULL,0) -# endif - -#define _CHECK_MEMORY_LIMIT(s,file,lineno) { AG(allocated_memory) += (s);\ - if (AG(memory_limit)persistent && p==AG(head)) { \ - AG(head) = p->pNext; \ - } else if (p->persistent && p==AG(phead)) { \ - AG(phead) = p->pNext; \ - } else { \ - p->pLast->pNext = p->pNext; \ - } \ - if (p->pNext) { \ - p->pNext->pLast = p->pLast; \ - } - -#define ADD_POINTER_TO_LIST(p) \ - if (p->persistent) { \ - p->pNext = AG(phead); \ - if (AG(phead)) { \ - AG(phead)->pLast = p; \ - } \ - AG(phead) = p; \ - } else { \ - p->pNext = AG(head); \ - if (AG(head)) { \ - AG(head)->pLast = p; \ - } \ - AG(head) = p; \ - } \ - p->pLast = (zend_mem_header *) NULL; - - - -ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) -{ - zend_mem_header *p; - ALS_FETCH(); - - if (!ZEND_DISABLE_MEMORY_CACHE && (size < MAX_CACHED_MEMORY) && (AG(cache_count)[size] > 0)) { - p = AG(cache)[size][--AG(cache_count)[size]]; -#if ZEND_DEBUG - p->filename = __zend_filename; - p->lineno = __zend_lineno; - p->orig_filename = __zend_orig_filename; - p->orig_lineno = __zend_orig_lineno; - p->magic = MEM_BLOCK_START_MAGIC; - p->reported = 0; - AG(cache_stats)[size][1]++; -#endif - p->persistent = 0; - p->cached = 0; - return (void *)((char *)p + sizeof(zend_mem_header) + PLATFORM_PADDING); - } else { -#if ZEND_DEBUG - if (sizepersistent = p->cached = 0; - ADD_POINTER_TO_LIST(p); - p->size = size; -#if ZEND_DEBUG - p->filename = __zend_filename; - p->lineno = __zend_lineno; - p->orig_filename = __zend_orig_filename; - p->orig_lineno = __zend_orig_lineno; - p->magic = MEM_BLOCK_START_MAGIC; - p->reported = 0; - *((long *)(((char *) p) + sizeof(zend_mem_header)+size+PLATFORM_PADDING+END_ALIGNMENT(size))) = MEM_BLOCK_END_MAGIC; -#endif -#if MEMORY_LIMIT - CHECK_MEMORY_LIMIT(size); -#endif - HANDLE_UNBLOCK_INTERRUPTIONS(); - return (void *)((char *)p + sizeof(zend_mem_header) + PLATFORM_PADDING); -} - - -ZEND_API void _efree(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) -{ - zend_mem_header *p = (zend_mem_header *) ((char *)ptr - sizeof(zend_mem_header) - PLATFORM_PADDING); - ALS_FETCH(); - -#if ZEND_DEBUG - if (!_mem_block_check(ptr, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC)) { - return; - } - memset(ptr, 0x5a, p->size); -#endif - - if (!ZEND_DISABLE_MEMORY_CACHE - && !p->persistent && (p->size < MAX_CACHED_MEMORY) && (AG(cache_count)[p->size] < MAX_CACHED_ENTRIES)) { - AG(cache)[p->size][AG(cache_count)[p->size]++] = p; - p->cached = 1; -#if ZEND_DEBUG - p->magic = MEM_BLOCK_CACHED_MAGIC; -#endif - return; - } - HANDLE_BLOCK_INTERRUPTIONS(); - REMOVE_POINTER_FROM_LIST(p); - -#if MEMORY_LIMIT - AG(allocated_memory) -= p->size; -#endif - - free(p); - HANDLE_UNBLOCK_INTERRUPTIONS(); -} - - -ZEND_API void *_ecalloc(size_t nmemb, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) -{ - void *p; - int final_size=size*nmemb; - - HANDLE_BLOCK_INTERRUPTIONS(); - p = _emalloc(final_size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); - if (!p) { - HANDLE_UNBLOCK_INTERRUPTIONS(); - return (void *) p; - } - memset(p,(int)NULL,final_size); - HANDLE_UNBLOCK_INTERRUPTIONS(); - return p; -} - - -ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) -{ - zend_mem_header *p = (zend_mem_header *) ((char *)ptr-sizeof(zend_mem_header)-PLATFORM_PADDING); - zend_mem_header *orig = p; - ALS_FETCH(); - - if (!ptr) { - return _emalloc(size ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); - } - HANDLE_BLOCK_INTERRUPTIONS(); - REMOVE_POINTER_FROM_LIST(p); - p = (zend_mem_header *) realloc(p,sizeof(zend_mem_header)+size+PLATFORM_PADDING+END_ALIGNMENT(size)+END_MAGIC_SIZE); - if (!p) { - if (!allow_failure) { - fprintf(stderr,"FATAL: erealloc(): Unable to allocate %ld bytes\n", (long) size); -#if ZEND_DEBUG && HAVE_KILL && HAVE_GETPID - kill(getpid(), SIGSEGV); -#else - exit(1); -#endif - } - ADD_POINTER_TO_LIST(orig); - HANDLE_UNBLOCK_INTERRUPTIONS(); - return (void *)NULL; - } - ADD_POINTER_TO_LIST(p); -#if ZEND_DEBUG - p->filename = __zend_filename; - p->lineno = __zend_lineno; - p->magic = MEM_BLOCK_START_MAGIC; - *((long *)(((char *) p) + sizeof(zend_mem_header)+size+PLATFORM_PADDING+END_ALIGNMENT(size))) = MEM_BLOCK_END_MAGIC; -#endif -#if MEMORY_LIMIT - CHECK_MEMORY_LIMIT(size - p->size); -#endif - p->size = size; - - HANDLE_UNBLOCK_INTERRUPTIONS(); - return (void *)((char *)p+sizeof(zend_mem_header)+PLATFORM_PADDING); -} - - -ZEND_API char *_estrdup(const char *s ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) -{ - int length; - char *p; - - length = strlen(s)+1; - HANDLE_BLOCK_INTERRUPTIONS(); - p = (char *) _emalloc(length ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); - if (!p) { - HANDLE_UNBLOCK_INTERRUPTIONS(); - return (char *)NULL; - } - HANDLE_UNBLOCK_INTERRUPTIONS(); - memcpy(p,s,length); - return p; -} - - -ZEND_API char *_estrndup(const char *s, uint length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) -{ - char *p; - - HANDLE_BLOCK_INTERRUPTIONS(); - p = (char *) _emalloc(length+1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); - if (!p) { - HANDLE_UNBLOCK_INTERRUPTIONS(); - return (char *)NULL; - } - HANDLE_UNBLOCK_INTERRUPTIONS(); - memcpy(p,s,length); - p[length]=0; - return p; -} - - -ZEND_API char *zend_strndup(const char *s, uint length) -{ - char *p; - - p = (char *) malloc(length+1); - if (!p) { - return (char *)NULL; - } - if (length) { - memcpy(p,s,length); - } - p[length]=0; - return p; -} - - -ZEND_API int zend_set_memory_limit(unsigned int memory_limit) -{ -#if MEMORY_LIMIT - ALS_FETCH(); - - AG(memory_limit) = memory_limit; - return SUCCESS; -#else - return FAILURE; -#endif -} - - -ZEND_API void start_memory_manager(ALS_D) -{ - AG(phead) = AG(head) = NULL; - -#if MEMORY_LIMIT - AG(memory_limit)=1<<30; /* rediculous limit, effectively no limit */ - AG(allocated_memory)=0; - AG(memory_exhausted)=0; -#endif - -#if ZEND_DEBUG - memset(AG(cache_stats), 0, sizeof(AG(cache_stats))); - memset(AG(fast_cache_stats), 0, sizeof(AG(fast_cache_stats))); -#endif - - memset(AG(fast_cache_list_head), 0, sizeof(AG(fast_cache_list_head))); - memset(AG(cache_count),0,MAX_CACHED_MEMORY*sizeof(unsigned char)); -} - - -ZEND_API void shutdown_memory_manager(int silent, int clean_cache) -{ - zend_mem_header *p, *t; - int fci; -#if ZEND_DEBUG - int had_leaks=0; -#endif - zend_fast_cache_list_entry *fast_cache_list_entry, *next_fast_cache_list_entry; - ALS_FETCH(); - - - for (fci=0; fcinext; - efree(fast_cache_list_entry); - fast_cache_list_entry = next_fast_cache_list_entry; - } - AG(fast_cache_list_head)[fci] = NULL; - } - - p=AG(head); - t=AG(head); - while (t) { - if (!t->cached || clean_cache) { -#if ZEND_DEBUG - if (!t->cached && !t->reported) { - zend_mem_header *iterator; - int total_leak=0, total_leak_count=0; - - had_leaks=1; - if (!silent) { - zend_message_dispatcher(ZMSG_MEMORY_LEAK_DETECTED, t); - } - t->reported = 1; - for (iterator=t->pNext; iterator; iterator=iterator->pNext) { - if (!iterator->cached - && iterator->filename==t->filename - && iterator->lineno==t->lineno) { - total_leak += iterator->size; - total_leak_count++; - iterator->reported = 1; - } - } - if (!silent && total_leak_count>0) { - zend_message_dispatcher(ZMSG_MEMORY_LEAK_REPEATED, (void *) (long) (total_leak_count)); - } - } -#endif - p = t->pNext; - REMOVE_POINTER_FROM_LIST(t); - free(t); - t = p; - } else { - t = t->pNext; - } - } - -#if (ZEND_DEBUG) - do { - zval display_memory_cache_stats; - int i, j; - - if (clean_cache) { - /* we're shutting down completely, don't even touch the INI subsystem */ - break; - } - if (zend_get_ini_entry("display_memory_cache_stats", sizeof("display_memory_cache_stats"), &display_memory_cache_stats)==FAILURE) { - break; - } - if (!atoi(display_memory_cache_stats.value.str.val)) { - break; - } - fprintf(stderr, "Memory cache statistics\n" - "-----------------------\n\n" - "[zval, %2ld]\t\t%d / %d (%.2f%%)\n" - "[hash, %2ld]\t\t%d / %d (%.2f%%)\n", - (long) sizeof(zval), - AG(fast_cache_stats)[ZVAL_CACHE_LIST][1], AG(fast_cache_stats)[ZVAL_CACHE_LIST][0]+AG(fast_cache_stats)[ZVAL_CACHE_LIST][1], - ((double) AG(fast_cache_stats)[ZVAL_CACHE_LIST][1] / (AG(fast_cache_stats)[ZVAL_CACHE_LIST][0]+AG(fast_cache_stats)[ZVAL_CACHE_LIST][1]))*100, - (long) sizeof(HashTable), - AG(fast_cache_stats)[HASHTABLE_CACHE_LIST][1], AG(fast_cache_stats)[HASHTABLE_CACHE_LIST][0]+AG(fast_cache_stats)[HASHTABLE_CACHE_LIST][1], - ((double) AG(fast_cache_stats)[HASHTABLE_CACHE_LIST][1] / (AG(fast_cache_stats)[HASHTABLE_CACHE_LIST][0]+AG(fast_cache_stats)[HASHTABLE_CACHE_LIST][1]))*100); - - - for (i=0; imagic) { - case MEM_BLOCK_START_MAGIC: - if (!silent) { - zend_debug_alloc_output("OK (allocated on %s:%d, %d bytes)\n", p->filename, p->lineno, p->size); - } - break; /* ok */ - case MEM_BLOCK_FREED_MAGIC: - if (!silent) { - zend_debug_alloc_output("Freed\n"); - had_problems=1; - } else { - return _mem_block_check(ptr, 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); - } - break; - case MEM_BLOCK_CACHED_MAGIC: - if (!silent) { - if (!no_cache_notice) { - zend_debug_alloc_output("Cached (allocated on %s:%d, %d bytes)\n", p->filename, p->lineno, p->size); - had_problems=1; - } - } else { - if (!no_cache_notice) { - return _mem_block_check(ptr, 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); - } - } - break; - default: - if (!silent) { - zend_debug_alloc_output("Overrun (magic=0x%0.8lX, expected=0x%0.8lX)\n", p->magic, MEM_BLOCK_START_MAGIC); - } else { - return _mem_block_check(ptr, 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); - } - had_problems=1; - valid_beginning=0; - break; - } - - - if (valid_beginning - && *((long *)(((char *) p)+sizeof(zend_mem_header)+p->size+PLATFORM_PADDING+END_ALIGNMENT(p->size))) != MEM_BLOCK_END_MAGIC) { - long magic_num = MEM_BLOCK_END_MAGIC; - char *overflow_ptr, *magic_ptr=(char *) &magic_num; - int overflows=0; - int i; - - if (silent) { - return _mem_block_check(ptr, 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); - } - had_problems=1; - overflow_ptr = ((char *) p)+sizeof(zend_mem_header)+p->size+PLATFORM_PADDING; - - for (i=0; isize+PLATFORM_PADDING+END_ALIGNMENT(p->size))), MEM_BLOCK_END_MAGIC); - zend_debug_alloc_output("%10s\t",""); - if (overflows>=sizeof(long)) { - zend_debug_alloc_output("At least %d bytes overflown\n", sizeof(long)); - } else { - zend_debug_alloc_output("%d byte(s) overflown\n", overflows); - } - } else if (!silent) { - zend_debug_alloc_output("%10s\t", "End:"); - if (valid_beginning) { - zend_debug_alloc_output("OK\n"); - } else { - zend_debug_alloc_output("Unknown\n"); - } - } - - if (had_problems) { - int foo = 5; - - foo+=1; - } - - if (!silent) { - zend_debug_alloc_output("---------------------------------------\n"); - } - return ((!had_problems) ? 1 : 0); -} - - -ZEND_API void _full_mem_check(int silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) -{ - zend_mem_header *p; - int errors=0; - ALS_FETCH(); - - p = AG(head); - - - zend_debug_alloc_output("------------------------------------------------\n"); - zend_debug_alloc_output("Full Memory Check at %s:%d\n" ZEND_FILE_LINE_RELAY_CC); - - while (p) { - if (!_mem_block_check((void *)((char *)p + sizeof(zend_mem_header) + PLATFORM_PADDING), (silent?2:3) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC)) { - errors++; - } - p = p->pNext; - } - zend_debug_alloc_output("End of full memory check %s:%d (%d errors)\n" ZEND_FILE_LINE_RELAY_CC, errors); - zend_debug_alloc_output("------------------------------------------------\n"); -} -#endif - - -ZEND_API void _persist_alloc(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) -{ - zend_mem_header *p = (zend_mem_header *) ((char *)ptr-sizeof(zend_mem_header)-PLATFORM_PADDING); - ALS_FETCH(); - -#if ZEND_DEBUG - _mem_block_check(ptr, 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_ORIG_RELAY_CC); -#endif - - HANDLE_BLOCK_INTERRUPTIONS(); - - /* remove the block from the non persistent list */ - REMOVE_POINTER_FROM_LIST(p); - - p->persistent = 1; - - /* add the block to the persistent list */ - ADD_POINTER_TO_LIST(p); - HANDLE_UNBLOCK_INTERRUPTIONS(); -} - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/Zend/zend_alloc.h b/Zend/zend_alloc.h deleted file mode 100644 index 9214fb6e4d..0000000000 --- a/Zend/zend_alloc.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _ALLOC_H -#define _ALLOC_H - -#include - -#include "zend_globals_macros.h" - -#define MEM_BLOCK_START_MAGIC 0x7312F8DCL -#define MEM_BLOCK_END_MAGIC 0x2A8FCC84L -#define MEM_BLOCK_FREED_MAGIC 0x99954317L -#define MEM_BLOCK_CACHED_MAGIC 0xFB8277DCL - -typedef struct _zend_mem_header { -#if ZEND_DEBUG - long magic; - char *filename; - uint lineno; - int reported; - char *orig_filename; - uint orig_lineno; -#endif - struct _zend_mem_header *pNext; - struct _zend_mem_header *pLast; - unsigned int size:30; - unsigned int persistent:1; - unsigned int cached:1; -} zend_mem_header; - -typedef union _align_test { - void *ptr; - double dbl; - long lng; -} align_test; - -#define MAX_CACHED_MEMORY 64 -#define MAX_CACHED_ENTRIES 16 -#if (defined (__GNUC__) && __GNUC__ >= 2) -#define PLATFORM_ALIGNMENT (__alignof__ (align_test)) -#else -#define PLATFORM_ALIGNMENT (sizeof(align_test)) -#endif - -#define PLATFORM_PADDING (((PLATFORM_ALIGNMENT-sizeof(zend_mem_header))%PLATFORM_ALIGNMENT+PLATFORM_ALIGNMENT)%PLATFORM_ALIGNMENT) - -ZEND_API char *zend_strndup(const char *s, unsigned int length); - -BEGIN_EXTERN_C() - -ZEND_API void *_emalloc(size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC); -ZEND_API void _efree(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC); -ZEND_API void *_ecalloc(size_t nmemb, size_t size ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC); -ZEND_API void *_erealloc(void *ptr, size_t size, int allow_failure ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC); -ZEND_API char *_estrdup(const char *s ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC); -ZEND_API char *_estrndup(const char *s, unsigned int length ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC); -ZEND_API void _persist_alloc(void *ptr ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC); - -/* Standard wrapper macros */ -#define emalloc(size) _emalloc((size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC) -#define efree(ptr) _efree((ptr) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC) -#define ecalloc(nmemb,size) _ecalloc((nmemb), (size) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC) -#define erealloc(ptr,size) _erealloc((ptr), (size),0 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC) -#define erealloc_recoverable(ptr,size) _erealloc((ptr), (size),1 ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC) -#define estrdup(s) _estrdup((s) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC) -#define estrndup(s,length) _estrndup((s), (length) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC) -#define persist_alloc(p) _persist_alloc((p) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC) - -/* Relay wrapper macros */ -#define emalloc_rel(size) _emalloc((size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC) -#define efree_rel(ptr) _efree((ptr) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC) -#define ecalloc_rel(nmemb, size) _ecalloc((nmemb), (size) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC) -#define erealloc_rel(ptr, size) _erealloc((ptr), (size), 0 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC) -#define erealloc_recoverable_rel(ptr, size) _erealloc((ptr), (size), 1 ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC) -#define estrdup_rel(s) _estrdup((s) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC) -#define estrndup_rel(s, length) _estrndup((s), (length) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC) -#define persist_alloc_rel(p) _persist_alloc((p) ZEND_FILE_LINE_RELAY_CC ZEND_FILE_LINE_CC) - -/* Selective persistent/non persistent allocation macros */ -#define pemalloc(size,persistent) ((persistent)?malloc(size):emalloc(size)) -#define pefree(ptr,persistent) ((persistent)?free(ptr):efree(ptr)) -#define pecalloc(nmemb,size,persistent) ((persistent)?calloc((nmemb),(size)):ecalloc((nmemb),(size))) -#define perealloc(ptr,size,persistent) ((persistent)?realloc((ptr),(size)):erealloc((ptr),(size))) -#define perealloc_recoverable(ptr,size,persistent) ((persistent)?realloc((ptr),(size)):erealloc_recoverable((ptr),(size))) -#define pestrdup(s,persistent) ((persistent)?strdup(s):estrdup(s)) - -#define safe_estrdup(ptr) ((ptr)?(estrdup(ptr)):(empty_string)) -#define safe_estrndup(ptr,len) ((ptr)?(estrndup((ptr),(len))):(empty_string)) - -ZEND_API int zend_set_memory_limit(unsigned int memory_limit); - -ZEND_API void start_memory_manager(ALS_D); -ZEND_API void shutdown_memory_manager(int silent, int clean_cache); - -#if ZEND_DEBUG -ZEND_API int _mem_block_check(void *ptr, int silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC); -ZEND_API void _full_mem_check(int silent ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC); -void zend_debug_alloc_output(char *format, ...); -#define mem_block_check(ptr, silent) _mem_block_check(ptr, silent ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC) -#define full_mem_check(silent) _full_mem_check(silent ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC) -#else -#define mem_block_check(type, ptr, silent) -#define full_mem_check(silent) -#endif - - -END_EXTERN_C() - -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/Zend/zend_builtin_functions.c b/Zend/zend_builtin_functions.c deleted file mode 100644 index b1b3ff2e7c..0000000000 --- a/Zend/zend_builtin_functions.c +++ /dev/null @@ -1,585 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include "zend.h" -#include "zend_API.h" -#include "zend_builtin_functions.h" -#include "zend_operators.h" -#include "zend_variables.h" -#include "zend_constants.h" - -#undef ZEND_TEST_EXCEPTIONS - -static ZEND_FUNCTION(zend_version); -static ZEND_FUNCTION(func_num_args); -static ZEND_FUNCTION(func_get_arg); -static ZEND_FUNCTION(func_get_args); -static ZEND_FUNCTION(strlen); -static ZEND_FUNCTION(strcmp); -static ZEND_FUNCTION(strncmp); -static ZEND_FUNCTION(strcasecmp); -static ZEND_FUNCTION(each); -static ZEND_FUNCTION(error_reporting); -static ZEND_FUNCTION(define); -static ZEND_FUNCTION(defined); -static ZEND_FUNCTION(get_class); -static ZEND_FUNCTION(get_parent_class); -static ZEND_FUNCTION(method_exists); -static ZEND_FUNCTION(class_exists); -static ZEND_FUNCTION(function_exists); -static ZEND_FUNCTION(leak); -#ifdef ZEND_TEST_EXCEPTIONS -static ZEND_FUNCTION(crash); -#endif -static ZEND_FUNCTION(get_used_files); -static ZEND_FUNCTION(get_imported_files); -static ZEND_FUNCTION(is_subclass_of); - -extern unsigned char first_arg_force_ref[]; - -static zend_function_entry builtin_functions[] = { - ZEND_FE(zend_version, NULL) - ZEND_FE(func_num_args, NULL) - ZEND_FE(func_get_arg, NULL) - ZEND_FE(func_get_args, NULL) - ZEND_FE(strlen, NULL) - ZEND_FE(strcmp, NULL) - ZEND_FE(strncmp, NULL) - ZEND_FE(strcasecmp, NULL) - ZEND_FE(each, first_arg_force_ref) - ZEND_FE(error_reporting, NULL) - ZEND_FE(define, NULL) - ZEND_FE(defined, NULL) - ZEND_FE(get_class, NULL) - ZEND_FE(get_parent_class, NULL) - ZEND_FE(method_exists, NULL) - ZEND_FE(class_exists, NULL) - ZEND_FE(function_exists, NULL) - ZEND_FE(leak, NULL) -#ifdef ZEND_TEST_EXCEPTIONS - ZEND_FE(crash, NULL) -#endif - ZEND_FE(get_used_files, NULL) - ZEND_FE(get_imported_files, NULL) - ZEND_FE(is_subclass_of, NULL) - { NULL, NULL, NULL } -}; - - -int zend_startup_builtin_functions() -{ - return zend_register_functions(builtin_functions, NULL); -} - - -ZEND_FUNCTION(zend_version) -{ - RETURN_STRINGL(ZEND_VERSION, sizeof(ZEND_VERSION)-1, 1); -} - - -ZEND_FUNCTION(func_num_args) -{ - void **p; - int arg_count; - - p = EG(argument_stack).top_element-1; - arg_count = (ulong) *p; /* this is the amount of arguments passed to func_num_args(); */ - - p = EG(argument_stack).top_element-1-arg_count-1; - if (p>=EG(argument_stack).elements) { - RETURN_LONG((ulong) *p); - } else { - zend_error(E_WARNING, "func_num_args(): Called from the global scope - no function context"); - RETURN_LONG(-1); - } -} - - -ZEND_FUNCTION(func_get_arg) -{ - void **p; - int arg_count; - zval **z_requested_offset; - zval *arg; - long requested_offset; - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &z_requested_offset)==FAILURE) { - RETURN_FALSE; - } - convert_to_long_ex(z_requested_offset); - requested_offset = (*z_requested_offset)->value.lval; - - p = EG(argument_stack).top_element-1; - arg_count = (ulong) *p; /* this is the amount of arguments passed to func_num_args(); */ - - p = EG(argument_stack).top_element-1-arg_count-1; - if (p=arg_count) { - zend_error(E_WARNING, "func_get_arg(): Argument %d not passed to function", requested_offset); - RETURN_FALSE; - } - - arg = *(p-(arg_count-requested_offset)); - *return_value = *arg; - zval_copy_ctor(return_value); -} - - -ZEND_FUNCTION(func_get_args) -{ - void **p; - int arg_count; - int i; - - p = EG(argument_stack).top_element-1; - arg_count = (ulong) *p; /* this is the amount of arguments passed to func_num_args(); */ - - p = EG(argument_stack).top_element-1-arg_count-1; - if (pvalue.ht, &element, sizeof(zval *), NULL); - } -} - - -/* {{{ proto int strlen(string str) - Get string length */ -ZEND_FUNCTION(strlen) -{ - zval **str; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &str) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(str); - RETVAL_LONG((*str)->value.str.len); -} -/* }}} */ - -/* {{{ proto int strcmp(string str1, string str2) - Binary safe string comparison */ -ZEND_FUNCTION(strcmp) -{ - zval **s1, **s2; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &s1, &s2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(s1); - convert_to_string_ex(s2); - RETURN_LONG(zend_binary_zval_strcmp(*s1,*s2)); -} -/* }}} */ - -/* {{{ proto int strncmp(string str1, string str2, int len) - Binary safe string comparison */ -ZEND_FUNCTION(strncmp) -{ - zval **s1, **s2, **s3; - - if (ZEND_NUM_ARGS() != 3 || zend_get_parameters_ex(3, &s1, &s2, &s3) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(s1); - convert_to_string_ex(s2); - convert_to_long_ex(s3); - RETURN_LONG(zend_binary_zval_strncmp(*s1,*s2,*s3)); -} -/* }}} */ - -/* {{{ proto int strcasecmp(string str1, string str2) - Binary safe case-insensitive string comparison */ -ZEND_FUNCTION(strcasecmp) -{ - zval **s1, **s2; - - if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &s1, &s2) == FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(s1); - convert_to_string_ex(s2); - RETURN_LONG(zend_binary_zval_strcasecmp(*s1, *s2)); -} -/* }}} */ - -ZEND_FUNCTION(each) -{ - zval **array,*entry,**entry_ptr, *tmp; - char *string_key; - ulong num_key; - zval **inserted_pointer; - HashTable *target_hash; - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &array) == FAILURE) { - WRONG_PARAM_COUNT; - } - target_hash = HASH_OF(*array); - if (!target_hash) { - zend_error(E_WARNING,"Variable passed to each() is not an array or object"); - return; - } - if (zend_hash_get_current_data(target_hash, (void **) &entry_ptr)==FAILURE) { - RETURN_FALSE; - } - array_init(return_value); - entry = *entry_ptr; - - /* add value elements */ - if (entry->is_ref) { - ALLOC_ZVAL(tmp); - *tmp = *entry; - zval_copy_ctor(tmp); - tmp->is_ref=0; - tmp->refcount=0; - entry=tmp; - } - zend_hash_index_update(return_value->value.ht, 1, &entry, sizeof(zval *), NULL); - entry->refcount++; - zend_hash_update_ptr(return_value->value.ht, "value", sizeof("value"), entry, sizeof(zval *), NULL); - entry->refcount++; - - /* add the key elements */ - switch (zend_hash_get_current_key(target_hash, &string_key, &num_key)) { - case HASH_KEY_IS_STRING: - add_get_index_string(return_value,0,string_key,(void **) &inserted_pointer,0); - break; - case HASH_KEY_IS_LONG: - add_get_index_long(return_value,0,num_key, (void **) &inserted_pointer); - break; - } - zend_hash_update(return_value->value.ht, "key", sizeof("key"), inserted_pointer, sizeof(zval *), NULL); - (*inserted_pointer)->refcount++; - zend_hash_move_forward(target_hash); -} - -ZEND_FUNCTION(error_reporting) -{ - zval **arg; - int old_error_reporting; - - old_error_reporting = EG(error_reporting); - switch (ZEND_NUM_ARGS()) { - case 0: - break; - case 1: - if (zend_get_parameters_ex(1,&arg) == FAILURE) { - RETURN_FALSE; - } - convert_to_long_ex(arg); - EG(error_reporting)=(*arg)->value.lval; - break; - default: - WRONG_PARAM_COUNT; - break; - } - - RETVAL_LONG(old_error_reporting); -} - -ZEND_FUNCTION(define) -{ - zval **var, **val, **non_cs; - int case_sensitive; - zend_constant c; - - switch(ZEND_NUM_ARGS()) { - case 2: - if (zend_get_parameters_ex(2, &var, &val)==FAILURE) { - RETURN_FALSE; - } - case_sensitive = CONST_CS; - break; - case 3: - if (zend_get_parameters_ex(3, &var, &val, &non_cs)==FAILURE) { - RETURN_FALSE; - } - convert_to_long_ex(non_cs); - if ((*non_cs)->value.lval) { - case_sensitive = 0; - } else { - case_sensitive = CONST_CS; - } - break; - default: - WRONG_PARAM_COUNT; - break; - } - switch((*val)->type) { - case IS_LONG: - case IS_DOUBLE: - case IS_STRING: - case IS_BOOL: - case IS_RESOURCE: - case IS_NULL: - break; - default: - zend_error(E_WARNING,"Constants may only evaluate to scalar values"); - RETURN_FALSE; - break; - } - convert_to_string_ex(var); - - c.value = **val; - zval_copy_ctor(&c.value); - c.flags = case_sensitive | ~CONST_PERSISTENT; /* non persistent */ - c.name = zend_strndup((*var)->value.str.val, (*var)->value.str.len); - c.name_len = (*var)->value.str.len+1; - zend_register_constant(&c ELS_CC); - RETURN_TRUE; -} - - -ZEND_FUNCTION(defined) -{ - zval **var; - zval c; - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &var)==FAILURE) { - WRONG_PARAM_COUNT; - } - - convert_to_string_ex(var); - if (zend_get_constant((*var)->value.str.val, (*var)->value.str.len, &c)) { - zval_dtor(&c); - RETURN_LONG(1); - } else { - RETURN_LONG(0); - } -} - -/* {{{ proto string get_class(object object) - Retrieves the class name ... -*/ -ZEND_FUNCTION(get_class) -{ - zval **arg; - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &arg)==FAILURE) { - RETURN_FALSE; - } - if ((*arg)->type != IS_OBJECT) { - RETURN_FALSE; - } - RETURN_STRINGL((*arg)->value.obj.ce->name, (*arg)->value.obj.ce->name_length, 1); -} -/* }}} */ - -/* {{{ proto string get_parent_class(object object) - Retrieves the parent class name ... -*/ -ZEND_FUNCTION(get_parent_class) -{ - zval **arg; - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &arg)==FAILURE) { - RETURN_FALSE; - } - if (((*arg)->type != IS_OBJECT) || !(*arg)->value.obj.ce->parent) { - RETURN_FALSE; - } - RETURN_STRINGL((*arg)->value.obj.ce->parent->name, (*arg)->value.obj.ce->parent->name_length, 1); -} -/* }}} */ - -/* {{{ proto bool is_subclass_of(object object, string class_name) - Returns true if the object has this class as one of its parents */ -ZEND_FUNCTION(is_subclass_of) -{ - zval **obj, **class_name; - char *lcname; - zend_class_entry *parent_ce = NULL; - - if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &obj, &class_name)==FAILURE) { - RETURN_FALSE; - } - - if ((*obj)->type != IS_OBJECT) { - RETURN_FALSE; - } - - convert_to_string_ex(class_name); - lcname = estrndup((*class_name)->value.str.val, (*class_name)->value.str.len); - zend_str_tolower(lcname, (*class_name)->value.str.len); - - for (parent_ce = (*obj)->value.obj.ce->parent; parent_ce != NULL; parent_ce = parent_ce->parent) { - if (!strcmp(parent_ce->name, lcname)) { - efree(lcname); - RETURN_TRUE; - } - } - efree(lcname); - RETURN_FALSE; -} -/* }}} */ - -/* {{{ proto bool method_exists(object object, string method) - Checks if the class method exists ... -*/ -ZEND_FUNCTION(method_exists) -{ - zval **klass, **method_name; - char *lcname; - - if (ZEND_NUM_ARGS()!=2 || zend_get_parameters_ex(2, &klass, &method_name)==FAILURE) { - RETURN_FALSE; - } - if ((*klass)->type != IS_OBJECT) { - RETURN_FALSE; - } - convert_to_string_ex(method_name); - lcname = estrndup((*method_name)->value.str.val, (*method_name)->value.str.len); - zend_str_tolower(lcname, (*method_name)->value.str.len); - if(zend_hash_exists(&(*klass)->value.obj.ce->function_table, lcname, (*method_name)->value.str.len+1)) { - efree(lcname); - RETURN_TRUE; - } else { - efree(lcname); - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto bool class_exists(string classname) - Checks if the class exists ... -*/ -ZEND_FUNCTION(class_exists) -{ - zval **class_name; - char *lcname; - CLS_FETCH(); - - if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &class_name)==FAILURE) { - RETURN_FALSE; - } - convert_to_string_ex(class_name); - lcname = estrndup((*class_name)->value.str.val, (*class_name)->value.str.len); - zend_str_tolower(lcname, (*class_name)->value.str.len); - if (zend_hash_exists(CG(class_table), lcname, (*class_name)->value.str.len+1)) { - efree(lcname); - RETURN_TRUE; - } else { - efree(lcname); - RETURN_FALSE; - } -} -/* }}} */ - -/* {{{ proto bool function_exists(string function_name) - Checks if the function exists */ -ZEND_FUNCTION(function_exists) -{ - zval **function_name; - char *lcname; - int retval; - - if (ZEND_NUM_ARGS()!=1 || zend_get_parameters_ex(1, &function_name)==FAILURE) { - WRONG_PARAM_COUNT; - } - convert_to_string_ex(function_name); - lcname = estrndup((*function_name)->value.str.val, (*function_name)->value.str.len); - zend_str_tolower(lcname, (*function_name)->value.str.len); - - retval = zend_hash_exists(EG(function_table), lcname, (*function_name)->value.str.len+1); - efree(lcname); - - RETURN_BOOL(retval); -} -/* }}} */ - - -ZEND_FUNCTION(leak) -{ - int leakbytes=3; - zval **leak; - - if (ZEND_NUM_ARGS()>=1) { - if (zend_get_parameters_ex(1, &leak)==SUCCESS) { - convert_to_long_ex(leak); - leakbytes = (*leak)->value.lval; - } - } - - emalloc(leakbytes); -} - - -#ifdef ZEND_TEST_EXCEPTIONS -ZEND_FUNCTION(crash) -{ - char *nowhere=NULL; - - memcpy(nowhere, "something", sizeof("something")); -} -#endif - - -static int copy_import_use_file(zend_file_handle *fh, zval *array) -{ - if (fh->filename) { - char *extension_start; - - extension_start = strstr(fh->filename, zend_uv.import_use_extension); - if (extension_start) { - *extension_start = 0; - if (fh->opened_path) { - add_assoc_string(array, fh->filename, fh->opened_path, 1); - } else { - add_assoc_stringl(array, fh->filename, "N/A", sizeof("N/A")-1, 1); - } - *extension_start = zend_uv.import_use_extension[0]; - } - } - return 0; -} - - -ZEND_FUNCTION(get_used_files) -{ - CLS_FETCH(); - - array_init(return_value); - zend_hash_apply_with_argument(&CG(used_files), (int (*)(void *, void *)) copy_import_use_file, return_value); -} - - -ZEND_FUNCTION(get_imported_files) -{ - array_init(return_value); - zend_hash_apply_with_argument(&EG(imported_files), (int (*)(void *, void *)) copy_import_use_file, return_value); -} diff --git a/Zend/zend_builtin_functions.h b/Zend/zend_builtin_functions.h deleted file mode 100644 index fa3f529463..0000000000 --- a/Zend/zend_builtin_functions.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _ZEND_BUILTIN_FUNCTIONS_H -#define _ZEND_BUILTIN_FUNCTIONS_H - -int zend_startup_builtin_functions(void); - -#endif /* _ZEND_BUILTIN_FUNCTIONS_H */ diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c deleted file mode 100644 index 4030c8a679..0000000000 --- a/Zend/zend_compile.c +++ /dev/null @@ -1,2303 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include "zend-parser.h" -#include "zend.h" -#include "zend_compile.h" -#include "zend_llist.h" -#include "zend_API.h" -#include "zend_variables.h" -#include "zend_operators.h" -#include "zend_fast_cache.h" - - -ZEND_API zend_op_array *(*zend_compile_files)(int mark_as_ref CLS_DC, int file_count, ...); - - -#ifndef ZTS -ZEND_API zend_compiler_globals compiler_globals; -ZEND_API zend_executor_globals executor_globals; -#endif - - -#define SET_UNUSED(op) (op).op_type = IS_UNUSED - -static int is_not_internal_function(zend_function *function) -{ - return(function->type != ZEND_INTERNAL_FUNCTION); -} - - -static int is_not_internal_class(zend_class_entry *ce) -{ - return(ce->type != ZEND_INTERNAL_CLASS); -} - - -static void free_filename(void *p) -{ - efree(*((char **) p)); -} - - -static void build_runtime_defined_function_key(zval *result, zval *name, zend_op *opline) -{ - char lineno_buf[32]; - uint lineno_len; - char *filename; - - lineno_len = zend_sprintf(lineno_buf, "%d", opline->lineno); - if (opline->filename) { - filename = opline->filename; - } else { - filename = "-"; - } - - /* NULL, name length, filename length, line number length */ - result->value.str.len = 1+name->value.str.len+strlen(filename)+lineno_len+1; - result->value.str.val = (char *) emalloc(result->value.str.len+1); - sprintf(result->value.str.val, "%c%s%s%s", '\0', name->value.str.val, filename, lineno_buf); - result->type = IS_STRING; - result->refcount = 1; -} - - -static void zend_open_file_dtor_wrapper(zend_file_handle *fh) -{ - zend_open_file_dtor(fh); -} - - -static void init_compiler_declarables(CLS_D ELS_DC) -{ - CG(declarables).ticks.type = IS_LONG; - CG(declarables).ticks.value.lval = 0; -} - - -void init_compiler(CLS_D ELS_DC) -{ - zend_stack_init(&CG(bp_stack)); - zend_stack_init(&CG(function_call_stack)); - zend_stack_init(&CG(switch_cond_stack)); - zend_stack_init(&CG(foreach_copy_stack)); - zend_stack_init(&CG(object_stack)); - zend_stack_init(&CG(declare_stack)); - CG(active_class_entry) = NULL; - zend_llist_init(&CG(list_llist), sizeof(list_llist_element), NULL, 0); - zend_llist_init(&CG(dimension_llist), sizeof(int), NULL, 0); - zend_llist_init(&CG(filenames_list), sizeof(char *), free_filename, 0); - CG(short_tags) = ZEND_UV(short_tags); - CG(asp_tags) = ZEND_UV(asp_tags); - CG(allow_call_time_pass_reference) = ZEND_UV(allow_call_time_pass_reference); - CG(handle_op_arrays) = 1; - CG(in_compilation) = 0; - init_resource_list(ELS_C); - CG(unclean_shutdown) = 0; - zend_llist_init(&CG(open_files), sizeof(zend_file_handle), (void (*)(void *)) zend_open_file_dtor, 0); - zend_hash_init(&CG(used_files), 5, NULL, (void (*)(void *)) zend_open_file_dtor_wrapper, 0); - init_compiler_declarables(CLS_C ELS_CC); -} - - -void shutdown_compiler(CLS_D) -{ - zend_stack_destroy(&CG(bp_stack)); - zend_stack_destroy(&CG(function_call_stack)); - zend_stack_destroy(&CG(switch_cond_stack)); - zend_stack_destroy(&CG(foreach_copy_stack)); - zend_stack_destroy(&CG(object_stack)); - zend_stack_destroy(&CG(declare_stack)); - zend_llist_destroy(&CG(filenames_list)); - zend_hash_apply(CG(function_table), (int (*)(void *)) is_not_internal_function); - zend_hash_apply(CG(class_table), (int (*)(void *)) is_not_internal_class); - zend_llist_destroy(&CG(open_files)); - zend_hash_destroy(&CG(used_files)); -} - - -ZEND_API char *zend_set_compiled_filename(char *new_compiled_filename) -{ - char *p = estrdup(new_compiled_filename); - CLS_FETCH(); - - zend_llist_add_element(&CG(filenames_list), &p); - CG(compiled_filename) = p; - return p; -} - - -ZEND_API void zend_restore_compiled_filename(char *original_compiled_filename) -{ - CLS_FETCH(); - - CG(compiled_filename) = original_compiled_filename; -} - - -ZEND_API char *zend_get_compiled_filename(CLS_D) -{ - return CG(compiled_filename); -} - - -ZEND_API int zend_get_compiled_lineno(CLS_D) -{ - return CG(zend_lineno); -} - - -ZEND_API zend_bool zend_is_compiling() -{ - CLS_FETCH(); - - return CG(in_compilation); -} - - -static int get_temporary_variable(zend_op_array *op_array) -{ - return (op_array->T)++; -} - - -void do_binary_op(int op, znode *result, znode *op1, znode *op2 CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = op; - opline->result.op_type = IS_TMP_VAR; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->op1 = *op1; - opline->op2 = *op2; - *result = opline->result; -} - - -void do_unary_op(int op, znode *result, znode *op1 CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = op; - opline->result.op_type = IS_TMP_VAR; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->op1 = *op1; - *result = opline->result; - SET_UNUSED(opline->op2); -} - - -void do_binary_assign_op(int op, znode *result, znode *op1, znode *op2 CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = op; - opline->result.op_type = IS_VAR; - opline->result.u.EA.type = 0; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->op1 = *op1; - opline->op2 = *op2; - *result = opline->result; -} - - - -void do_fetch_globals(znode *varname CLS_DC) -{ - if (!CG(active_op_array)->uses_globals - && varname->op_type == IS_CONST - && varname->u.constant.type == IS_STRING - && varname->u.constant.value.str.len == (sizeof("GLOBALS")-1) - && !memcmp(varname->u.constant.value.str.val, "GLOBALS", sizeof("GLOBALS")-1)) { - CG(active_op_array)->uses_globals = 1; - } -} - -void fetch_simple_variable_ex(znode *result, znode *varname, int bp, int op CLS_DC) -{ - zend_op opline; - zend_op *opline_ptr; - zend_llist *fetch_list_ptr; - - if (bp) { - opline_ptr = &opline; - init_op(opline_ptr CLS_CC); - } else { - opline_ptr = get_next_op(CG(active_op_array) CLS_CC); - } - - opline_ptr->opcode = op; - opline_ptr->result.op_type = IS_VAR; - opline_ptr->result.u.EA.type = 0; - opline_ptr->result.u.var = get_temporary_variable(CG(active_op_array)); - opline_ptr->op1 = *varname; - *result = opline_ptr->result; - SET_UNUSED(opline_ptr->op2); - opline_ptr->op2.u.fetch_type = ZEND_FETCH_LOCAL; - - if (bp) { - zend_stack_top(&CG(bp_stack), (void **) &fetch_list_ptr); - zend_llist_add_element(fetch_list_ptr, opline_ptr); - } -} - -void fetch_simple_variable(znode *result, znode *varname, int bp CLS_DC) -{ - /* the default mode must be Write, since fetch_simple_variable() is used to define function arguments */ - fetch_simple_variable_ex(result, varname, bp, ZEND_FETCH_W CLS_CC); -} - - -void fetch_array_begin(znode *result, znode *varname, znode *first_dim CLS_DC) -{ - fetch_simple_variable(result, varname, 1 CLS_CC); - - fetch_array_dim(result, result, first_dim CLS_CC); -} - - -void fetch_array_dim(znode *result, znode *parent, znode *dim CLS_DC) -{ - zend_op opline; - zend_llist *fetch_list_ptr; - - init_op(&opline CLS_CC); - opline.opcode = ZEND_FETCH_DIM_W; /* the backpatching routine assumes W */ - opline.result.op_type = IS_VAR; - opline.result.u.EA.type = 0; - opline.result.u.var = get_temporary_variable(CG(active_op_array)); - opline.op1 = *parent; - opline.op2 = *dim; - opline.extended_value = ZEND_FETCH_STANDARD; - *result = opline.result; - - zend_stack_top(&CG(bp_stack), (void **) &fetch_list_ptr); - zend_llist_add_element(fetch_list_ptr, &opline); -} - - -void fetch_string_offset(znode *result, znode *parent, znode *offset CLS_DC) -{ - fetch_array_dim(result, parent, offset CLS_CC); -} - - -void do_print(znode *result, znode *arg CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->result.op_type = IS_TMP_VAR; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->opcode = ZEND_PRINT; - opline->op1 = *arg; - SET_UNUSED(opline->op2); - *result = opline->result; -} - - -void do_echo(znode *arg CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_ECHO; - opline->op1 = *arg; - SET_UNUSED(opline->op2); -} - - -void do_assign(znode *result, znode *variable, znode *value CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_ASSIGN; - opline->result.op_type = IS_VAR; - opline->result.u.EA.type = 0; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->op1 = *variable; - opline->op2 = *value; - *result = opline->result; -} - - -void do_assign_ref(znode *result, znode *lvar, znode *rvar CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_ASSIGN_REF; - if (result) { - opline->result.op_type = IS_VAR; - opline->result.u.EA.type = 0; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - *result = opline->result; - } else { - SET_UNUSED(opline->result); - } - opline->op1 = *lvar; - opline->op2 = *rvar; -} - - -static inline void do_begin_loop(CLS_D) -{ - zend_brk_cont_element *brk_cont_element; - int parent; - - parent = CG(active_op_array)->current_brk_cont; - CG(active_op_array)->current_brk_cont = CG(active_op_array)->last_brk_cont; - brk_cont_element = get_next_brk_cont_element(CG(active_op_array)); - brk_cont_element->parent = parent; -} - - -static inline void do_end_loop(int cont_addr CLS_DC) -{ - CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].cont = cont_addr; - CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].brk = get_next_op_number(CG(active_op_array)); - CG(active_op_array)->current_brk_cont = CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].parent; -} - - -void do_while_cond(znode *expr, znode *close_bracket_token CLS_DC) -{ - int while_cond_op_number = get_next_op_number(CG(active_op_array)); - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_JMPZ; - opline->op1 = *expr; - close_bracket_token->u.opline_num = while_cond_op_number; - SET_UNUSED(opline->op2); - - do_begin_loop(CLS_C); - INC_BPC(CG(active_op_array)); -} - - -void do_while_end(znode *while_token, znode *close_bracket_token CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - /* add unconditional jump */ - opline->opcode = ZEND_JMP; - opline->op1.u.opline_num = while_token->u.opline_num; - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); - - /* update while's conditional jmp */ - CG(active_op_array)->opcodes[close_bracket_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array)); - - do_end_loop(while_token->u.opline_num CLS_CC); - - DEC_BPC(CG(active_op_array)); -} - - -void do_for_cond(znode *expr, znode *second_semicolon_token CLS_DC) -{ - int for_cond_op_number = get_next_op_number(CG(active_op_array)); - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_JMPZNZ; - opline->result = *expr; /* the conditional expression */ - second_semicolon_token->u.opline_num = for_cond_op_number; - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); -} - - -void do_for_before_statement(znode *cond_start, znode *second_semicolon_token CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_JMP; - opline->op1.u.opline_num = cond_start->u.opline_num; - CG(active_op_array)->opcodes[second_semicolon_token->u.opline_num].op1.u.opline_num = get_next_op_number(CG(active_op_array)); - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); - - do_begin_loop(CLS_C); - - INC_BPC(CG(active_op_array)); -} - - -void do_for_end(znode *second_semicolon_token CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_JMP; - opline->op1.u.opline_num = second_semicolon_token->u.opline_num+1; - CG(active_op_array)->opcodes[second_semicolon_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array)); - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); - - do_end_loop(second_semicolon_token->u.opline_num+1 CLS_CC); - - DEC_BPC(CG(active_op_array)); -} - - -void do_pre_incdec(znode *result, znode *op1, int op CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = op; - opline->result.op_type = IS_VAR; - opline->result.u.EA.type = 0; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->op1 = *op1; - *result = opline->result; - SET_UNUSED(opline->op2); -} - - -void do_post_incdec(znode *result, znode *op1, int op CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = op; - opline->result.op_type = IS_TMP_VAR; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->op1 = *op1; - *result = opline->result; - SET_UNUSED(opline->op2); -} - - -void do_if_cond(znode *cond, znode *closing_bracket_token CLS_DC) -{ - int if_cond_op_number = get_next_op_number(CG(active_op_array)); - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_JMPZ; - opline->op1 = *cond; - closing_bracket_token->u.opline_num = if_cond_op_number; - SET_UNUSED(opline->op2); - INC_BPC(CG(active_op_array)); -} - - -void do_if_after_statement(znode *closing_bracket_token, unsigned char initialize CLS_DC) -{ - int if_end_op_number = get_next_op_number(CG(active_op_array)); - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - zend_llist *jmp_list_ptr; - - opline->opcode = ZEND_JMP; - /* save for backpatching */ - if (initialize) { - zend_llist jmp_list; - - zend_llist_init(&jmp_list, sizeof(int), NULL, 0); - zend_stack_push(&CG(bp_stack), (void *) &jmp_list, sizeof(zend_llist)); - } - zend_stack_top(&CG(bp_stack), (void **) &jmp_list_ptr); - zend_llist_add_element(jmp_list_ptr, &if_end_op_number); - - CG(active_op_array)->opcodes[closing_bracket_token->u.opline_num].op2.u.opline_num = if_end_op_number+1; - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); -} - - -void do_if_end(CLS_D) -{ - int next_op_number = get_next_op_number(CG(active_op_array)); - zend_llist *jmp_list_ptr; - zend_llist_element *le; - - zend_stack_top(&CG(bp_stack), (void **) &jmp_list_ptr); - for (le=jmp_list_ptr->head; le; le = le->next) { - CG(active_op_array)->opcodes[*((int *) le->data)].op1.u.opline_num = next_op_number; - } - zend_llist_destroy(jmp_list_ptr); - zend_stack_del_top(&CG(bp_stack)); - DEC_BPC(CG(active_op_array)); -} - - -void do_begin_variable_parse(CLS_D) -{ - zend_llist fetch_list; - - /* zend_llist_init(&fetch_list, sizeof(int), NULL, 0); - zend_stack_push(&CG(bp_stack), (void *) &fetch_list, sizeof(zend_llist));*/ - zend_llist_init(&fetch_list, sizeof(zend_op), NULL, 0); - zend_stack_push(&CG(bp_stack), (void *) &fetch_list, sizeof(zend_llist)); -} - - -void do_end_variable_parse(int type, int arg_offset CLS_DC) -{ - zend_llist *fetch_list_ptr; - zend_llist_element *le; - zend_op *opline, *opline_ptr; - - zend_stack_top(&CG(bp_stack), (void **) &fetch_list_ptr); - - le = fetch_list_ptr->head; - - while (le) { - opline_ptr = (zend_op *)le->data; - opline = get_next_op(CG(active_op_array) CLS_CC); - memcpy(opline, opline_ptr, sizeof(zend_op)); - switch (type) { - case BP_VAR_R: - if (opline->opcode == ZEND_FETCH_DIM_W && opline->op2.op_type == IS_UNUSED) { - zend_error(E_COMPILE_ERROR, "Cannot use [] for reading"); - } - opline->opcode -= 3; - break; - case BP_VAR_W: - break; - case BP_VAR_RW: - opline->opcode += 3; - break; - case BP_VAR_IS: - opline->opcode += 6; /* 3+3 */ - break; - case BP_VAR_FUNC_ARG: - opline->opcode += 9; /* 3+3+3 */ - opline->extended_value = arg_offset; - break; - case BP_VAR_UNSET: - opline->opcode += 12; /* 3+3+3+3 */ - break; - } - le = le->next; - } - zend_llist_destroy(fetch_list_ptr); - zend_stack_del_top(&CG(bp_stack)); -} - - -void do_init_string(znode *result CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_INIT_STRING; - opline->result.op_type = IS_TMP_VAR; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - *result = opline->result; - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); -} - - -void do_add_char(znode *result, znode *op1, znode *op2 CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_ADD_CHAR; - opline->op1 = *op1; - opline->op2 = *op2; - opline->op2.op_type = IS_CONST; - opline->result = opline->op1; - *result = opline->result; -} - - -void do_add_string(znode *result, znode *op1, znode *op2 CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_ADD_STRING; - opline->op1 = *op1; - opline->op2 = *op2; - opline->op2.op_type = IS_CONST; - opline->result = opline->op1; - *result = opline->result; -} - - -void do_add_variable(znode *result, znode *op1, znode *op2 CLS_DC) -{ - zend_op *opline; - - if (op1->op_type == IS_CONST) { - opline = get_next_op(CG(active_op_array) CLS_CC); - opline->opcode = ZEND_INIT_STRING; - opline->result.op_type = IS_TMP_VAR; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - *result = opline->result; - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); - - if (op1->u.constant.value.str.len>0) { - opline = get_next_op(CG(active_op_array) CLS_CC); - opline->opcode = ZEND_ADD_STRING; - opline->result = *result; - opline->op1 = *result; - opline->op2 = *op1; - opline->result = opline->op1; - } else { - zval_dtor(&op1->u.constant); - } - } else { - *result = *op1; - } - - opline = get_next_op(CG(active_op_array) CLS_CC); - opline->opcode = ZEND_ADD_VAR; - opline->result = *result; - opline->op1 = *result; - opline->op2 = *op2; - *result = opline->result; -} - - -void do_free(znode *op1 CLS_DC) -{ - if (op1->op_type==IS_TMP_VAR) { - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_FREE; - opline->op1 = *op1; - SET_UNUSED(opline->op2); - } else if (op1->op_type==IS_VAR) { - zend_op *opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1]; - - if (opline->opcode == ZEND_END_SILENCE) { - opline--; - } - if (opline->result.op_type == op1->op_type - && opline->result.u.var == op1->u.var) { - opline->result.u.EA.type |= EXT_TYPE_UNUSED; - } else { - while (opline>CG(active_op_array)->opcodes) { - /* This should be an object instanciation - * Find JMP_NO_CTOR, mark the preceding ASSIGN and the - * proceeding INIT_FCALL_BY_NAME as unused - */ - if (opline->opcode == ZEND_JMP_NO_CTOR) { - (opline-1)->result.u.EA.type |= EXT_TYPE_UNUSED; - (opline+1)->op1.u.EA.type |= EXT_TYPE_UNUSED; - break; - } else if (opline->opcode == ZEND_FETCH_DIM_R - && opline->op1.op_type == IS_VAR - && opline->op1.u.var == op1->u.var) { - /* This should the end of a list() construct - * Mark its result as unused - */ - opline->extended_value = ZEND_FETCH_STANDARD; - break; - } else if (opline->result.op_type==IS_VAR - && opline->result.u.var == op1->u.var) { - break; - } - opline--; - } - } - } -} - - -void do_begin_function_declaration(znode *function_token, znode *function_name, int is_method, int return_reference CLS_DC) -{ - zend_op_array op_array; - char *name = function_name->u.constant.value.str.val; - int name_len = function_name->u.constant.value.str.len; - int function_begin_line = function_token->u.opline_num; - - function_token->u.op_array = CG(active_op_array); - zend_str_tolower(name, name_len); - - init_op_array(&op_array, INITIAL_OP_ARRAY_SIZE); - - op_array.function_name = name; - op_array.arg_types = NULL; - op_array.return_reference = return_reference; - - if (is_method) { - zend_hash_update(&CG(active_class_entry)->function_table, name, name_len+1, &op_array, sizeof(zend_op_array), (void **) &CG(active_op_array)); - } else { - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_DECLARE_FUNCTION_OR_CLASS; - opline->op1.op_type = IS_CONST; - build_runtime_defined_function_key(&opline->op1.u.constant, &function_name->u.constant, opline); - opline->op2.op_type = IS_CONST; - opline->op2.u.constant.type = IS_STRING; - opline->op2.u.constant.value.str.val = estrndup(name, name_len); - opline->op2.u.constant.value.str.len = name_len; - opline->op2.u.constant.refcount = 1; - opline->extended_value = ZEND_DECLARE_FUNCTION; - zend_hash_update(CG(function_table), opline->op1.u.constant.value.str.val, opline->op1.u.constant.value.str.len, &op_array, sizeof(zend_op_array), (void **) &CG(active_op_array)); - } - - if (CG(extended_info)) { - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_EXT_NOP; - opline->lineno = function_begin_line; - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); - } - - { - /* Push a seperator to the switch and foreach stacks */ - zend_switch_entry switch_entry; - - switch_entry.cond.op_type = IS_UNUSED; - switch_entry.default_case = 0; - switch_entry.control_var = 0; - - zend_stack_push(&CG(switch_cond_stack), (void *) &switch_entry, sizeof(switch_entry)); - - zend_stack_push(&CG(foreach_copy_stack), (void *) &switch_entry.cond, sizeof(znode)); - } -} - - -void do_end_function_declaration(znode *function_token CLS_DC) -{ - do_return(NULL, 0 CLS_CC); - pass_two(CG(active_op_array)); - CG(active_op_array) = function_token->u.op_array; - - /* Pop the switch and foreach seperators */ - zend_stack_del_top(&CG(switch_cond_stack)); - zend_stack_del_top(&CG(foreach_copy_stack)); -} - - -void do_receive_arg(int op, znode *var, znode *offset, znode *initialization, unsigned char pass_type CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = op; - opline->result = *var; - opline->op1 = *offset; - if ((op == ZEND_RECV_INIT)) { - opline->op2 = *initialization; - } else { - SET_UNUSED(opline->op2); - } - if (pass_type==BYREF_FORCE && !CG(active_op_array)->arg_types) { - int i; - - CG(active_op_array)->arg_types = (unsigned char *) emalloc(sizeof(unsigned char)*(offset->u.constant.value.lval+1)); - for (i=1; iu.constant.value.lval; i++) { - CG(active_op_array)->arg_types[i] = BYREF_NONE; - } - CG(active_op_array)->arg_types[0]=(unsigned char) offset->u.constant.value.lval; - } - if (CG(active_op_array)->arg_types) { - CG(active_op_array)->arg_types = (unsigned char *) erealloc(CG(active_op_array)->arg_types, sizeof(unsigned char)*(offset->u.constant.value.lval+1)); - CG(active_op_array)->arg_types[offset->u.constant.value.lval] = pass_type; - CG(active_op_array)->arg_types[0]++; - } -} - - -int do_begin_function_call(znode *function_name CLS_DC) -{ - zend_function *function; - - zend_str_tolower(function_name->u.constant.value.str.val, function_name->u.constant.value.str.len); - if (zend_hash_find(CG(function_table), function_name->u.constant.value.str.val,function_name->u.constant.value.str.len+1, (void **) &function)==FAILURE) { - znode tmp = *function_name; - - zval_copy_ctor(&tmp.u.constant); - do_begin_dynamic_function_call(&tmp CLS_CC); - return 1; /* Dynamic */ - } - - switch (function->type) { - case ZEND_USER_FUNCTION: { - zend_op_array *op_array = (zend_op_array *) function; - - zend_stack_push(&CG(function_call_stack), (void *) &op_array, sizeof(zend_function *)); - } - break; - case ZEND_INTERNAL_FUNCTION: { - zend_internal_function *internal_function = (zend_internal_function *) function; - - zend_stack_push(&CG(function_call_stack), (void *) &internal_function, sizeof(zend_function *)); - } - break; - } - return 0; -} - - -void do_begin_dynamic_function_call(znode *function_name CLS_DC) -{ - unsigned char *ptr = NULL; - int last_op_number = get_next_op_number(CG(active_op_array))-1; - - if (last_op_number>=0 && CG(active_op_array)->opcodes[last_op_number].opcode == ZEND_FETCH_OBJ_R) { - CG(active_op_array)->opcodes[last_op_number].opcode = ZEND_INIT_FCALL_BY_NAME; - CG(active_op_array)->opcodes[last_op_number].extended_value = ZEND_MEMBER_FUNC_CALL; - } else { - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_INIT_FCALL_BY_NAME; - opline->op2 = *function_name; - opline->extended_value = 0; - SET_UNUSED(opline->op1); - } - zend_stack_push(&CG(function_call_stack), (void *) &ptr, sizeof(zend_function *)); -} - - -void do_begin_class_member_function_call(znode *class_name, znode *function_name CLS_DC) -{ - unsigned char *ptr = NULL; - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_INIT_FCALL_BY_NAME; - zend_str_tolower(class_name->u.constant.value.str.val, class_name->u.constant.value.str.len); - opline->op1 = *class_name; - opline->op2 = *function_name; - opline->extended_value = ZEND_MEMBER_FUNC_CALL; - zval_copy_ctor(&opline->op2.u.constant); - zend_stack_push(&CG(function_call_stack), (void *) &ptr, sizeof(zend_function *)); -} - - -void do_end_function_call(znode *function_name, znode *result, znode *argument_list, int is_method, int is_dynamic_fcall CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - if (function_name->op_type==IS_CONST && !is_method && !is_dynamic_fcall) { - opline->opcode = ZEND_DO_FCALL; - } else { - opline->opcode = ZEND_DO_FCALL_BY_NAME; - } - opline->op1 = *function_name; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->result.op_type = IS_VAR; - *result = opline->result; - SET_UNUSED(opline->op2); - opline->op2.u.constant.value.lval = is_method; - zend_stack_del_top(&CG(function_call_stack)); - opline->extended_value = argument_list->u.constant.value.lval; -} - - -void do_pass_param(znode *param, int op, int offset CLS_DC) -{ - zend_op *opline; - unsigned char *arg_types; - int original_op=op; - zend_function **function_ptr_ptr, *function_ptr; - - - zend_stack_top(&CG(function_call_stack), (void **) &function_ptr_ptr); - function_ptr = *function_ptr_ptr; - - if (original_op==ZEND_SEND_REF - && !CG(allow_call_time_pass_reference)) { - zend_error(E_COMPILE_WARNING, - "Call-time pass-by-reference has been deprecated - argument passed by value; " - "If you would like to pass it by reference, modify the declaration of %s(). " - "If you would like to enable call-time pass-by-reference, you can set" - "allow_call_time_pass_reference to true in your INI file. " - "However, future versions may not support this any longer.", - (function_ptr?function_ptr->common.function_name:"[runtime function name]"), - offset+1); - } - - if (function_ptr) { - arg_types = function_ptr->common.arg_types; - } else { - arg_types = NULL; - } - - if (op == ZEND_SEND_VAL) { - switch (param->op_type) { - case IS_CONST: /* constants behave like variables when passed to functions, - * as far as reference counting is concerned. Treat them - * as if they were variables here. - */ - case IS_VAR: - op = ZEND_SEND_VAR; - break; - } - } - - - if (ARG_SHOULD_BE_SENT_BY_REF(offset, 1, arg_types)) { - /* change to passing by reference */ - switch (param->op_type) { - case IS_VAR: - op = ZEND_SEND_REF; - break; - default: - zend_error(E_COMPILE_ERROR, "Only variables can be passed by reference"); - break; - } - } - - if (original_op==ZEND_SEND_VAR) { - switch(op) { - case ZEND_SEND_VAR: - if (function_ptr) { - do_end_variable_parse(BP_VAR_R, 0 CLS_CC); - } else { - do_end_variable_parse(BP_VAR_FUNC_ARG, offset CLS_CC); - } - break; - case ZEND_SEND_REF: - do_end_variable_parse(BP_VAR_W, 0 CLS_CC); - break; - } - } - - opline = get_next_op(CG(active_op_array) CLS_CC); - if (function_ptr) { - opline->extended_value = ZEND_DO_FCALL; - } else { - opline->extended_value = ZEND_DO_FCALL_BY_NAME; - } - opline->opcode = op; - opline->op1 = *param; - opline->op2.u.opline_num = offset; - SET_UNUSED(opline->op2); -} - - -static int generate_free_switch_expr(zend_switch_entry *switch_entry CLS_DC) -{ - zend_op *opline; - - if (switch_entry->cond.op_type == IS_UNUSED) { - return 1; - } - - opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_SWITCH_FREE; - opline->op1 = switch_entry->cond; - SET_UNUSED(opline->op2); - opline->extended_value = 0; - return 0; -} - -static int generate_free_foreach_copy(znode *foreach_copy CLS_DC) -{ - zend_op *opline; - - if (foreach_copy->op_type == IS_UNUSED) { - return 1; - } - - opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_SWITCH_FREE; - opline->op1 = *foreach_copy; - SET_UNUSED(opline->op2); - opline->extended_value = 1; - return 0; -} - -void do_return(znode *expr, int do_end_vparse CLS_DC) -{ - zend_op *opline; - - if (do_end_vparse) { - if (CG(active_op_array)->return_reference) { - do_end_variable_parse(BP_VAR_W, 0 CLS_CC); - } else { - do_end_variable_parse(BP_VAR_R, 0 CLS_CC); - } - } -#ifdef ZTS - zend_stack_apply_with_argument(&CG(switch_cond_stack), (int (*)(void *element, void *)) generate_free_switch_expr, ZEND_STACK_APPLY_TOPDOWN CLS_CC); - zend_stack_apply_with_argument(&CG(foreach_copy_stack), (int (*)(void *element, void *)) generate_free_foreach_copy, ZEND_STACK_APPLY_TOPDOWN CLS_CC); -#else - zend_stack_apply(&CG(switch_cond_stack), (int (*)(void *element)) generate_free_switch_expr, ZEND_STACK_APPLY_TOPDOWN); - zend_stack_apply(&CG(foreach_copy_stack), (int (*)(void *element)) generate_free_foreach_copy, ZEND_STACK_APPLY_TOPDOWN); -#endif - - opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_RETURN; - - if (expr) { - opline->op1 = *expr; - } else { - opline->op1.op_type = IS_CONST; - INIT_ZVAL(opline->op1.u.constant); - } - SET_UNUSED(opline->op2); -} - - -static void function_add_ref(zend_function *function) -{ - if (function->type == ZEND_USER_FUNCTION) { - zend_op_array *op_array = &function->op_array; - - (*op_array->refcount)++; - if (op_array->static_variables) { - HashTable *static_variables = op_array->static_variables; - zval *tmp_zval; - - ALLOC_HASHTABLE(op_array->static_variables); - zend_hash_init(op_array->static_variables, 2, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(op_array->static_variables, static_variables, (copy_ctor_func_t) zval_add_ref, (void *) &tmp_zval, sizeof(zval *)); - } - } -} - - -static void do_inherit_parent_constructor(zend_class_entry *ce) -{ - if (ce->parent - && !zend_hash_exists(&ce->function_table, ce->name, ce->name_length+1)) { - zend_function *function; - - if (zend_hash_find(&ce->parent->function_table, ce->parent->name, ce->parent->name_length+1, (void **) &function)==SUCCESS) { - /* inherit parent's constructor */ - zend_hash_update(&ce->function_table, ce->name, ce->name_length+1, function, sizeof(zend_function), NULL); - function_add_ref(function); - } - } -} - - -ZEND_API int do_bind_function_or_class(zend_op *opline, HashTable *function_table, HashTable *class_table, int compile_time) -{ - switch (opline->extended_value) { - case ZEND_DECLARE_FUNCTION: { - zend_function *function; - - zend_hash_find(function_table, opline->op1.u.constant.value.str.val, opline->op1.u.constant.value.str.len, (void *) &function); - if (zend_hash_add(function_table, opline->op2.u.constant.value.str.val, opline->op2.u.constant.value.str.len+1, function, sizeof(zend_function), NULL)==FAILURE) { - if (!compile_time) { - zend_error(E_ERROR, "Cannot redeclare %s()", opline->op2.u.constant.value.str.val); - } - return FAILURE; - } else { - (*function->op_array.refcount)++; - function->op_array.static_variables = NULL; /* NULL out the unbound function */ - return SUCCESS; - } - } - break; - case ZEND_DECLARE_CLASS: { - zend_class_entry *ce; - - zend_hash_find(class_table, opline->op1.u.constant.value.str.val, opline->op1.u.constant.value.str.len, (void **) &ce); - (*ce->refcount)++; - if (zend_hash_add(class_table, opline->op2.u.constant.value.str.val, opline->op2.u.constant.value.str.len+1, ce, sizeof(zend_class_entry), NULL)==FAILURE) { - (*ce->refcount)--; - if (!compile_time) { - zend_error(E_ERROR, "Cannot redeclare class %s", opline->op2.u.constant.value.str.val); - } - return FAILURE; - } else { - return SUCCESS; - } - } - break; - case ZEND_DECLARE_INHERITED_CLASS: { - zend_class_entry *ce, *parent_ce; - char *class_name, *parent_name; - zend_function tmp_zend_function; - zval *tmp; - - zend_hash_find(class_table, opline->op1.u.constant.value.str.val, opline->op1.u.constant.value.str.len, (void **) &ce); - (*ce->refcount)++; - - /* Restore base class / derived class names */ - parent_name = opline->op2.u.constant.value.str.val; - class_name = strchr(opline->op2.u.constant.value.str.val, ':'); - if (!class_name) { - zend_error(E_CORE_ERROR, "Invalid runtime class entry"); - } - *class_name++ = 0; - - /* Obtain parent class */ - if (zend_hash_find(class_table, parent_name, strlen(parent_name)+1, (void **) &parent_ce)==FAILURE) { - if (!compile_time) { - zend_error(E_ERROR, "Class %s: Cannot inherit from undefined class %s", class_name, parent_name); - } - (*ce->refcount)--; - *(class_name-1) = ':'; - return FAILURE; - } - - /* Perform inheritance */ - zend_hash_merge(&ce->default_properties, &parent_ce->default_properties, (void (*)(void *)) zval_add_ref, (void *) &tmp, sizeof(zval *), 0); - zend_hash_merge(&ce->function_table, &parent_ce->function_table, (void (*)(void *)) function_add_ref, &tmp_zend_function, sizeof(zend_function), 0); - ce->parent = parent_ce; - do_inherit_parent_constructor(ce); - - /* Register the derived class */ - if (zend_hash_add(class_table, class_name, strlen(class_name)+1, ce, sizeof(zend_class_entry), NULL)==FAILURE) { - if (!compile_time) { - zend_error(E_ERROR, "Cannot redeclare class %s", opline->op2.u.constant.value.str.val); - } - (*ce->refcount)--; - zend_hash_destroy(&ce->function_table); - zend_hash_destroy(&ce->default_properties); - return FAILURE; - } - return SUCCESS; - } - break; - } - return FAILURE; -} - - -void do_early_binding(CLS_D) -{ - zend_op *opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1]; - HashTable *table; - - if (do_bind_function_or_class(opline, CG(function_table), CG(class_table), 1)==FAILURE) { - return; - } - switch (opline->extended_value) { - case ZEND_DECLARE_FUNCTION: - table = CG(function_table); - break; - case ZEND_DECLARE_CLASS: - table = CG(class_table); - break; - default: - zend_error(E_COMPILE_ERROR, "Invalid binding type"); - return; - } - zend_hash_del(table, opline->op1.u.constant.value.str.val, opline->op1.u.constant.value.str.len); - zval_dtor(&opline->op1.u.constant); - zval_dtor(&opline->op2.u.constant); - opline->opcode = ZEND_NOP; - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); -} - - -void do_boolean_or_begin(znode *expr1, znode *op_token CLS_DC) -{ - int next_op_number = get_next_op_number(CG(active_op_array)); - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_JMPNZ_EX; - if (expr1->op_type == IS_TMP_VAR) { - opline->result = *expr1; - } else { - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->result.op_type = IS_TMP_VAR; - } - opline->op1 = *expr1; - SET_UNUSED(opline->op2); - - op_token->u.opline_num = next_op_number; - - *expr1 = opline->result; -} - - -void do_boolean_or_end(znode *result, znode *expr1, znode *expr2, znode *op_token CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - *result = *expr1; /* we saved the original result in expr1 */ - opline->opcode = ZEND_BOOL; - opline->result = *result; - opline->op1 = *expr2; - SET_UNUSED(opline->op2); - - CG(active_op_array)->opcodes[op_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array)); -} - - -void do_boolean_and_begin(znode *expr1, znode *op_token CLS_DC) -{ - int next_op_number = get_next_op_number(CG(active_op_array)); - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_JMPZ_EX; - if (expr1->op_type == IS_TMP_VAR) { - opline->result = *expr1; - } else { - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->result.op_type = IS_TMP_VAR; - } - opline->op1 = *expr1; - SET_UNUSED(opline->op2); - - op_token->u.opline_num = next_op_number; - - *expr1 = opline->result; -} - - -void do_boolean_and_end(znode *result, znode *expr1, znode *expr2, znode *op_token CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - *result = *expr1; /* we saved the original result in expr1 */ - opline->opcode = ZEND_BOOL; - opline->result = *result; - opline->op1 = *expr2; - SET_UNUSED(opline->op2); - - CG(active_op_array)->opcodes[op_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array)); -} - - -void do_do_while_begin(CLS_D) -{ - do_begin_loop(CLS_C); - INC_BPC(CG(active_op_array)); -} - - -void do_do_while_end(znode *do_token, znode *expr_open_bracket, znode *expr CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_JMPNZ; - opline->op1 = *expr; - opline->op2.u.opline_num = do_token->u.opline_num; - SET_UNUSED(opline->op2); - - do_end_loop(expr_open_bracket->u.opline_num CLS_CC); - - DEC_BPC(CG(active_op_array)); -} - - -void do_brk_cont(int op, znode *expr CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = op; - opline->op1.u.opline_num = CG(active_op_array)->current_brk_cont; - SET_UNUSED(opline->op1); - if (expr) { - opline->op2 = *expr; - } else { - opline->op2.u.constant.type = IS_LONG; - opline->op2.u.constant.value.lval = 1; - INIT_PZVAL(&opline->op2.u.constant); - opline->op2.op_type = IS_CONST; - } -} - - -void do_switch_cond(znode *cond CLS_DC) -{ - zend_switch_entry switch_entry; - - switch_entry.cond = *cond; - switch_entry.default_case = -1; - switch_entry.control_var = -1; - zend_stack_push(&CG(switch_cond_stack), (void *) &switch_entry, sizeof(switch_entry)); - - do_begin_loop(CLS_C); - - INC_BPC(CG(active_op_array)); -} - - - -void do_switch_end(znode *case_list CLS_DC) -{ - zend_op *opline; - zend_switch_entry *switch_entry_ptr; - - zend_stack_top(&CG(switch_cond_stack), (void **) &switch_entry_ptr); - - if (case_list->u.opline_num != -1) { /* empty switch */ - int next_op_number = get_next_op_number(CG(active_op_array)); - - CG(active_op_array)->opcodes[case_list->u.opline_num].op1.u.opline_num = next_op_number; - } - - /* add code to jmp to default case */ - if (switch_entry_ptr->default_case != -1) { - opline = get_next_op(CG(active_op_array) CLS_CC); - opline->opcode = ZEND_JMPZ; - opline->op1.op_type = IS_TMP_VAR; - opline->op1.u.var = switch_entry_ptr->control_var; - opline->op2.u.opline_num = switch_entry_ptr->default_case; - SET_UNUSED(opline->op2); - } - - - /* remember break/continue loop information */ - CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].cont = CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].brk = get_next_op_number(CG(active_op_array)); - CG(active_op_array)->current_brk_cont = CG(active_op_array)->brk_cont_array[CG(active_op_array)->current_brk_cont].parent; - - /* emit free for the switch condition*/ - opline = get_next_op(CG(active_op_array) CLS_CC); - opline->opcode = ZEND_SWITCH_FREE; - opline->op1 = switch_entry_ptr->cond; - SET_UNUSED(opline->op2); - if (switch_entry_ptr->cond.op_type == IS_CONST) { - zval_dtor(&switch_entry_ptr->cond.u.constant); - } - - zend_stack_del_top(&CG(switch_cond_stack)); - - DEC_BPC(CG(active_op_array)); -} - - -void do_case_before_statement(znode *case_list, znode *case_token, znode *case_expr CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - int next_op_number; - zend_switch_entry *switch_entry_ptr; - znode result; - - zend_stack_top(&CG(switch_cond_stack), (void **) &switch_entry_ptr); - - opline->opcode = ZEND_CASE; - if (switch_entry_ptr->control_var==-1) { - switch_entry_ptr->control_var = get_temporary_variable(CG(active_op_array)); - } - opline->result.u.var = switch_entry_ptr->control_var; - opline->result.op_type = IS_TMP_VAR; - opline->op1 = switch_entry_ptr->cond; - opline->op2 = *case_expr; - if (opline->op1.op_type == IS_CONST) { - zval_copy_ctor(&opline->op1.u.constant); - } - result = opline->result; - - next_op_number = get_next_op_number(CG(active_op_array)); - opline = get_next_op(CG(active_op_array) CLS_CC); - opline->opcode = ZEND_JMPZ; - opline->op1 = result; - SET_UNUSED(opline->op2); - case_token->u.opline_num = next_op_number; - - if (case_list->u.opline_num==-1) { - return; - } - next_op_number = get_next_op_number(CG(active_op_array)); - CG(active_op_array)->opcodes[case_list->u.opline_num].op1.u.opline_num = next_op_number; -} - - -void do_case_after_statement(znode *result, znode *case_token CLS_DC) -{ - int next_op_number = get_next_op_number(CG(active_op_array)); - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_JMP; - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); - result->u.opline_num = next_op_number; - - switch (CG(active_op_array)->opcodes[case_token->u.opline_num].opcode) { - case ZEND_JMP: - CG(active_op_array)->opcodes[case_token->u.opline_num].op1.u.opline_num = get_next_op_number(CG(active_op_array)); - break; - case ZEND_JMPZ: - CG(active_op_array)->opcodes[case_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array)); - break; - } -} - - - -void do_default_before_statement(znode *case_list, znode *default_token CLS_DC) -{ - int next_op_number = get_next_op_number(CG(active_op_array)); - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - zend_switch_entry *switch_entry_ptr; - - zend_stack_top(&CG(switch_cond_stack), (void **) &switch_entry_ptr); - - opline->opcode = ZEND_JMP; - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); - default_token->u.opline_num = next_op_number; - - next_op_number = get_next_op_number(CG(active_op_array)); - opline = get_next_op(CG(active_op_array) CLS_CC); - opline->opcode = ZEND_BOOL; - if (switch_entry_ptr->control_var==-1) { - switch_entry_ptr->control_var = get_temporary_variable(CG(active_op_array)); - } - opline->result.u.var = switch_entry_ptr->control_var; - opline->result.op_type = IS_TMP_VAR; - opline->op1.op_type = IS_CONST; - opline->op1.u.constant.type = IS_LONG; - opline->op1.u.constant.value.lval = 1; - INIT_PZVAL(&opline->op1.u.constant); - SET_UNUSED(opline->op2); - switch_entry_ptr->default_case = next_op_number; - - next_op_number = get_next_op_number(CG(active_op_array)); - if (case_list->u.opline_num==-1) { - return; - } - CG(active_op_array)->opcodes[case_list->u.opline_num].op1.u.opline_num = next_op_number; -} - - -void do_begin_class_declaration(znode *class_name, znode *parent_class_name CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - int runtime_inheritance = 0; - - if (CG(active_class_entry)) { - zend_error(E_COMPILE_ERROR, "Class declarations may not be nested"); - return; - } - CG(class_entry).type = ZEND_USER_CLASS; - CG(class_entry).name = class_name->u.constant.value.str.val; - CG(class_entry).name_length = class_name->u.constant.value.str.len; - CG(class_entry).refcount = (int *) emalloc(sizeof(int)); - *CG(class_entry).refcount = 1; - CG(class_entry).constants_updated = 0; - - zend_str_tolower(CG(class_entry).name, CG(class_entry).name_length); - - zend_hash_init(&CG(class_entry).function_table, 10, NULL, ZEND_FUNCTION_DTOR, 0); - zend_hash_init(&CG(class_entry).default_properties, 10, NULL, ZVAL_PTR_DTOR, 0); - - /* code for inheritance from parent class */ - if (parent_class_name) { - zend_class_entry *parent_class; - zend_function tmp_zend_function; - zval *tmp; - - zend_str_tolower(parent_class_name->u.constant.value.str.val, parent_class_name->u.constant.value.str.len); - - if (zend_hash_find(CG(class_table), parent_class_name->u.constant.value.str.val, parent_class_name->u.constant.value.str.len+1, (void **) &parent_class)==SUCCESS) { - /* copy functions */ - zend_hash_copy(&CG(class_entry).function_table, &parent_class->function_table, (copy_ctor_func_t) function_add_ref, &tmp_zend_function, sizeof(zend_function)); - - /* copy default properties */ - zend_hash_copy(&CG(class_entry).default_properties, &parent_class->default_properties, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - - CG(class_entry).parent = parent_class; - - zval_dtor(&parent_class_name->u.constant); - } else { - runtime_inheritance = 1; - CG(class_entry).parent = NULL; - } - } else { - CG(class_entry).parent = NULL; - } - - CG(class_entry).handle_function_call = NULL; - CG(class_entry).handle_property_set = NULL; - CG(class_entry).handle_property_get = NULL; - - opline->opcode = ZEND_DECLARE_FUNCTION_OR_CLASS; - opline->op1.op_type = IS_CONST; - build_runtime_defined_function_key(&opline->op1.u.constant, &class_name->u.constant, opline); - opline->op2.op_type = IS_CONST; - opline->op2.u.constant.type = IS_STRING; - opline->op2.u.constant.refcount = 1; - if (runtime_inheritance) { - char *full_class_name; - - opline->op2.u.constant.value.str.len = parent_class_name->u.constant.value.str.len+1+CG(class_entry).name_length; - full_class_name = opline->op2.u.constant.value.str.val = (char *) emalloc(opline->op2.u.constant.value.str.len+1); - - memcpy(full_class_name, parent_class_name->u.constant.value.str.val, parent_class_name->u.constant.value.str.len); - full_class_name += parent_class_name->u.constant.value.str.len; - full_class_name[0] = ':'; - full_class_name++; - memcpy(full_class_name, CG(class_entry).name, CG(class_entry).name_length); - zval_dtor(&parent_class_name->u.constant); - full_class_name += CG(class_entry).name_length; - full_class_name[0] = 0; - opline->extended_value = ZEND_DECLARE_INHERITED_CLASS; - } else { - opline->op2.u.constant.value.str.val = estrndup(CG(class_entry).name, CG(class_entry).name_length); - opline->op2.u.constant.value.str.len = CG(class_entry).name_length; - opline->extended_value = ZEND_DECLARE_CLASS; - } - - zend_hash_update(CG(class_table), opline->op1.u.constant.value.str.val, opline->op1.u.constant.value.str.len, &CG(class_entry), sizeof(zend_class_entry), (void **) &CG(active_class_entry)); -} - - -void do_end_class_declaration(CLS_D) -{ - do_inherit_parent_constructor(CG(active_class_entry)); - CG(active_class_entry) = NULL; -} - - -void do_declare_property(znode *var_name, znode *value CLS_DC) -{ - if (value) { - zval *property; - - ALLOC_ZVAL(property); - - *property = value->u.constant; - zend_hash_update(&CG(active_class_entry)->default_properties, var_name->u.constant.value.str.val, var_name->u.constant.value.str.len+1, &property, sizeof(zval *), NULL); - } - FREE_PNODE(var_name); -} - - -void do_fetch_property(znode *result, znode *object, znode *property CLS_DC) -{ - zend_op opline; - zend_llist *fetch_list_ptr; - - init_op(&opline CLS_CC); - opline.opcode = ZEND_FETCH_OBJ_W; /* the backpatching routine assumes W */ - opline.result.op_type = IS_VAR; - opline.result.u.EA.type = 0; - opline.result.u.var = get_temporary_variable(CG(active_op_array)); - opline.op1 = *object; - opline.op2 = *property; - *result = opline.result; - - zend_stack_top(&CG(bp_stack), (void **) &fetch_list_ptr); - zend_llist_add_element(fetch_list_ptr, &opline); -} - - -void do_push_object(znode *object CLS_DC) -{ - zend_stack_push(&CG(object_stack), object, sizeof(znode)); -} - - -void do_pop_object(znode *object CLS_DC) -{ - znode *tmp; - - zend_stack_top(&CG(object_stack), (void **) &tmp); - *object = *tmp; - zend_stack_del_top(&CG(object_stack)); -} - - -void do_begin_new_object(znode *new_token, znode *class_name CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - unsigned char *ptr = NULL; - - opline->opcode = ZEND_NEW; - opline->result.op_type = IS_TMP_VAR; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->op1 = *class_name; - SET_UNUSED(opline->op2); - - /* *result = opline->result; - do_assign(result, variable, &opline->result CLS_CC); */ - - - new_token->u.opline_num = get_next_op_number(CG(active_op_array)); - opline = get_next_op(CG(active_op_array) CLS_CC); - opline->opcode = ZEND_JMP_NO_CTOR; - opline->op1 = (opline-1)->result; - SET_UNUSED(opline->op2); - - if (class_name->op_type == IS_CONST) { - zval_copy_ctor(&class_name->u.constant); - } - opline = get_next_op(CG(active_op_array) CLS_CC); - opline->opcode = ZEND_INIT_FCALL_BY_NAME; - opline->op1 = (opline-2)->result; - opline->op2 = *class_name; - opline->extended_value = ZEND_MEMBER_FUNC_CALL | ZEND_CTOR_CALL; - zend_stack_push(&CG(function_call_stack), (void *) &ptr, sizeof(unsigned char *)); -} - - -void do_end_new_object(znode *result, znode *class_name, znode *new_token, znode *argument_list CLS_DC) -{ - znode ctor_result; - - if (class_name->op_type == IS_CONST) { - zval_copy_ctor(&class_name->u.constant); - } - do_end_function_call(class_name, &ctor_result, argument_list, 1, 0 CLS_CC); - do_free(&ctor_result CLS_CC); - - CG(active_op_array)->opcodes[new_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array)); - *result = CG(active_op_array)->opcodes[new_token->u.opline_num].op1; -} - - -void do_fetch_constant(znode *result, znode *constant_name, int mode CLS_DC) -{ - switch (mode) { - case ZEND_CT: - *result = *constant_name; - result->u.constant.type = IS_CONSTANT; - break; - case ZEND_RT: { - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_FETCH_CONSTANT; - opline->result.op_type = IS_TMP_VAR; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->op1 = *constant_name; - *result = opline->result; - SET_UNUSED(opline->op2); - } - break; - } -} - - -void do_shell_exec(znode *result, znode *cmd CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - switch (cmd->op_type) { - case IS_TMP_VAR: - opline->opcode = ZEND_SEND_VAL; - break; - default: - opline->opcode = ZEND_SEND_VAR; - break; - } - opline->op1 = *cmd; - opline->op2.u.opline_num = 0; - opline->extended_value = ZEND_DO_FCALL; - SET_UNUSED(opline->op2); - - opline = get_next_op(CG(active_op_array) CLS_CC); - opline->opcode = ZEND_DO_FCALL; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->result.op_type = IS_VAR; - opline->op1.u.constant.value.str.val = estrndup("shell_exec",sizeof("shell_exec")-1); - opline->op1.u.constant.value.str.len = sizeof("shell_exec")-1; - INIT_PZVAL(&opline->op1.u.constant); - opline->op1.u.constant.type = IS_STRING; - opline->op1.op_type = IS_CONST; - opline->extended_value = 1; - SET_UNUSED(opline->op2); - *result = opline->result; -} - - - -void do_init_array(znode *result, znode *expr, znode *offset, int is_ref CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_INIT_ARRAY; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->result.op_type = IS_TMP_VAR; - *result = opline->result; - if (expr) { - opline->op1 = *expr; - if (offset) { - opline->op2 = *offset; - } else { - SET_UNUSED(opline->op2); - } - } else { - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); - } - opline->extended_value = is_ref; -} - - -void do_add_array_element(znode *result, znode *expr, znode *offset, int is_ref CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_ADD_ARRAY_ELEMENT; - opline->result = *result; - opline->op1 = *expr; - if (offset) { - opline->op2 = *offset; - } else { - SET_UNUSED(opline->op2); - } - opline->extended_value = is_ref; -} - - - -void do_add_static_array_element(znode *result, znode *offset, znode *expr) -{ - zval *element; - - ALLOC_ZVAL(element); - *element = expr->u.constant; - if (offset) { - switch (offset->u.constant.type) { - case IS_STRING: - zend_hash_update(result->u.constant.value.ht, offset->u.constant.value.str.val, offset->u.constant.value.str.len+1, &element, sizeof(zval *), NULL); - zval_dtor(&offset->u.constant); - break; - case IS_LONG: - zend_hash_index_update(result->u.constant.value.ht, offset->u.constant.value.lval, &element, sizeof(zval *), NULL); - break; - } - } else { - zend_hash_next_index_insert(result->u.constant.value.ht, &element, sizeof(zval *), NULL); - } -} - - -void do_add_list_element(znode *element CLS_DC) -{ - list_llist_element lle; - - if (element) { - lle.var = *element; - zend_llist_copy(&lle.dimensions, &CG(dimension_llist)); - zend_llist_prepend_element(&CG(list_llist), &lle); - } - (*((int *)CG(dimension_llist).tail->data))++; -} - - -void do_new_list_begin(CLS_D) -{ - int current_dimension = 0; - zend_llist_add_element(&CG(dimension_llist), ¤t_dimension); -} - - -void do_new_list_end(CLS_D) -{ - zend_llist_remove_tail(&CG(dimension_llist)); - (*((int *)CG(dimension_llist).tail->data))++; -} - - -void do_list_init(CLS_D) -{ - zend_llist_init(&CG(list_llist), sizeof(list_llist_element), NULL, 0); - zend_llist_init(&CG(dimension_llist), sizeof(int), NULL, 0); - do_new_list_begin(CLS_C); -} - - -void do_list_end(znode *result, znode *expr CLS_DC) -{ - zend_llist_element *le; - zend_llist_element *dimension; - zend_op *opline; - znode last_container; - - le = CG(list_llist).head; - while (le) { - zend_llist *tmp_dimension_llist = &((list_llist_element *)le->data)->dimensions; - dimension = tmp_dimension_llist->head; - while (dimension) { - opline = get_next_op(CG(active_op_array) CLS_CC); - if (dimension == tmp_dimension_llist->head) { /* first */ - last_container = *expr; - switch(expr->op_type) { - case IS_VAR: - opline->opcode = ZEND_FETCH_DIM_R; - break; - case IS_TMP_VAR: - case IS_CONST: /* fetch_dim_tmp_var will handle this bogus fetch */ - opline->opcode = ZEND_FETCH_DIM_TMP_VAR; - break; - } - } else { - opline->opcode = ZEND_FETCH_DIM_R; - } - opline->result.op_type = IS_VAR; - opline->result.u.EA.type = 0; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->op1 = last_container; - opline->op2.op_type = IS_CONST; - opline->op2.u.constant.type = IS_LONG; - opline->op2.u.constant.value.lval = *((int *) dimension->data); - INIT_PZVAL(&opline->op2.u.constant); - opline->extended_value = ZEND_FETCH_ADD_LOCK; - last_container = opline->result; - dimension = dimension->next; - } - ((list_llist_element *) le->data)->value = last_container; - zend_llist_destroy(&((list_llist_element *) le->data)->dimensions); - do_end_variable_parse(BP_VAR_W, 0 CLS_CC); - do_assign(result, &((list_llist_element *) le->data)->var, &((list_llist_element *) le->data)->value CLS_CC); - CG(active_op_array)->opcodes[CG(active_op_array)->last-1].result.u.EA.type |= EXT_TYPE_UNUSED; - le = le->next; - } - zend_llist_destroy(&CG(dimension_llist)); - zend_llist_destroy(&CG(list_llist)); - *result = *expr; -} - - -void do_fetch_global_or_static_variable(znode *varname, znode *static_assignment, int fetch_type CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - znode lval; - - if (fetch_type==ZEND_FETCH_STATIC && static_assignment) { - zval *tmp; - - ALLOC_ZVAL(tmp); - convert_to_string(&varname->u.constant); - *tmp = static_assignment->u.constant; - if (!CG(active_op_array)->static_variables) { - ALLOC_HASHTABLE(CG(active_op_array)->static_variables); - zend_hash_init(CG(active_op_array)->static_variables, 2, NULL, ZVAL_PTR_DTOR, 0); - } - zend_hash_update_ptr(CG(active_op_array)->static_variables, varname->u.constant.value.str.val, varname->u.constant.value.str.len+1, tmp, sizeof(zval *), NULL); - } - - - opline->opcode = ZEND_FETCH_W; /* the default mode must be Write, since fetch_simple_variable() is used to define function arguments */ - opline->result.op_type = IS_VAR; - opline->result.u.EA.type = 0; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->op1 = *varname; - SET_UNUSED(opline->op2); - opline->op2.u.fetch_type = fetch_type; - - if (varname->op_type == IS_CONST) { - zval_copy_ctor(&varname->u.constant); - } - fetch_simple_variable(&lval, varname, 0 CLS_CC); /* Relies on the fact that the default fetch is BP_VAR_W */ - - - do_assign_ref(NULL, &lval, &opline->result CLS_CC); - CG(active_op_array)->opcodes[CG(active_op_array)->last-1].result.u.EA.type |= EXT_TYPE_UNUSED; -} - - -void do_cast(znode *result, znode *expr, int type CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_CAST; - opline->result.op_type = IS_TMP_VAR; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->op1 = *expr; - SET_UNUSED(opline->op2); - opline->op2.u.constant.type = type; - *result = opline->result; -} - - -void do_include_or_eval(int type, znode *result, znode *op1 CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_INCLUDE_OR_EVAL; - opline->result.op_type = IS_VAR; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->op1 = *op1; - SET_UNUSED(opline->op2); - opline->op2.u.constant.value.lval = type; - *result = opline->result; - if (type==ZEND_REQUIRE) { - opline->result.u.EA.type |= EXT_TYPE_UNUSED; - } -} - - -void do_require(znode *filename CLS_DC) -{ - if (filename->op_type==IS_CONST - && filename->u.constant.type==IS_STRING) { - require_filename(filename->u.constant.value.str.val CLS_CC); - zval_dtor(&filename->u.constant); - } else { - znode result; - - do_include_or_eval(ZEND_REQUIRE, &result, filename CLS_CC); - } -} - - -void do_indirect_references(znode *result, znode *num_references, znode *variable CLS_DC) -{ - int i; - - do_end_variable_parse(BP_VAR_R, 0 CLS_CC); - for (i=1; iu.constant.value.lval; i++) { - fetch_simple_variable_ex(result, variable, 0, ZEND_FETCH_R CLS_CC); - *variable = *result; - } - do_begin_variable_parse(CLS_C); - fetch_simple_variable(result, variable, 1 CLS_CC); -} - - -void do_unset(znode *variable CLS_DC) -{ - zend_op *last_op; - - last_op = &CG(active_op_array)->opcodes[get_next_op_number(CG(active_op_array))-1]; - - switch (last_op->opcode) { - case ZEND_FETCH_UNSET: - last_op->opcode = ZEND_UNSET_VAR; - break; - case ZEND_FETCH_DIM_UNSET: - case ZEND_FETCH_OBJ_UNSET: - last_op->opcode = ZEND_UNSET_DIM_OBJ; - break; - - } -} - - -void do_isset_or_isempty(int type, znode *result, znode *variable CLS_DC) -{ - zend_op *opline; - - do_end_variable_parse(BP_VAR_IS, 0 CLS_CC); - opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_ISSET_ISEMPTY; - opline->result.op_type = IS_TMP_VAR; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->op1 = *variable; - opline->op2.u.constant.value.lval = type; - SET_UNUSED(opline->op2); - *result = opline->result; -} - - -void do_foreach_begin(znode *foreach_token, znode *array, znode *open_brackets_token, znode *as_token CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - /* Preform array reset */ - opline->opcode = ZEND_FE_RESET; - opline->result.op_type = IS_VAR; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->op1 = *array; - SET_UNUSED(opline->op2); - *open_brackets_token = opline->result; - - zend_stack_push(&CG(foreach_copy_stack), (void *) &opline->result, sizeof(znode)); - - /* save the location of the beginning of the loop (array fetching) */ - foreach_token->u.opline_num = get_next_op_number(CG(active_op_array)); - - opline = get_next_op(CG(active_op_array) CLS_CC); - opline->opcode = ZEND_FE_FETCH; - opline->result.op_type = IS_TMP_VAR; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->op1 = *open_brackets_token; - SET_UNUSED(opline->op2); - *as_token = opline->result; -} - - -void do_foreach_cont(znode *value, znode *key, znode *as_token CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - znode result_value, result_key, dummy; - - if (key->op_type != IS_UNUSED) { - znode *tmp; - - /* switch between the key and value... */ - tmp = key; - key = value; - value = tmp; - } - - opline->opcode = ZEND_FETCH_DIM_TMP_VAR; - opline->result.op_type = IS_VAR; - opline->result.u.EA.type = 0; - opline->result.u.opline_num = get_temporary_variable(CG(active_op_array)); - opline->op1 = *as_token; - opline->op2.op_type = IS_CONST; - opline->op2.u.constant.type = IS_LONG; - opline->op2.u.constant.value.lval = 0; - opline->extended_value = ZEND_FETCH_STANDARD; /* ignored in fetch_dim_tmp_var, but what the hell. */ - result_value = opline->result; - - if (key->op_type != IS_UNUSED) { - opline = get_next_op(CG(active_op_array) CLS_CC); - opline->opcode = ZEND_FETCH_DIM_TMP_VAR; - opline->result.op_type = IS_VAR; - opline->result.u.EA.type = 0; - opline->result.u.opline_num = get_temporary_variable(CG(active_op_array)); - opline->op1 = *as_token; - opline->op2.op_type = IS_CONST; - opline->op2.u.constant.type = IS_LONG; - opline->op2.u.constant.value.lval = 1; - opline->extended_value = ZEND_FETCH_STANDARD; /* ignored in fetch_dim_tmp_var, but what the hell. */ - result_key = opline->result; - } - - do_assign(&dummy, value, &result_value CLS_CC); - CG(active_op_array)->opcodes[CG(active_op_array)->last-1].result.u.EA.type |= EXT_TYPE_UNUSED; - if (key->op_type != IS_UNUSED) { - do_assign(&dummy, key, &result_key CLS_CC); - CG(active_op_array)->opcodes[CG(active_op_array)->last-1].result.u.EA.type |= EXT_TYPE_UNUSED; - } - do_free(as_token CLS_CC); - - do_begin_loop(CLS_C); - INC_BPC(CG(active_op_array)); -} - - -void do_foreach_end(znode *foreach_token, znode *open_brackets_token CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_JMP; - opline->op1.u.opline_num = foreach_token->u.opline_num; - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); - - CG(active_op_array)->opcodes[foreach_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array)); - - do_end_loop(foreach_token->u.opline_num CLS_CC); - - generate_free_foreach_copy(open_brackets_token CLS_CC); - - zend_stack_del_top(&CG(foreach_copy_stack)); - - DEC_BPC(CG(active_op_array)); -} - - -void do_declare_begin(CLS_D) -{ - zend_stack_push(&CG(declare_stack), &CG(declarables), sizeof(zend_declarables)); -} - - -void do_declare_stmt(znode *var, znode *val CLS_DC) -{ - convert_to_string(&var->u.constant); - - if (!zend_binary_strcasecmp(var->u.constant.value.str.val, var->u.constant.value.str.len, "ticks", sizeof("ticks")-1)) { - convert_to_long(&val->u.constant); - CG(declarables).ticks = val->u.constant; - } - zval_dtor(&var->u.constant); -} - - -void do_declare_end(CLS_D) -{ - zend_declarables *declarables; - - zend_stack_top(&CG(declare_stack), (void **) &declarables); - CG(declarables) = *declarables; -} - - -void do_end_heredoc(CLS_D) -{ - int opline_num = get_next_op_number(CG(active_op_array))-1; - zend_op *opline = &CG(active_op_array)->opcodes[opline_num]; - - if (opline->opcode != ZEND_ADD_STRING) { - return; - } - - opline->op2.u.constant.value.str.val[(opline->op2.u.constant.value.str.len--)-1] = 0; - if (opline->op2.u.constant.value.str.len>0) { - if (opline->op2.u.constant.value.str.val[opline->op2.u.constant.value.str.len-1]=='\r') { - opline->op2.u.constant.value.str.val[(opline->op2.u.constant.value.str.len--)-1] = 0; - } - } -} - - -void do_exit(znode *result, znode *message CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_EXIT; - opline->op1 = *message; - SET_UNUSED(opline->op2); - - result->op_type = IS_CONST; - result->u.constant.type = IS_BOOL; - result->u.constant.value.lval = 1; -} - - -void do_begin_silence(znode *strudel_token CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_BEGIN_SILENCE; - opline->result.op_type = IS_TMP_VAR; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); - *strudel_token = opline->result; -} - - -void do_end_silence(znode *strudel_token CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_END_SILENCE; - opline->op1 = *strudel_token; - SET_UNUSED(opline->op2); -} - - -void do_begin_qm_op(znode *cond, znode *qm_token CLS_DC) -{ - int jmpz_op_number = get_next_op_number(CG(active_op_array)); - zend_op *opline; - - opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_JMPZ; - opline->op1 = *cond; - SET_UNUSED(opline->op2); - opline->op2.u.opline_num = jmpz_op_number; - *qm_token = opline->op2; - - INC_BPC(CG(active_op_array)); -} - - -void do_qm_true(znode *true_value, znode *qm_token, znode *colon_token CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - CG(active_op_array)->opcodes[qm_token->u.opline_num].op2.u.opline_num = get_next_op_number(CG(active_op_array))+1; /* jmp over the ZEND_JMP */ - - opline->opcode = ZEND_QM_ASSIGN; - opline->result.op_type = IS_TMP_VAR; - opline->result.u.var = get_temporary_variable(CG(active_op_array)); - opline->op1 = *true_value; - SET_UNUSED(opline->op2); - - *qm_token = opline->result; - colon_token->u.opline_num = get_next_op_number(CG(active_op_array)); - - opline = get_next_op(CG(active_op_array) CLS_CC); - opline->opcode = ZEND_JMP; - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); -} - - -void do_qm_false(znode *result, znode *false_value, znode *qm_token, znode *colon_token CLS_DC) -{ - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_QM_ASSIGN; - opline->result = *qm_token; - opline->op1 = *false_value; - SET_UNUSED(opline->op2); - - CG(active_op_array)->opcodes[colon_token->u.opline_num].op1.u.opline_num = get_next_op_number(CG(active_op_array)); - - *result = opline->result; - - DEC_BPC(CG(active_op_array)); -} - - -void do_extended_info(CLS_D) -{ - zend_op *opline; - - if (!CG(extended_info)) { - return; - } - - opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_EXT_STMT; - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); -} - - -void do_extended_fcall_begin(CLS_D) -{ - zend_op *opline; - - if (!CG(extended_info)) { - return; - } - - opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_EXT_FCALL_BEGIN; - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); -} - - -void do_extended_fcall_end(CLS_D) -{ - zend_op *opline; - - if (!CG(extended_info)) { - return; - } - - opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_EXT_FCALL_END; - SET_UNUSED(opline->op1); - SET_UNUSED(opline->op2); -} - -void do_ticks(CLS_D) -{ - if (CG(declarables).ticks.value.lval) { - zend_op *opline = get_next_op(CG(active_op_array) CLS_CC); - - opline->opcode = ZEND_TICKS; - opline->op1.u.constant = CG(declarables).ticks; - opline->op1.op_type = IS_CONST; - SET_UNUSED(opline->op2); - } -} - - -int zendlex(znode *zendlval CLS_DC) -{ - int retval; - - zendlval->u.constant.type = IS_LONG; - retval = lex_scan(&zendlval->u.constant CLS_CC); - switch(retval) { - case T_COMMENT: - case T_OPEN_TAG: - case T_WHITESPACE: - case T_PHP_TRACK_VARS: - retval = zendlex(zendlval CLS_CC); - break; - case T_CLOSE_TAG: - retval = ';'; /* implicit ; */ - break; - case T_OPEN_TAG_WITH_ECHO: - retval = T_ECHO; - break; - case T_END_HEREDOC: - efree(zendlval->u.constant.value.str.val); - break; - } - - INIT_PZVAL(&zendlval->u.constant); - zendlval->op_type = IS_CONST; - return retval; -} diff --git a/Zend/zend_compile.h b/Zend/zend_compile.h deleted file mode 100644 index f5cc994cd1..0000000000 --- a/Zend/zend_compile.h +++ /dev/null @@ -1,610 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _COMPILE_H -#define _COMPILE_H - -#include "zend.h" - -#ifdef HAVE_STDARG_H -# include -#endif - -#include "zend_llist.h" - -#define DEBUG_ZEND 0 - -#ifndef ZTS -# define SUPPORT_INTERACTIVE 1 -#else -# define SUPPORT_INTERACTIVE 0 -#endif - -#define FREE_PNODE(znode) zval_dtor(&znode->u.constant); -#define FREE_OP(op, should_free) if (should_free) zval_dtor(&Ts[(op)->u.var].tmp_var); - - -#if SUPPORT_INTERACTIVE -#define INC_BPC(op_array) ((op_array)->backpatch_count++) -#define DEC_BPC(op_array) ((op_array)->backpatch_count--) -#define HANDLE_INTERACTIVE() if (EG(interactive)) { execute_new_code(CLS_C); } -#else -#define INC_BPC(op_array) -#define DEC_BPC(op_array) -#define HANDLE_INTERACTIVE() -#endif - -typedef struct _zend_op_array zend_op_array; - -typedef struct _znode { - int op_type; - union { - zval constant; - - int var; - int opline_num; - int fetch_type; - zend_op_array *op_array; - struct { - int var; /* dummy */ - int type; - } EA; - } u; -} znode; - - -typedef struct _zend_op { - int opcode; - znode result; - znode op1; - znode op2; - ulong extended_value; - char *filename; - uint lineno; -} zend_op; - - -typedef struct _zend_brk_cont_element { - int cont; - int brk; - int parent; -} zend_brk_cont_element; - - -struct _zend_op_array { - int type; /* MUST be the first element of this struct! */ - - unsigned char *arg_types; /* MUST be the second element of this struct! */ - char *function_name; /* MUST be the third element of this struct! */ - - int *refcount; - - zend_op *opcodes; - int last, size; - - int T; - - - zend_brk_cont_element *brk_cont_array; - int last_brk_cont; - int current_brk_cont; - unsigned char uses_globals; - - /* static variables support */ - HashTable *static_variables; - -#if SUPPORT_INTERACTIVE - int start_op_number, end_op_number; - int last_executed_op_number; - int backpatch_count; -#endif - zend_bool return_reference; - - void *reserved[ZEND_MAX_RESERVED_RESOURCES]; -}; - - -typedef struct _zend_internal_function { - int type; /* MUST be the first element of this struct! */ - - unsigned char *arg_types; /* MUST be the second element of this struct */ - char *function_name; /* MUST be the third element of this struct */ - - void (*handler)(INTERNAL_FUNCTION_PARAMETERS); -} zend_internal_function; - - -typedef union _zend_function { - int type; /* MUST be the first element of this struct! */ - struct { - int type; /* never used */ - unsigned char *arg_types; - char *function_name; - } common; - - zend_op_array op_array; - zend_internal_function internal_function; -} zend_function; - - -typedef struct _zend_function_state { - HashTable *function_symbol_table; - zend_function *function; - void *reserved[ZEND_MAX_RESERVED_RESOURCES]; -} zend_function_state; - - -typedef struct _zend_switch_entry { - znode cond; - int default_case; - int control_var; -} zend_switch_entry; - - -typedef struct _list_llist_element { - znode var; - zend_llist dimensions; - znode value; -} list_llist_element; - - -typedef struct _zend_file_handle { - int type; - char *filename; - char *opened_path; - union { - int fd; - FILE *fp; -#ifdef __cplusplus - istream *is; -#endif - } handle; - zend_bool free_filename; -} zend_file_handle; - - -#include "zend_globals.h" - -#define IS_CONST (1<<0) -#define IS_TMP_VAR (1<<1) -#define IS_VAR (1<<2) -#define IS_UNUSED (1<<3) /* Unused variable */ - - -#define EXT_TYPE_UNUSED (1<<0) - -BEGIN_EXTERN_C() - -void init_compiler(CLS_D ELS_DC); -void shutdown_compiler(CLS_D); - -extern ZEND_API zend_op_array *(*zend_compile_files)(int mark_as_ref CLS_DC, int file_count, ...); - -void zend_activate(CLS_D ELS_DC); -void zend_deactivate(CLS_D ELS_DC); -void zend_activate_modules(); - - -int lex_scan(zval *zendlval CLS_DC); -void startup_scanner(CLS_D); -void shutdown_scanner(CLS_D); - -ZEND_API char *zend_set_compiled_filename(char *new_compiled_filename); -ZEND_API void zend_restore_compiled_filename(char *original_compiled_filename); -ZEND_API char *zend_get_compiled_filename(CLS_D); -ZEND_API int zend_get_compiled_lineno(CLS_D); - -#ifdef ZTS -const char *zend_get_zendtext(CLS_D); -int zend_get_zendleng(CLS_D); -#endif - - -/* parser-driven code generators */ -void do_binary_op(int op, znode *result, znode *op1, znode *op2 CLS_DC); -void do_unary_op(int op, znode *result, znode *op1 CLS_DC); -void do_binary_assign_op(int op, znode *result, znode *op1, znode *op2 CLS_DC); -void do_assign(znode *result, znode *variable, znode *value CLS_DC); -void do_assign_ref(znode *result, znode *lvar, znode *rvar CLS_DC); -void fetch_simple_variable(znode *result, znode *varname, int bp CLS_DC); -void fetch_simple_variable_ex(znode *result, znode *varname, int bp, int op CLS_DC); -void do_indirect_references(znode *result, znode *num_references, znode *variable CLS_DC); -void do_fetch_global_or_static_variable(znode *varname, znode *static_assignment, int fetch_type CLS_DC); -void do_fetch_globals(znode *varname CLS_DC); - -void fetch_array_begin(znode *result, znode *varname, znode *first_dim CLS_DC); -void fetch_array_dim(znode *result, znode *parent, znode *dim CLS_DC); -void fetch_string_offset(znode *result, znode *parent, znode *offset CLS_DC); -void do_print(znode *result, znode *arg CLS_DC); -void do_echo(znode *arg CLS_DC); -typedef int (*unary_op_type)(zval *, zval *); -ZEND_API unary_op_type get_unary_op(int opcode); -ZEND_API void *get_binary_op(int opcode); - -void do_while_cond(znode *expr, znode *close_bracket_token CLS_DC); -void do_while_end(znode *while_token, znode *close_bracket_token CLS_DC); -void do_do_while_begin(CLS_D); -void do_do_while_end(znode *do_token, znode *expr_open_bracket, znode *expr CLS_DC); - - -void do_if_cond(znode *cond, znode *closing_bracket_token CLS_DC); -void do_if_after_statement(znode *closing_bracket_token, unsigned char initialize CLS_DC); -void do_if_end(CLS_D); - -void do_for_cond(znode *expr, znode *second_semicolon_token CLS_DC); -void do_for_before_statement(znode *cond_start, znode *second_semicolon_token CLS_DC); -void do_for_end(znode *second_semicolon_token CLS_DC); - -void do_pre_incdec(znode *result, znode *op1, int op CLS_DC); -void do_post_incdec(znode *result, znode *op1, int op CLS_DC); - -void do_begin_variable_parse(CLS_D); -void do_end_variable_parse(int type, int arg_offset CLS_DC); - -void do_free(znode *op1 CLS_DC); - -void do_init_string(znode *result CLS_DC); -void do_add_char(znode *result, znode *op1, znode *op2 CLS_DC); -void do_add_string(znode *result, znode *op1, znode *op2 CLS_DC); -void do_add_variable(znode *result, znode *op1, znode *op2 CLS_DC); - -void do_begin_function_declaration(znode *function_token, znode *function_name, int is_method, int return_reference CLS_DC); -void do_end_function_declaration(znode *function_token CLS_DC); -void do_receive_arg(int op, znode *var, znode *offset, znode *initialization, unsigned char pass_type CLS_DC); -int do_begin_function_call(znode *function_name CLS_DC); -void do_begin_dynamic_function_call(znode *function_name CLS_DC); -void do_begin_class_member_function_call(znode *class_name, znode *function_name CLS_DC); -void do_end_function_call(znode *function_name, znode *result, znode *argument_list, int is_method, int is_dynamic_fcall CLS_DC); -void do_return(znode *expr, int do_end_vparse CLS_DC); -ZEND_API int do_bind_function_or_class(zend_op *opline, HashTable *function_table, HashTable *class_table, int compile_time); -void do_early_binding(CLS_D); - -void do_pass_param(znode *param, int op, int offset CLS_DC); - - -void do_boolean_or_begin(znode *expr1, znode *op_token CLS_DC); -void do_boolean_or_end(znode *result, znode *expr1, znode *expr2, znode *op_token CLS_DC); -void do_boolean_and_begin(znode *expr1, znode *op_token CLS_DC); -void do_boolean_and_end(znode *result, znode *expr1, znode *expr2, znode *op_token CLS_DC); - -void do_brk_cont(int op, znode *expr CLS_DC); - -void do_switch_cond(znode *cond CLS_DC); -void do_switch_end(znode *case_list CLS_DC); -void do_case_before_statement(znode *case_list, znode *case_token, znode *case_expr CLS_DC); -void do_case_after_statement(znode *result, znode *case_token CLS_DC); -void do_default_before_statement(znode *case_list, znode *default_token CLS_DC); - -void do_begin_class_declaration(znode *class_name, znode *parent_class_name CLS_DC); -void do_end_class_declaration(CLS_D); -void do_declare_property(znode *var_name, znode *value CLS_DC); - -void do_fetch_property(znode *result, znode *object, znode *property CLS_DC); - - -void do_push_object(znode *object CLS_DC); -void do_pop_object(znode *object CLS_DC); - - -void do_begin_new_object(znode *new_token, znode *class_name CLS_DC); -void do_end_new_object(znode *result, znode *class_name, znode *new_token, znode *argument_list CLS_DC); - -void do_fetch_constant(znode *result, znode *constant_name, int mode CLS_DC); - -void do_shell_exec(znode *result, znode *cmd CLS_DC); - -void do_init_array(znode *result, znode *expr, znode *offset, int is_ref CLS_DC); -void do_add_array_element(znode *result, znode *expr, znode *offset, int is_ref CLS_DC); -void do_add_static_array_element(znode *result, znode *offset, znode *expr); -void do_list_init(CLS_D); -void do_list_end(znode *result, znode *expr CLS_DC); -void do_add_list_element(znode *element CLS_DC); -void do_new_list_begin(CLS_D); -void do_new_list_end(CLS_D); - -void do_cast(znode *result, znode *expr, int type CLS_DC); -void do_include_or_eval(int type, znode *result, znode *op1 CLS_DC); -void do_require(znode *filename CLS_DC); - -void do_unset(znode *variable CLS_DC); -void do_isset_or_isempty(int type, znode *result, znode *variable CLS_DC); - -void do_foreach_begin(znode *foreach_token, znode *array, znode *open_brackets_token, znode *as_token CLS_DC); -void do_foreach_cont(znode *value, znode *key, znode *as_token CLS_DC); -void do_foreach_end(znode *foreach_token, znode *open_brackets_token CLS_DC); - -void do_declare_begin(CLS_D); -void do_declare_stmt(znode *var, znode *val CLS_DC); -void do_declare_end(CLS_D); - -void do_end_heredoc(CLS_D); - -void do_exit(znode *result, znode *message CLS_DC); - -void do_begin_silence(znode *strudel_token CLS_DC); -void do_end_silence(znode *strudel_token CLS_DC); - -void do_begin_qm_op(znode *cond, znode *qm_token CLS_DC); -void do_qm_true(znode *true_value, znode *qm_token, znode *colon_token CLS_DC); -void do_qm_false(znode *result, znode *false_value, znode *qm_token, znode *colon_token CLS_DC); - -void do_extended_info(CLS_D); -void do_extended_fcall_begin(CLS_D); -void do_extended_fcall_end(CLS_D); - -void do_ticks(CLS_D); - -#define INITIAL_OP_ARRAY_SIZE 64 - - -/* helper functions in zend-scanner.l */ -ZEND_API int require_file(zend_file_handle *file_handle, zend_bool unique CLS_DC); -ZEND_API int require_filename(char *filename CLS_DC); -ZEND_API int use_filename(char *filename, uint filename_length CLS_DC); -ZEND_API zend_op_array *compile_files(int mark_as_ref CLS_DC, int file_count, ...); -ZEND_API zend_op_array *v_compile_files(int mark_as_ref CLS_DC, int file_count, va_list files); -ZEND_API zend_op_array *compile_string(zval *source_string CLS_DC); -ZEND_API zend_op_array *compile_filename(int mode, zval *filename CLS_DC ELS_DC); -ZEND_API int open_file_for_scanning(zend_file_handle *file_handle CLS_DC); -ZEND_API void init_op_array(zend_op_array *op_array, int initial_ops_size); -ZEND_API void destroy_op_array(zend_op_array *op_array); -ZEND_API void zend_close_file_handle(zend_file_handle *file_handle CLS_DC); -ZEND_API void zend_open_file_dtor(zend_file_handle *fh); - -ZEND_API void destroy_zend_function(zend_function *function); -ZEND_API void destroy_zend_class(zend_class_entry *ce); -void zend_class_add_ref(zend_class_entry *ce); - -#define ZEND_FUNCTION_DTOR (void (*)(void *)) destroy_zend_function -#define ZEND_CLASS_DTOR (void (*)(void *)) destroy_zend_class - -zend_op *get_next_op(zend_op_array *op_array CLS_DC); -void init_op(zend_op *op CLS_DC); -int get_next_op_number(zend_op_array *op_array); -int print_class(zend_class_entry *class_entry); -void print_op_array(zend_op_array *op_array, int optimizations); -int pass_two(zend_op_array *op_array); -void pass_include_eval(zend_op_array *op_array); -zend_brk_cont_element *get_next_brk_cont_element(zend_op_array *op_array); -ZEND_API zend_bool zend_is_compiling(void); - -int zendlex(znode *zendlval CLS_DC); - -#define ZEND_NOP 0 - -#define ZEND_ADD 1 -#define ZEND_SUB 2 -#define ZEND_MUL 3 -#define ZEND_DIV 4 -#define ZEND_MOD 5 -#define ZEND_SL 6 -#define ZEND_SR 7 -#define ZEND_CONCAT 8 -#define ZEND_BW_OR 9 -#define ZEND_BW_AND 10 -#define ZEND_BW_XOR 11 -#define ZEND_BW_NOT 12 -#define ZEND_BOOL_NOT 13 -#define ZEND_BOOL_XOR 14 -#define ZEND_IS_IDENTICAL 15 -#define ZEND_IS_EQUAL 16 -#define ZEND_IS_NOT_EQUAL 17 -#define ZEND_IS_SMALLER 18 -#define ZEND_IS_SMALLER_OR_EQUAL 19 -#define ZEND_CAST 20 -#define ZEND_QM_ASSIGN 21 - -#define ZEND_ASSIGN_ADD 22 -#define ZEND_ASSIGN_SUB 23 -#define ZEND_ASSIGN_MUL 24 -#define ZEND_ASSIGN_DIV 25 -#define ZEND_ASSIGN_MOD 26 -#define ZEND_ASSIGN_SL 27 -#define ZEND_ASSIGN_SR 28 -#define ZEND_ASSIGN_CONCAT 29 -#define ZEND_ASSIGN_BW_OR 30 -#define ZEND_ASSIGN_BW_AND 31 -#define ZEND_ASSIGN_BW_XOR 32 - -#define ZEND_PRE_INC 33 -#define ZEND_PRE_DEC 34 -#define ZEND_POST_INC 35 -#define ZEND_POST_DEC 36 - -#define ZEND_ASSIGN 37 -#define ZEND_ASSIGN_REF 38 - -#define ZEND_ECHO 39 -#define ZEND_PRINT 40 - -#define ZEND_JMP 41 -#define ZEND_JMPZ 42 -#define ZEND_JMPNZ 43 -#define ZEND_JMPZNZ 44 -#define ZEND_JMPZ_EX 45 -#define ZEND_JMPNZ_EX 46 -#define ZEND_CASE 47 -#define ZEND_SWITCH_FREE 48 -#define ZEND_BRK 49 -#define ZEND_CONT 50 -#define ZEND_BOOL 51 - -#define ZEND_INIT_STRING 52 -#define ZEND_ADD_CHAR 53 -#define ZEND_ADD_STRING 54 -#define ZEND_ADD_VAR 55 - -#define ZEND_BEGIN_SILENCE 56 -#define ZEND_END_SILENCE 57 - -#define ZEND_INIT_FCALL_BY_NAME 58 -#define ZEND_DO_FCALL 59 -#define ZEND_DO_FCALL_BY_NAME 60 -#define ZEND_RETURN 61 - -#define ZEND_RECV 62 -#define ZEND_RECV_INIT 63 - -#define ZEND_SEND_VAL 64 -#define ZEND_SEND_VAR 65 -#define ZEND_SEND_REF 66 - -#define ZEND_NEW 67 -#define ZEND_JMP_NO_CTOR 68 -#define ZEND_FREE 69 - -#define ZEND_INIT_ARRAY 70 -#define ZEND_ADD_ARRAY_ELEMENT 71 - -#define ZEND_INCLUDE_OR_EVAL 72 - -#define ZEND_UNSET_VAR 73 -#define ZEND_UNSET_DIM_OBJ 74 -#define ZEND_ISSET_ISEMPTY 75 - -#define ZEND_FE_RESET 76 -#define ZEND_FE_FETCH 77 - -#define ZEND_EXIT 78 - - -/* the following 18 opcodes are 6 groups of 3 opcodes each, and must - * remain in that order! - */ -#define ZEND_FETCH_R 79 -#define ZEND_FETCH_DIM_R 80 -#define ZEND_FETCH_OBJ_R 81 -#define ZEND_FETCH_W 82 -#define ZEND_FETCH_DIM_W 83 -#define ZEND_FETCH_OBJ_W 84 -#define ZEND_FETCH_RW 85 -#define ZEND_FETCH_DIM_RW 86 -#define ZEND_FETCH_OBJ_RW 87 -#define ZEND_FETCH_IS 88 -#define ZEND_FETCH_DIM_IS 89 -#define ZEND_FETCH_OBJ_IS 90 -#define ZEND_FETCH_FUNC_ARG 91 -#define ZEND_FETCH_DIM_FUNC_ARG 92 -#define ZEND_FETCH_OBJ_FUNC_ARG 93 -#define ZEND_FETCH_UNSET 94 -#define ZEND_FETCH_DIM_UNSET 95 -#define ZEND_FETCH_OBJ_UNSET 96 - -#define ZEND_FETCH_DIM_TMP_VAR 97 -#define ZEND_FETCH_CONSTANT 98 - -#define ZEND_DECLARE_FUNCTION_OR_CLASS 99 - -#define ZEND_EXT_STMT 100 -#define ZEND_EXT_FCALL_BEGIN 101 -#define ZEND_EXT_FCALL_END 102 -#define ZEND_EXT_NOP 103 - -#define ZEND_TICKS 104 - -/* end of block */ - - - - -/* global/local fetches */ -#define ZEND_FETCH_GLOBAL 0 -#define ZEND_FETCH_LOCAL 1 -#define ZEND_FETCH_STATIC 2 - -/* var status for backpatching */ -#define BP_VAR_R 0 -#define BP_VAR_W 1 -#define BP_VAR_RW 2 -#define BP_VAR_IS 3 -#define BP_VAR_NA 4 /* if not applicable */ -#define BP_VAR_FUNC_ARG 5 -#define BP_VAR_UNSET 6 - - -#define ZEND_INTERNAL_FUNCTION 1 -#define ZEND_USER_FUNCTION 2 -#define ZEND_OVERLOADED_FUNCTION 3 -#define ZEND_EVAL_CODE 4 - -#define ZEND_INTERNAL_CLASS 1 -#define ZEND_USER_CLASS 2 - -#define ZEND_EVAL (1<<0) -#define ZEND_INCLUDE (1<<1) -#define ZEND_IMPORT (1<<2) -#define ZEND_REQUIRE (1<<3) - -#define ZEND_ISSET (1<<0) -#define ZEND_ISEMPTY (1<<1) - -#define ZEND_CT (1<<0) -#define ZEND_RT (1<<1) - - -#define ZEND_HANDLE_FILENAME 0 -#define ZEND_HANDLE_FD 1 -#define ZEND_HANDLE_FP 2 -#define ZEND_HANDLE_STDIOSTREAM 3 -#define ZEND_HANDLE_FSTREAM 4 - -#define ZEND_DECLARE_CLASS 1 -#define ZEND_DECLARE_FUNCTION 2 -#define ZEND_DECLARE_INHERITED_CLASS 3 - -#define ZEND_FETCH_STANDARD 0 -#define ZEND_FETCH_ADD_LOCK 1 - -#define ZEND_MEMBER_FUNC_CALL 1<<0 -#define ZEND_CTOR_CALL 1<<1 - - -#define AI_USE_PTR(ai) \ - if ((ai).ptr_ptr) { \ - (ai).ptr = *((ai).ptr_ptr); \ - (ai).ptr_ptr = &((ai).ptr); \ - } else { \ - (ai).ptr = NULL; \ - } - -/* Lost In Stupid Parentheses */ -#define ARG_SHOULD_BE_SENT_BY_REF(offset, conduct_check, arg_types) \ - ( \ - conduct_check \ - && arg_types \ - && \ - ( \ - ( \ - offset<=arg_types[0] \ - && arg_types[offset]==BYREF_FORCE \ - ) \ - || ( \ - offset>=arg_types[0] \ - && arg_types[arg_types[0]]==BYREF_FORCE_REST \ - ) \ - ) \ - ) - -#define ZEND_RETURN_VAL 0 -#define ZEND_RETURN_REF 1 - -END_EXTERN_C() - -#endif /* _COMPILE_H */ diff --git a/Zend/zend_config.w32.h b/Zend/zend_config.w32.h deleted file mode 100644 index 8171727c2e..0000000000 --- a/Zend/zend_config.w32.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _ZEND_CONFIG_W32_H -#define _ZEND_CONFIG_W32_H - - -#include -#include - -typedef unsigned long ulong; -typedef unsigned int uint; - -#define HAVE_ALLOCA 1 -#define HAVE_LIMITS_H 1 -#include - -#undef HAVE_KILL -#define HAVE_GETPID 1 -/* #define HAVE_ALLOCA_H 1 */ -#define HAVE_MEMCPY 1 -#define HAVE_STRDUP 1 -#define HAVE_SYS_TYPES_H 1 -#define HAVE_STDIOSTR_H 1 -#define HAVE_CLASS_ISTDIOSTREAM -#define istdiostream stdiostream - -#ifdef inline -#undef inline -#endif - -#define zend_sprintf sprintf - -/* This will cause the compilation process to be MUCH longer, but will generate - * a much quicker PHP binary - */ -#ifdef ZEND_WIN32_FORCE_INLINE -# define inline __forceinline -#else -# define inline -#endif - - -#ifdef LIBZEND_EXPORTS -# define ZEND_API __declspec(dllexport) -#else -# define ZEND_API __declspec(dllimport) -#endif - -#endif /* _ZEND_CONFIG_W32_H */ diff --git a/Zend/zend_constants.c b/Zend/zend_constants.c deleted file mode 100644 index 54ba984d47..0000000000 --- a/Zend/zend_constants.c +++ /dev/null @@ -1,254 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include "zend.h" -#include "zend_constants.h" -#include "zend_variables.h" -#include "zend_operators.h" -#include "zend_globals.h" - - -void free_zend_constant(zend_constant *c) -{ - if (!(c->flags & CONST_PERSISTENT)) { - zval_dtor(&c->value); - } - free(c->name); -} - - -void copy_zend_constant(zend_constant *c) -{ - c->name = zend_strndup(c->name, c->name_len); - if (!(c->flags & CONST_PERSISTENT)) { - zval_copy_ctor(&c->value); - } -} - - -void zend_copy_constants(HashTable *target, HashTable *source) -{ - zend_constant tmp_constant; - - zend_hash_copy(target, source, (copy_ctor_func_t) copy_zend_constant, &tmp_constant, sizeof(zend_constant)); -} - - -static int clean_non_persistent_constant(zend_constant *c) -{ - if (c->flags & CONST_PERSISTENT) { - return 0; - } else { - return 1; - } -} - - -static int clean_module_constant(zend_constant *c, int *module_number) -{ - if (c->module_number == *module_number) { - return 1; - } else { - return 0; - } -} - - -void clean_module_constants(int module_number) -{ - ELS_FETCH(); - - zend_hash_apply_with_argument(EG(zend_constants), (int (*)(void *,void *)) clean_module_constant, (void *) &module_number); -} - - -int zend_startup_constants(ELS_D) -{ -#ifdef ZEND_WIN32 - DWORD dwBuild=0; - DWORD dwVersion = GetVersion(); - DWORD dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion))); - DWORD dwWindowsMinorVersion = (DWORD)(HIBYTE(LOWORD(dwVersion))); -#endif - - EG(zend_constants) = (HashTable *) malloc(sizeof(HashTable)); - - if (zend_hash_init(EG(zend_constants), 20, NULL, ZEND_CONSTANT_DTOR, 1)==FAILURE) { - return FAILURE; - } - return SUCCESS; -} - - - -void zend_register_standard_constants(ELS_D) -{ - REGISTER_MAIN_LONG_CONSTANT("E_ERROR", E_ERROR, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_LONG_CONSTANT("E_WARNING", E_WARNING, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_LONG_CONSTANT("E_PARSE", E_PARSE, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_LONG_CONSTANT("E_NOTICE", E_NOTICE, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_LONG_CONSTANT("E_CORE_ERROR", E_CORE_ERROR, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_LONG_CONSTANT("E_CORE_WARNING", E_CORE_WARNING, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_LONG_CONSTANT("E_COMPILE_ERROR", E_COMPILE_ERROR, CONST_PERSISTENT | CONST_CS); - REGISTER_MAIN_LONG_CONSTANT("E_COMPILE_WARNING", E_COMPILE_WARNING, CONST_PERSISTENT | CONST_CS); - - REGISTER_MAIN_LONG_CONSTANT("E_ALL", E_ALL, CONST_PERSISTENT | CONST_CS); - - /* true/false constants */ - { - zend_constant c; - - c.value.type = IS_BOOL; - c.flags = CONST_PERSISTENT; - c.module_number = 0; - - c.name = zend_strndup(ZEND_STRL("TRUE")); - c.name_len = sizeof("TRUE"); - c.value.value.lval = 1; - c.value.type = IS_BOOL; - zend_register_constant(&c ELS_CC); - - c.name = zend_strndup(ZEND_STRL("FALSE")); - c.name_len = sizeof("FALSE"); - c.value.value.lval = 0; - c.value.type = IS_BOOL; - zend_register_constant(&c ELS_CC); - - c.name = zend_strndup(ZEND_STRL("NULL")); - c.name_len = sizeof("NULL"); - c.value.type = IS_NULL; - zend_register_constant(&c ELS_CC); - } -} - - -int zend_shutdown_constants(ELS_D) -{ - zend_hash_destroy(EG(zend_constants)); - free(EG(zend_constants)); - return SUCCESS; -} - - -void clean_non_persistent_constants(void) -{ - ELS_FETCH(); - - zend_hash_apply(EG(zend_constants), (int (*)(void *)) clean_non_persistent_constant); -} - - -ZEND_API void zend_register_long_constant(char *name, uint name_len, long lval, int flags, int module_number ELS_DC) -{ - zend_constant c; - - c.value.type = IS_LONG; - c.value.value.lval = lval; - c.flags = flags; - c.name = zend_strndup(name,name_len); - c.name_len = name_len; - c.module_number = module_number; - zend_register_constant(&c ELS_CC); -} - - -ZEND_API void zend_register_double_constant(char *name, uint name_len, double dval, int flags, int module_number ELS_DC) -{ - zend_constant c; - - c.value.type = IS_DOUBLE; - c.value.value.dval = dval; - c.flags = flags; - c.name = zend_strndup(name,name_len); - c.name_len = name_len; - c.module_number = module_number; - zend_register_constant(&c ELS_CC); -} - - -ZEND_API void zend_register_stringl_constant(char *name, uint name_len, char *strval, uint strlen, int flags, int module_number ELS_DC) -{ - zend_constant c; - - c.value.type = IS_STRING; - c.value.value.str.val = strval; - c.value.value.str.len = strlen; - c.flags = flags; - c.name = zend_strndup(name,name_len); - c.name_len = name_len; - c.module_number = module_number; - zend_register_constant(&c ELS_CC); -} - - -ZEND_API void zend_register_string_constant(char *name, uint name_len, char *strval, int flags, int module_number ELS_DC) -{ - zend_register_stringl_constant(name, name_len, strval, strlen(strval), flags, module_number ELS_CC); -} - - -ZEND_API int zend_get_constant(char *name, uint name_len, zval *result) -{ - zend_constant *c; - char *lookup_name = estrndup(name,name_len); - int retval; - ELS_FETCH(); - - zend_str_tolower(lookup_name, name_len); - - if (zend_hash_find(EG(zend_constants), lookup_name, name_len+1, (void **) &c)==SUCCESS) { - if ((c->flags & CONST_CS) && memcmp(c->name, name, name_len)!=0) { - retval=0; - } else { - retval=1; - *result = c->value; - zval_copy_ctor(result); - } - } else { - retval=0; - } - - efree(lookup_name); - return retval; -} - - -ZEND_API void zend_register_constant(zend_constant *c ELS_DC) -{ - char *lowercase_name = zend_strndup(c->name, c->name_len); - -#if 0 - printf("Registering constant for module %d\n",c->module_number); -#endif - - zend_str_tolower(lowercase_name, c->name_len); - if (zend_hash_add(EG(zend_constants), lowercase_name, c->name_len, (void *) c, sizeof(zend_constant), NULL)==FAILURE) { - zval_dtor(&c->value); - } - free(lowercase_name); -} - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/Zend/zend_constants.h b/Zend/zend_constants.h deleted file mode 100644 index 9ebb7409a0..0000000000 --- a/Zend/zend_constants.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _CONSTANTS_H -#define _CONSTANTS_H - -#include "zend_globals.h" - -#define CONST_CS 0x1 /* Case Sensitive */ -#define CONST_PERSISTENT 0x2 - -typedef struct _zend_constant { - zval value; - int flags; - char *name; - uint name_len; - int module_number; -} zend_constant; - -#define REGISTER_LONG_CONSTANT(name,lval,flags) zend_register_long_constant((name),sizeof(name),(lval),(flags),module_number ELS_CC) -#define REGISTER_DOUBLE_CONSTANT(name,dval,flags) zend_register_double_constant((name),sizeof(name),(dval),(flags),module_number ELS_CC) -#define REGISTER_STRING_CONSTANT(name,str,flags) zend_register_string_constant((name),sizeof(name),(str),(flags),module_number ELS_CC) -#define REGISTER_STRINGL_CONSTANT(name,str,len,flags) zend_register_stringl_constant((name),sizeof(name),(str),(len),(flags),module_number ELS_CC) - -#define REGISTER_MAIN_LONG_CONSTANT(name,lval,flags) zend_register_long_constant((name),sizeof(name),(lval),(flags),0 ELS_CC) -#define REGISTER_MAIN_DOUBLE_CONSTANT(name,dval,flags) zend_register_double_constant((name),sizeof(name),(dval),(flags),0 ELS_CC) -#define REGISTER_MAIN_STRING_CONSTANT(name,str,flags) zend_register_string_constant((name),sizeof(name),(str),(flags),0 ELS_CC) -#define REGISTER_MAIN_STRINGL_CONSTANT(name,str,len,flags) zend_register_stringl_constant((name),sizeof(name),(str),(len),(flags),0 ELS_CC) - -void clean_module_constants(int module_number); -void free_zend_constant(zend_constant *c); -int zend_startup_constants(ELS_D); -int zend_shutdown_constants(ELS_D); -void zend_register_standard_constants(ELS_D); -void clean_non_persistent_constants(void); -ZEND_API int zend_get_constant(char *name, uint name_len, zval *result); -ZEND_API void zend_register_long_constant(char *name, uint name_len, long lval, int flags, int module_number ELS_DC); -ZEND_API void zend_register_double_constant(char *name, uint name_len, double dval, int flags, int module_number ELS_DC); -ZEND_API void zend_register_string_constant(char *name, uint name_len, char *strval, int flags, int module_number ELS_DC); -ZEND_API void zend_register_stringl_constant(char *name, uint name_len, char *strval, uint strlen, int flags, int module_number ELS_DC); -ZEND_API void zend_register_constant(zend_constant *c ELS_DC); -void zend_copy_constants(HashTable *target, HashTable *sourc); -void copy_zend_constant(zend_constant *c); - -#define ZEND_CONSTANT_DTOR (void (*)(void *)) free_zend_constant - -#endif diff --git a/Zend/zend_errors.h b/Zend/zend_errors.h deleted file mode 100644 index 36b6123d14..0000000000 --- a/Zend/zend_errors.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _ZEND_ERRORS_H -#define _ZEND_ERRORS_H - -#define E_ERROR (1<<0L) -#define E_WARNING (1<<1L) -#define E_PARSE (1<<2L) -#define E_NOTICE (1<<3L) -#define E_CORE_ERROR (1<<4L) -#define E_CORE_WARNING (1<<5L) -#define E_COMPILE_ERROR (1<<6L) -#define E_COMPILE_WARNING (1<<7L) - -#define E_ALL (E_ERROR | E_WARNING | E_PARSE | E_NOTICE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING) -#define E_CORE (E_CORE_ERROR | E_CORE_WARNING) - -#endif /* _ZEND_ERRORS_H */ - diff --git a/Zend/zend_execute.c b/Zend/zend_execute.c deleted file mode 100644 index 017b072cba..0000000000 --- a/Zend/zend_execute.c +++ /dev/null @@ -1,2350 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - -#define ZEND_INTENSIVE_DEBUGGING 0 - -#include -#include - -#include "zend.h" -#include "zend_compile.h" -#include "zend_execute.h" -#include "zend_API.h" -#include "zend_ptr_stack.h" -#include "zend_variables.h" -#include "zend_operators.h" -#include "zend_constants.h" -#include "zend_extensions.h" -#include "zend_fast_cache.h" -#include "zend_execute_locks.h" - -#if defined(HAVE_ALLOCA) && defined(HAVE_ALLOCA_H) -# include -#endif - -#define get_zval_ptr(node, Ts, should_free, type) _get_zval_ptr(node, Ts, should_free ELS_CC) -#define get_zval_ptr_ptr(node, Ts, type) _get_zval_ptr_ptr(node, Ts ELS_CC) - -#define get_incdec_op(op, opcode) \ - switch (opcode) { \ - case ZEND_PRE_INC: \ - case ZEND_POST_INC: \ - (op) = increment_function; \ - break; \ - case ZEND_PRE_DEC: \ - case ZEND_POST_DEC: \ - (op) = decrement_function; \ - break; \ - default: \ - (op) = NULL; \ - break; \ - } \ - -/* These globals don't have to be thread safe since they're never modified */ - - -/* Prototypes */ -static zval get_overloaded_property(ELS_D); -static void set_overloaded_property(zval *value ELS_DC); -static void call_overloaded_function(int arg_count, zval *return_value ELS_DC); -static inline void zend_fetch_var_address(znode *result, znode *op1, znode *op2, temp_variable *Ts, int type ELS_DC); -static inline void zend_fetch_dimension_address(znode *result, znode *op1, znode *op2, temp_variable *Ts, int type ELS_DC); -static inline void zend_fetch_property_address(znode *result, znode *op1, znode *op2, temp_variable *Ts, int type ELS_DC); -static inline void zend_fetch_dimension_address_from_tmp_var(znode *result, znode *op1, znode *op2, temp_variable *Ts ELS_DC); -static void zend_extension_statement_handler(zend_extension *extension, zend_op_array *op_array); -static void zend_extension_fcall_begin_handler(zend_extension *extension, zend_op_array *op_array); -static void zend_extension_fcall_end_handler(zend_extension *extension, zend_op_array *op_array); - - - -#define SEPARATE_ON_READ_OBJECT(obj, _type) \ -if ((obj) && ((_type) == BP_VAR_R) && ((*(obj))->type == IS_OBJECT)) { \ - SEPARATE_ZVAL_IF_NOT_REF((obj)); \ - (*(obj))->is_ref = 1; \ - } - -#define RETURN_VALUE_USED(opline) (!((opline)->result.u.EA.type & EXT_TYPE_UNUSED)) - -static inline zval *_get_zval_ptr(znode *node, temp_variable *Ts, int *should_free ELS_DC) -{ - switch(node->op_type) { - case IS_CONST: - *should_free = 0; - return &node->u.constant; - break; - case IS_TMP_VAR: - *should_free = 1; - return &Ts[node->u.var].tmp_var; - break; - case IS_VAR: - if (Ts[node->u.var].var.ptr) { - PZVAL_UNLOCK(Ts[node->u.var].var.ptr); - *should_free = 0; - return Ts[node->u.var].var.ptr; - } else { - *should_free = 1; - - switch (Ts[node->u.var].EA.type) { - case IS_OVERLOADED_OBJECT: - Ts[node->u.var].tmp_var = get_overloaded_property(ELS_C); - Ts[node->u.var].tmp_var.refcount=1; - Ts[node->u.var].tmp_var.is_ref=1; - return &Ts[node->u.var].tmp_var; - break; - case IS_STRING_OFFSET: { - temp_variable *T = &Ts[node->u.var]; - zval *str = T->EA.str; - - if (T->EA.str->type != IS_STRING - || (T->EA.str->value.str.len <= T->EA.offset)) { - T->tmp_var.value.str.val = empty_string; - T->tmp_var.value.str.len = 0; - } else { - char c = str->value.str.val[T->EA.offset]; - - T->tmp_var.value.str.val = estrndup(&c, 1); - T->tmp_var.value.str.len = 1; - } - PZVAL_UNLOCK(str); - T->tmp_var.refcount=1; - T->tmp_var.is_ref=1; - T->tmp_var.type = IS_STRING; - return &T->tmp_var; - } - break; - } - } - break; - case IS_UNUSED: - *should_free = 0; - return NULL; - break; - EMPTY_SWITCH_DEFAULT_CASE() - } - return NULL; -} - -static inline zval *_get_object_zval_ptr(znode *node, temp_variable *Ts, int *should_free ELS_DC) -{ - switch(node->op_type) { - case IS_TMP_VAR: - *should_free = 1; - return &Ts[node->u.var].tmp_var; - break; - case IS_VAR: - if (Ts[node->u.var].var.ptr) { - PZVAL_UNLOCK(Ts[node->u.var].var.ptr); - *should_free = 0; - return Ts[node->u.var].var.ptr; - } else { - if (Ts[node->u.var].EA.type==IS_STRING_OFFSET) { - PZVAL_UNLOCK(Ts[node->u.var].EA.str); - } - *should_free = 1; - return NULL; - } - break; - case IS_UNUSED: - return NULL; - break; - EMPTY_SWITCH_DEFAULT_CASE() - } - return NULL; -} - - -static inline zval **_get_zval_ptr_ptr(znode *node, temp_variable *Ts ELS_DC) -{ - if (node->op_type==IS_VAR) { - if (Ts[node->u.var].var.ptr_ptr) { - PZVAL_UNLOCK(*Ts[node->u.var].var.ptr_ptr); - } else if (Ts[node->u.var].EA.type==IS_STRING_OFFSET) { - PZVAL_UNLOCK(Ts[node->u.var].EA.str); - } - return Ts[node->u.var].var.ptr_ptr; - } else { - return NULL; - } -} - - -static inline zval **zend_fetch_property_address_inner(HashTable *ht, znode *op2, temp_variable *Ts, int type ELS_DC) -{ - int free_op2; - zval *prop_ptr = get_zval_ptr(op2, Ts, &free_op2, BP_VAR_R); - zval **retval; - zval tmp; - - - switch (op2->op_type) { - case IS_CONST: - /* already a constant string */ - break; - case IS_VAR: - tmp = *prop_ptr; - zval_copy_ctor(&tmp); - convert_to_string(&tmp); - prop_ptr = &tmp; - break; - case IS_TMP_VAR: - convert_to_string(prop_ptr); - break; - } - - if (zend_hash_find(ht, prop_ptr->value.str.val, prop_ptr->value.str.len+1, (void **) &retval) == FAILURE) { - switch (type) { - case BP_VAR_R: - zend_error(E_NOTICE,"Undefined property: %s", prop_ptr->value.str.val); - /* break missing intentionally */ - case BP_VAR_IS: - retval = &EG(uninitialized_zval_ptr); - break; - case BP_VAR_RW: - zend_error(E_NOTICE,"Undefined property: %s", prop_ptr->value.str.val); - /* break missing intentionally */ - case BP_VAR_W: { - zval *new_zval = &EG(uninitialized_zval); - - new_zval->refcount++; - zend_hash_update_ptr(ht, prop_ptr->value.str.val, prop_ptr->value.str.len+1, new_zval, sizeof(zval *), (void **) &retval); - } - break; - EMPTY_SWITCH_DEFAULT_CASE() - } - } - - if (prop_ptr == &tmp) { - zval_dtor(prop_ptr); - } - FREE_OP(op2, free_op2); - return retval; -} - - - -static inline void zend_switch_free(zend_op *opline, temp_variable *Ts ELS_DC) -{ - switch (opline->op1.op_type) { - case IS_VAR: - if (!Ts[opline->op1.u.var].var.ptr_ptr) { - get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R); - FREE_OP(&opline->op1, EG(free_op1)); - } else { - zval_ptr_dtor(&Ts[opline->op1.u.var].var.ptr); - if (opline->extended_value) { /* foreach() free */ - zval_ptr_dtor(&Ts[opline->op1.u.var].var.ptr); - } - } - break; - case IS_TMP_VAR: - zendi_zval_dtor(Ts[opline->op1.u.var].tmp_var); - break; - EMPTY_SWITCH_DEFAULT_CASE() - } -} - - -static inline void zend_assign_to_variable(znode *result, znode *op1, znode *op2, zval *value, int type, temp_variable *Ts ELS_DC) -{ - zval **variable_ptr_ptr = get_zval_ptr_ptr(op1, Ts, BP_VAR_W); - zval *variable_ptr; - - if (!variable_ptr_ptr) { - switch (Ts[op1->u.var].EA.type) { - case IS_OVERLOADED_OBJECT: - set_overloaded_property(value ELS_CC); - if (type == IS_TMP_VAR) { - zval_dtor(value); - } - break; - case IS_STRING_OFFSET: { - temp_variable *T = &Ts[op1->u.var]; - - if (T->EA.str->type == IS_STRING - && (T->EA.offset < T->EA.str->value.str.len)) { - zval tmp; - zval *final_value = value; - - if (value->type!=IS_STRING) { - tmp = *value; - if (op2 && op2->op_type == IS_VAR) { - zval_copy_ctor(&tmp); - } - convert_to_string(&tmp); - final_value = &tmp; - } - - T->EA.str->value.str.val[T->EA.offset] = final_value->value.str.val[0]; - if (op2 - && op2->op_type == IS_VAR - && value==&Ts[op2->u.var].tmp_var) { - efree(value->value.str.val); - } - if (final_value == &tmp) { - zval_dtor(final_value); - } - /* - * the value of an assignment to a string offset is undefined - Ts[result->u.var].var = &T->EA.str; - */ - } - /* zval_ptr_dtor(&T->EA.str); Nuke this line if it doesn't cause a leak */ - T->tmp_var.type = IS_STRING; - } - break; - EMPTY_SWITCH_DEFAULT_CASE() - } - Ts[result->u.var].var.ptr_ptr = &EG(uninitialized_zval_ptr); - SELECTIVE_PZVAL_LOCK(*Ts[result->u.var].var.ptr_ptr, result); - AI_USE_PTR(Ts[result->u.var].var); - return; - } - - variable_ptr = *variable_ptr_ptr; - - if (variable_ptr == EG(error_zval_ptr)) { - if (result) { - Ts[result->u.var].var.ptr_ptr = &EG(uninitialized_zval_ptr); - SELECTIVE_PZVAL_LOCK(*Ts[result->u.var].var.ptr_ptr, result); - AI_USE_PTR(Ts[result->u.var].var); - } - if (type==IS_TMP_VAR) { - zval_dtor(value); - } - return; - } - - if (PZVAL_IS_REF(variable_ptr)) { - if (variable_ptr!=value) { - short refcount=variable_ptr->refcount; - zval garbage; - - if (type!=IS_TMP_VAR) { - value->refcount++; - } - garbage = *variable_ptr; - *variable_ptr = *value; - variable_ptr->refcount = refcount; - variable_ptr->is_ref = 1; - if (type!=IS_TMP_VAR) { - zendi_zval_copy_ctor(*variable_ptr); - value->refcount--; - } - zendi_zval_dtor(garbage); - } - } else { - variable_ptr->refcount--; - if (variable_ptr->refcount==0) { - switch (type) { - case IS_VAR: - /* - if (PZVAL_IS_LOCKED(value)) { - zval *orig_value = value; - - ALLOC_ZVAL(value); - *value = *orig_value; - value->refcount=0; - zval_copy_ctor(value); - } - */ - /* break missing intentionally */ - case IS_CONST: - if (variable_ptr==value) { - variable_ptr->refcount++; - } else if (PZVAL_IS_REF(value)) { - zval tmp = *value; - - tmp = *value; - zval_copy_ctor(&tmp); - tmp.refcount=1; - zendi_zval_dtor(*variable_ptr); - *variable_ptr = tmp; - } else { - value->refcount++; - zendi_zval_dtor(*variable_ptr); - safe_free_zval_ptr(variable_ptr); - *variable_ptr_ptr = value; - } - break; - case IS_TMP_VAR: - zendi_zval_dtor(*variable_ptr); - value->refcount=1; - *variable_ptr = *value; - break; - EMPTY_SWITCH_DEFAULT_CASE() - } - } else { /* we need to split */ - switch (type) { - case IS_VAR: - /* - if (PZVAL_IS_LOCKED(value)) { - zval *orig_value = value; - - ALLOC_ZVAL(value); - *value = *orig_value; - value->refcount=0; - zval_copy_ctor(value); - } - */ - /* break missing intentionally */ - case IS_CONST: - if (PZVAL_IS_REF(value) && value->refcount > 0) { - ALLOC_ZVAL(variable_ptr); - *variable_ptr_ptr = variable_ptr; - *variable_ptr = *value; - zval_copy_ctor(variable_ptr); - variable_ptr->refcount=1; - break; - } - *variable_ptr_ptr = value; - value->refcount++; - break; - case IS_TMP_VAR: - ALLOC_ZVAL(*variable_ptr_ptr); - value->refcount=1; - **variable_ptr_ptr = *value; - break; - EMPTY_SWITCH_DEFAULT_CASE() - } - } - (*variable_ptr_ptr)->is_ref=0; - } - if (result) { - Ts[result->u.var].var.ptr_ptr = variable_ptr_ptr; - SELECTIVE_PZVAL_LOCK(*variable_ptr_ptr, result); - AI_USE_PTR(Ts[result->u.var].var); - } -} - - -/* Utility Functions for Extensions */ -static void zend_extension_statement_handler(zend_extension *extension, zend_op_array *op_array) -{ - if (extension->statement_handler) { - extension->statement_handler(op_array); - } -} - - -static void zend_extension_fcall_begin_handler(zend_extension *extension, zend_op_array *op_array) -{ - if (extension->fcall_begin_handler) { - extension->fcall_begin_handler(op_array); - } -} - - -static void zend_extension_fcall_end_handler(zend_extension *extension, zend_op_array *op_array) -{ - if (extension->fcall_end_handler) { - extension->fcall_end_handler(op_array); - } -} - - -static void print_refcount(zval *p, char *str) -{ - print_refcount(NULL, NULL); -} - - -static inline void zend_fetch_var_address(znode *result, znode *op1, znode *op2, temp_variable *Ts, int type ELS_DC) -{ - int free_op1; - zval *varname = get_zval_ptr(op1, Ts, &free_op1, BP_VAR_R); - zval **retval; - zval tmp_varname; - HashTable *target_symbol_table=0; - - switch (op2->u.fetch_type) { - case ZEND_FETCH_LOCAL: - target_symbol_table = EG(active_symbol_table); - break; - case ZEND_FETCH_GLOBAL: - if (op1->op_type == IS_VAR) { - PZVAL_LOCK(varname); - } - target_symbol_table = &EG(symbol_table); - break; - case ZEND_FETCH_STATIC: - if (!EG(active_op_array)->static_variables) { - ALLOC_HASHTABLE(EG(active_op_array)->static_variables); - zend_hash_init(EG(active_op_array)->static_variables, 2, NULL, ZVAL_PTR_DTOR, 0); - } - target_symbol_table = EG(active_op_array)->static_variables; - break; - EMPTY_SWITCH_DEFAULT_CASE() - } - - if (varname->type != IS_STRING) { - tmp_varname = *varname; - zval_copy_ctor(&tmp_varname); - convert_to_string(&tmp_varname); - varname = &tmp_varname; - } - if (zend_hash_find(target_symbol_table, varname->value.str.val, varname->value.str.len+1, (void **) &retval) == FAILURE) { - switch (type) { - case BP_VAR_R: - zend_error(E_NOTICE,"Undefined variable: %s", varname->value.str.val); - /* break missing intentionally */ - case BP_VAR_IS: - retval = &EG(uninitialized_zval_ptr); - break; - case BP_VAR_RW: - zend_error(E_NOTICE,"Undefined variable: %s", varname->value.str.val); - /* break missing intentionally */ - case BP_VAR_W: { - zval *new_zval = &EG(uninitialized_zval); - - new_zval->refcount++; - zend_hash_update_ptr(target_symbol_table, varname->value.str.val, varname->value.str.len+1, new_zval, sizeof(zval *), (void **) &retval); - } - break; - EMPTY_SWITCH_DEFAULT_CASE() - } - } - if (op2->u.fetch_type == ZEND_FETCH_LOCAL) { - FREE_OP(op1, free_op1); - } else if (op2->u.fetch_type == ZEND_FETCH_STATIC) { - zval_update_constant(retval); - } - - if (varname == &tmp_varname) { - zval_dtor(varname); - } - Ts[result->u.var].var.ptr_ptr = retval; - SEPARATE_ON_READ_OBJECT(retval, type); - SELECTIVE_PZVAL_LOCK(*retval, result); -} - - -static inline zval **zend_fetch_dimension_address_inner(HashTable *ht, znode *op2, temp_variable *Ts, int type ELS_DC) -{ - int free_op2; - zval *dim = get_zval_ptr(op2, Ts, &free_op2, BP_VAR_R); - zval **retval; - char *offset_key; - int offset_key_length; - - switch (dim->type) { - case IS_NULL: - offset_key = ""; - offset_key_length = 0; - goto fetch_string_dim; - case IS_STRING: - offset_key = dim->value.str.val; - offset_key_length = dim->value.str.len; - -fetch_string_dim: - if (zend_hash_find(ht, offset_key, offset_key_length+1, (void **) &retval) == FAILURE) { - switch (type) { - case BP_VAR_R: - zend_error(E_NOTICE,"Undefined index: %s", offset_key); - /* break missing intentionally */ - case BP_VAR_IS: - retval = &EG(uninitialized_zval_ptr); - break; - case BP_VAR_RW: - zend_error(E_NOTICE,"Undefined index: %s", offset_key); - /* break missing intentionally */ - case BP_VAR_W: { - zval *new_zval = &EG(uninitialized_zval); - - new_zval->refcount++; - zend_hash_update_ptr(ht, offset_key, offset_key_length+1, new_zval, sizeof(zval *), (void **) &retval); - } - break; - } - } - break; - case IS_DOUBLE: - case IS_RESOURCE: - case IS_BOOL: - case IS_LONG: { - long index; - - if (dim->type == IS_DOUBLE) { - index = (long)dim->value.dval; - } else { - index = dim->value.lval; - } - if (zend_hash_index_find(ht, index, (void **) &retval) == FAILURE) { - switch (type) { - case BP_VAR_R: - zend_error(E_NOTICE,"Undefined offset: %d", index); - /* break missing intentionally */ - case BP_VAR_IS: - retval = &EG(uninitialized_zval_ptr); - break; - case BP_VAR_RW: - zend_error(E_NOTICE,"Undefined offset: %d", index); - /* break missing intentionally */ - case BP_VAR_W: { - zval *new_zval = &EG(uninitialized_zval); - - new_zval->refcount++; - zend_hash_index_update(ht, index, &new_zval, sizeof(zval *), (void **) &retval); - } - break; - } - } - } - break; - default: - zend_error(E_WARNING, "Illegal offset type"); - if (type == BP_VAR_R || type == BP_VAR_IS) { - retval = &EG(uninitialized_zval_ptr); - } else { - retval = &EG(error_zval_ptr); - } - break; - } - FREE_OP(op2, free_op2); - return retval; -} - - -static inline void zend_fetch_dimension_address(znode *result, znode *op1, znode *op2, temp_variable *Ts, int type ELS_DC) -{ - int free_op2; - zval **container_ptr = get_zval_ptr_ptr(op1, Ts, type); - zval *container; - zval ***retval = &Ts[result->u.var].var.ptr_ptr; - - - if (container_ptr == NULL) { - zend_property_reference *property_reference; - zend_overloaded_element overloaded_element; - - if (Ts[op1->u.var].EA.type == IS_STRING_OFFSET) { - switch (type) { - case BP_VAR_R: - case BP_VAR_IS: - *retval = &EG(uninitialized_zval_ptr); - break; - case BP_VAR_W: - case BP_VAR_RW: - *retval = &EG(error_zval_ptr); - break; - EMPTY_SWITCH_DEFAULT_CASE() - } - SELECTIVE_PZVAL_LOCK(**retval, result); - return; - } - - /* prepare the new element */ - overloaded_element.element = *get_zval_ptr(op2, Ts, &free_op2, type); - overloaded_element.type = OE_IS_ARRAY; - if (!free_op2) { - zval_copy_ctor(&overloaded_element.element); - } - - zend_stack_top(&EG(overloaded_objects_stack), (void **) &property_reference); - - zend_llist_add_element(&property_reference->elements_list, &overloaded_element); - - Ts[result->u.var].EA.type = IS_OVERLOADED_OBJECT; - *retval = NULL; - return; - } - container = *container_ptr; - - if (container == EG(error_zval_ptr)) { - *retval = &EG(error_zval_ptr); - SELECTIVE_PZVAL_LOCK(**retval, result); - return; - } - - if (container->type==IS_NULL - || (container->type==IS_STRING && container->value.str.len==0)) { - switch (type) { - case BP_VAR_RW: - case BP_VAR_W: - if (!PZVAL_IS_REF(container)) { - container->refcount--; - if (container->refcount>0) { - ALLOC_ZVAL(container); - *container_ptr = container; - container->is_ref=0; - } - container->refcount=1; - } - array_init(container); - break; - } - } - - switch (container->type) { - case IS_ARRAY: - if ((type==BP_VAR_W || type==BP_VAR_RW) && container->refcount>1 && !PZVAL_IS_REF(container)) { - container->refcount--; - ALLOC_ZVAL(*container_ptr); - **container_ptr = *container; - container = *container_ptr; - INIT_PZVAL(container); - zendi_zval_copy_ctor(*container); - } - if (op2->op_type == IS_UNUSED) { - zval *new_zval = &EG(uninitialized_zval); - - new_zval->refcount++; - zend_hash_next_index_insert_ptr(container->value.ht, new_zval, sizeof(zval *), (void **) retval); - } else { - *retval = zend_fetch_dimension_address_inner(container->value.ht, op2, Ts, type ELS_CC); - } - SEPARATE_ON_READ_OBJECT(*retval, type); - SELECTIVE_PZVAL_LOCK(**retval, result); - break; - case IS_NULL: - /* for read-mode only */ - get_zval_ptr(op2, Ts, &free_op2, BP_VAR_R); - *retval = &EG(uninitialized_zval_ptr); - SELECTIVE_PZVAL_LOCK(**retval, result); - FREE_OP(op2, free_op2); - break; - case IS_STRING: { - zval *offset; - zval tmp; - - if (op2->op_type==IS_UNUSED) { - zend_error(E_ERROR, "[] operator not supported for strings"); - } - - offset = get_zval_ptr(op2, Ts, &free_op2, BP_VAR_R); - - if (offset->type != IS_LONG) { - tmp = *offset; - zval_copy_ctor(&tmp); - convert_to_long(&tmp); - offset = &tmp; - } - if (type!=BP_VAR_R && type!=BP_VAR_IS) { - SEPARATE_ZVAL_IF_NOT_REF(container_ptr); - } - container = *container_ptr; - Ts[result->u.var].EA.str = container; - PZVAL_LOCK(container); - Ts[result->u.var].EA.offset = offset->value.lval; - Ts[result->u.var].EA.type = IS_STRING_OFFSET; - FREE_OP(op2, free_op2); - *retval = NULL; - return; - } - break; - default: { - zval *offset; - - offset = get_zval_ptr(op2, Ts, &free_op2, BP_VAR_R); - if (type==BP_VAR_R || type==BP_VAR_IS) { - *retval = &EG(uninitialized_zval_ptr); - } else { - *retval = &EG(error_zval_ptr); - } - FREE_OP(op2, free_op2); - SELECTIVE_PZVAL_LOCK(**retval, result); - } - break; - } -} - - -static inline void zend_fetch_dimension_address_from_tmp_var(znode *result, znode *op1, znode *op2, temp_variable *Ts ELS_DC) -{ - int free_op1; - zval *container = get_zval_ptr(op1, Ts, &free_op1, BP_VAR_R); - - if (container->type != IS_ARRAY) { - Ts[result->u.var].var.ptr_ptr = &EG(uninitialized_zval_ptr); - SELECTIVE_PZVAL_LOCK(*Ts[result->u.var].var.ptr_ptr, result); - return; - } - - Ts[result->u.var].var.ptr_ptr = zend_fetch_dimension_address_inner(container->value.ht, op2, Ts, BP_VAR_R ELS_CC); - SELECTIVE_PZVAL_LOCK(*Ts[result->u.var].var.ptr_ptr, result); -} - - -static inline void zend_fetch_property_address(znode *result, znode *op1, znode *op2, temp_variable *Ts, int type ELS_DC) -{ - int free_op2; - zval **container_ptr = get_zval_ptr_ptr(op1, Ts, type); - zval *container; - zval ***retval = &Ts[result->u.var].var.ptr_ptr; - - - if (container_ptr == NULL) { - zend_property_reference *property_reference; - zend_overloaded_element overloaded_element; - - if (Ts[op1->u.var].EA.type == IS_STRING_OFFSET) { - zval_ptr_dtor(&Ts[op1->u.var].EA.str); - switch (type) { - case BP_VAR_R: - case BP_VAR_IS: - *retval = &EG(uninitialized_zval_ptr); - break; - case BP_VAR_W: - case BP_VAR_RW: - *retval = &EG(error_zval_ptr); - break; - EMPTY_SWITCH_DEFAULT_CASE() - } - SELECTIVE_PZVAL_LOCK(**retval, result); - return; - } - - overloaded_element.element = *get_zval_ptr(op2, Ts, &free_op2, type); - overloaded_element.type = OE_IS_OBJECT; - if (!free_op2) { - zval_copy_ctor(&overloaded_element.element); - } - - zend_stack_top(&EG(overloaded_objects_stack), (void **) &property_reference); - - zend_llist_add_element(&property_reference->elements_list, &overloaded_element); - - Ts[result->u.var].EA.type = IS_OVERLOADED_OBJECT; - *retval = NULL; - return; - } - - container = *container_ptr; - if (container == EG(error_zval_ptr)) { - *retval = &EG(error_zval_ptr); - SELECTIVE_PZVAL_LOCK(**retval, result); - return; - } - - if (container->type == IS_OBJECT - && container->value.obj.ce->handle_property_get) { - zend_property_reference property_reference; - zend_overloaded_element overloaded_element; - - property_reference.object = container; - property_reference.type = type; - zend_llist_init(&property_reference.elements_list, sizeof(zend_overloaded_element), NULL, 0); - overloaded_element.element = *get_zval_ptr(op2, Ts, &free_op2, type); - overloaded_element.type = OE_IS_OBJECT; - if (!free_op2) { - zval_copy_ctor(&overloaded_element.element); - } - zend_llist_add_element(&property_reference.elements_list, &overloaded_element); - zend_stack_push(&EG(overloaded_objects_stack), &property_reference, sizeof(zend_property_reference)); - Ts[result->u.var].EA.type = IS_OVERLOADED_OBJECT; - *retval = NULL; - return; - } - - - - if (container->type == IS_STRING && container->value.str.len==0) { - switch (type) { - case BP_VAR_RW: - case BP_VAR_W: - if (!PZVAL_IS_REF(container)) { - container->refcount--; - if (container->refcount>0) { - ALLOC_ZVAL(container); - *container_ptr = container; - container->is_ref=0; - } - container->refcount=1; - } - object_init(container); - break; - } - } - - if (container->type != IS_OBJECT) { - zval *offset; - - offset = get_zval_ptr(op2, Ts, &free_op2, BP_VAR_R); - FREE_OP(op2, free_op2); - if (type==BP_VAR_R || type==BP_VAR_IS) { - *retval = &EG(uninitialized_zval_ptr); - } else { - *retval = &EG(error_zval_ptr); - } - SELECTIVE_PZVAL_LOCK(**retval, result); - return; - } - - - if ((type==BP_VAR_W || type==BP_VAR_RW) && container->refcount>1 && !PZVAL_IS_REF(container)) { - container->refcount--; - ALLOC_ZVAL(*container_ptr); - **container_ptr = *container; - container = *container_ptr; - INIT_PZVAL(container); - zendi_zval_copy_ctor(*container); - } - *retval = zend_fetch_property_address_inner(container->value.obj.properties, op2, Ts, type ELS_CC); - SEPARATE_ON_READ_OBJECT(*retval, type); - SELECTIVE_PZVAL_LOCK(**retval, result); -} - - -static zval get_overloaded_property(ELS_D) -{ - zend_property_reference *property_reference; - zval result; - - zend_stack_top(&EG(overloaded_objects_stack), (void **) &property_reference); - result = (property_reference->object)->value.obj.ce->handle_property_get(property_reference); - - zend_llist_destroy(&property_reference->elements_list); - - zend_stack_del_top(&EG(overloaded_objects_stack)); - return result; -} - - -static void set_overloaded_property(zval *value ELS_DC) -{ - zend_property_reference *property_reference; - - zend_stack_top(&EG(overloaded_objects_stack), (void **) &property_reference); - (property_reference->object)->value.obj.ce->handle_property_set(property_reference, value); - - zend_llist_destroy(&property_reference->elements_list); - - zend_stack_del_top(&EG(overloaded_objects_stack)); -} - - -static void call_overloaded_function(int arg_count, zval *return_value ELS_DC) -{ - zend_property_reference *property_reference; - - zend_stack_top(&EG(overloaded_objects_stack), (void **) &property_reference); - (property_reference->object)->value.obj.ce->handle_function_call(arg_count, return_value, property_reference->object, 1 ELS_CC, property_reference); - zend_llist_destroy(&property_reference->elements_list); - - zend_stack_del_top(&EG(overloaded_objects_stack)); -} - - -#if ZEND_INTENSIVE_DEBUGGING - -#define CHECK_SYMBOL_TABLES() \ - zend_hash_apply(&EG(symbol_table), (int (*)()) zend_check_symbol); \ - if (&EG(symbol_table)!=EG(active_symbol_table)) { \ - zend_hash_apply(EG(active_symbol_table), (int (*)()) zend_check_symbol); \ - } - -static int zend_check_symbol(zval **pz) -{ - if ((*pz)->type>9) { - fprintf(stderr, "Warning! %x has invalid type!\n", *pz); - } else if ((*pz)->type==IS_ARRAY) { - zend_hash_apply((*pz)->value.ht, (int (*)()) zend_check_symbol); - } else if ((*pz)->type==IS_OBJECT) { - zend_hash_apply((*pz)->value.obj.properties, (int (*)()) zend_check_symbol); - } - - return 0; -} - - -#else -#define CHECK_SYMBOL_TABLES() -#endif - - -#if (HAVE_ALLOCA || (defined (__GNUC__) && __GNUC__ >= 2)) && !(defined(ZTS) && defined(ZEND_WIN32)) -# define do_alloca(p) alloca(p) -# define free_alloca(p) -#else -# define do_alloca(p) emalloc(p) -# define free_alloca(p) efree(p) -#endif - -#define NEXT_OPCODE() \ - CHECK_SYMBOL_TABLES() \ - opline++; \ - continue; - -typedef struct _object_info { - zval *ptr; -} object_info; - -void execute(zend_op_array *op_array ELS_DC) -{ - zend_op *opline = op_array->opcodes; -#if SUPPORT_INTERACTIVE - zend_op *end = op_array->opcodes + op_array->last; -#endif - zend_function_state function_state; - zend_function *fbc=NULL; /* Function Being Called */ - object_info object = {NULL}; -#if ZEND_DEBUG || (!defined (__GNUC__) || __GNUC__ < 2) - temp_variable *Ts = (temp_variable *) do_alloca(sizeof(temp_variable)*op_array->T); -#else - temp_variable Ts[op_array->T]; -#endif - zend_bool original_in_execution=EG(in_execution); - - EG(in_execution) = 1; -#if SUPPORT_INTERACTIVE - if (EG(interactive)) { - opline = op_array->opcodes + op_array->start_op_number; - end = op_array->opcodes + op_array->end_op_number; - } -#endif - - EG(opline_ptr) = &opline; - - function_state.function = (zend_function *) op_array; - EG(function_state_ptr) = &function_state; -#if ZEND_DEBUG - /* function_state.function_symbol_table is saved as-is to a stack, - * which is an intentional UMR. Shut it up if we're in DEBUG. - */ - function_state.function_symbol_table = NULL; -#endif - - if (op_array->uses_globals) { - zval *globals; - - ALLOC_ZVAL(globals); - globals->refcount=1; - globals->is_ref=1; - globals->type = IS_ARRAY; - globals->value.ht = &EG(symbol_table); - if (zend_hash_add(EG(active_symbol_table), "GLOBALS", sizeof("GLOBALS"), &globals, sizeof(zval *), NULL)==FAILURE) { - FREE_ZVAL(globals); - } - } - -#if SUPPORT_INTERACTIVE - while (oplineopcode) { - case ZEND_ADD: - EG(binary_op) = add_function; - goto binary_op_addr; - case ZEND_SUB: - EG(binary_op) = sub_function; - goto binary_op_addr; - case ZEND_MUL: - EG(binary_op) = mul_function; - goto binary_op_addr; - case ZEND_DIV: - EG(binary_op) = div_function; - goto binary_op_addr; - case ZEND_MOD: - EG(binary_op) = mod_function; - goto binary_op_addr; - case ZEND_SL: - EG(binary_op) = shift_left_function; - goto binary_op_addr; - case ZEND_SR: - EG(binary_op) = shift_right_function; - goto binary_op_addr; - case ZEND_CONCAT: - EG(binary_op) = concat_function; - goto binary_op_addr; - case ZEND_IS_IDENTICAL: - EG(binary_op) = is_identical_function; - goto binary_op_addr; - case ZEND_IS_EQUAL: - EG(binary_op) = is_equal_function; - goto binary_op_addr; - case ZEND_IS_NOT_EQUAL: - EG(binary_op) = is_not_equal_function; - goto binary_op_addr; - case ZEND_IS_SMALLER: - EG(binary_op) = is_smaller_function; - goto binary_op_addr; - case ZEND_IS_SMALLER_OR_EQUAL: - EG(binary_op) = is_smaller_or_equal_function; - goto binary_op_addr; - case ZEND_BW_OR: - EG(binary_op) = bitwise_or_function; - goto binary_op_addr; - case ZEND_BW_AND: - EG(binary_op) = bitwise_and_function; - goto binary_op_addr; - case ZEND_BW_XOR: - EG(binary_op) = bitwise_xor_function; - goto binary_op_addr; - case ZEND_BOOL_XOR: - EG(binary_op) = boolean_xor_function; - /* Fall through */ -binary_op_addr: - EG(binary_op)(&Ts[opline->result.u.var].tmp_var, - get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R), - get_zval_ptr(&opline->op2, Ts, &EG(free_op2), BP_VAR_R) ); - FREE_OP(&opline->op1, EG(free_op1)); - FREE_OP(&opline->op2, EG(free_op2)); - NEXT_OPCODE(); - case ZEND_BW_NOT: - case ZEND_BOOL_NOT: - EG(unary_op) = get_unary_op(opline->opcode); - EG(unary_op)(&Ts[opline->result.u.var].tmp_var, - get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R) ); - FREE_OP(&opline->op1, EG(free_op1)); - NEXT_OPCODE(); - case ZEND_ASSIGN_ADD: - EG(binary_op) = add_function; - goto binary_assign_op_addr; - case ZEND_ASSIGN_SUB: - EG(binary_op) = sub_function; - goto binary_assign_op_addr; - case ZEND_ASSIGN_MUL: - EG(binary_op) = mul_function; - goto binary_assign_op_addr; - case ZEND_ASSIGN_DIV: - EG(binary_op) = div_function; - goto binary_assign_op_addr; - case ZEND_ASSIGN_MOD: - EG(binary_op) = mod_function; - goto binary_assign_op_addr; - case ZEND_ASSIGN_SL: - EG(binary_op) = shift_left_function; - goto binary_assign_op_addr; - case ZEND_ASSIGN_SR: - EG(binary_op) = shift_right_function; - goto binary_assign_op_addr; - case ZEND_ASSIGN_CONCAT: - EG(binary_op) = concat_function; - goto binary_assign_op_addr; - case ZEND_ASSIGN_BW_OR: - EG(binary_op) = bitwise_or_function; - goto binary_assign_op_addr; - case ZEND_ASSIGN_BW_AND: - EG(binary_op) = bitwise_and_function; - goto binary_assign_op_addr; - case ZEND_ASSIGN_BW_XOR: - EG(binary_op) = bitwise_xor_function; - /* Fall through */ -binary_assign_op_addr: { - zval **var_ptr = get_zval_ptr_ptr(&opline->op1, Ts, BP_VAR_RW); - - if (!var_ptr) { - zend_error(E_ERROR, "Cannot use assign-op operators with overloaded objects nor string offsets"); - } - if (*var_ptr == EG(error_zval_ptr)) { - Ts[opline->result.u.var].var.ptr_ptr = &EG(uninitialized_zval_ptr); - SELECTIVE_PZVAL_LOCK(*Ts[opline->result.u.var].var.ptr_ptr, &opline->result); - AI_USE_PTR(Ts[opline->result.u.var].var); - opline++; - continue; - } - if (!PZVAL_IS_REF(*var_ptr)) { - if ((*var_ptr)->refcount>1) { - zval *orig_var=*var_ptr; - - (*var_ptr)->refcount--; - ALLOC_ZVAL(*var_ptr); - **var_ptr = *orig_var; - zendi_zval_copy_ctor(**var_ptr); - (*var_ptr)->refcount=1; - } - } - EG(binary_op)(*var_ptr, *var_ptr, get_zval_ptr(&opline->op2, Ts, &EG(free_op2), BP_VAR_R)); - Ts[opline->result.u.var].var.ptr_ptr = var_ptr; - SELECTIVE_PZVAL_LOCK(*var_ptr, &opline->result); - FREE_OP(&opline->op2, EG(free_op2)); - AI_USE_PTR(Ts[opline->result.u.var].var); - } - NEXT_OPCODE(); - case ZEND_PRE_INC: - case ZEND_PRE_DEC: - case ZEND_POST_INC: - case ZEND_POST_DEC: { - int (*incdec_op)(zval *op); - zval **var_ptr = get_zval_ptr_ptr(&opline->op1, Ts, BP_VAR_RW); - - if (!var_ptr) { - zend_error(E_ERROR, "Cannot increment/decrement overloaded objects nor string offsets"); - } - if (*var_ptr == EG(error_zval_ptr)) { - Ts[opline->result.u.var].var.ptr_ptr = &EG(uninitialized_zval_ptr); - SELECTIVE_PZVAL_LOCK(*Ts[opline->result.u.var].var.ptr_ptr, &opline->result); - AI_USE_PTR(Ts[opline->result.u.var].var); - opline++; - continue; - } - - get_incdec_op(incdec_op, opline->opcode); - - switch (opline->opcode) { - case ZEND_POST_INC: - case ZEND_POST_DEC: - Ts[opline->result.u.var].tmp_var = **var_ptr; - zendi_zval_copy_ctor(Ts[opline->result.u.var].tmp_var); - break; - } - if (!PZVAL_IS_REF(*var_ptr)) { - if ((*var_ptr)->refcount>1) { - zval *orig_var = *var_ptr; - - (*var_ptr)->refcount--; - ALLOC_ZVAL(*var_ptr); - **var_ptr = *orig_var; - zendi_zval_copy_ctor(**var_ptr); - (*var_ptr)->refcount=1; - } - } - incdec_op(*var_ptr); - switch (opline->opcode) { - case ZEND_PRE_INC: - case ZEND_PRE_DEC: - Ts[opline->result.u.var].var.ptr_ptr = var_ptr; - SELECTIVE_PZVAL_LOCK(*var_ptr, &opline->result); - AI_USE_PTR(Ts[opline->result.u.var].var); - break; - } - } - NEXT_OPCODE(); - case ZEND_PRINT: - zend_print_variable(get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R)); - Ts[opline->result.u.var].tmp_var.value.lval = 1; - Ts[opline->result.u.var].tmp_var.type = IS_LONG; - FREE_OP(&opline->op1, EG(free_op1)); - NEXT_OPCODE(); - case ZEND_ECHO: - zend_print_variable(get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R)); - FREE_OP(&opline->op1, EG(free_op1)); - NEXT_OPCODE(); - case ZEND_FETCH_R: - zend_fetch_var_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_R ELS_CC); - AI_USE_PTR(Ts[opline->result.u.var].var); - NEXT_OPCODE(); - case ZEND_FETCH_W: - zend_fetch_var_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_W ELS_CC); - NEXT_OPCODE(); - case ZEND_FETCH_RW: - zend_fetch_var_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_RW ELS_CC); - NEXT_OPCODE(); - case ZEND_FETCH_FUNC_ARG: - if (ARG_SHOULD_BE_SENT_BY_REF(opline->extended_value, fbc, fbc->common.arg_types)) { - /* Behave like FETCH_W */ - zend_fetch_var_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_W ELS_CC); - } else { - /* Behave like FETCH_R */ - zend_fetch_var_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_R ELS_CC); - AI_USE_PTR(Ts[opline->result.u.var].var); - } - NEXT_OPCODE(); - case ZEND_FETCH_UNSET: - zend_fetch_var_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_R ELS_CC); - PZVAL_UNLOCK(*Ts[opline->result.u.var].var.ptr_ptr); - if (Ts[opline->result.u.var].var.ptr_ptr != &EG(uninitialized_zval_ptr)) { - SEPARATE_ZVAL_IF_NOT_REF(Ts[opline->result.u.var].var.ptr_ptr); - } - PZVAL_LOCK(*Ts[opline->result.u.var].var.ptr_ptr); - NEXT_OPCODE(); - case ZEND_FETCH_IS: - zend_fetch_var_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_IS ELS_CC); - AI_USE_PTR(Ts[opline->result.u.var].var); - NEXT_OPCODE(); - case ZEND_FETCH_DIM_R: - if (opline->extended_value == ZEND_FETCH_ADD_LOCK) { - PZVAL_LOCK(*Ts[opline->op1.u.var].var.ptr_ptr); - } - zend_fetch_dimension_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_R ELS_CC); - AI_USE_PTR(Ts[opline->result.u.var].var); - NEXT_OPCODE(); - case ZEND_FETCH_DIM_W: - zend_fetch_dimension_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_W ELS_CC); - NEXT_OPCODE(); - case ZEND_FETCH_DIM_RW: - zend_fetch_dimension_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_RW ELS_CC); - NEXT_OPCODE(); - case ZEND_FETCH_DIM_IS: - zend_fetch_dimension_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_IS ELS_CC); - AI_USE_PTR(Ts[opline->result.u.var].var); - NEXT_OPCODE(); - case ZEND_FETCH_DIM_FUNC_ARG: - if (ARG_SHOULD_BE_SENT_BY_REF(opline->extended_value, fbc, fbc->common.arg_types)) { - /* Behave like FETCH_DIM_W */ - zend_fetch_dimension_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_W ELS_CC); - } else { - /* Behave like FETCH_DIM_R, except for locking used for list() */ - zend_fetch_dimension_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_R ELS_CC); - AI_USE_PTR(Ts[opline->result.u.var].var); - } - NEXT_OPCODE(); - case ZEND_FETCH_DIM_UNSET: - /* Not needed in DIM_UNSET - if (opline->extended_value == ZEND_FETCH_ADD_LOCK) { - PZVAL_LOCK(*Ts[opline->op1.u.var].var.ptr_ptr); - } - */ - zend_fetch_dimension_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_R ELS_CC); - PZVAL_UNLOCK(*Ts[opline->result.u.var].var.ptr_ptr); - if (Ts[opline->result.u.var].var.ptr_ptr != &EG(uninitialized_zval_ptr)) { - SEPARATE_ZVAL_IF_NOT_REF(Ts[opline->result.u.var].var.ptr_ptr); - } - PZVAL_LOCK(*Ts[opline->result.u.var].var.ptr_ptr); - NEXT_OPCODE(); - case ZEND_FETCH_OBJ_R: - zend_fetch_property_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_R ELS_CC); - AI_USE_PTR(Ts[opline->result.u.var].var); - NEXT_OPCODE(); - case ZEND_FETCH_OBJ_W: - zend_fetch_property_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_W ELS_CC); - NEXT_OPCODE(); - case ZEND_FETCH_OBJ_RW: - zend_fetch_property_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_RW ELS_CC); - NEXT_OPCODE(); - case ZEND_FETCH_OBJ_IS: - zend_fetch_property_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_IS ELS_CC); - AI_USE_PTR(Ts[opline->result.u.var].var); - NEXT_OPCODE(); - case ZEND_FETCH_OBJ_FUNC_ARG: - if (ARG_SHOULD_BE_SENT_BY_REF(opline->extended_value, fbc, fbc->common.arg_types)) { - /* Behave like FETCH_OBJ_W */ - zend_fetch_property_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_W ELS_CC); - } else { - zend_fetch_property_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_R ELS_CC); - AI_USE_PTR(Ts[opline->result.u.var].var); - } - NEXT_OPCODE(); - case ZEND_FETCH_OBJ_UNSET: - zend_fetch_property_address(&opline->result, &opline->op1, &opline->op2, Ts, BP_VAR_R ELS_CC); - - PZVAL_UNLOCK(*Ts[opline->result.u.var].var.ptr_ptr); - if (Ts[opline->result.u.var].var.ptr_ptr != &EG(uninitialized_zval_ptr)) { - SEPARATE_ZVAL_IF_NOT_REF(Ts[opline->result.u.var].var.ptr_ptr); - } - PZVAL_LOCK(*Ts[opline->result.u.var].var.ptr_ptr); - NEXT_OPCODE(); - case ZEND_FETCH_DIM_TMP_VAR: - zend_fetch_dimension_address_from_tmp_var(&opline->result, &opline->op1, &opline->op2, Ts ELS_CC); - AI_USE_PTR(Ts[opline->result.u.var].var); - NEXT_OPCODE(); - case ZEND_ASSIGN: { - zval *value; - value = get_zval_ptr(&opline->op2, Ts, &EG(free_op2), BP_VAR_R); - - zend_assign_to_variable(&opline->result, &opline->op1, &opline->op2, value, (EG(free_op2)?IS_TMP_VAR:opline->op2.op_type), Ts ELS_CC); - /* zend_assign_to_variable() always takes care of op2, never free it! */ - } - NEXT_OPCODE(); - case ZEND_ASSIGN_REF: - zend_assign_to_variable_reference(&opline->result, get_zval_ptr_ptr(&opline->op1, Ts, BP_VAR_W), get_zval_ptr_ptr(&opline->op2, Ts, BP_VAR_W), Ts ELS_CC); - NEXT_OPCODE(); - case ZEND_JMP: -#if DEBUG_ZEND>=2 - printf("Jumping to %d\n", opline->op1.u.opline_num); -#endif - opline = &op_array->opcodes[opline->op1.u.opline_num]; - continue; - break; - case ZEND_JMPZ: { - znode *op1 = &opline->op1; - - if (!i_zend_is_true(get_zval_ptr(op1, Ts, &EG(free_op1), BP_VAR_R))) { -#if DEBUG_ZEND>=2 - printf("Conditional jmp to %d\n", opline->op2.u.opline_num); -#endif - opline = &op_array->opcodes[opline->op2.u.opline_num]; - FREE_OP(op1, EG(free_op1)); - continue; - } - FREE_OP(op1, EG(free_op1)); - } - NEXT_OPCODE(); - case ZEND_JMPNZ: { - znode *op1 = &opline->op1; - - if (zend_is_true(get_zval_ptr(op1, Ts, &EG(free_op1), BP_VAR_R))) { -#if DEBUG_ZEND>=2 - printf("Conditional jmp to %d\n", opline->op2.u.opline_num); -#endif - opline = &op_array->opcodes[opline->op2.u.opline_num]; - FREE_OP(op1, EG(free_op1)); - continue; - } - FREE_OP(op1, EG(free_op1)); - } - NEXT_OPCODE(); - case ZEND_JMPZNZ: { - znode *res = &opline->result; - - if (!zend_is_true(get_zval_ptr(res, Ts, &EG(free_op1), BP_VAR_R))) { -#if DEBUG_ZEND>=2 - printf("Conditional jmp on false to %d\n", opline->op2.u.opline_num); -#endif - opline = &op_array->opcodes[opline->op2.u.opline_num]; - } else { -#if DEBUG_ZEND>=2 - printf("Conditional jmp on true to %d\n", opline->op1.u.opline_num); -#endif - opline = &op_array->opcodes[opline->op1.u.opline_num]; - } - FREE_OP(res, EG(free_op1)); - } - continue; - break; - case ZEND_JMPZ_EX: { - zend_op *original_opline = opline; - int retval = zend_is_true(get_zval_ptr(&original_opline->op1, Ts, &EG(free_op1), BP_VAR_R)); - - if (!retval) { -#if DEBUG_ZEND>=2 - printf("Conditional jmp to %d\n", opline->op2.u.opline_num); -#endif - opline = &op_array->opcodes[opline->op2.u.opline_num]; - FREE_OP(&original_opline->op1, EG(free_op1)); - Ts[original_opline->result.u.var].tmp_var.value.lval = retval; - Ts[original_opline->result.u.var].tmp_var.type = IS_LONG; - continue; - } - FREE_OP(&original_opline->op1, EG(free_op1)); - Ts[original_opline->result.u.var].tmp_var.value.lval = retval; - Ts[original_opline->result.u.var].tmp_var.type = IS_LONG; - } - NEXT_OPCODE(); - case ZEND_JMPNZ_EX: { - zend_op *original_opline = opline; - int retval = zend_is_true(get_zval_ptr(&original_opline->op1, Ts, &EG(free_op1), BP_VAR_R)); - - if (retval) { -#if DEBUG_ZEND>=2 - printf("Conditional jmp to %d\n", opline->op2.u.opline_num); -#endif - opline = &op_array->opcodes[opline->op2.u.opline_num]; - FREE_OP(&original_opline->op1, EG(free_op1)); - Ts[original_opline->result.u.var].tmp_var.value.lval = retval; - Ts[original_opline->result.u.var].tmp_var.type = IS_LONG; - continue; - } - FREE_OP(&original_opline->op1, EG(free_op1)); - Ts[original_opline->result.u.var].tmp_var.value.lval = retval; - Ts[original_opline->result.u.var].tmp_var.type = IS_LONG; - } - NEXT_OPCODE(); - case ZEND_FREE: - zendi_zval_dtor(Ts[opline->op1.u.var].tmp_var); - NEXT_OPCODE(); - case ZEND_INIT_STRING: - Ts[opline->result.u.var].tmp_var.value.str.val = emalloc(1); - Ts[opline->result.u.var].tmp_var.value.str.val[0] = 0; - Ts[opline->result.u.var].tmp_var.value.str.len = 0; - Ts[opline->result.u.var].tmp_var.refcount = 1; - NEXT_OPCODE(); - case ZEND_ADD_CHAR: - add_char_to_string( &Ts[opline->result.u.var].tmp_var, - get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_NA), - &opline->op2.u.constant); - /* FREE_OP is missing intentionally here - we're always working on the same temporary variable */ - NEXT_OPCODE(); - case ZEND_ADD_STRING: - add_string_to_string( &Ts[opline->result.u.var].tmp_var, - get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_NA), - &opline->op2.u.constant); - /* FREE_OP is missing intentionally here - we're always working on the same temporary variable */ - NEXT_OPCODE(); - case ZEND_ADD_VAR: { - zval *var = get_zval_ptr(&opline->op2, Ts, &EG(free_op2), BP_VAR_R); - zval var_copy; - int use_copy; - - zend_make_printable_zval(var, &var_copy, &use_copy); - if (use_copy) { - var = &var_copy; - } - add_string_to_string( &Ts[opline->result.u.var].tmp_var, - get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_NA), - var); - if (use_copy) { - zval_dtor(var); - } - /* original comment, possibly problematic: - * FREE_OP is missing intentionally here - we're always working on the same temporary variable - * (Zeev): I don't think it's problematic, we only use variables - * which aren't affected by FREE_OP()'s anyway, unless they're - * string offsets or overloaded objects - */ - FREE_OP(&opline->op2, EG(free_op2)); - } - NEXT_OPCODE(); - case ZEND_INIT_FCALL_BY_NAME: { - zval *function_name; - zend_function *function; - HashTable *active_function_table; - zval tmp; - - zend_ptr_stack_n_push(&EG(arg_types_stack), 2, fbc, object.ptr); - if (opline->extended_value & ZEND_CTOR_CALL) { - /* constructor call */ - - if (opline->op1.op_type == IS_VAR) { - PZVAL_LOCK(*Ts[opline->op1.u.var].var.ptr_ptr); - } - if (opline->op2.op_type==IS_VAR) { - PZVAL_LOCK(*Ts[opline->op2.u.var].var.ptr_ptr); - } - } - function_name = get_zval_ptr(&opline->op2, Ts, &EG(free_op2), BP_VAR_R); - - tmp = *function_name; - zval_copy_ctor(&tmp); - convert_to_string(&tmp); - function_name = &tmp; - zend_str_tolower(tmp.value.str.val, tmp.value.str.len); - - if (opline->op1.op_type != IS_UNUSED) { - if (opline->op1.op_type==IS_CONST) { /* used for class_name::function() */ - zend_class_entry *ce; - zval **object_ptr_ptr; - - if (zend_hash_find(EG(class_table), opline->op1.u.constant.value.str.val, opline->op1.u.constant.value.str.len+1, (void **) &ce)==FAILURE) { - zend_error(E_ERROR, "Undefined class name '%s'", opline->op1.u.constant.value.str.val); - } - active_function_table = &ce->function_table; - if (zend_hash_find(EG(active_symbol_table), "this", sizeof("this"), (void **) &object_ptr_ptr)==FAILURE) { - object.ptr=NULL; - } else { - /* We assume that "this" is already is_ref and pointing to the object. - If it isn't then tough */ - object.ptr = *object_ptr_ptr; - object.ptr->refcount++; /* For this pointer */ - } - } else { /* used for member function calls */ - object.ptr = _get_object_zval_ptr(&opline->op1, Ts, &EG(free_op1) ELS_CC); - - if ((!object.ptr && Ts[opline->op1.u.var].EA.type==IS_OVERLOADED_OBJECT) - || ((object.ptr && object.ptr->type==IS_OBJECT) && (object.ptr->value.obj.ce->handle_function_call))) { /* overloaded function call */ - zend_overloaded_element overloaded_element; - zend_property_reference *property_reference; - - overloaded_element.element = *function_name; - overloaded_element.type = OE_IS_METHOD; - - if (object.ptr) { - zend_property_reference property_reference; - - property_reference.object = object.ptr; - property_reference.type = BP_VAR_NA; - zend_llist_init(&property_reference.elements_list, sizeof(zend_overloaded_element), NULL, 0); - zend_stack_push(&EG(overloaded_objects_stack), &property_reference, sizeof(zend_property_reference)); - } - zend_stack_top(&EG(overloaded_objects_stack), (void **) &property_reference); - zend_llist_add_element(&property_reference->elements_list, &overloaded_element); - fbc = (zend_function *) emalloc(sizeof(zend_function)); - fbc->type = ZEND_OVERLOADED_FUNCTION; - fbc->common.arg_types = NULL; - goto overloaded_function_call_cont; - } - - if (!object.ptr || object.ptr->type != IS_OBJECT) { - zend_error(E_ERROR, "Call to a member function on a non-object"); - } - object.ptr->refcount++; /* For this pointer */ - active_function_table = &(object.ptr->value.obj.ce->function_table); - } - } else { /* function pointer */ - object.ptr = NULL; - active_function_table = EG(function_table); - } - if (zend_hash_find(active_function_table, function_name->value.str.val, function_name->value.str.len+1, (void **) &function)==FAILURE) { - zend_error(E_ERROR, "Call to undefined function: %s()", function_name->value.str.val); - } - zval_dtor(&tmp); - fbc = function; -overloaded_function_call_cont: - FREE_OP(&opline->op2, EG(free_op2)); - } - NEXT_OPCODE(); - case ZEND_DO_FCALL_BY_NAME: - function_state.function = fbc; - goto do_fcall_common; - case ZEND_DO_FCALL: { - zval *fname = get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R); - - if (zend_hash_find(EG(function_table), fname->value.str.val, fname->value.str.len+1, (void **) &function_state.function)==FAILURE) { - zend_error(E_ERROR, "Unknown function: %s()\n", fname->value.str.val); - } - FREE_OP(&opline->op1, EG(free_op1)); - zend_ptr_stack_push(&EG(arg_types_stack), object.ptr); - object.ptr = NULL; - goto do_fcall_common; - } -do_fcall_common: - { - zval **original_return_value; - int return_value_used = RETURN_VALUE_USED(opline); - - zend_ptr_stack_push(&EG(argument_stack), (void *) opline->extended_value); - - Ts[opline->result.u.var].var.ptr_ptr = &Ts[opline->result.u.var].var.ptr; - - if (function_state.function->type==ZEND_INTERNAL_FUNCTION) { - ALLOC_ZVAL(Ts[opline->result.u.var].var.ptr); - INIT_ZVAL(*(Ts[opline->result.u.var].var.ptr)); - ((zend_internal_function *) function_state.function)->handler(opline->extended_value, Ts[opline->result.u.var].var.ptr, object.ptr, return_value_used ELS_CC); - if (object.ptr) { - object.ptr->refcount--; - } - Ts[opline->result.u.var].var.ptr->is_ref = 0; - Ts[opline->result.u.var].var.ptr->refcount = 1; - if (!return_value_used) { - zval_ptr_dtor(&Ts[opline->result.u.var].var.ptr); - } - } else if (function_state.function->type==ZEND_USER_FUNCTION) { - HashTable *calling_symbol_table; - - Ts[opline->result.u.var].var.ptr = NULL; - if (EG(symtable_cache_ptr)>=EG(symtable_cache)) { - /*printf("Cache hit! Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/ - function_state.function_symbol_table = *(EG(symtable_cache_ptr)--); - } else { - ALLOC_HASHTABLE(function_state.function_symbol_table); - zend_hash_init(function_state.function_symbol_table, 0, NULL, ZVAL_PTR_DTOR, 0); - /*printf("Cache miss! Initialized %x\n", function_state.function_symbol_table);*/ - } - calling_symbol_table = EG(active_symbol_table); - EG(active_symbol_table) = function_state.function_symbol_table; - if (opline->opcode==ZEND_DO_FCALL_BY_NAME - && object.ptr - && fbc->type!=ZEND_OVERLOADED_FUNCTION) { - zval **this_ptr; - - zend_hash_update_ptr(function_state.function_symbol_table, "this", sizeof("this"), NULL, sizeof(zval *), (void **) &this_ptr); - if (!PZVAL_IS_REF(object.ptr)) { - zend_error(E_WARNING,"Problem with method call. Report this bug\n"); - } - *this_ptr = object.ptr; - object.ptr = NULL; - } - original_return_value = EG(return_value_ptr_ptr); - EG(return_value_ptr_ptr) = Ts[opline->result.u.var].var.ptr_ptr; - EG(active_op_array) = (zend_op_array *) function_state.function; - - zend_execute(EG(active_op_array) ELS_CC); - - if (return_value_used && !Ts[opline->result.u.var].var.ptr) { - ALLOC_ZVAL(Ts[opline->result.u.var].var.ptr); - INIT_ZVAL(*Ts[opline->result.u.var].var.ptr); - } else if (!return_value_used && Ts[opline->result.u.var].var.ptr) { - zval_ptr_dtor(&Ts[opline->result.u.var].var.ptr); - } - EG(opline_ptr) = &opline; - EG(active_op_array) = op_array; - EG(return_value_ptr_ptr)=original_return_value; - if (EG(symtable_cache_ptr)>=EG(symtable_cache_limit)) { - zend_hash_destroy(function_state.function_symbol_table); - FREE_HASHTABLE(function_state.function_symbol_table); - } else { - *(++EG(symtable_cache_ptr)) = function_state.function_symbol_table; - zend_hash_clean(*EG(symtable_cache_ptr)); - } - EG(active_symbol_table) = calling_symbol_table; - } else { /* ZEND_OVERLOADED_FUNCTION */ - ALLOC_ZVAL(Ts[opline->result.u.var].var.ptr); - INIT_ZVAL(*(Ts[opline->result.u.var].var.ptr)); - call_overloaded_function(opline->extended_value, Ts[opline->result.u.var].var.ptr ELS_CC); - efree(fbc); - if (!return_value_used) { - zval_ptr_dtor(&Ts[opline->result.u.var].var.ptr); - } - } - object.ptr = zend_ptr_stack_pop(&EG(arg_types_stack)); - if (opline->opcode == ZEND_DO_FCALL_BY_NAME) { - fbc = zend_ptr_stack_pop(&EG(arg_types_stack)); - } - function_state.function = (zend_function *) op_array; - EG(function_state_ptr) = &function_state; - zend_ptr_stack_clear_multiple(ELS_C); - } - NEXT_OPCODE(); - case ZEND_RETURN: { - zval *retval_ptr; - zval **retval_ptr_ptr; - - if ((EG(active_op_array)->return_reference == ZEND_RETURN_REF) && - (opline->op1.op_type != IS_CONST) && - (opline->op1.op_type != IS_TMP_VAR)) { - - retval_ptr_ptr = get_zval_ptr_ptr(&opline->op1, Ts, BP_VAR_W); - - if (!PZVAL_IS_REF(*retval_ptr_ptr)) { - SEPARATE_ZVAL(retval_ptr_ptr); - (*retval_ptr_ptr)->is_ref = 1; - } - (*retval_ptr_ptr)->refcount++; - (*EG(return_value_ptr_ptr)) = (*retval_ptr_ptr); - } else { - retval_ptr = get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R); - - if (!EG(free_op1)) { /* Not a temp var */ - if (PZVAL_IS_REF(retval_ptr) && retval_ptr->refcount > 0) { - ALLOC_ZVAL(*(EG(return_value_ptr_ptr))); - **EG(return_value_ptr_ptr) = *retval_ptr; - (*EG(return_value_ptr_ptr))->is_ref = 0; - (*EG(return_value_ptr_ptr))->refcount = 1; - zval_copy_ctor(*EG(return_value_ptr_ptr)); - } else { - *EG(return_value_ptr_ptr) = retval_ptr; - retval_ptr->refcount++; - } - } else { - ALLOC_ZVAL(*(EG(return_value_ptr_ptr))); - **EG(return_value_ptr_ptr) = *retval_ptr; - (*EG(return_value_ptr_ptr))->refcount = 1; - (*EG(return_value_ptr_ptr))->is_ref = 0; - } - } -#if SUPPORT_INTERACTIVE - op_array->last_executed_op_number = opline-op_array->opcodes; -#endif - free_alloca(Ts); - EG(in_execution) = original_in_execution; - return; - } - break; - case ZEND_SEND_VAL: - if (opline->extended_value==ZEND_DO_FCALL_BY_NAME - && ARG_SHOULD_BE_SENT_BY_REF(opline->op2.u.opline_num, fbc, fbc->common.arg_types)) { - zend_error(E_ERROR, "Cannot pass parameter %d by reference", opline->op2.u.opline_num); - } - { - zval *valptr; - - ALLOC_ZVAL(valptr); - *valptr = Ts[opline->op1.u.var].tmp_var; - INIT_PZVAL(valptr); - zend_ptr_stack_push(&EG(argument_stack), valptr); - } - NEXT_OPCODE(); - case ZEND_SEND_VAR: - if (opline->extended_value==ZEND_DO_FCALL_BY_NAME - && ARG_SHOULD_BE_SENT_BY_REF(opline->op2.u.opline_num, fbc, fbc->common.arg_types)) { - goto send_by_ref; - } - { - zval *varptr; - varptr = get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R); - - if (varptr == &EG(uninitialized_zval)) { - ALLOC_ZVAL(varptr); - INIT_ZVAL(*varptr); - varptr->refcount = 0; - } else if (PZVAL_IS_REF(varptr)) { - zval *original_var = varptr; - - ALLOC_ZVAL(varptr); - *varptr = *original_var; - varptr->is_ref = 0; - varptr->refcount = 0; - zval_copy_ctor(varptr); - } - varptr->refcount++; - zend_ptr_stack_push(&EG(argument_stack), varptr); - FREE_OP(&opline->op1, EG(free_op1)); /* for string offsets */ - } - NEXT_OPCODE(); -send_by_ref: - case ZEND_SEND_REF: { - zval **varptr_ptr; - zval *varptr; - varptr_ptr = get_zval_ptr_ptr(&opline->op1, Ts, BP_VAR_W); - - varptr = *varptr_ptr; - - if (!PZVAL_IS_REF(varptr)) { - /* code to break away this variable */ - if (varptr->refcount>1) { - varptr->refcount--; - ALLOC_ZVAL(*varptr_ptr); - **varptr_ptr = *varptr; - varptr = *varptr_ptr; - varptr->refcount = 1; - zval_copy_ctor(varptr); - } - varptr->is_ref = 1; - /* at the end of this code refcount is always 1 */ - } - varptr->refcount++; - zend_ptr_stack_push(&EG(argument_stack), varptr); - } - NEXT_OPCODE(); - case ZEND_RECV: { - zval **param; - - if (zend_ptr_stack_get_arg(opline->op1.u.constant.value.lval, (void **) ¶m ELS_CC)==FAILURE) { - zend_error(E_NOTICE, "Missing argument %d for %s()\n", opline->op1.u.constant.value.lval, get_active_function_name()); - if (opline->result.op_type == IS_VAR) { - PZVAL_UNLOCK(*Ts[opline->result.u.var].var.ptr_ptr); - } - } else if (PZVAL_IS_REF(*param)) { - zend_assign_to_variable_reference(NULL, get_zval_ptr_ptr(&opline->result, Ts, BP_VAR_W), param, NULL ELS_CC); - } else { - zend_assign_to_variable(NULL, &opline->result, NULL, *param, IS_VAR, Ts ELS_CC); - } - } - NEXT_OPCODE(); - case ZEND_RECV_INIT: { - zval **param, *assignment_value; - - if (zend_ptr_stack_get_arg(opline->op1.u.constant.value.lval, (void **) ¶m ELS_CC)==FAILURE) { - if (opline->op2.u.constant.type == IS_CONSTANT) { - zval *default_value; - zval tmp; - - ALLOC_ZVAL(default_value); - *default_value = opline->op2.u.constant; - if (!zend_get_constant(default_value->value.str.val, default_value->value.str.len, &tmp)) { - default_value->type = IS_STRING; - zval_copy_ctor(default_value); - } else { - *default_value = tmp; - } - default_value->refcount=0; - default_value->is_ref=0; - param = &default_value; - assignment_value = default_value; - } else { - param = NULL; - assignment_value = &opline->op2.u.constant; - } - } else { - assignment_value = *param; - } - - if (PZVAL_IS_REF(assignment_value)) { - zend_assign_to_variable_reference(NULL, get_zval_ptr_ptr(&opline->result, Ts, BP_VAR_W), param, NULL ELS_CC); - } else { - zend_assign_to_variable(NULL, &opline->result, NULL, assignment_value, IS_VAR, Ts ELS_CC); - } - } - NEXT_OPCODE(); - case ZEND_BOOL: - /* PHP 3.0 returned "" for false and 1 for true, here we use 0 and 1 for now */ - Ts[opline->result.u.var].tmp_var.value.lval = zend_is_true(get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R)); - Ts[opline->result.u.var].tmp_var.type = IS_LONG; - FREE_OP(&opline->op1, EG(free_op1)); - NEXT_OPCODE(); - case ZEND_BRK: - case ZEND_CONT: { - zval *nest_levels_zval = get_zval_ptr(&opline->op2, Ts, &EG(free_op2), BP_VAR_R); - zval tmp; - int array_offset, nest_levels, original_nest_levels; - zend_brk_cont_element *jmp_to; - - if (nest_levels_zval->type != IS_LONG) { - tmp = *nest_levels_zval; - zval_copy_ctor(&tmp); - convert_to_long(&tmp); - nest_levels = tmp.value.lval; - } else { - nest_levels = nest_levels_zval->value.lval; - } - original_nest_levels = nest_levels; - array_offset = opline->op1.u.opline_num; - do { - if (array_offset==-1) { - zend_error(E_ERROR, "Cannot break/continue %d levels\n", original_nest_levels); - } - jmp_to = &op_array->brk_cont_array[array_offset]; - if (nest_levels>1) { - zend_op *brk_opline = &op_array->opcodes[jmp_to->brk]; - - switch (brk_opline->opcode) { - case ZEND_SWITCH_FREE: - zend_switch_free(brk_opline, Ts ELS_CC); - break; - case ZEND_FREE: - zendi_zval_dtor(Ts[brk_opline->op1.u.var].tmp_var); - break; - } - } - array_offset = jmp_to->parent; - } while (--nest_levels > 0); - - if (opline->opcode == ZEND_BRK) { - opline = op_array->opcodes+jmp_to->brk; - } else { - opline = op_array->opcodes+jmp_to->cont; - } - FREE_OP(&opline->op2, EG(free_op2)); - continue; - } - NEXT_OPCODE(); - case ZEND_CASE: { - int switch_expr_is_overloaded=0; - - if (opline->op1.op_type==IS_VAR) { - if (Ts[opline->op1.u.var].var.ptr_ptr) { - PZVAL_LOCK(*Ts[opline->op1.u.var].var.ptr_ptr); - } else { - switch_expr_is_overloaded = 1; - if (Ts[opline->op1.u.var].EA.type==IS_STRING_OFFSET) { - Ts[opline->op1.u.var].EA.str->refcount++; - } - } - } - is_equal_function(&Ts[opline->result.u.var].tmp_var, - get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R), - get_zval_ptr(&opline->op2, Ts, &EG(free_op2), BP_VAR_R)); - - FREE_OP(&opline->op2, EG(free_op2)); - if (switch_expr_is_overloaded) { - /* We only free op1 if this is a string offset, - * Since if it is a TMP_VAR, it'll be reused by - * other CASE opcodes (whereas string offsets - * are allocated at each get_zval_ptr()) - */ - FREE_OP(&opline->op1, EG(free_op1)); - Ts[opline->op1.u.var].var.ptr_ptr = NULL; - AI_USE_PTR(Ts[opline->op1.u.var].var); - } - } - NEXT_OPCODE(); - case ZEND_SWITCH_FREE: - zend_switch_free(opline, Ts ELS_CC); - NEXT_OPCODE(); - case ZEND_NEW: { - zval *tmp = get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R); - zval class_name; - zend_class_entry *ce; - - class_name = *tmp; - zval_copy_ctor(&class_name); - convert_to_string(&class_name); - zend_str_tolower(class_name.value.str.val, class_name.value.str.len); - - if (zend_hash_find(EG(class_table), class_name.value.str.val, class_name.value.str.len+1, (void **) &ce)==FAILURE) { - zend_error(E_ERROR, "Cannot instanciate non-existant class: %s", class_name.value.str.val); - } - object_init_ex(&Ts[opline->result.u.var].tmp_var, ce); - Ts[opline->result.u.var].tmp_var.refcount=1; - Ts[opline->result.u.var].tmp_var.is_ref=1; - zval_dtor(&class_name); - FREE_OP(&opline->op1, EG(free_op1)); - } - NEXT_OPCODE(); - case ZEND_FETCH_CONSTANT: - if (!zend_get_constant(opline->op1.u.constant.value.str.val, opline->op1.u.constant.value.str.len, &Ts[opline->result.u.var].tmp_var)) { - zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", - opline->op1.u.constant.value.str.val, - opline->op1.u.constant.value.str.val); - Ts[opline->result.u.var].tmp_var = opline->op1.u.constant; - zval_copy_ctor(&Ts[opline->result.u.var].tmp_var); - } - NEXT_OPCODE(); - case ZEND_INIT_ARRAY: - case ZEND_ADD_ARRAY_ELEMENT: { - zval *array_ptr = &Ts[opline->result.u.var].tmp_var; - zval *expr_ptr, **expr_ptr_ptr = NULL; - zval *offset=get_zval_ptr(&opline->op2, Ts, &EG(free_op2), BP_VAR_R); - - if (opline->extended_value) { - expr_ptr_ptr=get_zval_ptr_ptr(&opline->op1, Ts, BP_VAR_R); - expr_ptr = *expr_ptr_ptr; - } else { - expr_ptr=get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R); - } - - if (opline->opcode==ZEND_INIT_ARRAY) { - array_init(array_ptr); - if (!expr_ptr) { - NEXT_OPCODE(); - } - } - if (opline->op1.op_type == IS_TMP_VAR) { /* temporary variable */ - zval *new_expr; - - ALLOC_ZVAL(new_expr); - *new_expr = *expr_ptr; - expr_ptr = new_expr; - INIT_PZVAL(expr_ptr); - } else { - if (opline->extended_value) { - if (!PZVAL_IS_REF(expr_ptr)) { - SEPARATE_ZVAL(expr_ptr_ptr); - expr_ptr = *expr_ptr_ptr; - expr_ptr->is_ref = 1; - } - expr_ptr->refcount++; - } else if (PZVAL_IS_REF(expr_ptr)) { - zval *new_expr; - - ALLOC_ZVAL(new_expr); - *new_expr = *expr_ptr; - expr_ptr = new_expr; - zendi_zval_copy_ctor(*expr_ptr); - INIT_PZVAL(expr_ptr); - } else { - expr_ptr->refcount++; - } - } - if (offset) { - switch(offset->type) { - case IS_DOUBLE: - zend_hash_index_update(array_ptr->value.ht, (long) offset->value.lval, &expr_ptr, sizeof(zval *), NULL); - break; - case IS_LONG: - zend_hash_index_update(array_ptr->value.ht, offset->value.lval, &expr_ptr, sizeof(zval *), NULL); - break; - case IS_STRING: - zend_hash_update(array_ptr->value.ht, offset->value.str.val, offset->value.str.len+1, &expr_ptr, sizeof(zval *), NULL); - break; - default: - /* do nothing */ - break; - } - FREE_OP(&opline->op2, EG(free_op2)); - } else { - zend_hash_next_index_insert(array_ptr->value.ht, &expr_ptr, sizeof(zval *), NULL); - } - } - NEXT_OPCODE(); - case ZEND_CAST: { - zval *expr = get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R); - zval *result = &Ts[opline->result.u.var].tmp_var; - - *result = *expr; - if (!EG(free_op1)) { - zendi_zval_copy_ctor(*result); - } - switch (opline->op2.u.constant.type) { - case IS_NULL: - convert_to_unset(result); - break; - case IS_BOOL: - convert_to_boolean(result); - break; - case IS_LONG: - convert_to_long(result); - break; - case IS_DOUBLE: - convert_to_double(result); - break; - case IS_STRING: - convert_to_string(result); - break; - case IS_ARRAY: - convert_to_array(result); - break; - case IS_OBJECT: - convert_to_object(result); - break; - } - } - NEXT_OPCODE(); - case ZEND_INCLUDE_OR_EVAL: { - zend_op_array *new_op_array=NULL; - zval **original_return_value = EG(return_value_ptr_ptr); - int return_value_used; - CLS_FETCH(); - - return_value_used = RETURN_VALUE_USED(opline); - - switch (opline->op2.u.constant.value.lval) { - case ZEND_INCLUDE: - case ZEND_IMPORT: - 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); - break; - case ZEND_EVAL: - new_op_array = compile_string(get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R) CLS_CC); - break; - EMPTY_SWITCH_DEFAULT_CASE() - } - FREE_OP(&opline->op1, EG(free_op1)); - Ts[opline->result.u.var].var.ptr = NULL; - Ts[opline->result.u.var].var.ptr_ptr = &Ts[opline->result.u.var].var.ptr; - if (new_op_array) { - EG(return_value_ptr_ptr) = Ts[opline->result.u.var].var.ptr_ptr; - EG(active_op_array) = new_op_array; - - zend_execute(new_op_array ELS_CC); - - if (!return_value_used) { - if (Ts[opline->result.u.var].var.ptr) { - zval_ptr_dtor(&Ts[opline->result.u.var].var.ptr); - } - } else { /* return value is used */ - if (!Ts[opline->result.u.var].var.ptr) { /* there was no return statement */ - ALLOC_ZVAL(Ts[opline->result.u.var].var.ptr); - INIT_PZVAL(Ts[opline->result.u.var].var.ptr); - Ts[opline->result.u.var].var.ptr->value.lval = 1; - Ts[opline->result.u.var].var.ptr->type = IS_LONG; - } - } - - EG(opline_ptr) = &opline; - EG(active_op_array) = op_array; - EG(function_state_ptr) = &function_state; - destroy_op_array(new_op_array); - efree(new_op_array); - } else { - if (return_value_used) { - ALLOC_ZVAL(Ts[opline->result.u.var].var.ptr); - INIT_ZVAL(*Ts[opline->result.u.var].var.ptr); - } - } - EG(return_value_ptr_ptr) = original_return_value; - } - NEXT_OPCODE(); - case ZEND_UNSET_VAR: { - zval tmp, *variable = get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R); - - if (variable->type != IS_STRING) { - tmp = *variable; - zval_copy_ctor(&tmp); - convert_to_string(&tmp); - variable = &tmp; - } - - zend_hash_del(EG(active_symbol_table), variable->value.str.val, variable->value.str.len+1); - - if (variable == &tmp) { - zval_dtor(&tmp); - } - FREE_OP(&opline->op1, EG(free_op1)); - } - NEXT_OPCODE(); - case ZEND_UNSET_DIM_OBJ: { - zval **container = get_zval_ptr_ptr(&opline->op1, Ts, BP_VAR_R); - zval *offset = get_zval_ptr(&opline->op2, Ts, &EG(free_op2), BP_VAR_R); - - if (container) { - HashTable *ht; - - switch ((*container)->type) { - case IS_ARRAY: - ht = (*container)->value.ht; - break; - case IS_OBJECT: - ht = (*container)->value.obj.properties; - break; - default: - ht = NULL; - break; - } - if (ht) { - switch (offset->type) { - case IS_LONG: - zend_hash_index_del(ht, offset->value.lval); - break; - case IS_STRING: - zend_hash_del(ht, offset->value.str.val, offset->value.str.len+1); - break; - } - } - } else { - /* overloaded element */ - } - FREE_OP(&opline->op2, EG(free_op2)); - } - NEXT_OPCODE(); - case ZEND_FE_RESET: { - zval *array_ptr; - HashTable *fe_ht; - - array_ptr = get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R); - - if (EG(free_op1)) { /* IS_TMP_VAR */ - zval *tmp; - - ALLOC_ZVAL(tmp); - *tmp = *array_ptr; - INIT_PZVAL(tmp); - array_ptr = tmp; - } else { - array_ptr->refcount++; - } - - PZVAL_LOCK(array_ptr); - Ts[opline->result.u.var].var.ptr = array_ptr; - Ts[opline->result.u.var].var.ptr_ptr = &Ts[opline->result.u.var].var.ptr; - - if ((fe_ht = HASH_OF(array_ptr)) != NULL) { - /* probably redundant */ - zend_hash_internal_pointer_reset(fe_ht); - } else { - /* JMP to the end of foreach - TBD */ - } - } - NEXT_OPCODE(); - case ZEND_FE_FETCH: { - zval *array = get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R); - zval *result = &Ts[opline->result.u.var].tmp_var; - zval **value, *key; - char *str_key; - ulong int_key; - HashTable *fe_ht; - - PZVAL_LOCK(array); - - fe_ht = HASH_OF(array); - - if (!fe_ht) { - zend_error(E_WARNING, "Invalid argument supplied for foreach()"); - opline = op_array->opcodes+opline->op2.u.opline_num; - continue; - } else if (zend_hash_get_current_data(fe_ht, (void **) &value)==FAILURE) { - opline = op_array->opcodes+opline->op2.u.opline_num; - continue; - } - array_init(result); - - - (*value)->refcount++; - zend_hash_index_update(result->value.ht, 0, value, sizeof(zval *), NULL); - - ALLOC_ZVAL(key); - INIT_PZVAL(key); - switch (zend_hash_get_current_key(fe_ht, &str_key, &int_key)) { - case HASH_KEY_IS_STRING: - key->value.str.val = str_key; - key->value.str.len = strlen(str_key); - key->type = IS_STRING; - break; - case HASH_KEY_IS_LONG: - key->value.lval = int_key; - key->type = IS_LONG; - break; - EMPTY_SWITCH_DEFAULT_CASE() - } - zend_hash_index_update(result->value.ht, 1, &key, sizeof(zval *), NULL); - zend_hash_move_forward(fe_ht); - } - NEXT_OPCODE(); - case ZEND_JMP_NO_CTOR: { - zval *object; - - if (opline->op1.op_type == IS_VAR) { - PZVAL_LOCK(*Ts[opline->op1.u.var].var.ptr_ptr); - } - - object = get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R); - if (!object->value.obj.ce->handle_function_call - && !zend_hash_exists(&object->value.obj.ce->function_table, object->value.obj.ce->name, object->value.obj.ce->name_length+1)) { - opline = op_array->opcodes + opline->op2.u.opline_num; - continue; - } - } - NEXT_OPCODE(); - case ZEND_ISSET_ISEMPTY: { - zval **var = get_zval_ptr_ptr(&opline->op1, Ts, BP_VAR_IS); - int isset; - - if (!var) { - if (Ts[opline->op1.u.var].EA.type==IS_STRING_OFFSET) { - if (Ts[opline->op1.u.var].EA.offset>=0 - && Ts[opline->op1.u.var].EA.offsetop1.u.var].EA.str->value.str.len) { - isset = 1; - } else { - isset = 0; - } - } else { - isset = 1; - } - } else if (*var==EG(uninitialized_zval_ptr) - || ((*var)->type == IS_NULL)) { - isset = 0; - } else { - isset = 1; - } - - switch (opline->op2.u.constant.value.lval) { - case ZEND_ISSET: - Ts[opline->result.u.var].tmp_var.value.lval = isset; - break; - case ZEND_ISEMPTY: - if (!var) { - if (!isset - || Ts[opline->op1.u.var].EA.str->value.str.val[Ts[opline->op1.u.var].EA.offset]=='0') { - Ts[opline->result.u.var].tmp_var.value.lval = 1; - } else { - Ts[opline->result.u.var].tmp_var.value.lval = 0; - } - } else if (!isset || !zend_is_true((*var))) { - Ts[opline->result.u.var].tmp_var.value.lval = 1; - } else { - Ts[opline->result.u.var].tmp_var.value.lval = 0; - } - break; - } - Ts[opline->result.u.var].tmp_var.type = IS_BOOL; - } - NEXT_OPCODE(); - case ZEND_EXIT: - if (opline->op1.op_type != IS_UNUSED) { - zend_print_variable(get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R)); - FREE_OP(&opline->op1, EG(free_op1)); - } - zend_bailout(); - NEXT_OPCODE(); - case ZEND_BEGIN_SILENCE: - Ts[opline->result.u.var].tmp_var.value.lval = EG(error_reporting); - Ts[opline->result.u.var].tmp_var.type = IS_LONG; /* shouldn't be necessary */ - EG(error_reporting) = 0; - NEXT_OPCODE(); - case ZEND_END_SILENCE: - EG(error_reporting) = Ts[opline->op1.u.var].tmp_var.value.lval; - NEXT_OPCODE(); - case ZEND_QM_ASSIGN: { - zval *value = get_zval_ptr(&opline->op1, Ts, &EG(free_op1), BP_VAR_R); - - Ts[opline->result.u.var].tmp_var = *value; - if (!EG(free_op1)) { - zval_copy_ctor(&Ts[opline->result.u.var].tmp_var); - } - } - NEXT_OPCODE(); - case ZEND_EXT_STMT: - if (!EG(no_extensions)) { - zend_llist_apply_with_argument(&zend_extensions, (void (*)(void *, void *)) zend_extension_statement_handler, op_array); - } - NEXT_OPCODE(); - case ZEND_EXT_FCALL_BEGIN: - if (!EG(no_extensions)) { - zend_llist_apply_with_argument(&zend_extensions, (void (*)(void *, void *)) zend_extension_fcall_begin_handler, op_array); - } - NEXT_OPCODE(); - case ZEND_EXT_FCALL_END: - if (!EG(no_extensions)) { - zend_llist_apply_with_argument(&zend_extensions, (void (*)(void *, void *)) zend_extension_fcall_end_handler, op_array); - } - NEXT_OPCODE(); - case ZEND_DECLARE_FUNCTION_OR_CLASS: - do_bind_function_or_class(opline, EG(function_table), EG(class_table), 0); - NEXT_OPCODE(); - case ZEND_TICKS: - if (++EG(ticks_count)==opline->op1.u.constant.value.lval) { - EG(ticks_count)=0; - if (zend_ticks_function) { - zend_ticks_function(opline->op1.u.constant.value.lval); - } - } - NEXT_OPCODE(); - case ZEND_EXT_NOP: - case ZEND_NOP: - NEXT_OPCODE(); - EMPTY_SWITCH_DEFAULT_CASE() - } - } -#if SUPPORT_INTERACTIVE - op_array->last_executed_op_number = opline-op_array->opcodes; - free_alloca(Ts); -#else - zend_error(E_ERROR,"Arrived at end of main loop which shouldn't happen"); -#endif -} diff --git a/Zend/zend_execute.h b/Zend/zend_execute.h deleted file mode 100644 index 84208fd7ac..0000000000 --- a/Zend/zend_execute.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _EXECUTE_H -#define _EXECUTE_H - -#include "zend_compile.h" -#include "zend_hash.h" - -typedef union _temp_variable { - zval tmp_var; - struct { - zval **ptr_ptr; - zval *ptr; - } var; - struct { - zval tmp_var; /* a dummy */ - - zval *str; - int offset; - unsigned char type; - } EA; -} temp_variable; - - -ZEND_API extern void (*zend_execute)(zend_op_array *op_array ELS_DC); - -void init_executor(CLS_D ELS_DC); -void shutdown_executor(ELS_D); -void execute(zend_op_array *op_array ELS_DC); -ZEND_API int zend_is_true(zval *op); -ZEND_API inline void safe_free_zval_ptr(zval *p); -ZEND_API void zend_eval_string(char *str, zval *retval_ptr CLS_DC ELS_DC); -ZEND_API inline int i_zend_is_true(zval *op); -ZEND_API int zval_update_constant(zval **pp); -ZEND_API inline void zend_assign_to_variable_reference(znode *result, zval **variable_ptr_ptr, zval **value_ptr_ptr, temp_variable *Ts ELS_DC); - -/* dedicated Zend executor functions - do not use! */ -ZEND_API inline void zend_ptr_stack_clear_multiple(ELS_D); -ZEND_API inline int zend_ptr_stack_get_arg(int requested_arg, void **data ELS_DC); - -#if SUPPORT_INTERACTIVE -void execute_new_code(CLS_D); -#endif - - -/* services */ -ZEND_API char *get_active_function_name(void); -ZEND_API char *zend_get_executed_filename(ELS_D); -ZEND_API uint zend_get_executed_lineno(ELS_D); -ZEND_API zend_bool zend_is_executing(void); - -#define zendi_zval_copy_ctor(p) zval_copy_ctor(&(p)) -#define zendi_zval_dtor(p) zval_dtor(&(p)) - -#define active_opline (*EG(opline_ptr)) - - -#define IS_OVERLOADED_OBJECT 1 -#define IS_STRING_OFFSET 2 - -#endif /* _EXECUTE_H */ diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c deleted file mode 100644 index b8e4aa62db..0000000000 --- a/Zend/zend_execute_API.c +++ /dev/null @@ -1,592 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include -#include - -#include "zend.h" -#include "zend_compile.h" -#include "zend_execute.h" -#include "zend_API.h" -#include "zend_ptr_stack.h" -#include "zend_variables.h" -#include "zend_operators.h" -#include "zend_constants.h" -#include "zend_extensions.h" -#include "zend_execute_locks.h" - - -ZEND_API void (*zend_execute)(zend_op_array *op_array ELS_DC); - - -#if ZEND_DEBUG -static void (*original_sigsegv_handler)(int); -static void zend_handle_sigsegv(int dummy) -{ - fflush(stdout); - fflush(stderr); - if (original_sigsegv_handler==zend_handle_sigsegv) { - signal(SIGSEGV, original_sigsegv_handler); - } else { - signal(SIGSEGV, SIG_DFL); - } - { - ELS_FETCH(); - - fprintf(stderr, "SIGSEGV caught on opcode %d on opline %d of %s() at %s:%d\n\n", - active_opline->opcode, - active_opline-EG(active_op_array)->opcodes, - get_active_function_name(), - zend_get_executed_filename(ELS_C), - zend_get_executed_lineno(ELS_C)); - } - if (original_sigsegv_handler!=zend_handle_sigsegv) { - original_sigsegv_handler(dummy); - } -} -#endif - - -static void zend_extension_activator(zend_extension *extension) -{ - if (extension->activate) { - extension->activate(); - } -} - - -static void zend_extension_deactivator(zend_extension *extension) -{ - if (extension->deactivate) { - extension->deactivate(); - } -} - - -void init_executor(CLS_D ELS_DC) -{ - INIT_ZVAL(EG(uninitialized_zval)); - INIT_ZVAL(EG(error_zval)); - EG(uninitialized_zval_ptr)=&EG(uninitialized_zval); - EG(error_zval_ptr)=&EG(error_zval); - zend_ptr_stack_init(&EG(arg_types_stack)); - zend_stack_init(&EG(overloaded_objects_stack)); -/* destroys stack frame, therefore makes core dumps worthless */ -#if 0&&ZEND_DEBUG - original_sigsegv_handler = signal(SIGSEGV, zend_handle_sigsegv); -#endif - EG(return_value_ptr_ptr) = &EG(global_return_value_ptr); - EG(global_return_value_ptr) = &EG(global_return_value); - INIT_ZVAL(EG(global_return_value)); - - EG(symtable_cache_ptr) = EG(symtable_cache)-1; - EG(symtable_cache_limit)=EG(symtable_cache)+SYMTABLE_CACHE_SIZE-1; - EG(no_extensions)=0; - - EG(function_table) = CG(function_table); - EG(class_table) = CG(class_table); - - EG(in_execution) = 0; - - zend_ptr_stack_init(&EG(argument_stack)); - - EG(main_op_array) = NULL; - zend_hash_init(&EG(symbol_table), 50, NULL, ZVAL_PTR_DTOR, 0); - EG(active_symbol_table) = &EG(symbol_table); - - zend_llist_apply(&zend_extensions, (void (*)(void *)) zend_extension_activator); - EG(opline_ptr) = NULL; - EG(garbage_ptr) = 0; - - zend_hash_init(&EG(imported_files), 5, NULL, NULL, 0); - - EG(ticks_count) = 0; -} - - -void shutdown_executor(ELS_D) -{ - zval_dtor(&EG(global_return_value)); - zend_ptr_stack_destroy(&EG(arg_types_stack)); - zend_stack_destroy(&EG(overloaded_objects_stack)); - - while (EG(symtable_cache_ptr)>=EG(symtable_cache)) { - zend_hash_destroy(*EG(symtable_cache_ptr)); - efree(*EG(symtable_cache_ptr)); - EG(symtable_cache_ptr)--; - } - zend_llist_apply(&zend_extensions, (void (*)(void *)) zend_extension_deactivator); - - zend_hash_destroy(&EG(symbol_table)); - - while (EG(garbage_ptr)--) { - if (EG(garbage)[EG(garbage_ptr)]->refcount==1) { - zval_ptr_dtor(&EG(garbage)[EG(garbage_ptr)]); - } - } - - destroy_resource_list(ELS_C); /* must be destroyed after the main symbol table is destroyed */ - - zend_ptr_stack_destroy(&EG(argument_stack)); - if (EG(main_op_array)) { - destroy_op_array(EG(main_op_array)); - efree(EG(main_op_array)); - } - clean_non_persistent_constants(); -#if ZEND_DEBUG - signal(SIGSEGV, original_sigsegv_handler); -#endif - - - zend_hash_destroy(&EG(imported_files)); -} - - -ZEND_API char *get_active_function_name() -{ - ELS_FETCH(); - - switch(EG(function_state_ptr)->function->type) { - case ZEND_USER_FUNCTION: { - char *function_name = ((zend_op_array *) EG(function_state_ptr)->function)->function_name; - - if (function_name) { - return function_name; - } else { - return "main"; - } - } - break; - case ZEND_INTERNAL_FUNCTION: - return ((zend_internal_function *) EG(function_state_ptr)->function)->function_name; - break; - default: - return NULL; - } -} - - -ZEND_API char *zend_get_executed_filename(ELS_D) -{ - if (EG(opline_ptr)) { - return active_opline->filename; - } else { - return "[no active file]"; - } -} - - -ZEND_API uint zend_get_executed_lineno(ELS_D) -{ - if (EG(opline_ptr)) { - return active_opline->lineno; - } else { - return 0; - } -} - - -ZEND_API zend_bool zend_is_executing() -{ - ELS_FETCH(); - - return EG(in_execution); -} - - -ZEND_API inline void safe_free_zval_ptr(zval *p) -{ - ELS_FETCH(); - - if (p!=EG(uninitialized_zval_ptr)) { - FREE_ZVAL(p); - } -} - - -ZEND_API void _zval_ptr_dtor(zval **zval_ptr ZEND_FILE_LINE_DC) -{ -#if DEBUG_ZEND>=2 - printf("Reducing refcount for %x (%x): %d->%d\n", *zval_ptr, zval_ptr, (*zval_ptr)->refcount, (*zval_ptr)->refcount-1); -#endif - (*zval_ptr)->refcount--; - if ((*zval_ptr)->refcount==0) { - zval_dtor(*zval_ptr); - safe_free_zval_ptr(*zval_ptr); - } else if (((*zval_ptr)->refcount == 1) && ((*zval_ptr)->type != IS_OBJECT)) { - (*zval_ptr)->is_ref = 0; - } -} - - -ZEND_API inline int i_zend_is_true(zval *op) -{ - int result; - - switch (op->type) { - case IS_NULL: - result = 0; - break; - case IS_LONG: - case IS_BOOL: - case IS_RESOURCE: - result = (op->value.lval?1:0); - break; - case IS_DOUBLE: - result = (op->value.dval ? 1 : 0); - break; - case IS_STRING: - if (op->value.str.len == 0 - || (op->value.str.len==1 && op->value.str.val[0]=='0')) { - result = 0; - } else { - result = 1; - } - break; - case IS_ARRAY: - result = (zend_hash_num_elements(op->value.ht)?1:0); - break; - case IS_OBJECT: - result = (zend_hash_num_elements(op->value.obj.properties)?1:0); - break; - default: - result = 0; - break; - } - return result; -} - - -ZEND_API int zend_is_true(zval *op) -{ - return i_zend_is_true(op); -} - - -ZEND_API int zval_update_constant(zval **pp) -{ - zval *p = *pp; - - if (p->type == IS_CONSTANT) { - zval c; - int refcount = p->refcount; - - if (!zend_get_constant(p->value.str.val, p->value.str.len, &c)) { - zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", - p->value.str.val, - p->value.str.val); - p->type = IS_STRING; - } else { - STR_FREE(p->value.str.val); - *p = c; - } - INIT_PZVAL(p); - p->refcount = refcount; - } else if (p->type == IS_ARRAY) { - zend_hash_apply(p->value.ht, (int (*)(void *)) zval_update_constant); - } - return 0; -} - - -int call_user_function(HashTable *function_table, zval *object, zval *function_name, zval *retval_ptr, int param_count, zval *params[]) -{ - zval ***params_array = (zval ***) emalloc(sizeof(zval **)*param_count); - int i; - int ex_retval; - zval *local_retval_ptr; - - for (i=0; itype != IS_OBJECT) { - return FAILURE; - } - function_table = &object->value.obj.ce->function_table; - } - original_function_state_ptr = EG(function_state_ptr); - zend_str_tolower(function_name->value.str.val, function_name->value.str.len); - if (zend_hash_find(function_table, function_name->value.str.val, function_name->value.str.len+1, (void **) &function_state.function)==FAILURE) { - return FAILURE; - } - - for (i=0; icommon.arg_types - && icommon.arg_types[0] - && function_state.function->common.arg_types[i+1]==BYREF_FORCE - && !PZVAL_IS_REF(*params[i])) { - if ((*params[i])->refcount>1) { - zval *new_zval; - - if (no_separation) { - return FAILURE; - } - ALLOC_ZVAL(new_zval); - *new_zval = **params[i]; - zval_copy_ctor(new_zval); - new_zval->refcount = 1; - (*params[i])->refcount--; - *params[i] = new_zval; - } - (*params[i])->refcount++; - (*params[i])->is_ref = 1; - param = *params[i]; - } else if (*params[i] != &EG(uninitialized_zval)) { - (*params[i])->refcount++; - param = *params[i]; - } else { - ALLOC_ZVAL(param); - *param = **(params[i]); - INIT_PZVAL(param); - } - zend_ptr_stack_push(&EG(argument_stack), param); - } - - zend_ptr_stack_push(&EG(argument_stack), (void *) (long) param_count); - - if (function_state.function->type == ZEND_USER_FUNCTION) { - calling_symbol_table = EG(active_symbol_table); - ALLOC_HASHTABLE(EG(active_symbol_table)); - zend_hash_init(EG(active_symbol_table), 0, NULL, ZVAL_PTR_DTOR, 0); - if (object) { - zval *dummy, **this_ptr; - - ALLOC_ZVAL(dummy); - INIT_ZVAL(*dummy); - - zend_hash_update_ptr(EG(active_symbol_table), "this", sizeof("this"), dummy, sizeof(zval *), (void **) &this_ptr); - zend_assign_to_variable_reference(NULL, this_ptr, &object, NULL ELS_CC); - } - original_return_value = EG(return_value_ptr_ptr); - original_op_array = EG(active_op_array); - EG(return_value_ptr_ptr) = retval_ptr_ptr; - EG(active_op_array) = (zend_op_array *) function_state.function; - original_opline_ptr = EG(opline_ptr); - zend_execute(EG(active_op_array) ELS_CC); - zend_hash_destroy(EG(active_symbol_table)); - FREE_HASHTABLE(EG(active_symbol_table)); - EG(active_symbol_table) = calling_symbol_table; - EG(active_op_array) = original_op_array; - EG(return_value_ptr_ptr)=original_return_value; - EG(opline_ptr) = original_opline_ptr; - } else { - ALLOC_INIT_ZVAL(*retval_ptr_ptr); - ((zend_internal_function *) function_state.function)->handler(param_count, *retval_ptr_ptr, object, 1 ELS_CC); - INIT_PZVAL(*retval_ptr_ptr); - } - zend_ptr_stack_clear_multiple(ELS_C); - EG(function_state_ptr) = original_function_state_ptr; - - return SUCCESS; -} - - -ZEND_API void zend_eval_string(char *str, zval *retval_ptr CLS_DC ELS_DC) -{ - zval pv; - zend_op_array *new_op_array; - zend_op_array *original_active_op_array = EG(active_op_array); - zend_function_state *original_function_state_ptr = EG(function_state_ptr); - int original_handle_op_arrays; - - if (retval_ptr) { - pv.value.str.len = strlen(str)+sizeof("return ;")-1; - pv.value.str.val = emalloc(pv.value.str.len+1); - strcpy(pv.value.str.val, "return "); - strcat(pv.value.str.val, str); - strcat(pv.value.str.val, " ;"); - } else { - pv.value.str.len = strlen(str); - pv.value.str.val = estrndup(str, pv.value.str.len); - } - pv.type = IS_STRING; - - /*printf("Evaluating '%s'\n", pv.value.str.val);*/ - - original_handle_op_arrays = CG(handle_op_arrays); - CG(handle_op_arrays) = 0; - new_op_array = compile_string(&pv CLS_CC); - CG(handle_op_arrays) = original_handle_op_arrays; - - if (new_op_array) { - zval *local_retval_ptr=NULL; - zval **original_return_value_ptr_ptr = EG(return_value_ptr_ptr); - zend_op **original_opline_ptr = EG(opline_ptr); - - EG(return_value_ptr_ptr) = &local_retval_ptr; - EG(active_op_array) = new_op_array; - EG(no_extensions)=1; - - zend_execute(new_op_array ELS_CC); - - if (local_retval_ptr) { - if (retval_ptr) { - COPY_PZVAL_TO_ZVAL(*retval_ptr, local_retval_ptr); - } else { - zval_ptr_dtor(&local_retval_ptr); - } - } else { - if (retval_ptr) { - INIT_ZVAL(*retval_ptr); - } - } - - EG(no_extensions)=0; - EG(opline_ptr) = original_opline_ptr; - EG(active_op_array) = original_active_op_array; - EG(function_state_ptr) = original_function_state_ptr; - destroy_op_array(new_op_array); - efree(new_op_array); - EG(return_value_ptr_ptr) = original_return_value_ptr_ptr; - } else { - printf("Failed executing:\n%s\n", str); - } - zval_dtor(&pv); -} - - -ZEND_API inline void zend_assign_to_variable_reference(znode *result, zval **variable_ptr_ptr, zval **value_ptr_ptr, temp_variable *Ts ELS_DC) -{ - zval *variable_ptr = *variable_ptr_ptr; - zval *value_ptr; - - - if (!value_ptr_ptr) { - zend_error(E_ERROR, "Cannot create references to string offsets nor overloaded objects"); - return; - } - - value_ptr = *value_ptr_ptr; - if (variable_ptr == EG(error_zval_ptr) || value_ptr==EG(error_zval_ptr)) { - variable_ptr_ptr = &EG(uninitialized_zval_ptr); -/* } else if (variable_ptr==&EG(uninitialized_zval) || variable_ptr!=value_ptr) { */ - } else if (variable_ptr_ptr != value_ptr_ptr) { - variable_ptr->refcount--; - if (variable_ptr->refcount==0) { - zendi_zval_dtor(*variable_ptr); - FREE_ZVAL(variable_ptr); - } - - if (!PZVAL_IS_REF(value_ptr)) { - /* break it away */ - value_ptr->refcount--; - if (value_ptr->refcount>0) { - ALLOC_ZVAL(*value_ptr_ptr); - **value_ptr_ptr = *value_ptr; - value_ptr = *value_ptr_ptr; - zendi_zval_copy_ctor(*value_ptr); - } - value_ptr->refcount = 1; - value_ptr->is_ref = 1; - } - - *variable_ptr_ptr = value_ptr; - value_ptr->refcount++; - } else { - if (variable_ptr->refcount>1) { /* we need to break away */ - SEPARATE_ZVAL(variable_ptr_ptr); - } - (*variable_ptr_ptr)->is_ref = 1; - } - - if (result && (result->op_type != IS_UNUSED)) { - Ts[result->u.var].var.ptr_ptr = variable_ptr_ptr; - SELECTIVE_PZVAL_LOCK(*variable_ptr_ptr, result); - AI_USE_PTR(Ts[result->u.var].var); - } -} - - -#if SUPPORT_INTERACTIVE -void execute_new_code(CLS_D) -{ - ELS_FETCH(); - - if (!EG(interactive) - || CG(active_op_array)->backpatch_count>0 - || CG(active_op_array)->function_name - || CG(active_op_array)->type!=ZEND_USER_FUNCTION) { - return; - } - CG(active_op_array)->start_op_number = CG(active_op_array)->last_executed_op_number; - CG(active_op_array)->end_op_number = CG(active_op_array)->last; - EG(active_op_array) = CG(active_op_array); - zend_execute(CG(active_op_array) ELS_CC); - CG(active_op_array)->start_op_number = CG(active_op_array)->last_executed_op_number; -} -#endif - - -/* these are a dedicated, optimized, function, and shouldn't be used for any purpose - * other than by Zend's executor - */ -ZEND_API inline void zend_ptr_stack_clear_multiple(ELS_D) -{ - void **p = EG(argument_stack).top_element-1; - int delete_count = (ulong) *p; - - EG(argument_stack).top -= (delete_count+1); - while (--delete_count>=0) { - zval_ptr_dtor((zval **) --p); - } - EG(argument_stack).top_element = p; -} - - - -ZEND_API int zend_ptr_stack_get_arg(int requested_arg, void **data ELS_DC) -{ - void **p = EG(argument_stack).top_element-1; - int arg_count = (ulong) *p; - - if (requested_arg>arg_count) { - return FAILURE; - } - *data = (p-arg_count+requested_arg-1); - return SUCCESS; -} - diff --git a/Zend/zend_execute_locks.h b/Zend/zend_execute_locks.h deleted file mode 100644 index b24ec642e9..0000000000 --- a/Zend/zend_execute_locks.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _ZEND_EXECUTE_LOCKS_H -#define _ZEND_EXECUTE_LOCKS_H - -#define PZVAL_LOCK(z) ((z)->refcount++) -#define PZVAL_UNLOCK(z) { ((z)->refcount--); \ - if (!(z)->refcount) { \ - (z)->refcount = 1; \ - (z)->is_ref = 0; \ - EG(garbage)[EG(garbage_ptr)++] = (z); \ - if (EG(garbage_ptr) == 4) { \ - zval_ptr_dtor(&EG(garbage)[0]); \ - zval_ptr_dtor(&EG(garbage)[1]); \ - EG(garbage)[0] = EG(garbage)[2]; \ - EG(garbage)[1] = EG(garbage)[3]; \ - EG(garbage_ptr) -= 2; \ - } \ - } \ - } - -#define SELECTIVE_PZVAL_LOCK(pzv, pzn) if (!((pzn)->u.EA.type & EXT_TYPE_UNUSED)) { PZVAL_LOCK(pzv); } - -#endif /* _ZEND_EXECUTE_LOCKS_H */ diff --git a/Zend/zend_extensions.c b/Zend/zend_extensions.c deleted file mode 100644 index fb2f071032..0000000000 --- a/Zend/zend_extensions.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include "zend_extensions.h" - -ZEND_API zend_llist zend_extensions; -static int last_resource_number; - -int zend_load_extensions(char **extension_paths) -{ - char **p = extension_paths; - - if (!p) { - return SUCCESS; - } - while (*p) { - if (zend_load_extension(*p)==FAILURE) { - return FAILURE; - } - p++; - } - return SUCCESS; -} - - -int zend_load_extension(char *path) -{ -#if ZEND_EXTENSIONS_SUPPORT - DL_HANDLE handle; - zend_extension extension, *new_extension; - zend_extension_version_info *extension_version_info; - - handle = DL_LOAD(path); - if (!handle) { -#ifndef ZEND_WIN32 - fprintf(stderr, "Failed loading %s: %s\n", path, dlerror()); -#else - fprintf(stderr, "Failed loading %s\n", path); -#endif - return FAILURE; - } - - extension_version_info = (zend_extension_version_info *) DL_FETCH_SYMBOL(handle, "extension_version_info"); - new_extension = (zend_extension *) DL_FETCH_SYMBOL(handle, "zend_extension_entry"); - if (!extension_version_info || !new_extension) { - fprintf(stderr, "%s doesn't appear to be a valid Zend extension\n", path); - return FAILURE; - } - - if (extension_version_info->zend_extension_api_no > ZEND_EXTENSION_API_NO) { - fprintf(stderr, "%s requires Zend version %s or later\n" - "Current version %s, API version %d\n", - new_extension->name, - extension_version_info->required_zend_version, - ZEND_VERSION, - ZEND_EXTENSION_API_NO); - DL_UNLOAD(handle); - return FAILURE; - } else if (extension_version_info->zend_extension_api_no < ZEND_EXTENSION_API_NO) { - /* we may be able to allow for downwards compatability in some harmless cases. */ - fprintf(stderr, "%s is outdated (API version %d, current version %d)\n" - "Contact %s at %s for a later version of this module.\n", - new_extension->name, - extension_version_info->zend_extension_api_no, - ZEND_EXTENSION_API_NO, - new_extension->author, - new_extension->URL); - DL_UNLOAD(handle); - return FAILURE; - } else if (ZTS_V!=extension_version_info->thread_safe) { - fprintf(stderr, "Cannot load %s - it %s thread safe, whereas Zend %s\n", - new_extension->name, - (extension_version_info->thread_safe?"is":"isn't"), - (ZTS_V?"is":"isn't")); - DL_UNLOAD(handle); - return FAILURE; - } else if (ZEND_DEBUG!=extension_version_info->debug) { - fprintf(stderr, "Cannot load %s - it %s debug information, whereas Zend %s\n", - new_extension->name, - (extension_version_info->debug?"contains":"does not contain"), - (ZEND_DEBUG?"does":"does not")); - DL_UNLOAD(handle); - return FAILURE; - } - - if (new_extension->startup) { - if (new_extension->startup(new_extension)!=SUCCESS) { - DL_UNLOAD(handle); - return FAILURE; - } - } - extension = *new_extension; - extension.handle = handle; - - zend_llist_add_element(&zend_extensions, &extension); - - /*fprintf(stderr, "Loaded %s, version %s\n", extension.name, extension.version);*/ - - zend_append_version_info(&extension); - return SUCCESS; -#else - fprintf(stderr, "Extensions are not supported on this platform.\n"); - return FAILURE; -#endif -} - -static void zend_extension_shutdown(zend_extension *extension) -{ -#if ZEND_EXTENSIONS_SUPPORT - if (extension->shutdown) { - extension->shutdown(extension); - } -#endif -} - - -void zend_shutdown_extensions() -{ - zend_llist_apply(&zend_extensions, (void (*)(void *)) zend_extension_shutdown); - zend_llist_destroy(&zend_extensions); -} - - -void zend_extension_dtor(zend_extension *extension) -{ -#if ZEND_EXTENSIONS_SUPPORT - DL_UNLOAD(extension->handle); -#endif -} - - -ZEND_API int zend_get_resource_handle(zend_extension *extension) -{ - if (last_resource_number<4) { - extension->resource_number = last_resource_number; - return last_resource_number; - } else { - return -1; - } -} diff --git a/Zend/zend_extensions.h b/Zend/zend_extensions.h deleted file mode 100644 index 08a1305100..0000000000 --- a/Zend/zend_extensions.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _ZEND_EXTENSIONS_H -#define _ZEND_EXTENSIONS_H - -#include "zend_compile.h" - -#define ZEND_EXTENSION_API_NO 19990619 - -typedef struct _zend_extension_version_info { - int zend_extension_api_no; - char *required_zend_version; - unsigned char thread_safe; - unsigned char debug; -} zend_extension_version_info; - - -typedef struct _zend_extension zend_extension; - -struct _zend_extension { - char *name; - char *version; - char *author; - char *URL; - char *copyright; - - int (*startup)(zend_extension *extension); - void (*shutdown)(zend_extension *extension); - void (*activate)(); - void (*deactivate)(); - - void (*op_array_handler)(zend_op_array *op_array); - - void (*statement_handler)(zend_op_array *op_array); - void (*fcall_begin_handler)(zend_op_array *op_array); - void (*fcall_end_handler)(zend_op_array *op_array); - - void (*op_array_ctor)(void **resource); - void (*op_array_dtor)(void **resource); - - void *reserved1; - void *reserved2; - void *reserved3; - void *reserved4; - void *reserved5; - void *reserved6; - void *reserved7; - void *reserved8; - - DL_HANDLE handle; - int resource_number; -}; - - -ZEND_API int zend_get_resource_handle(zend_extension *extension); - -#ifdef ZTS -#define ZTS_V 1 -#else -#define ZTS_V 0 -#endif - - -#define ZEND_EXTENSION() \ - ZEND_EXT_API zend_extension_version_info extension_version_info = { ZEND_EXTENSION_API_NO, "0.90", ZTS_V, ZEND_DEBUG } - -#define STANDARD_ZEND_EXTENSION_PROPERTIES NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, -1 - - -ZEND_API extern zend_llist zend_extensions; - -void zend_extension_dtor(zend_extension *extension); -int zend_load_extension(char *path); -int zend_load_extensions(char **extension_paths); -void zend_append_version_info(zend_extension *extension); -void zend_shutdown_extensions(void); - -#endif /* _ZEND_EXTENSIONS_H */ diff --git a/Zend/zend_fast_cache.h b/Zend/zend_fast_cache.h deleted file mode 100644 index f62f0ee12a..0000000000 --- a/Zend/zend_fast_cache.h +++ /dev/null @@ -1,116 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _ZEND_FAST_CACHE_H -#define _ZEND_FAST_CACHE_H - -#ifndef ZEND_ENABLE_FAST_CACHE -# if ZEND_DEBUG -# define ZEND_ENABLE_FAST_CACHE 0 -# else -# define ZEND_ENABLE_FAST_CACHE 1 -# endif -#endif - -typedef struct _zend_fast_cache_list_entry { - struct _zend_fast_cache_list_entry *next; -} zend_fast_cache_list_entry; - -#define MAX_FAST_CACHE_TYPES 4 - - -#define ZVAL_CACHE_LIST 0 -#define HASHTABLE_CACHE_LIST 1 - -#if ZEND_ENABLE_FAST_CACHE - - -#include "zend_globals.h" -#include "zend_globals_macros.h" -#include "zend_alloc.h" - - -#if ZEND_DEBUG -# define RECORD_ZVAL_CACHE_HIT(fc_type) AG(fast_cache_stats)[fc_type][1]++; -# define RECORD_ZVAL_CACHE_MISS(fc_type) AG(fast_cache_stats)[fc_type][0]++; -#else -# define RECORD_ZVAL_CACHE_HIT(fc_type) -# define RECORD_ZVAL_CACHE_MISS(fc_type) -#endif - - -#define ZEND_FAST_ALLOC(p, type, fc_type) \ - { \ - ALS_FETCH(); \ - \ - if (((p) = (type *) AG(fast_cache_list_head)[fc_type])) { \ - AG(fast_cache_list_head)[fc_type] = ((zend_fast_cache_list_entry *) AG(fast_cache_list_head)[fc_type])->next; \ - RECORD_ZVAL_CACHE_HIT(fc_type); \ - } else { \ - (p) = (type *) emalloc(sizeof(type)); \ - RECORD_ZVAL_CACHE_MISS(fc_type); \ - } \ - } - - -#define ZEND_FAST_FREE(p, fc_type) \ - { \ - ALS_FETCH(); \ - \ - ((zend_fast_cache_list_entry *) (p))->next = AG(fast_cache_list_head)[fc_type]; \ - AG(fast_cache_list_head)[fc_type] = (zend_fast_cache_list_entry *) (p); \ - } - - -#else /* !ZEND_ENABLE_FAST_CACHE */ - -#define ZEND_FAST_ALLOC(p, type, fc_type) \ - (p) = (type *) emalloc(sizeof(type)) - -#define ZEND_FAST_FREE(p, fc_type) \ - efree(p) - -#endif /* ZEND_ENABLE_FAST_CACHE */ - - - - -/* fast cache for zval's */ -#define ALLOC_ZVAL(z) \ - ZEND_FAST_ALLOC(z, zval, ZVAL_CACHE_LIST) - -#define FREE_ZVAL(z) \ - ZEND_FAST_FREE(z, ZVAL_CACHE_LIST) - -/* fast cache for HashTable's */ -#define ALLOC_HASHTABLE(b) \ - ZEND_FAST_ALLOC(b, HashTable, HASHTABLE_CACHE_LIST) - -#define FREE_HASHTABLE(ht) \ - ZEND_FAST_FREE(ht, HASHTABLE_CACHE_LIST) - -#endif /* _ZEND_FAST_CACHE_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/Zend/zend_globals.h b/Zend/zend_globals.h deleted file mode 100644 index 7abd6b135f..0000000000 --- a/Zend/zend_globals.h +++ /dev/null @@ -1,210 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _T_GLOBALS_H -#define _T_GLOBALS_H - - -#include - -#include "zend_globals_macros.h" - -#include "zend_stack.h" -#include "zend_ptr_stack.h" -#include "zend_hash.h" -#include "zend_llist.h" -#include "zend_fast_cache.h" - -/* Define ZTS if you want a thread-safe Zend */ -/*#undef ZTS*/ - -#ifdef ZTS -#include "../TSRM/TSRM.h" - -#ifdef __cplusplus -class ZendFlexLexer; -#endif - -BEGIN_EXTERN_C() -ZEND_API extern int compiler_globals_id; -ZEND_API extern int executor_globals_id; -ZEND_API extern int alloc_globals_id; -END_EXTERN_C() - -#endif - -#define SYMTABLE_CACHE_SIZE 32 - - -#include "zend_compile.h" -#include "zend_execute.h" - -/* excpt.h on Digital Unix 4.0 defines function_table */ -#undef function_table - - -typedef struct _zend_declarables { - zval ticks; -} zend_declarables; - - -struct _zend_compiler_globals { - zend_stack bp_stack; - zend_stack switch_cond_stack; - zend_stack foreach_copy_stack; - zend_stack object_stack; - zend_stack declare_stack; - - zend_class_entry class_entry, *active_class_entry; - - /* variables for list() compilation */ - zend_llist list_llist; - zend_llist dimension_llist; - - zend_stack function_call_stack; - - char *compiled_filename; - - int zend_lineno; - int comment_start_line; - char *heredoc; - int heredoc_len; - - zend_op_array *active_op_array; - - HashTable *function_table; /* function symbol table */ - HashTable *class_table; /* class table */ - - HashTable used_files; /* files already included using 'use' */ - - zend_llist filenames_list; - - zend_bool in_compilation; - zend_bool short_tags; - zend_bool asp_tags; - zend_bool allow_call_time_pass_reference; - - zend_declarables declarables; - - /* For extensions support */ - zend_bool extended_info; /* generate extension information for debugger/profiler */ - zend_bool handle_op_arrays; /* run op_arrays through op_array handlers */ - - zend_bool unclean_shutdown; - - zend_llist open_files; -#ifdef ZTS -#ifdef __cplusplus - ZendFlexLexer *ZFL; -#else - void *ZFL; -#endif -#endif -}; - - -struct _zend_executor_globals { - zval **return_value_ptr_ptr; - - zval uninitialized_zval; - zval *uninitialized_zval_ptr; - - zval error_zval; - zval *error_zval_ptr; - - zend_function_state *function_state_ptr; - zend_ptr_stack arg_types_stack; - zend_stack overloaded_objects_stack; - - /* for global return() support */ - zval *global_return_value_ptr; - zval global_return_value; - - /* symbol table cache */ - HashTable *symtable_cache[SYMTABLE_CACHE_SIZE]; - HashTable **symtable_cache_limit; - HashTable **symtable_cache_ptr; - - zend_op **opline_ptr; - - HashTable *active_symbol_table; - HashTable symbol_table; /* main symbol table */ - - HashTable imported_files; /* files already included using 'import' */ - - jmp_buf bailout; - - int error_reporting; - - zend_op_array *active_op_array; - zend_op_array *main_op_array; - - HashTable *function_table; /* function symbol table */ - HashTable *class_table; /* class table */ - HashTable *zend_constants; /* constants table */ - - long precision; - - int ticks_count; - - zend_bool in_execution; - - /* for extended information support */ - zend_bool no_extensions; - - HashTable regular_list; - HashTable persistent_list; - - zend_ptr_stack argument_stack; - int free_op1, free_op2; - int (*unary_op)(zval *result, zval *op1); - int (*binary_op)(zval *result, zval *op1, zval *op2); - - zval *garbage[4]; - int garbage_ptr; - - void *reserved[ZEND_MAX_RESERVED_RESOURCES]; -#if SUPPORT_INTERACTIVE - int interactive; -#endif -}; - - -struct _zend_alloc_globals { - zend_mem_header *head; /* standard list */ - zend_mem_header *phead; /* persistent list */ - void *cache[MAX_CACHED_MEMORY][MAX_CACHED_ENTRIES]; - unsigned char cache_count[MAX_CACHED_MEMORY]; - void *fast_cache_list_head[MAX_FAST_CACHE_TYPES]; - -#if ZEND_DEBUG - /* for performance tuning */ - int cache_stats[MAX_CACHED_MEMORY][2]; - int fast_cache_stats[MAX_FAST_CACHE_TYPES][2]; -#endif -#if MEMORY_LIMIT - unsigned int memory_limit; - unsigned int allocated_memory; - unsigned char memory_exhausted; -#endif -}; - - -#endif /* _T_GLOBALS_H */ diff --git a/Zend/zend_globals_macros.h b/Zend/zend_globals_macros.h deleted file mode 100644 index 02ef168e8f..0000000000 --- a/Zend/zend_globals_macros.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _ZEND_GLOBALS_MACROS_H -#define _ZEND_GLOBALS_MACROS_H - -typedef struct _zend_compiler_globals zend_compiler_globals; -typedef struct _zend_executor_globals zend_executor_globals; -typedef struct _zend_alloc_globals zend_alloc_globals; - -/* Compiler */ -#ifdef ZTS -# define CLS_D zend_compiler_globals *compiler_globals -# define CLS_DC , CLS_D -# define CLS_C compiler_globals -# define CLS_CC , CLS_C -# define CG(v) (((zend_compiler_globals *) compiler_globals)->v) -# define CLS_FETCH() zend_compiler_globals *compiler_globals = (zend_compiler_globals *) ts_resource(compiler_globals_id) -BEGIN_EXTERN_C() -int zendparse(void *compiler_globals); -END_EXTERN_C() -#else -# define CLS_D void -# define CLS_DC -# define CLS_C -# define CLS_CC -# define CG(v) (compiler_globals.v) -# define CLS_FETCH() -extern ZEND_API struct _zend_compiler_globals compiler_globals; -int zendparse(void); -#endif - - -/* Executor */ -#ifdef ZTS -# define ELS_D zend_executor_globals *executor_globals -# define ELS_DC , ELS_D -# define ELS_C executor_globals -# define ELS_CC , ELS_C -# define EG(v) (executor_globals->v) -# define ELS_FETCH() zend_executor_globals *executor_globals = (zend_executor_globals *) ts_resource(executor_globals_id) -#else -# define ELS_D void -# define ELS_DC -# define ELS_C -# define ELS_CC -# define EG(v) (executor_globals.v) -# define ELS_FETCH() -extern ZEND_API zend_executor_globals executor_globals; -#endif - - -/* Memory Manager */ -#ifdef ZTS -# define ALS_D zend_alloc_globals *alloc_globals -# define ALS_DC , ALS_D -# define ALS_C alloc_globals -# define ALS_CC , ALS_C -# define AG(v) (((zend_alloc_globals *) alloc_globals)->v) -# define ALS_FETCH() zend_alloc_globals *alloc_globals = (zend_alloc_globals *) ts_resource(alloc_globals_id) -#else -# define ALS_D void -# define ALS_DC -# define ALS_C -# define ALS_CC -# define AG(v) (alloc_globals.v) -# define ALS_FETCH() -extern ZEND_API zend_alloc_globals alloc_globals; -#endif - -#endif /* _ZEND_GLOBALS_MACROS_H */ - diff --git a/Zend/zend_hash.c b/Zend/zend_hash.c deleted file mode 100644 index b4be2f6cda..0000000000 --- a/Zend/zend_hash.c +++ /dev/null @@ -1,1117 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include "zend.h" - -#include - -#ifdef HAVE_STDLIB_H -# include -#endif - -#ifdef HAVE_LIMITS_H -# include -#endif - -#define HANDLE_NUMERIC(key, length, func) { \ - register char *tmp=key; \ - \ - if ((*tmp>='0' && *tmp<='9')) do { /* possibly a numeric index */ \ - char *end=tmp+length-1; \ - ulong idx; \ - \ - if (*tmp++=='0' && length>2) { /* don't accept numbers with leading zeros */ \ - break; \ - } \ - while (tmp='0' && *tmp<='9')) { \ - break; \ - } \ - tmp++; \ - } \ - if (tmp==end && *tmp=='\0') { /* a numeric index */ \ - idx = strtol(key, NULL, 10); \ - if (idx!=LONG_MAX) { \ - return func; \ - } \ - } \ - } while(0); \ -} - - -#define CONNECT_TO_BUCKET_DLLIST(element, list_head) \ - (element)->pNext = (list_head); \ - (element)->pLast = NULL; \ - if ((element)->pNext) { \ - (element)->pNext->pLast = (element); \ - } - -#define CONNECT_TO_GLOBAL_DLLIST(element, ht) \ - (element)->pListLast = (ht)->pListTail; \ - (ht)->pListTail = (element); \ - (element)->pListNext = NULL; \ - if ((element)->pListLast != NULL) { \ - (element)->pListLast->pListNext = (element); \ - } \ - if (!(ht)->pListHead) { \ - (ht)->pListHead = (element); \ - } \ - if ((ht)->pInternalPointer == NULL) { \ - (ht)->pInternalPointer = (element); \ - } - -#if ZEND_DEBUG -#define HT_IS_DESTROYING 1 -#define HT_DESTROYED 2 -#define HT_CLEANING 3 -#define HT_OK 0 - -static void _zend_is_inconsistent(HashTable *ht, char *file, int line) -{ - switch (ht->inconsistent) { - case HT_IS_DESTROYING: - zend_error(E_CORE_ERROR, "ht=%08x is destroying in %s:%d", ht, file, line); - break; - case HT_DESTROYED: - zend_error(E_CORE_ERROR, "ht=%08x is already destroyed in %s:%d", ht, file, line); - break; - case HT_CLEANING: - zend_error(E_CORE_ERROR, "ht=%08x is cleaning %s:%d", ht, file, line); - break; - } -} -#define IS_CONSISTENT(a) _zend_is_inconsistent(a,__FILE__,__LINE__); -#define SET_INCONSISTENT(n) ht->inconsistent = n; -#else -#define IS_CONSISTENT(a) -#define SET_INCONSISTENT(n) -#endif - -/* Generated on an Octa-ALPHA 300MHz CPU & 2.5GB RAM monster */ -static uint PrimeNumbers[] = -{5, 11, 19, 53, 107, 223, 463, 983, 1979, 3907, 7963, 16229, 32531, 65407, 130987, 262237, 524521, 1048793, 2097397, 4194103, 8388857, 16777447, 33554201, 67108961, 134217487, 268435697, 536870683, 1073741621, 2147483399}; - -#define ZEND_HASH_IF_FULL_DO_RESIZE(ht) \ - if ((ht)->nNumOfElements > (ht)->nTableSize) { \ - zend_hash_do_resize(ht); \ - } - -static int zend_hash_do_resize(HashTable *ht); - -static uint nNumPrimeNumbers = sizeof(PrimeNumbers) / sizeof(ulong); - -ZEND_API ulong hashpjw(char *arKey, uint nKeyLength) -{ - ulong h = 0, g; - char *arEnd=arKey+nKeyLength; - - while (arKey < arEnd) { - h = (h << 4) + *arKey++; - if ((g = (h & 0xF0000000))) { - h = h ^ (g >> 24); - h = h ^ g; - } - } - return h; -} - - -#define UPDATE_DATA(ht, p, pData, nDataSize) \ - if (flag & HASH_ADD_PTR) { \ - if (!(p)->pDataPtr) { \ - pefree(p, (ht)->persistent); \ - } \ - (p)->pDataPtr = pData; \ - (p)->pData = &(p)->pDataPtr; \ - } else { \ - if ((p)->pDataPtr) { \ - (p)->pData = (void *) pemalloc(nDataSize, (ht)->persistent); \ - (p)->pDataPtr=NULL; \ - } \ - memcpy((p)->pData, pData, nDataSize); \ - } - -#define INIT_DATA(ht, p, pData, nDataSize); \ - if (flag & HASH_ADD_PTR) { \ - (p)->pDataPtr = pData; \ - (p)->pData = &(p)->pDataPtr; \ - } else { \ - (p)->pData = (void *) pemalloc(nDataSize, (ht)->persistent); \ - if (!(p)->pData) { \ - pefree(p, (ht)->persistent); \ - return FAILURE; \ - } \ - memcpy((p)->pData, pData, nDataSize); \ - (p)->pDataPtr=NULL; \ - } - - -ZEND_API int zend_hash_init(HashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t pDestructor, int persistent) -{ - uint i; - - SET_INCONSISTENT(HT_OK); - - for (i = 0; i < nNumPrimeNumbers; i++) { - if (nSize <= PrimeNumbers[i]) { - nSize = PrimeNumbers[i]; - ht->nHashSizeIndex = i; - break; - } - } - if (i == nNumPrimeNumbers) { /* This shouldn't really happen unless the ask for a ridiculous size */ - nSize = PrimeNumbers[i - 1]; - ht->nHashSizeIndex = i - 1; - } - - /* Uses ecalloc() so that Bucket* == NULL */ - ht->arBuckets = (Bucket **) pecalloc(nSize, sizeof(Bucket *), persistent); - - if (!ht->arBuckets) { - return FAILURE; - } - if (pHashFunction == NULL) { - ht->pHashFunction = hashpjw; - } else { - ht->pHashFunction = pHashFunction; - } - ht->pDestructor = pDestructor; - ht->nTableSize = nSize; - ht->pListHead = NULL; - ht->pListTail = NULL; - ht->nNumOfElements = 0; - ht->nNextFreeElement = 0; - ht->pInternalPointer = NULL; - ht->persistent = persistent; - return SUCCESS; -} - -ZEND_API int zend_hash_add_or_update(HashTable *ht, char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest, int flag) -{ - ulong h; - uint nIndex; - Bucket *p; - - IS_CONSISTENT(ht); - - if (nKeyLength <= 0) { -#if ZEND_DEBUG - ZEND_PUTS("zend_hash_update: Can't put in empty key\n"); -#endif - return FAILURE; - } - - HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_update_or_next_insert(ht, idx, pData, nDataSize, pDest, flag)); - - h = ht->pHashFunction(arKey, nKeyLength); - nIndex = h % ht->nTableSize; - - p = ht->arBuckets[nIndex]; - while (p != NULL) { - if ((p->h == h) && (p->nKeyLength == nKeyLength)) { - if (!memcmp(p->arKey, arKey, nKeyLength)) { - if (flag & HASH_ADD) { - return FAILURE; - } - HANDLE_BLOCK_INTERRUPTIONS(); -#if ZEND_DEBUG - if (p->pData == pData) { - ZEND_PUTS("Fatal error in zend_hash_update: p->pData == pData\n"); - HANDLE_UNBLOCK_INTERRUPTIONS(); - return FAILURE; - } -#endif - if (ht->pDestructor) { - ht->pDestructor(p->pData); - } - UPDATE_DATA(ht, p, pData, nDataSize); - if (pDest) { - *pDest = p->pData; - } - HANDLE_UNBLOCK_INTERRUPTIONS(); - return SUCCESS; - } - } - p = p->pNext; - } - - p = (Bucket *) pemalloc(sizeof(Bucket)-1+nKeyLength, ht->persistent); - if (!p) { - return FAILURE; - } - memcpy(p->arKey, arKey, nKeyLength); - p->nKeyLength = nKeyLength; - INIT_DATA(ht, p, pData, nDataSize); - p->h = h; - CONNECT_TO_BUCKET_DLLIST(p, ht->arBuckets[nIndex]); - if (pDest) { - *pDest = p->pData; - } - - HANDLE_BLOCK_INTERRUPTIONS(); - CONNECT_TO_GLOBAL_DLLIST(p, ht); - ht->arBuckets[nIndex] = p; - HANDLE_UNBLOCK_INTERRUPTIONS(); - - ht->nNumOfElements++; - ZEND_HASH_IF_FULL_DO_RESIZE(ht); /* If the Hash table is full, resize it */ - return SUCCESS; -} - -ZEND_API int zend_hash_quick_add_or_update(HashTable *ht, char *arKey, uint nKeyLength, ulong h, void *pData, uint nDataSize, void **pDest, int flag) -{ - uint nIndex; - Bucket *p; - - IS_CONSISTENT(ht); - - if (nKeyLength <= 0) { -#if ZEND_DEBUG - ZEND_PUTS("zend_hash_update: Can't put in empty key\n"); -#endif - return FAILURE; - } - - nIndex = h % ht->nTableSize; - - p = ht->arBuckets[nIndex]; - while (p != NULL) { - if ((p->h == h) && (p->nKeyLength == nKeyLength)) { - if (!memcmp(p->arKey, arKey, nKeyLength)) { - if (flag & HASH_ADD) { - return FAILURE; - } - HANDLE_BLOCK_INTERRUPTIONS(); -#if ZEND_DEBUG - if (p->pData == pData) { - ZEND_PUTS("Fatal error in zend_hash_update: p->pData == pData\n"); - HANDLE_UNBLOCK_INTERRUPTIONS(); - return FAILURE; - } -#endif - if (ht->pDestructor) { - ht->pDestructor(p->pData); - } - UPDATE_DATA(ht, p, pData, nDataSize); - if (pDest) { - *pDest = p->pData; - } - HANDLE_UNBLOCK_INTERRUPTIONS(); - return SUCCESS; - } - } - p = p->pNext; - } - - p = (Bucket *) pemalloc(sizeof(Bucket)-1+nKeyLength, ht->persistent); - if (!p) { - return FAILURE; - } - - memcpy(p->arKey, arKey, nKeyLength); - p->nKeyLength = nKeyLength; - INIT_DATA(ht, p, pData, nDataSize); - p->h = h; - - CONNECT_TO_BUCKET_DLLIST(p, ht->arBuckets[nIndex]); - - if (pDest) { - *pDest = p->pData; - } - - HANDLE_BLOCK_INTERRUPTIONS(); - ht->arBuckets[nIndex] = p; - CONNECT_TO_GLOBAL_DLLIST(p, ht); - HANDLE_UNBLOCK_INTERRUPTIONS(); - - ht->nNumOfElements++; - ZEND_HASH_IF_FULL_DO_RESIZE(ht); /* If the Hash table is full, resize it */ - return SUCCESS; -} - - -ZEND_API int zend_hash_index_update_or_next_insert(HashTable *ht, ulong h, void *pData, uint nDataSize, void **pDest, int flag) -{ - uint nIndex; - Bucket *p; - - IS_CONSISTENT(ht); - - if (flag & HASH_NEXT_INSERT) { - h = ht->nNextFreeElement; - } - nIndex = h % ht->nTableSize; - - p = ht->arBuckets[nIndex]; - while (p != NULL) { - if ((p->nKeyLength == 0) && (p->h == h)) { - if (flag & HASH_NEXT_INSERT || flag & HASH_ADD) { - return FAILURE; - } - HANDLE_BLOCK_INTERRUPTIONS(); -#if ZEND_DEBUG - if (p->pData == pData) { - ZEND_PUTS("Fatal error in zend_hash_index_update: p->pData == pData\n"); - HANDLE_UNBLOCK_INTERRUPTIONS(); - return FAILURE; - } -#endif - if (ht->pDestructor) { - ht->pDestructor(p->pData); - } - UPDATE_DATA(ht, p, pData, nDataSize); - HANDLE_UNBLOCK_INTERRUPTIONS(); - if (h >= ht->nNextFreeElement) { - ht->nNextFreeElement = h + 1; - } - if (pDest) { - *pDest = p->pData; - } - return SUCCESS; - } - p = p->pNext; - } - p = (Bucket *) pemalloc(sizeof(Bucket)-1, ht->persistent); - if (!p) { - return FAILURE; - } - p->nKeyLength = 0; /* Numeric indices are marked by making the nKeyLength == 0 */ - p->h = h; - INIT_DATA(ht, p, pData, nDataSize); - if (pDest) { - *pDest = p->pData; - } - - CONNECT_TO_BUCKET_DLLIST(p, ht->arBuckets[nIndex]); - - HANDLE_BLOCK_INTERRUPTIONS(); - ht->arBuckets[nIndex] = p; - CONNECT_TO_GLOBAL_DLLIST(p, ht); - HANDLE_UNBLOCK_INTERRUPTIONS(); - - if (h >= ht->nNextFreeElement) { - ht->nNextFreeElement = h + 1; - } - ht->nNumOfElements++; - ZEND_HASH_IF_FULL_DO_RESIZE(ht); - return SUCCESS; -} - - -static int zend_hash_do_resize(HashTable *ht) -{ - Bucket **t; - - IS_CONSISTENT(ht); - - if ((ht->nHashSizeIndex < nNumPrimeNumbers - 1)) { /* Let's double the table size */ - t = (Bucket **) perealloc_recoverable(ht->arBuckets, PrimeNumbers[ht->nHashSizeIndex + 1] * sizeof(Bucket *), ht->persistent); - if (t) { - HANDLE_BLOCK_INTERRUPTIONS(); - ht->arBuckets = t; - ht->nTableSize = PrimeNumbers[ht->nHashSizeIndex + 1]; - ht->nHashSizeIndex++; - zend_hash_rehash(ht); - HANDLE_UNBLOCK_INTERRUPTIONS(); - return SUCCESS; - } - return FAILURE; - } - return SUCCESS; -} - -ZEND_API int zend_hash_rehash(HashTable *ht) -{ - Bucket *p; - uint nIndex; - - IS_CONSISTENT(ht); - - memset(ht->arBuckets, 0, PrimeNumbers[ht->nHashSizeIndex] * sizeof(Bucket *)); - p = ht->pListHead; - while (p != NULL) { - nIndex = p->h % ht->nTableSize; - CONNECT_TO_BUCKET_DLLIST(p, ht->arBuckets[nIndex]); - ht->arBuckets[nIndex] = p; - p = p->pListNext; - } - return SUCCESS; -} - -ZEND_API int zend_hash_del_key_or_index(HashTable *ht, char *arKey, uint nKeyLength, ulong h, int flag) -{ - uint nIndex; - Bucket *p; - - IS_CONSISTENT(ht); - - if (flag == HASH_DEL_KEY) { - HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_del_key_or_index(ht, arKey, nKeyLength, idx, HASH_DEL_INDEX)); - h = ht->pHashFunction(arKey, nKeyLength); - } - nIndex = h % ht->nTableSize; - - p = ht->arBuckets[nIndex]; - while (p != NULL) { - if ((p->h == h) && ((p->nKeyLength == 0) || /* Numeric index */ - ((p->nKeyLength == nKeyLength) && (!memcmp(p->arKey, arKey, nKeyLength))))) { - HANDLE_BLOCK_INTERRUPTIONS(); - if (p == ht->arBuckets[nIndex]) { - ht->arBuckets[nIndex] = p->pNext; - } else { - p->pLast->pNext = p->pNext; - } - if (p->pNext) { - p->pNext->pLast = p->pLast; - } - if (p->pListLast != NULL) { - p->pListLast->pListNext = p->pListNext; - } else { - /* Deleting the head of the list */ - ht->pListHead = p->pListNext; - } - if (p->pListNext != NULL) { - p->pListNext->pListLast = p->pListLast; - } else { - ht->pListTail = p->pListLast; - } - if (ht->pInternalPointer == p) { - ht->pInternalPointer = p->pListNext; - } - if (ht->pDestructor) { - ht->pDestructor(p->pData); - } - if (!p->pDataPtr) { - pefree(p->pData, ht->persistent); - } - pefree(p, ht->persistent); - HANDLE_UNBLOCK_INTERRUPTIONS(); - ht->nNumOfElements--; - return SUCCESS; - } - p = p->pNext; - } - return FAILURE; -} - - -ZEND_API void zend_hash_destroy(HashTable *ht) -{ - Bucket *p, *q; - - IS_CONSISTENT(ht); - - SET_INCONSISTENT(HT_IS_DESTROYING); - - p = ht->pListHead; - while (p != NULL) { - q = p; - p = p->pListNext; - if (ht->pDestructor) { - ht->pDestructor(q->pData); - } - if (!q->pDataPtr && q->pData) { - pefree(q->pData, ht->persistent); - } - pefree(q, ht->persistent); - } - pefree(ht->arBuckets, ht->persistent); - - SET_INCONSISTENT(HT_DESTROYED); -} - - -ZEND_API void zend_hash_clean(HashTable *ht) -{ - Bucket *p, *q; - - IS_CONSISTENT(ht); - - SET_INCONSISTENT(HT_CLEANING); - - p = ht->pListHead; - while (p != NULL) { - q = p; - p = p->pListNext; - if (ht->pDestructor) { - ht->pDestructor(q->pData); - } - if (!q->pDataPtr && q->pData) { - pefree(q->pData, ht->persistent); - } - pefree(q, ht->persistent); - } - memset(ht->arBuckets, 0, ht->nTableSize*sizeof(Bucket *)); - ht->pListHead = NULL; - ht->pListTail = NULL; - ht->nNumOfElements = 0; - ht->nNextFreeElement = 0; - ht->pInternalPointer = NULL; - - SET_INCONSISTENT(HT_OK); -} - -/* This function is used by the various apply() functions. - * It deletes the passed bucket, and returns the address of the - * next bucket. The hash *may* be altered during that time, the - * returned value will still be valid. - */ -static Bucket *zend_hash_apply_deleter(HashTable *ht, Bucket *p) -{ - Bucket *retval; - - HANDLE_BLOCK_INTERRUPTIONS(); - - if (ht->pDestructor) { - ht->pDestructor(p->pData); - } - if (!p->pDataPtr) { - pefree(p->pData, ht->persistent); - } - retval = p->pListNext; - - if (p->pLast) { - p->pLast->pNext = p->pNext; - } else { - uint nIndex; - - nIndex = p->h % ht->nTableSize; - ht->arBuckets[nIndex] = p->pNext; - } - if (p->pNext) { - p->pNext->pLast = p->pLast; - } else { - /* Nothing to do as this list doesn't have a tail */ - } - - if (p->pListLast != NULL) { - p->pListLast->pListNext = p->pListNext; - } else { - /* Deleting the head of the list */ - ht->pListHead = p->pListNext; - } - if (p->pListNext != NULL) { - p->pListNext->pListLast = p->pListLast; - } else { - ht->pListTail = p->pListLast; - } - if (ht->pInternalPointer == p) { - ht->pInternalPointer = p->pListNext; - } - pefree(p, ht->persistent); - HANDLE_UNBLOCK_INTERRUPTIONS(); - ht->nNumOfElements--; - - return retval; -} - - -ZEND_API void zend_hash_graceful_destroy(HashTable *ht) -{ - Bucket *p; - - IS_CONSISTENT(ht); - - p = ht->pListHead; - while (p != NULL) { - p = zend_hash_apply_deleter(ht, p); - } - pefree(ht->arBuckets, ht->persistent); - - SET_INCONSISTENT(HT_DESTROYED); -} - -/* This is used to selectively delete certain entries from a hashtable. - * destruct() receives the data and decides if the entry should be deleted - * or not - */ - - -ZEND_API void zend_hash_apply(HashTable *ht, apply_func_t apply_func) -{ - Bucket *p; - - IS_CONSISTENT(ht); - - p = ht->pListHead; - while (p != NULL) { - if (apply_func(p->pData)) { - p = zend_hash_apply_deleter(ht, p); - } else { - p = p->pListNext; - } - } -} - - -ZEND_API void zend_hash_apply_with_argument(HashTable *ht, apply_func_arg_t apply_func, void *argument) -{ - Bucket *p; - - IS_CONSISTENT(ht); - - p = ht->pListHead; - while (p != NULL) { - if (apply_func(p->pData, argument)) { - p = zend_hash_apply_deleter(ht, p); - } else { - p = p->pListNext; - } - } -} - - -ZEND_API void zend_hash_apply_with_arguments(HashTable *ht, int (*destruct)(void *, int, va_list, zend_hash_key *), int num_args, ...) -{ - Bucket *p; - va_list args; - zend_hash_key hash_key; - - IS_CONSISTENT(ht); - - va_start(args, num_args); - - p = ht->pListHead; - while (p != NULL) { - hash_key.arKey = p->arKey; - hash_key.nKeyLength = p->nKeyLength; - hash_key.h = p->h; - if (destruct(p->pData, num_args, args, &hash_key)) { - p = zend_hash_apply_deleter(ht, p); - } else { - p = p->pListNext; - } - } - - va_end(args); -} - - - -ZEND_API void zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size) -{ - Bucket *p; - - IS_CONSISTENT(source); - IS_CONSISTENT(target); - - p = source->pListHead; - while (p) { - memcpy(tmp, p->pData, size); - if (pCopyConstructor) { - pCopyConstructor(tmp); - } - if (p->nKeyLength) { - zend_hash_update(target, p->arKey, p->nKeyLength, tmp, size, NULL); - } else { - zend_hash_index_update(target, p->h, tmp, size, NULL); - } - p = p->pListNext; - } - target->pInternalPointer = target->pListHead; -} - - -ZEND_API void zend_hash_merge(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, int overwrite) -{ - Bucket *p; - void *t; - int mode = (overwrite?HASH_UPDATE:HASH_ADD); - - IS_CONSISTENT(source); - IS_CONSISTENT(target); - - p = source->pListHead; - while (p) { - memcpy(tmp, p->pData, size); - if (p->nKeyLength>0) { - if (zend_hash_add_or_update(target, p->arKey, p->nKeyLength, tmp, size, &t, mode)==SUCCESS && pCopyConstructor) { - pCopyConstructor(t); - } - } else { - if ((mode==HASH_UPDATE || !zend_hash_index_exists(target, p->h)) && zend_hash_index_update(target, p->h, tmp, size, &t)==SUCCESS && pCopyConstructor) { - pCopyConstructor(t); - } - } - p = p->pListNext; - } - target->pInternalPointer = target->pListHead; -} - - -ZEND_API ulong zend_get_hash_value(HashTable *ht, char *arKey, uint nKeyLength) -{ - IS_CONSISTENT(ht); - - return ht->pHashFunction(arKey, nKeyLength); -} - - -/* Returns SUCCESS if found and FAILURE if not. The pointer to the - * data is returned in pData. The reason is that there's no reason - * someone using the hash table might not want to have NULL data - */ -ZEND_API int zend_hash_find(HashTable *ht, char *arKey, uint nKeyLength, void **pData) -{ - ulong h; - uint nIndex; - Bucket *p; - - IS_CONSISTENT(ht); - - HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_find(ht, idx, pData)); - - h = ht->pHashFunction(arKey, nKeyLength); - nIndex = h % ht->nTableSize; - - p = ht->arBuckets[nIndex]; - while (p != NULL) { - if ((p->h == h) && (p->nKeyLength == nKeyLength)) { - if (!memcmp(p->arKey, arKey, nKeyLength)) { - *pData = p->pData; - return SUCCESS; - } - } - p = p->pNext; - } - return FAILURE; -} - - -ZEND_API int zend_hash_quick_find(HashTable *ht, char *arKey, uint nKeyLength, ulong h, void **pData) -{ - uint nIndex; - Bucket *p; - - IS_CONSISTENT(ht); - - nIndex = h % ht->nTableSize; - - p = ht->arBuckets[nIndex]; - while (p != NULL) { - if ((p->h == h) && (p->nKeyLength == nKeyLength)) { - if (!memcmp(p->arKey, arKey, nKeyLength)) { - *pData = p->pData; - return SUCCESS; - } - } - p = p->pNext; - } - return FAILURE; -} - - -ZEND_API int zend_hash_exists(HashTable *ht, char *arKey, uint nKeyLength) -{ - ulong h; - uint nIndex; - Bucket *p; - - IS_CONSISTENT(ht); - - HANDLE_NUMERIC(arKey, nKeyLength, zend_hash_index_exists(ht, idx)); - - h = ht->pHashFunction(arKey, nKeyLength); - nIndex = h % ht->nTableSize; - - p = ht->arBuckets[nIndex]; - while (p != NULL) { - if ((p->h == h) && (p->nKeyLength == nKeyLength)) { - if (!memcmp(p->arKey, arKey, nKeyLength)) { - return 1; - } - } - p = p->pNext; - } - return 0; -} - - -ZEND_API int zend_hash_index_find(HashTable *ht, ulong h, void **pData) -{ - uint nIndex; - Bucket *p; - - IS_CONSISTENT(ht); - - nIndex = h % ht->nTableSize; - - p = ht->arBuckets[nIndex]; - while (p != NULL) { - if ((p->h == h) && (p->nKeyLength == 0)) { - *pData = p->pData; - return SUCCESS; - } - p = p->pNext; - } - return FAILURE; -} - - -ZEND_API int zend_hash_index_exists(HashTable *ht, ulong h) -{ - uint nIndex; - Bucket *p; - - IS_CONSISTENT(ht); - - nIndex = h % ht->nTableSize; - - p = ht->arBuckets[nIndex]; - while (p != NULL) { - if ((p->h == h) && (p->nKeyLength == 0)) { - return 1; - } - p = p->pNext; - } - return 0; -} - - -ZEND_API int zend_hash_num_elements(HashTable *ht) -{ - IS_CONSISTENT(ht); - - return ht->nNumOfElements; -} - - -ZEND_API void zend_hash_internal_pointer_reset(HashTable *ht) -{ - IS_CONSISTENT(ht); - - ht->pInternalPointer = ht->pListHead; -} - - -/* This function will be extremely optimized by remembering - * the end of the list - */ -ZEND_API void zend_hash_internal_pointer_end(HashTable *ht) -{ - IS_CONSISTENT(ht); - - ht->pInternalPointer = ht->pListTail; -} - - -ZEND_API void zend_hash_move_forward(HashTable *ht) -{ - IS_CONSISTENT(ht); - - if (ht->pInternalPointer) { - ht->pInternalPointer = ht->pInternalPointer->pListNext; - } -} - -ZEND_API void zend_hash_move_backwards(HashTable *ht) -{ - IS_CONSISTENT(ht); - - if (ht->pInternalPointer) { - ht->pInternalPointer = ht->pInternalPointer->pListLast; - } -} - - -/* This function should be made binary safe */ -ZEND_API int zend_hash_get_current_key(HashTable *ht, char **str_index, ulong *num_index) -{ - Bucket *p = ht->pInternalPointer; - - IS_CONSISTENT(ht); - - if (p) { - if (p->nKeyLength) { - *str_index = (char *) pemalloc(p->nKeyLength, ht->persistent); - memcpy(*str_index, p->arKey, p->nKeyLength); - return HASH_KEY_IS_STRING; - } else { - *num_index = p->h; - return HASH_KEY_IS_LONG; - } - } - return HASH_KEY_NON_EXISTANT; -} - - -ZEND_API int zend_hash_get_current_key_type(HashTable *ht) -{ - Bucket *p = ht->pInternalPointer; - - IS_CONSISTENT(ht); - - if (p) { - if (p->nKeyLength) { - return HASH_KEY_IS_STRING; - } else { - return HASH_KEY_IS_LONG; - } - } - return HASH_KEY_NON_EXISTANT; -} - - -ZEND_API int zend_hash_get_current_data(HashTable *ht, void **pData) -{ - Bucket *p = ht->pInternalPointer; - - IS_CONSISTENT(ht); - - if (p) { - *pData = p->pData; - return SUCCESS; - } else { - return FAILURE; - } -} - - -ZEND_API int zend_hash_sort(HashTable *ht, sort_func_t sort_func, - compare_func_t compar, int renumber) -{ - Bucket **arTmp; - Bucket *p; - int i, j; - - IS_CONSISTENT(ht); - - if (ht->nNumOfElements <= 1) { /* Doesn't require sorting */ - return SUCCESS; - } - arTmp = (Bucket **) pemalloc(ht->nNumOfElements * sizeof(Bucket *), ht->persistent); - if (!arTmp) { - return FAILURE; - } - p = ht->pListHead; - i = 0; - while (p) { - arTmp[i] = p; - p = p->pListNext; - i++; - } - - (*sort_func)((void *) arTmp, i, sizeof(Bucket *), compar); - - HANDLE_BLOCK_INTERRUPTIONS(); - ht->pListHead = arTmp[0]; - ht->pListTail = NULL; - ht->pInternalPointer = ht->pListHead; - - for (j = 0; j < i; j++) { - if (ht->pListTail) { - ht->pListTail->pListNext = arTmp[j]; - } - arTmp[j]->pListLast = ht->pListTail; - arTmp[j]->pListNext = NULL; - ht->pListTail = arTmp[j]; - } - pefree(arTmp, ht->persistent); - HANDLE_UNBLOCK_INTERRUPTIONS(); - - if (renumber) { - p = ht->pListHead; - i=0; - while (p != NULL) { - p->nKeyLength = 0; - p->h = i++; - p = p->pListNext; - } - ht->nNextFreeElement = i; - zend_hash_rehash(ht); - } - return SUCCESS; -} - - -ZEND_API int zend_hash_minmax(HashTable *ht, int (*compar) (const void *, const void *), int flag, void **pData) -{ - Bucket *p,*res; - - IS_CONSISTENT(ht); - - if (ht->nNumOfElements == 0 ) { - *pData=NULL; - return FAILURE; - } - - res = p = ht->pListHead; - while ((p = p->pListNext)) { - if (flag) { - if (compar(&res,&p) < 0) { /* max */ - res = p; - } - } else { - if (compar(&res,&p) > 0) { /* min */ - res = p; - } - } - } - *pData = res->pData; - return SUCCESS; -} - -ZEND_API ulong zend_hash_next_free_element(HashTable *ht) -{ - IS_CONSISTENT(ht); - - return ht->nNextFreeElement; - -} - -#if ZEND_DEBUG -void zend_hash_display_pListTail(HashTable *ht) -{ - Bucket *p; - - p = ht->pListTail; - while (p != NULL) { - zend_printf("pListTail has key %s\n", p->arKey); - p = p->pListLast; - } -} - -void zend_hash_display(HashTable *ht) -{ - Bucket *p; - uint i; - - for (i = 0; i < ht->nTableSize; i++) { - p = ht->arBuckets[i]; - while (p != NULL) { - zend_printf("%s <==> 0x%X\n", p->arKey, p->h); - p = p->pNext; - } - } - - p = ht->pListTail; - while (p != NULL) { - zend_printf("%s <==> 0x%X\n", p->arKey, p->h); - p = p->pListLast; - } -} -#endif - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/Zend/zend_hash.h b/Zend/zend_hash.h deleted file mode 100644 index f7dbe86a35..0000000000 --- a/Zend/zend_hash.h +++ /dev/null @@ -1,177 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - -#ifndef _HASH_ -#define _HASH_ - -#include - -#define HASH_KEY_IS_STRING 1 -#define HASH_KEY_IS_LONG 2 -#define HASH_KEY_NON_EXISTANT 3 - -#define HASH_UPDATE (1<<0) -#define HASH_ADD (1<<1) -#define HASH_NEXT_INSERT (1<<2) -#define HASH_ADD_PTR (1<<3) - -#define HASH_DEL_KEY 0 -#define HASH_DEL_INDEX 1 - -typedef int (*compare_func_t)(const void *, const void *); -typedef void (*sort_func_t)(void *, size_t, register size_t, compare_func_t); -typedef void (*dtor_func_t)(void *pDest); -typedef int (*apply_func_t)(void *pDest); -typedef int (*apply_func_arg_t)(void *pDest, void *argument); -typedef ulong (*hash_func_t)(char *arKey, uint nKeyLength); -typedef void (*copy_ctor_func_t)(void *pElement); - -struct hashtable; - -typedef struct bucket { - ulong h; /* Used for numeric indexing */ - uint nKeyLength; - void *pData; - void *pDataPtr; - struct bucket *pListNext; - struct bucket *pListLast; - struct bucket *pNext; - struct bucket *pLast; - char arKey[1]; /* Must be last element */ -} Bucket; - -typedef struct hashtable { - uint nTableSize; - uint nHashSizeIndex; - uint nNumOfElements; - ulong nNextFreeElement; - hash_func_t pHashFunction; - Bucket *pInternalPointer; /* Used for element traversal */ - Bucket *pListHead; - Bucket *pListTail; - Bucket **arBuckets; - dtor_func_t pDestructor; - unsigned char persistent; -#if ZEND_DEBUG - int inconsistent; -#endif -} HashTable; - -BEGIN_EXTERN_C() - -/* startup/shutdown */ -ZEND_API int zend_hash_init(HashTable *ht, uint nSize, hash_func_t pHashFunction, dtor_func_t pDestructor, int persistent); -ZEND_API void zend_hash_destroy(HashTable *ht); - -ZEND_API void zend_hash_clean(HashTable *ht); - -/* additions/updates/changes */ -ZEND_API int zend_hash_add_or_update(HashTable *ht, char *arKey, uint nKeyLength, void *pData, uint nDataSize, void **pDest,int flag); -#define zend_hash_update(ht,arKey,nKeyLength,pData,nDataSize,pDest) \ - zend_hash_add_or_update(ht,arKey,nKeyLength,pData,nDataSize,pDest,HASH_UPDATE) -#define zend_hash_add(ht,arKey,nKeyLength,pData,nDataSize,pDest) \ - zend_hash_add_or_update(ht,arKey,nKeyLength,pData,nDataSize,pDest,HASH_ADD) -#define zend_hash_update_ptr(ht,arKey,nKeyLength,pData,nDataSize,pDest) \ - zend_hash_add_or_update(ht,arKey,nKeyLength,pData,0,pDest,(HASH_UPDATE|HASH_ADD_PTR)) -#define zend_hash_add_ptr(ht,arKey,nKeyLength,pData,nDataSize,pDest) \ - zend_hash_add_or_update(ht,arKey,nKeyLength,pData,nDataSize,pDest,(HASH_ADD|HASH_ADD_PTR)) - -ZEND_API int zend_hash_quick_add_or_update(HashTable *ht, char *arKey, uint nKeyLength, ulong h, void *pData, uint nDataSize, void **pDest,int flag); -#define zend_hash_quick_update(ht,arKey,nKeyLength,h,pData,nDataSize,pDest) \ - zend_hash_quick_add_or_update(ht,arKey,nKeyLength,h,pData,nDataSize,pDest,HASH_UPDATE) -#define zend_hash_quick_add(ht,arKey,nKeyLength,h,pData,nDataSize,pDest) \ - zend_hash_quick_add_or_update(ht,arKey,nKeyLength,h,pData,nDataSize,pDest,HASH_ADD) -#define zend_hash_quick_update_ptr(ht,arKey,nKeyLength,h,pData,nDataSize,pDest) \ - zend_hash_quick_add_or_update(ht,arKey,nKeyLength,h,pData,0,pDest,HASH_UPDATE|HASH_ADD_PTR) - -ZEND_API int zend_hash_index_update_or_next_insert(HashTable *ht, ulong h, void *pData, uint nDataSize, void **pDest, int flag); -#define zend_hash_index_update(ht,h,pData,nDataSize,pDest) \ - zend_hash_index_update_or_next_insert(ht,h,pData,nDataSize,pDest,HASH_UPDATE) -#define zend_hash_next_index_insert(ht,pData,nDataSize,pDest) \ - zend_hash_index_update_or_next_insert(ht,0,pData,nDataSize,pDest,HASH_NEXT_INSERT) -#define zend_hash_next_index_insert_ptr(ht,pData,nDataSize,pDest) \ - zend_hash_index_update_or_next_insert(ht,0,pData,nDataSize,pDest,HASH_NEXT_INSERT|HASH_ADD_PTR) - -typedef struct _zend_hash_key { - char *arKey; - uint nKeyLength; - ulong h; -} zend_hash_key; - - -#define ZEND_STD_HASH_APPLIER \ - int (*)(void *element, int num_args, va_list args, zend_hash_key *hash_key) - -ZEND_API void zend_hash_graceful_destroy(HashTable *ht); -ZEND_API void zend_hash_apply(HashTable *ht, apply_func_t apply_func); -ZEND_API void zend_hash_apply_with_argument(HashTable *ht, apply_func_arg_t apply_func, void *); -ZEND_API void zend_hash_apply_with_arguments(HashTable *ht, ZEND_STD_HASH_APPLIER, int, ...); - - - - -/* Deletes */ -ZEND_API int zend_hash_del_key_or_index(HashTable *ht, char *arKey, uint nKeyLength, ulong h, int flag); -#define zend_hash_del(ht,arKey,nKeyLength) \ - zend_hash_del_key_or_index(ht,arKey,nKeyLength,0,HASH_DEL_KEY) -#define zend_hash_index_del(ht,h) \ - zend_hash_del_key_or_index(ht,NULL,0,h,HASH_DEL_INDEX) - -ZEND_API ulong zend_get_hash_value(HashTable *ht, char *arKey, uint nKeyLength); - -/* Data retreival */ -ZEND_API int zend_hash_find(HashTable *ht, char *arKey, uint nKeyLength, void **pData); -ZEND_API int zend_hash_quick_find(HashTable *ht, char *arKey, uint nKeyLength, ulong h, void **pData); -ZEND_API int zend_hash_index_find(HashTable *ht, ulong h, void **pData); - -/* Misc */ -ZEND_API int zend_hash_exists(HashTable *ht, char *arKey, uint nKeyLength); -ZEND_API int zend_hash_index_exists(HashTable *ht, ulong h); -ZEND_API ulong zend_hash_next_free_element(HashTable *ht); - -/* traversing */ -ZEND_API void zend_hash_move_forward(HashTable *ht); -ZEND_API void zend_hash_move_backwards(HashTable *ht); -ZEND_API int zend_hash_get_current_key(HashTable *ht, char **str_index, ulong *num_index); -ZEND_API int zend_hash_get_current_key_type(HashTable *ht); -ZEND_API int zend_hash_get_current_data(HashTable *ht, void **pData); -ZEND_API void zend_hash_internal_pointer_reset(HashTable *ht); -ZEND_API void zend_hash_internal_pointer_end(HashTable *ht); - -/* Copying, merging and sorting */ -ZEND_API void zend_hash_copy(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size); -ZEND_API void zend_hash_merge(HashTable *target, HashTable *source, copy_ctor_func_t pCopyConstructor, void *tmp, uint size, int overwrite); -ZEND_API int zend_hash_sort(HashTable *ht, sort_func_t sort_func, compare_func_t compare_func, int renumber); -ZEND_API int zend_hash_minmax(HashTable *ht, int (*compar)(const void *, const void *), int flag, void **pData); - -ZEND_API int zend_hash_num_elements(HashTable *ht); - -ZEND_API int zend_hash_rehash(HashTable *ht); - -ZEND_API ulong hashpjw(char *arKey, uint nKeyLength); - -#if ZEND_DEBUG -/* debug */ -void zend_hash_display_pListTail(HashTable *ht); -void zend_hash_display(HashTable *ht); -#endif - -END_EXTERN_C() - -#endif /* _HASH_ */ diff --git a/Zend/zend_highlight.c b/Zend/zend_highlight.c deleted file mode 100644 index 39fb8fc981..0000000000 --- a/Zend/zend_highlight.c +++ /dev/null @@ -1,178 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include "zend.h" -#include "zend-parser.h" -#include "zend_compile.h" -#include "zend_highlight.h" -#include "zend_ptr_stack.h" -#include "zend_globals.h" - -#ifndef ZTS -extern char *zendtext; -extern int zendleng; -#else -#define zendtext ((char *) zend_get_zendtext(CLS_C)) -#define zendleng zend_get_zendleng(CLS_C) -#endif - -static void html_putc(char c) -{ - switch (c) { - case '\n': - ZEND_PUTS("
"); - break; - case '<': - ZEND_PUTS("<"); - break; - case '>': - ZEND_PUTS(">"); - break; - case '&': - ZEND_PUTS("&"); - break; - case ' ': - ZEND_PUTS(" "); - break; - case '\t': - ZEND_PUTS("    "); - break; - default: - ZEND_PUTC(c); - break; - } -} - - -static void html_puts(char *s, uint len) -{ - register char *ptr=s, *end=s+len; - - while (ptrhighlight_html; - char *next_color; - int in_string=0; - CLS_FETCH(); - - zend_printf(""); - zend_printf("\n", last_color); - /* highlight stuff coming back from zendlex() */ - token.type = 0; - while ((token_type=lex_scan(&token CLS_CC))) { - switch (token_type) { - case T_INLINE_HTML: - next_color = syntax_highlighter_ini->highlight_html; - break; - case T_COMMENT: - next_color = syntax_highlighter_ini->highlight_comment; - break; - case T_OPEN_TAG: - next_color = syntax_highlighter_ini->highlight_default; - break; - case T_CLOSE_TAG: - next_color = syntax_highlighter_ini->highlight_default; - break; - case T_CONSTANT_ENCAPSED_STRING: - next_color = syntax_highlighter_ini->highlight_string; - break; - case '"': - next_color = syntax_highlighter_ini->highlight_string; - in_string = !in_string; - break; - case T_WHITESPACE: - html_puts(zendtext, zendleng); /* no color needed */ - token.type = 0; - continue; - break; - default: - if (token.type==0) { - next_color = syntax_highlighter_ini->highlight_keyword; - } else { - if (in_string) { - next_color = syntax_highlighter_ini->highlight_string; - } else { - next_color = syntax_highlighter_ini->highlight_default; - } - } - break; - } - - if (last_color != next_color) { - if (last_color != syntax_highlighter_ini->highlight_html) { - zend_printf(""); - } - last_color = next_color; - if (last_color != syntax_highlighter_ini->highlight_html) { - zend_printf("", last_color); - } - } - switch (token_type) { - case T_END_HEREDOC: - html_puts(token.value.str.val, token.value.str.len); - break; - default: - html_puts(zendtext, zendleng); - break; - } - - if (token.type == IS_STRING) { - switch (token_type) { - case T_OPEN_TAG: - case T_CLOSE_TAG: - case T_WHITESPACE: - break; - default: - efree(token.value.str.val); - break; - } - } else if (token_type == T_END_HEREDOC) { - zend_bool has_semicolon=(strchr(token.value.str.val, ';')?1:0); - - efree(token.value.str.val); - if (has_semicolon) { - /* the following semicolon was unput(), ignore it */ - lex_scan(&token CLS_CC); - } - } - token.type = 0; - } - if (last_color != syntax_highlighter_ini->highlight_html) { - zend_printf("\n"); - } - zend_printf("\n"); - zend_printf(""); -} - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/Zend/zend_highlight.h b/Zend/zend_highlight.h deleted file mode 100644 index 61b75ebab9..0000000000 --- a/Zend/zend_highlight.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _HIGHLIGHT_H -#define _HIGHLIGHT_H - -#define HL_COMMENT_COLOR "#FF8000" /* orange */ -#define HL_DEFAULT_COLOR "#0000BB" /* blue */ -#define HL_HTML_COLOR "#000000" /* black */ -#define HL_STRING_COLOR "#DD0000" /* red */ -#define HL_BG_COLOR "#FFFFFF" /* white */ -#define HL_KEYWORD_COLOR "#007700" /* green */ - - -typedef struct _zend_syntax_highlighter_ini { - char *highlight_html; - char *highlight_comment; - char *highlight_default; - char *highlight_string; - char *highlight_keyword; -} zend_syntax_highlighter_ini; - - -BEGIN_EXTERN_C() -ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini); -int highlight_file(char *filename, zend_syntax_highlighter_ini *syntax_highlighter_ini); -int highlight_string(zval *str, zend_syntax_highlighter_ini *syntax_highlighter_ini); -END_EXTERN_C() - -extern zend_syntax_highlighter_ini syntax_highlighter_ini; - -#endif diff --git a/Zend/zend_indent.c b/Zend/zend_indent.c deleted file mode 100644 index 969848d1e9..0000000000 --- a/Zend/zend_indent.c +++ /dev/null @@ -1,152 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -/* This indenter doesn't really work, it's here for no particular reason. */ - - -#include "zend.h" -#include "zend-parser.h" -#include "zend_compile.h" -#include "zend_indent.h" - -#ifndef ZTS -extern char *zendtext; -extern int zendleng; -#else -#define zendtext ((char *) zend_get_zendtext(CLS_C)) -#define zendleng zend_get_zendleng(CLS_C) -#endif - - -static void handle_whitespace(int *emit_whitespace) -{ - unsigned char c; - int i; - - for (c=0; c<128; c++) { - if (emit_whitespace[c]>0) { - for (i=0; i0) { - ZEND_PUTS(" {\n"); - memset(emit_whitespace, 0, sizeof(int)*256); - } else { - ZEND_PUTS("{"); - } - break; - case '}': - nest_level--; - if (emit_whitespace['\n']==0) { - ZEND_PUTS("\n"); - } - for (i=0; i0) { - for (i=0; i | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _ZEND_INDENT_H -#define _ZEND_INDENT_H - -ZEND_API void zend_indent(void); - -#endif /* _ZEND_INDENT_H */ diff --git a/Zend/zend_list.c b/Zend/zend_list.c deleted file mode 100644 index 1d64603d33..0000000000 --- a/Zend/zend_list.c +++ /dev/null @@ -1,289 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -/* resource lists */ - -#include "zend.h" -#include "zend_list.h" -#include "zend_API.h" -#include "zend_globals.h" - -ZEND_API int le_index_ptr; - -static inline int zend_list_do_insert(HashTable *list,void *ptr, int type) -{ - int index; - list_entry le; - - index = zend_hash_next_free_element(list); - - if (index==0) index++; - - le.ptr=ptr; - le.type=type; - le.refcount=1; - zend_hash_index_update(list, index, (void *) &le, sizeof(list_entry), NULL); - return index; -} - -static inline int zend_list_do_delete(HashTable *list,int id) -{ - list_entry *le; - ELS_FETCH(); - - if (zend_hash_index_find(&EG(regular_list), id, (void **) &le)==SUCCESS) { -/* printf("del(%d): %d->%d\n", id, le->refcount, le->refcount-1); */ - if (--le->refcount<=0) { - return zend_hash_index_del(&EG(regular_list), id); - } else { - return SUCCESS; - } - } else { - return FAILURE; - } -} - - -static inline void *zend_list_do_find(HashTable *list,int id, int *type) -{ - list_entry *le; - - if (zend_hash_index_find(list, id, (void **) &le)==SUCCESS) { - *type = le->type; - return le->ptr; - } else { - *type = -1; - return NULL; - } -} - - -ZEND_API int zend_list_insert(void *ptr, int type) -{ - ELS_FETCH(); - - return zend_list_do_insert(&EG(regular_list), ptr, type); -} - - -ZEND_API int zend_plist_insert(void *ptr, int type) -{ - ELS_FETCH(); - - return zend_list_do_insert(&EG(persistent_list), ptr, type); -} - - -ZEND_API int zend_list_addref(int id) -{ - list_entry *le; - ELS_FETCH(); - - if (zend_hash_index_find(&EG(regular_list), id, (void **) &le)==SUCCESS) { -/* printf("add(%d): %d->%d\n", id, le->refcount, le->refcount+1); */ - le->refcount++; - return SUCCESS; - } else { - return FAILURE; - } -} - - -ZEND_API int zend_list_delete(int id) -{ - ELS_FETCH(); - - return zend_list_do_delete(&EG(regular_list), id); -} - - -ZEND_API int zend_plist_delete(int id) -{ - ELS_FETCH(); - - return zend_list_do_delete(&EG(persistent_list), id); -} - - -ZEND_API void *zend_list_find(int id, int *type) -{ - ELS_FETCH(); - - return zend_list_do_find(&EG(regular_list), id, type); -} - - -ZEND_API void *zend_plist_find(int id, int *type) -{ - ELS_FETCH(); - - return zend_list_do_find(&EG(persistent_list), id, type); -} - - -ZEND_API int zend_register_resource(zval *rsrc_result, void *rsrc_pointer, int rsrc_type) -{ - int rsrc_id; - - rsrc_id = zend_list_insert(rsrc_pointer, rsrc_type); - - if (rsrc_result) { - rsrc_result->value.lval = rsrc_id; - rsrc_result->type = IS_RESOURCE; - } - - return rsrc_id; -} - - -ZEND_API void *zend_fetch_resource(zval **passed_id, int default_id, char *resource_type_name, int *found_resource_type, int num_resource_types, ...) -{ - int id; - int actual_resource_type; - void *resource; - va_list resource_types; - int i; - - if (default_id==-1) { /* use id */ - if (!passed_id) { - if (resource_type_name) { - zend_error(E_WARNING, "No %s resource supplied", resource_type_name); - } - return NULL; - } else if ((*passed_id)->type != IS_RESOURCE) { - if (resource_type_name) { - zend_error(E_WARNING, "Supplied argument is not a valid %s resource", resource_type_name); - } - return NULL; - } - id = (*passed_id)->value.lval; - } else { - id = default_id; - } - - resource = zend_list_find(id, &actual_resource_type); - if (!resource) { - if (resource_type_name) - zend_error(E_WARNING, "%d is not a valid %s resource", id, resource_type_name); - return NULL; - } - - va_start(resource_types, num_resource_types); - for (i=0; itype,(void **) &ld)==SUCCESS) { - if (ld->list_destructor) { - (ld->list_destructor)(le->ptr); - } - } else { - zend_error(E_WARNING,"Unknown list entry type in request shutdown (%d)",le->type); - } -} - - -void plist_entry_destructor(void *ptr) -{ - list_entry *le = (list_entry *) ptr; - list_destructors_entry *ld; - - if (zend_hash_index_find(&list_destructors,le->type,(void **) &ld)==SUCCESS) { - if (ld->plist_destructor) { - (ld->plist_destructor)(le->ptr); - } - } else { - zend_error(E_WARNING,"Unknown persistent list entry type in module shutdown (%d)",le->type); - } -} - - -int init_resource_list(ELS_D) -{ - return zend_hash_init(&EG(regular_list), 0, NULL, list_entry_destructor, 0); -} - - -int init_resource_plist(ELS_D) -{ - return zend_hash_init(&EG(persistent_list), 0, NULL, plist_entry_destructor, 1); -} - - -void destroy_resource_list(ELS_D) -{ - zend_hash_graceful_destroy(&EG(regular_list)); -} - - -void destroy_resource_plist(ELS_D) -{ - zend_hash_graceful_destroy(&EG(persistent_list)); -} - - -static int clean_module_resource(list_entry *le, int *resource_id) -{ - if (le->type == *resource_id) { - return 1; - } else { - return 0; - } -} - - -int clean_module_resource_destructors(list_destructors_entry *ld, int *module_number) -{ - if (ld->module_number == *module_number) { - ELS_FETCH(); - - zend_hash_apply_with_argument(&EG(persistent_list), (int (*)(void *,void *)) clean_module_resource, (void *) &(ld->resource_id)); - return 1; - } else { - return 0; - } -} - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/Zend/zend_list.h b/Zend/zend_list.h deleted file mode 100644 index c306fc1940..0000000000 --- a/Zend/zend_list.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _LIST_H -#define _LIST_H - -#include "zend_hash.h" -#include "zend_globals.h" - -extern HashTable list_destructors; - -typedef struct _list_entry { - void *ptr; - int type; - int refcount; -} list_entry; - -typedef struct _list_destructors_entry { - void (*list_destructor)(void *); - void (*plist_destructor)(void *); - int module_number; - int resource_id; -} list_destructors_entry; - -#define register_list_destructors(ld,pld) _register_list_destructors((void (*)(void *))ld, (void (*)(void *))pld, module_number); -ZEND_API int _register_list_destructors(void (*ld)(void *), void (*pld)(void *), int module_number); - -enum list_entry_type { - LE_DB=1000 -}; - -void list_entry_destructor(void *ptr); -void plist_entry_destructor(void *ptr); - -int clean_module_resource_destructors(list_destructors_entry *ld, int *module_number); -int init_resource_list(ELS_D); -int init_resource_plist(ELS_D); -void destroy_resource_list(ELS_D); -void destroy_resource_plist(ELS_D); - -ZEND_API int zend_list_insert(void *ptr, int type); -ZEND_API int zend_plist_insert(void *ptr, int type); -ZEND_API int zend_list_addref(int id); -ZEND_API int zend_list_delete(int id); -ZEND_API int zend_plist_delete(int id); -ZEND_API void *zend_list_find(int id, int *type); -ZEND_API void *zend_plist_find(int id, int *type); - -ZEND_API int zend_register_resource(zval *rsrc_result, void *rsrc_pointer, int rsrc_type); -ZEND_API void *zend_fetch_resource(zval **passed_id, int default_id, char *resource_type_name, int *found_resource_type, int num_resource_types, ...); - -extern ZEND_API int le_index_ptr; /* list entry type for index pointers */ - -#define ZEND_VERIFY_RESOURCE(rsrc) \ - if (!rsrc) { \ - RETURN_FALSE; \ - } - -#define ZEND_FETCH_RESOURCE(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type) \ - rsrc = (rsrc_type) zend_fetch_resource(passed_id, default_id, resource_type_name, NULL, 1, resource_type); \ - ZEND_VERIFY_RESOURCE(rsrc); - -#define ZEND_FETCH_RESOURCE2(rsrc, rsrc_type, passed_id, default_id, resource_type_name, resource_type1,resource_type2) \ - rsrc = (rsrc_type) zend_fetch_resource(passed_id, default_id, resource_type_name, NULL, 2, resource_type1, resource_type2); \ - ZEND_VERIFY_RESOURCE(rsrc); - -#define ZEND_REGISTER_RESOURCE(rsrc_result, rsrc_pointer, rsrc_type) \ - zend_register_resource(rsrc_result, rsrc_pointer, rsrc_type); - -#endif diff --git a/Zend/zend_llist.c b/Zend/zend_llist.c deleted file mode 100644 index 1024f0fa8e..0000000000 --- a/Zend/zend_llist.c +++ /dev/null @@ -1,217 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include "zend.h" -#include "zend_llist.h" - -ZEND_API void zend_llist_init(zend_llist *l, size_t size, void (*dtor)(void *data), unsigned char persistent) -{ - l->head = NULL; - l->tail = NULL; - l->size = size; - l->dtor = dtor; - l->persistent = persistent; -} - - -ZEND_API void zend_llist_add_element(zend_llist *l, void *element) -{ - zend_llist_element *tmp = pemalloc(sizeof(zend_llist_element)+l->size-1, l->persistent); - - tmp->prev = l->tail; - tmp->next = NULL; - if (l->tail) { - l->tail->next = tmp; - } else { - l->head = tmp; - } - l->tail = tmp; - memcpy(tmp->data, element, l->size); -} - - -ZEND_API void zend_llist_prepend_element(zend_llist *l, void *element) -{ - zend_llist_element *tmp = pemalloc(sizeof(zend_llist_element)+l->size-1, l->persistent); - - tmp->next = l->head; - tmp->prev = NULL; - if (l->head) { - l->head->prev = tmp; - } else { - l->tail = tmp; - } - l->head = tmp; - memcpy(tmp->data, element, l->size); -} - - -ZEND_API void zend_llist_del_element(zend_llist *l, void *element, int (*compare)(void *element1, void *element2)) -{ - zend_llist_element *current=l->head; - - while (current) { - if (compare(current->data, element)) { - if (current->prev) { - current->prev->next = current->next; - } else { - l->head = current->next; - } - if (current->next) { - current->next->prev = current->prev; - } else { - l->tail = current->prev; - } - if (l->dtor) { - l->dtor(current->data); - efree(current); - } - break; - } - current = current->next; - } -} - - -ZEND_API void zend_llist_destroy(zend_llist *l) -{ - zend_llist_element *current=l->head, *next; - - while (current) { - next = current->next; - if (l->dtor) { - l->dtor(current->data); - } - pefree(current, l->persistent); - current = next; - } -} - - -ZEND_API void zend_llist_clean(zend_llist *l) -{ - zend_llist_destroy(l); - l->head = l->tail = NULL; -} - - -ZEND_API void zend_llist_remove_tail(zend_llist *l) -{ - zend_llist_element *old_tail; - - if ((old_tail = l->tail)) { - if (l->tail->prev) { - l->tail->prev->next = NULL; - } - l->tail = l->tail->prev; - efree(old_tail); - } -} - - -ZEND_API void zend_llist_copy(zend_llist *dst, zend_llist *src) -{ - zend_llist_element *ptr; - - zend_llist_init(dst, src->size, src->dtor, src->persistent); - ptr = src->head; - while (ptr) { - zend_llist_add_element(dst, ptr->data); - ptr = ptr->next; - } -} - - -ZEND_API void zend_llist_apply(zend_llist *l, void (*func)(void *data)) -{ - zend_llist_element *element; - - for (element=l->head; element; element=element->next) { - func(element->data); - } -} - - -ZEND_API void zend_llist_apply_with_argument(zend_llist *l, void (*func)(void *data, void *arg), void *arg) -{ - zend_llist_element *element; - - for (element=l->head; element; element=element->next) { - func(element->data, arg); - } -} - - -ZEND_API int zend_llist_count(zend_llist *l) -{ - zend_llist_element *element; - int element_count=0; - - for (element=l->head; element; element=element->next) { - element_count++; - } - return element_count; -} - - -ZEND_API void *zend_llist_get_first(zend_llist *l) -{ - l->traverse_ptr = l->head; - if (l->traverse_ptr) { - return l->traverse_ptr->data; - } else { - return NULL; - } -} - - -ZEND_API void *zend_llist_get_last(zend_llist *l) -{ - l->traverse_ptr = l->tail; - if (l->traverse_ptr) { - return l->traverse_ptr->data; - } else { - return NULL; - } -} - - -ZEND_API void *zend_llist_get_next(zend_llist *l) -{ - if (l->traverse_ptr) { - l->traverse_ptr = l->traverse_ptr->next; - if (l->traverse_ptr) { - return l->traverse_ptr->data; - } - } - return NULL; -} - - -ZEND_API void *zend_llist_get_prev(zend_llist *l) -{ - if (l->traverse_ptr) { - l->traverse_ptr = l->traverse_ptr->prev; - if (l->traverse_ptr) { - return l->traverse_ptr->data; - } - } - return NULL; -} diff --git a/Zend/zend_llist.h b/Zend/zend_llist.h deleted file mode 100644 index c6eddb59b2..0000000000 --- a/Zend/zend_llist.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _ZEND_LLIST_H -#define _ZEND_LLIST_H - -#include - -typedef struct _zend_llist_element { - struct _zend_llist_element *next; - struct _zend_llist_element *prev; - char data[1]; /* Needs to always be last in the struct */ -} zend_llist_element; - -typedef struct _zend_llist { - zend_llist_element *head; - zend_llist_element *tail; - size_t size; - void (*dtor)(void *data); - unsigned char persistent; - zend_llist_element *traverse_ptr; -} zend_llist; - -BEGIN_EXTERN_C() -ZEND_API void zend_llist_init(zend_llist *l, size_t size, void (*dtor)(void *data), unsigned char persistent); -ZEND_API void zend_llist_add_element(zend_llist *l, void *element); -ZEND_API void zend_llist_prepend_element(zend_llist *l, void *element); -ZEND_API void zend_llist_del_element(zend_llist *l, void *element, int (*compare)(void *element1, void *element2)); -ZEND_API void zend_llist_destroy(zend_llist *l); -ZEND_API void zend_llist_clean(zend_llist *l); -ZEND_API void zend_llist_remove_tail(zend_llist *l); -ZEND_API void zend_llist_copy(zend_llist *dst, zend_llist *src); -ZEND_API void zend_llist_apply(zend_llist *l, void (*func)(void *data)); -ZEND_API void zend_llist_apply_with_argument(zend_llist *l, void (*func)(void *data, void *arg), void *arg); -ZEND_API int zend_llist_count(zend_llist *l); - -/* traversal */ -ZEND_API void *zend_llist_get_first(zend_llist *l); -ZEND_API void *zend_llist_get_last(zend_llist *l); -ZEND_API void *zend_llist_get_next(zend_llist *l); -ZEND_API void *zend_llist_get_prev(zend_llist *l); -END_EXTERN_C() - -#endif /* _ZEND_LLIST_H */ diff --git a/Zend/zend_modules.h b/Zend/zend_modules.h deleted file mode 100644 index aa4dd4c80f..0000000000 --- a/Zend/zend_modules.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _MODULES_H -#define _MODULES_H - -#define INIT_FUNC_ARGS int type, int module_number ELS_DC -#define INIT_FUNC_ARGS_PASSTHRU type, module_number ELS_CC -#define SHUTDOWN_FUNC_ARGS int type, int module_number -#define SHUTDOWN_FUNC_ARGS_PASSTHRU type, module_number -#define ZEND_MODULE_INFO_FUNC_ARGS zend_module_entry *zend_module - -#define STANDARD_MODULE_PROPERTIES_EX 0, 0, NULL, 0 - -#define STANDARD_MODULE_PROPERTIES \ - NULL, NULL, STANDARD_MODULE_PROPERTIES_EX - -#define MODULE_PERSISTENT 1 -#define MODULE_TEMPORARY 2 - -typedef struct _zend_module_entry zend_module_entry; - -struct _zend_module_entry { - char *name; - zend_function_entry *functions; - int (*module_startup_func)(INIT_FUNC_ARGS); - int (*module_shutdown_func)(SHUTDOWN_FUNC_ARGS); - int (*request_startup_func)(INIT_FUNC_ARGS); - int (*request_shutdown_func)(SHUTDOWN_FUNC_ARGS); - void (*info_func)(ZEND_MODULE_INFO_FUNC_ARGS); - int (*global_startup_func)(void); - int (*global_shutdown_func)(void); - int module_started; - unsigned char type; - void *handle; - int module_number; -}; - - -extern HashTable module_registry; - -void module_destructor(zend_module_entry *module); -int module_registry_cleanup(zend_module_entry *module); -int module_registry_request_startup(zend_module_entry *module); - -#define ZEND_MODULE_DTOR (void (*)(void *)) module_destructor -#endif diff --git a/Zend/zend_opcode.c b/Zend/zend_opcode.c deleted file mode 100644 index 7f680f3ec1..0000000000 --- a/Zend/zend_opcode.c +++ /dev/null @@ -1,417 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include - -#include "zend.h" -#include "zend_alloc.h" -#include "zend_compile.h" -#include "zend_variables.h" -#include "zend_operators.h" -#include "zend_extensions.h" -#include "zend_API.h" - - -static void zend_extension_op_array_ctor_handler(zend_extension *extension, zend_op_array *op_array) -{ - if (extension->op_array_ctor) { - if (extension->resource_number>=0) { - extension->op_array_ctor(&op_array->reserved[extension->resource_number]); - } else { - extension->op_array_ctor(NULL); - } - } -} - - -static void zend_extension_op_array_dtor_handler(zend_extension *extension, zend_op_array *op_array) -{ - if (extension->op_array_dtor) { - if (extension->resource_number>=0) { - extension->op_array_dtor(&op_array->reserved[extension->resource_number]); - } else { - extension->op_array_dtor(NULL); - } - } -} - - -static void op_array_alloc_ops(zend_op_array *op_array) -{ - op_array->opcodes = erealloc(op_array->opcodes, (op_array->size)*sizeof(zend_op)); -} - - - -void init_op_array(zend_op_array *op_array, int initial_ops_size) -{ - op_array->type = ZEND_USER_FUNCTION; -#if SUPPORT_INTERACTIVE - { - ELS_FETCH(); - - op_array->start_op_number = op_array->end_op_number = op_array->last_executed_op_number = 0; - op_array->backpatch_count = 0; - if (EG(interactive)) { - /* We must avoid a realloc() on the op_array in interactive mode, since pointers to constants - * will become invalid - */ - initial_ops_size = 8192; - } - } -#endif - - op_array->refcount = (int *) emalloc(sizeof(int)); - *op_array->refcount = 1; - op_array->size = initial_ops_size; - op_array->last = 0; - op_array->opcodes = NULL; - op_array_alloc_ops(op_array); - - op_array->T = 0; - - op_array->function_name = NULL; - - op_array->arg_types = NULL; - - op_array->brk_cont_array = NULL; - op_array->last_brk_cont = 0; - op_array->current_brk_cont = -1; - - op_array->static_variables = NULL; - - op_array->uses_globals = 0; - - op_array->return_reference = 0; - - zend_llist_apply_with_argument(&zend_extensions, (void (*)(void *, void *)) zend_extension_op_array_ctor_handler, op_array); -} - - -ZEND_API void destroy_zend_function(zend_function *function) -{ - switch (function->type) { - case ZEND_USER_FUNCTION: - destroy_op_array((zend_op_array *) function); - break; - case ZEND_INTERNAL_FUNCTION: - /* do nothing */ - break; - } -} - - -ZEND_API void destroy_zend_class(zend_class_entry *ce) -{ - if (--(*ce->refcount)>0) { - return; - } - switch (ce->type) { - case ZEND_USER_CLASS: - efree(ce->name); - efree(ce->refcount); - zend_hash_destroy(&ce->function_table); - zend_hash_destroy(&ce->default_properties); - break; - case ZEND_INTERNAL_CLASS: - free(ce->name); - free(ce->refcount); - zend_hash_destroy(&ce->function_table); - zend_hash_destroy(&ce->default_properties); - break; - } -} - - -void zend_class_add_ref(zend_class_entry *ce) -{ - (*ce->refcount)++; -} - - -ZEND_API void destroy_op_array(zend_op_array *op_array) -{ - zend_op *opline = op_array->opcodes; - zend_op *end = op_array->opcodes+op_array->last; - - if (op_array->static_variables) { - zend_hash_destroy(op_array->static_variables); - FREE_HASHTABLE(op_array->static_variables); - } - - if (--(*op_array->refcount)>0) { - return; - } - - efree(op_array->refcount); - - while (oplineop1.op_type==IS_CONST) { -#if DEBUG_ZEND>2 - printf("Reducing refcount for %x 1=>0 (destroying)\n", &opline->op1.u.constant); -#endif - zval_dtor(&opline->op1.u.constant); - } - if (opline->op2.op_type==IS_CONST) { -#if DEBUG_ZEND>2 - printf("Reducing refcount for %x 1=>0 (destroying)\n", &opline->op2.u.constant); -#endif - zval_dtor(&opline->op2.u.constant); - } - opline++; - } - efree(op_array->opcodes); - if (op_array->function_name) { - efree(op_array->function_name); - } - if (op_array->arg_types) { - efree(op_array->arg_types); - } - if (op_array->brk_cont_array) { - efree(op_array->brk_cont_array); - } - zend_llist_apply_with_argument(&zend_extensions, (void (*)(void *, void *)) zend_extension_op_array_dtor_handler, op_array); -} - - -void init_op(zend_op *op CLS_DC) -{ - op->lineno = CG(zend_lineno); - op->filename = zend_get_compiled_filename(CLS_C); - op->result.op_type = IS_UNUSED; - op->extended_value = 0; - op->op1.u.EA.var = 0; - op->op1.u.EA.type = 0; - op->op2.u.EA.var = 0; - op->op2.u.EA.type = 0; - op->result.u.EA.var = 0; - op->result.u.EA.type = 0; -} - -zend_op *get_next_op(zend_op_array *op_array CLS_DC) -{ - int next_op_num = op_array->last++; - zend_op *next_op; - - if (next_op_num >= op_array->size) { -#if SUPPORT_INTERACTIVE - ELS_FETCH(); - - if (EG(interactive)) { - /* we messed up */ - zend_printf("Ran out of opcode space!\n" - "You should probably consider writing this huge script into a file!\n"); - zend_bailout(); - } -#endif - op_array->size *= 2; - op_array_alloc_ops(op_array); - } - - next_op = &(op_array->opcodes[next_op_num]); - - init_op(next_op CLS_CC); - - return next_op; -} - - -int get_next_op_number(zend_op_array *op_array) -{ - return op_array->last; -} - - - - -zend_brk_cont_element *get_next_brk_cont_element(zend_op_array *op_array) -{ - op_array->last_brk_cont++; - op_array->brk_cont_array = erealloc(op_array->brk_cont_array, sizeof(zend_brk_cont_element)*op_array->last_brk_cont); - return &op_array->brk_cont_array[op_array->last_brk_cont-1]; -} - - -static void zend_update_extended_info(zend_op_array *op_array CLS_DC) -{ - zend_op *opline = op_array->opcodes, *end=opline+op_array->last; - - while (oplineopcode == ZEND_EXT_STMT) { - if (opline+1opcode == ZEND_EXT_STMT) { - opline->opcode = ZEND_NOP; - opline++; - continue; - } - opline->lineno = (opline+1)->lineno; - opline->filename = (opline+1)->filename; - } else { - opline->opcode = ZEND_NOP; - } - } - opline++; - } - opline = get_next_op(op_array CLS_CC); - opline->opcode = ZEND_EXT_STMT; - opline->op1.op_type = IS_UNUSED; - opline->op2.op_type = IS_UNUSED; - if (op_array->last>0) { - opline->filename = op_array->opcodes[op_array->last-2].filename; - opline->lineno= op_array->opcodes[op_array->last-2].lineno; - } -} - - - -static void zend_extension_op_array_handler(zend_extension *extension, zend_op_array *op_array) -{ - if (extension->op_array_handler) { - extension->op_array_handler(op_array); - } -} - - -int pass_two(zend_op_array *op_array) -{ - CLS_FETCH(); - - if (op_array->type!=ZEND_USER_FUNCTION && op_array->type!=ZEND_EVAL_CODE) { - return 0; - } - if (CG(extended_info)) { - zend_update_extended_info(op_array CLS_CC); - } - if (CG(handle_op_arrays)) { - zend_llist_apply_with_argument(&zend_extensions, (void (*)(void *, void *)) zend_extension_op_array_handler, op_array); - } - return 0; -} - - -void pass_include_eval(zend_op_array *op_array) -{ - zend_op *opline=op_array->opcodes, *end=opline+op_array->last; - - while (oplineop1.op_type==IS_CONST) { - opline->op1.u.constant.is_ref = 1; - opline->op1.u.constant.refcount = 2; /* Make sure is_ref won't be reset */ - } - if (opline->op2.op_type==IS_CONST) { - opline->op2.u.constant.is_ref = 1; - opline->op2.u.constant.refcount = 2; - } - opline++; - } -} - - -int print_class(zend_class_entry *class_entry) -{ - printf("Class %s:\n", class_entry->name); - zend_hash_apply(&class_entry->function_table, (int (*)(void *)) pass_two); - printf("End of class %s.\n\n", class_entry->name); - return 0; -} - -ZEND_API unary_op_type get_unary_op(int opcode) -{ - switch(opcode) { - case ZEND_BW_NOT: - return (unary_op_type) bitwise_not_function; - break; - case ZEND_BOOL_NOT: - return (unary_op_type) boolean_not_function; - break; - default: - return (unary_op_type) NULL; - break; - } -} - - -ZEND_API void *get_binary_op(int opcode) -{ - switch (opcode) { - case ZEND_ADD: - case ZEND_ASSIGN_ADD: - return (void *) add_function; - break; - case ZEND_SUB: - case ZEND_ASSIGN_SUB: - return (void *) sub_function; - break; - case ZEND_MUL: - case ZEND_ASSIGN_MUL: - return (void *) mul_function; - break; - case ZEND_DIV: - case ZEND_ASSIGN_DIV: - return (void *) div_function; - break; - case ZEND_MOD: - case ZEND_ASSIGN_MOD: - return (void *) mod_function; - break; - case ZEND_SL: - case ZEND_ASSIGN_SL: - return (void *) shift_left_function; - break; - case ZEND_SR: - case ZEND_ASSIGN_SR: - return (void *) shift_right_function; - break; - case ZEND_CONCAT: - case ZEND_ASSIGN_CONCAT: - return (void *) concat_function; - break; - case ZEND_IS_IDENTICAL: - return (void *) is_identical_function; - break; - case ZEND_IS_EQUAL: - return (void *) is_equal_function; - break; - case ZEND_IS_NOT_EQUAL: - return (void *) is_not_equal_function; - break; - case ZEND_IS_SMALLER: - return (void *) is_smaller_function; - break; - case ZEND_IS_SMALLER_OR_EQUAL: - return (void *) is_smaller_or_equal_function; - break; - case ZEND_BW_OR: - case ZEND_ASSIGN_BW_OR: - return (void *) bitwise_or_function; - break; - case ZEND_BW_AND: - case ZEND_ASSIGN_BW_AND: - return (void *) bitwise_and_function; - break; - case ZEND_BW_XOR: - case ZEND_ASSIGN_BW_XOR: - return (void *) bitwise_xor_function; - break; - default: - return (void *) NULL; - break; - } -} diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c deleted file mode 100644 index f76cbb8849..0000000000 --- a/Zend/zend_operators.c +++ /dev/null @@ -1,1463 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include -#include -#include -#include -#include - -#include "zend.h" -#include "zend_operators.h" -#include "zend_variables.h" -#include "zend_globals.h" -#include "zend_list.h" -#include "zend_fast_cache.h" - - -#if WITH_BCMATH -#include "ext/bcmath/number.h" -#endif - - -ZEND_API void convert_scalar_to_number(zval *op) -{ - char *strval; - - if (op->type == IS_STRING) { - strval = op->value.str.val; - switch ((op->type=is_numeric_string(strval, op->value.str.len, &op->value.lval, &op->value.dval))) { - case IS_DOUBLE: - case IS_LONG: - break; -#if WITH_BCMATH - case FLAG_IS_BC: - op->type = IS_DOUBLE; /* may have lost significant digits */ - break; -#endif - default: - op->value.lval = strtol(op->value.str.val, NULL, 10); - op->type = IS_LONG; - break; - } - STR_FREE(strval); - } else if (op->type==IS_BOOL || op->type==IS_RESOURCE) { - op->type = IS_LONG; - } else if (op->type==IS_NULL) { - op->type = IS_LONG; - op->value.lval = 0; - } -} - -#define zendi_convert_scalar_to_number(op, holder, result) \ - if (op==result) { \ - convert_scalar_to_number(op); \ - } else if ((op)->type == IS_STRING) { \ - switch (((holder).type=is_numeric_string((op)->value.str.val, (op)->value.str.len, &(holder).value.lval, &(holder).value.dval))) { \ - case IS_DOUBLE: \ - case IS_LONG: \ - break; \ - case FLAG_IS_BC: \ - (holder).type = IS_DOUBLE; /* may have lost significant digits */ \ - break; \ - default: \ - (holder).value.lval = strtol((op)->value.str.val, NULL, 10); \ - (holder).type = IS_LONG; \ - break; \ - } \ - (op) = &(holder); \ - } else if ((op)->type==IS_BOOL || (op)->type==IS_RESOURCE) { \ - (holder).value.lval = (op)->value.lval; \ - (holder).type = IS_LONG; \ - (op) = &(holder); \ - } else if ((op)->type==IS_NULL) { \ - (holder).value.lval = 0; \ - (holder).type = IS_LONG; \ - (op) = &(holder); \ - } - - - -#define zendi_convert_to_long(op, holder, result) \ - if (op==result) { \ - convert_to_long(op); \ - } else if ((op)->type==IS_BOOL || (op)->type==IS_RESOURCE) { \ - (holder).value.lval = (op)->value.lval; \ - (holder).type = IS_LONG; \ - (op) = &(holder); \ - } else if ((op)->type != IS_LONG) { \ - switch ((op)->type) { \ - case IS_NULL: \ - (holder).value.lval = 0; \ - break; \ - case IS_DOUBLE: \ - (holder).value.lval = (long) (op)->value.dval; \ - break; \ - case IS_STRING: \ - (holder).value.lval = strtol((op)->value.str.val, NULL, 10); \ - break; \ - case IS_ARRAY: \ - (holder).value.lval = (zend_hash_num_elements((op)->value.ht)?1:0); \ - break; \ - case IS_OBJECT: \ - (holder).value.lval = (zend_hash_num_elements((op)->value.obj.properties)?1:0); \ - break; \ - default: \ - zend_error(E_WARNING, "Cannot convert to ordinal value"); \ - (holder).value.lval = 0; \ - break; \ - } \ - (holder).type = IS_LONG; \ - (op) = &(holder); \ - } - - -#define zendi_convert_to_boolean(op, holder, result) \ - if (op==result) { \ - convert_to_boolean(op); \ - } else if ((op)->type != IS_BOOL) { \ - switch ((op)->type) { \ - case IS_NULL: \ - (holder).value.lval = 0; \ - break; \ - case IS_RESOURCE: \ - case IS_LONG: \ - (holder).value.lval = ((op)->value.lval ? 1 : 0); \ - break; \ - case IS_DOUBLE: \ - (holder).value.lval = ((op)->value.dval ? 1 : 0); \ - break; \ - case IS_STRING: \ - if ((op)->value.str.len == 0 \ - || ((op)->value.str.len==1 && (op)->value.str.val[0]=='0')) { \ - (holder).value.lval = 0; \ - } else { \ - (holder).value.lval = 1; \ - } \ - break; \ - case IS_ARRAY: \ - (holder).value.lval = (zend_hash_num_elements((op)->value.ht)?1:0); \ - break; \ - case IS_OBJECT: \ - (holder).value.lval = (zend_hash_num_elements((op)->value.obj.properties)?1:0); \ - break; \ - default: \ - (holder).value.lval = 0; \ - break; \ - } \ - (holder).type = IS_BOOL; \ - (op) = &(holder); \ - } - - -ZEND_API void convert_to_long(zval *op) -{ - convert_to_long_base(op, 10); -} - - -ZEND_API void convert_to_long_base(zval *op, int base) -{ - char *strval; - long tmp; - - switch (op->type) { - case IS_NULL: - op->value.lval = 0; - break; - case IS_RESOURCE: - case IS_BOOL: - case IS_LONG: - break; - case IS_DOUBLE: - op->value.lval = (long) op->value.dval; - break; - case IS_STRING: - strval = op->value.str.val; - op->value.lval = strtol(strval, NULL, base); - STR_FREE(strval); - break; - case IS_ARRAY: - tmp = (zend_hash_num_elements(op->value.ht)?1:0); - zval_dtor(op); - op->value.lval = tmp; - break; - case IS_OBJECT: - tmp = (zend_hash_num_elements(op->value.obj.properties)?1:0); - zval_dtor(op); - op->value.lval = tmp; - break; - default: - zend_error(E_WARNING, "Cannot convert to ordinal value"); - zval_dtor(op); - op->value.lval = 0; - break; - } - - op->type = IS_LONG; -} - - -ZEND_API void convert_to_double(zval *op) -{ - char *strval; - double tmp; - - switch (op->type) { - case IS_NULL: - op->value.dval = 0.0; - break; - case IS_RESOURCE: - case IS_BOOL: - case IS_LONG: - op->value.dval = (double) op->value.lval; - break; - case IS_DOUBLE: - break; - case IS_STRING: - strval = op->value.str.val; - - op->value.dval = strtod(strval, NULL); - STR_FREE(strval); - break; - case IS_ARRAY: - tmp = (zend_hash_num_elements(op->value.ht)?1:0); - zval_dtor(op); - op->value.dval = tmp; - break; - case IS_OBJECT: - tmp = (zend_hash_num_elements(op->value.obj.properties)?1:0); - zval_dtor(op); - op->value.dval = tmp; - break; - default: - zend_error(E_WARNING, "Cannot convert to real value (type=%d)", op->type); - zval_dtor(op); - op->value.dval = 0; - break; - } - op->type = IS_DOUBLE; -} - - -ZEND_API void convert_to_unset(zval *op) -{ - zval_dtor(op); - op->type = IS_NULL; -} - - -ZEND_API void convert_to_boolean(zval *op) -{ - char *strval; - int tmp; - - switch (op->type) { - case IS_BOOL: - break; - case IS_NULL: - op->value.lval = 0; - break; - case IS_RESOURCE: - case IS_LONG: - op->value.lval = (op->value.lval ? 1 : 0); - break; - case IS_DOUBLE: - op->value.lval = (op->value.dval ? 1 : 0); - break; - case IS_STRING: - strval = op->value.str.val; - - if (op->value.str.len == 0 - || (op->value.str.len==1 && op->value.str.val[0]=='0')) { - op->value.lval = 0; - } else { - op->value.lval = 1; - } - STR_FREE(strval); - break; - case IS_ARRAY: - tmp = (zend_hash_num_elements(op->value.ht)?1:0); - zval_dtor(op); - op->value.lval = tmp; - break; - case IS_OBJECT: - tmp = (zend_hash_num_elements(op->value.obj.properties)?1:0); - zval_dtor(op); - op->value.lval = tmp; - break; - default: - zval_dtor(op); - op->value.lval = 0; - break; - } - op->type = IS_BOOL; -} - - -ZEND_API void convert_to_string(zval *op) -{ - long lval; - double dval; - ELS_FETCH(); - - switch (op->type) { - case IS_NULL: - op->value.str.val = empty_string; - op->value.str.len = 0; - break; - case IS_STRING: - break; - case IS_BOOL: - if (op->value.lval) { - op->value.str.val = estrndup("1", 1); - op->value.str.len = 1; - } else { - op->value.str.val = empty_string; - op->value.str.len = 0; - } - break; - case IS_LONG: - lval = op->value.lval; - - op->value.str.val = (char *) emalloc(MAX_LENGTH_OF_LONG + 1); - op->value.str.len = zend_sprintf(op->value.str.val, "%ld", lval); /* SAFE */ - break; - case IS_DOUBLE: { - dval = op->value.dval; - op->value.str.val = (char *) emalloc(MAX_LENGTH_OF_DOUBLE + EG(precision) + 1); - op->value.str.len = zend_sprintf(op->value.str.val, "%.*G", (int) EG(precision), dval); /* SAFE */ - /* %G already handles removing trailing zeros from the fractional part, yay */ - break; - } - case IS_ARRAY: - zval_dtor(op); - op->value.str.val = estrndup("Array",sizeof("Array")-1); - op->value.str.len = sizeof("Array")-1; - break; - case IS_OBJECT: - zval_dtor(op); - op->value.str.val = estrndup("Object",sizeof("Object")-1); - op->value.str.len = sizeof("Object")-1; - break; - default: - zval_dtor(op); - var_reset(op); - break; - } - op->type = IS_STRING; -} - - -static void convert_scalar_to_array(zval *op, int type) -{ - zval *entry; - - ALLOC_ZVAL(entry); - *entry = *op; - INIT_PZVAL(entry); - - switch (type) { - case IS_ARRAY: - ALLOC_HASHTABLE(op->value.ht); - zend_hash_init(op->value.ht, 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_index_update(op->value.ht, 0, (void *) &entry, sizeof(zval *), NULL); - op->type = IS_ARRAY; - break; - case IS_OBJECT: - ALLOC_HASHTABLE(op->value.obj.properties); - zend_hash_init(op->value.obj.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_update(op->value.obj.properties, "scalar", sizeof("scalar"), (void *) &entry, sizeof(zval *), NULL); - op->value.obj.ce = &zend_standard_class_def; - op->type = IS_OBJECT; - break; - } -} - - -ZEND_API void convert_to_array(zval *op) -{ - switch(op->type) { - case IS_ARRAY: - return; - break; - case IS_OBJECT: - op->type = IS_ARRAY; - op->value.ht = op->value.obj.properties; - return; - case IS_NULL: - ALLOC_HASHTABLE(op->value.ht); - zend_hash_init(op->value.ht, 0, NULL, ZVAL_PTR_DTOR, 0); - op->type = IS_ARRAY; - break; - default: - convert_scalar_to_array(op, IS_ARRAY); - break; - } -} - - -ZEND_API void convert_to_object(zval *op) -{ - switch(op->type) { - case IS_ARRAY: - op->type = IS_OBJECT; - op->value.obj.properties = op->value.ht; - op->value.obj.ce = &zend_standard_class_def; - return; - break; - case IS_OBJECT: - return; - case IS_NULL: - ALLOC_HASHTABLE(op->value.obj.properties); - zend_hash_init(op->value.obj.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - op->value.obj.ce = &zend_standard_class_def; - op->type = IS_OBJECT; - break; - default: - convert_scalar_to_array(op, IS_OBJECT); - break; - } -} - - -ZEND_API int add_function(zval *result, zval *op1, zval *op2) -{ - zval op1_copy, op2_copy; - - if (op1->type == IS_ARRAY && op2->type == IS_ARRAY) { - zval *tmp; - - if ((result == op1) && (result == op2)) { - /* $a += $a */ - return SUCCESS; - } - if (result != op1) { - /* $a += $b */ - *result = *op1; - zval_copy_ctor(result); - } - zend_hash_merge(result->value.ht, op2->value.ht, (void (*)(void *pData)) zval_add_ref, (void *) &tmp, sizeof(zval *), 0); - return SUCCESS; - } - zendi_convert_scalar_to_number(op1, op1_copy, result); - zendi_convert_scalar_to_number(op2, op2_copy, result); - - - if (op1->type == IS_LONG && op2->type == IS_LONG) { - double dval = (double) op1->value.lval + (double) op2->value.lval; - - if (dval > (double) LONG_MAX) { - result->value.dval = dval; - result->type = IS_DOUBLE; - } else { - result->value.lval = op1->value.lval + op2->value.lval; - result->type = IS_LONG; - } - return SUCCESS; - } - if ((op1->type == IS_DOUBLE && op2->type == IS_LONG) - || (op1->type == IS_LONG && op2->type == IS_DOUBLE)) { - result->value.dval = (op1->type == IS_LONG ? - (((double) op1->value.lval) + op2->value.dval) : - (op1->value.dval + ((double) op2->value.lval))); - result->type = IS_DOUBLE; - return SUCCESS; - } - if (op1->type == IS_DOUBLE && op2->type == IS_DOUBLE) { - result->type = IS_DOUBLE; - result->value.dval = op1->value.dval + op2->value.dval; - return SUCCESS; - } - zend_error(E_ERROR, "Unsupported operand types"); - return FAILURE; /* unknown datatype */ -} - - -ZEND_API int sub_function(zval *result, zval *op1, zval *op2) -{ - zval op1_copy, op2_copy; - - zendi_convert_scalar_to_number(op1, op1_copy, result); - zendi_convert_scalar_to_number(op2, op2_copy, result); - - if (op1->type == IS_LONG && op2->type == IS_LONG) { - double dval = (double) op1->value.lval - (double) op2->value.lval; - - if (dval < (double) LONG_MIN) { - result->value.dval = dval; - result->type = IS_DOUBLE; - } else { - result->value.lval = op1->value.lval - op2->value.lval; - result->type = IS_LONG; - } - return SUCCESS; - } - if ((op1->type == IS_DOUBLE && op2->type == IS_LONG) - || (op1->type == IS_LONG && op2->type == IS_DOUBLE)) { - result->value.dval = (op1->type == IS_LONG ? - (((double) op1->value.lval) - op2->value.dval) : - (op1->value.dval - ((double) op2->value.lval))); - result->type = IS_DOUBLE; - return SUCCESS; - } - if (op1->type == IS_DOUBLE && op2->type == IS_DOUBLE) { - result->type = IS_DOUBLE; - result->value.dval = op1->value.dval - op2->value.dval; - return SUCCESS; - } - zend_error(E_ERROR, "Unsupported operand types"); - return FAILURE; /* unknown datatype */ -} - - -ZEND_API int mul_function(zval *result, zval *op1, zval *op2) -{ - zval op1_copy, op2_copy; - - zendi_convert_scalar_to_number(op1, op1_copy, result); - zendi_convert_scalar_to_number(op2, op2_copy, result); - - if (op1->type == IS_LONG && op2->type == IS_LONG) { - double dval = (double) op1->value.lval * (double) op2->value.lval; - - if (dval > (double) LONG_MAX) { - result->value.dval = dval; - result->type = IS_DOUBLE; - } else { - result->value.lval = op1->value.lval * op2->value.lval; - result->type = IS_LONG; - } - return SUCCESS; - } - if ((op1->type == IS_DOUBLE && op2->type == IS_LONG) - || (op1->type == IS_LONG && op2->type == IS_DOUBLE)) { - result->value.dval = (op1->type == IS_LONG ? - (((double) op1->value.lval) * op2->value.dval) : - (op1->value.dval * ((double) op2->value.lval))); - result->type = IS_DOUBLE; - return SUCCESS; - } - if (op1->type == IS_DOUBLE && op2->type == IS_DOUBLE) { - result->type = IS_DOUBLE; - result->value.dval = op1->value.dval * op2->value.dval; - return SUCCESS; - } - zend_error(E_ERROR, "Unsupported operand types"); - return FAILURE; /* unknown datatype */ -} - -ZEND_API int div_function(zval *result, zval *op1, zval *op2) -{ - zval op1_copy, op2_copy; - - zendi_convert_scalar_to_number(op1, op1_copy, result); - zendi_convert_scalar_to_number(op2, op2_copy, result); - - if ((op2->type == IS_LONG && op2->value.lval == 0) || (op2->type == IS_DOUBLE && op2->value.dval == 0.0)) { - zend_error(E_WARNING, "Division by zero"); - var_reset(result); - return FAILURE; /* division by zero */ - } - if (op1->type == IS_LONG && op2->type == IS_LONG) { - if (op1->value.lval % op2->value.lval == 0) { /* integer */ - result->type = IS_LONG; - result->value.lval = op1->value.lval / op2->value.lval; - } else { - result->type = IS_DOUBLE; - result->value.dval = ((double) op1->value.lval) / op2->value.lval; - } - return SUCCESS; - } - if ((op1->type == IS_DOUBLE && op2->type == IS_LONG) - || (op1->type == IS_LONG && op2->type == IS_DOUBLE)) { - result->value.dval = (op1->type == IS_LONG ? - (((double) op1->value.lval) / op2->value.dval) : - (op1->value.dval / ((double) op2->value.lval))); - result->type = IS_DOUBLE; - return SUCCESS; - } - if (op1->type == IS_DOUBLE && op2->type == IS_DOUBLE) { - result->type = IS_DOUBLE; - result->value.dval = op1->value.dval / op2->value.dval; - return SUCCESS; - } - zend_error(E_ERROR, "Unsupported operand types"); - return FAILURE; /* unknown datatype */ -} - - -ZEND_API int mod_function(zval *result, zval *op1, zval *op2) -{ - zval op1_copy, op2_copy; - - zendi_convert_to_long(op1, op1_copy, result); - zendi_convert_to_long(op2, op2_copy, result); - - if (op2->value.lval == 0) { - var_reset(result); - return FAILURE; /* modulus by zero */ - } - - result->type = IS_LONG; - result->value.lval = op1->value.lval % op2->value.lval; - return SUCCESS; -} - - -ZEND_API int boolean_or_function(zval *result, zval *op1, zval *op2) -{ - zval op1_copy, op2_copy; - - result->type = IS_BOOL; - - zendi_convert_to_boolean(op1, op1_copy, result); - if (op1->value.lval) { - result->value.lval = 1; - return SUCCESS; - } - zendi_convert_to_boolean(op2, op2_copy, result); - if (op2->value.lval) { - result->value.lval = 1; - return SUCCESS; - } - result->value.lval = 0; - return SUCCESS; -} - - -ZEND_API int boolean_and_function(zval *result, zval *op1, zval *op2) -{ - zval op1_copy, op2_copy; - - result->type = IS_BOOL; - - zendi_convert_to_boolean(op1, op1_copy, result); - if (!op1->value.lval) { - result->value.lval = 0; - return SUCCESS; - } - zendi_convert_to_boolean(op2, op2_copy, result); - if (!op2->value.lval) { - result->value.lval = 0; - return SUCCESS; - } - result->value.lval = 1; - return SUCCESS; -} - - -ZEND_API int boolean_xor_function(zval *result, zval *op1, zval *op2) -{ - zval op1_copy, op2_copy; - - result->type = IS_BOOL; - - zendi_convert_to_boolean(op1, op1_copy, result); - zendi_convert_to_boolean(op2, op2_copy, result); - result->value.lval = op1->value.lval ^ op2->value.lval; - return SUCCESS; -} - - -ZEND_API int boolean_not_function(zval *result, zval *op1) -{ - zval op1_copy; - - zendi_convert_to_boolean(op1, op1_copy, result); - - result->type = IS_BOOL; - result->value.lval = !op1->value.lval; - return SUCCESS; -} - - -ZEND_API int bitwise_not_function(zval *result, zval *op1) -{ - zval op1_copy = *op1; - - op1 = &op1_copy; - - if (op1->type == IS_DOUBLE) { - op1->value.lval = (long) op1->value.dval; - op1->type = IS_LONG; - } - if (op1->type == IS_LONG) { - result->value.lval = ~op1->value.lval; - result->type = IS_LONG; - return SUCCESS; - } - if (op1->type == IS_STRING) { - int i; - - result->type = IS_STRING; - result->value.str.val = estrndup(op1->value.str.val, op1->value.str.len); - result->value.str.len = op1->value.str.len; - for (i = 0; i < op1->value.str.len; i++) { - result->value.str.val[i] = ~op1->value.str.val[i]; - } - return SUCCESS; - } - zend_error(E_ERROR, "Unsupported operand types"); - return FAILURE; /* unknown datatype */ -} - - -ZEND_API int bitwise_or_function(zval *result, zval *op1, zval *op2) -{ - zval op1_copy, op2_copy; - - if (op1->type == IS_STRING && op2->type == IS_STRING) { - zval *longer, *shorter; - int i; - - if (op1->value.str.len >= op2->value.str.len) { - longer = op1; - shorter = op2; - } else { - longer = op2; - shorter = op1; - } - - result->value.str.len = longer->value.str.len; - result->value.str.val = estrndup(longer->value.str.val, longer->value.str.len); - for (i = 0; i < shorter->value.str.len; i++) { - result->value.str.val[i] |= shorter->value.str.val[i]; - } - return SUCCESS; - } - zendi_convert_to_long(op1, op1_copy, result); - zendi_convert_to_long(op2, op2_copy, result); - - result->type = IS_LONG; - result->value.lval = op1->value.lval | op2->value.lval; - return SUCCESS; -} - - -ZEND_API int bitwise_and_function(zval *result, zval *op1, zval *op2) -{ - zval op1_copy, op2_copy; - - if (op1->type == IS_STRING && op2->type == IS_STRING) { - zval *longer, *shorter; - int i; - - if (op1->value.str.len >= op2->value.str.len) { - longer = op1; - shorter = op2; - } else { - longer = op2; - shorter = op1; - } - - result->value.str.len = shorter->value.str.len; - result->value.str.val = estrndup(shorter->value.str.val, shorter->value.str.len); - for (i = 0; i < shorter->value.str.len; i++) { - result->value.str.val[i] &= longer->value.str.val[i]; - } - return SUCCESS; - } - - - zendi_convert_to_long(op1, op1_copy, result); - zendi_convert_to_long(op2, op2_copy, result); - - result->type = IS_LONG; - result->value.lval = op1->value.lval & op2->value.lval; - return SUCCESS; -} - - -ZEND_API int bitwise_xor_function(zval *result, zval *op1, zval *op2) -{ - zval op1_copy, op2_copy; - - if (op1->type == IS_STRING && op2->type == IS_STRING) { - zval *longer, *shorter; - int i; - - if (op1->value.str.len >= op2->value.str.len) { - longer = op1; - shorter = op2; - } else { - longer = op2; - shorter = op1; - } - - result->value.str.len = shorter->value.str.len; - result->value.str.val = estrndup(shorter->value.str.val, shorter->value.str.len); - for (i = 0; i < shorter->value.str.len; i++) { - result->value.str.val[i] ^= longer->value.str.val[i]; - } - return SUCCESS; - } - - zendi_convert_to_long(op1, op1_copy, result); - zendi_convert_to_long(op2, op2_copy, result); - - result->type = IS_LONG; - result->value.lval = op1->value.lval ^ op2->value.lval; - return SUCCESS; -} - - -ZEND_API int shift_left_function(zval *result, zval *op1, zval *op2) -{ - zval op1_copy, op2_copy; - - zendi_convert_to_long(op1, op1_copy, result); - zendi_convert_to_long(op2, op2_copy, result); - result->value.lval = op1->value.lval << op2->value.lval; - result->type = IS_LONG; - return SUCCESS; -} - - -ZEND_API int shift_right_function(zval *result, zval *op1, zval *op2) -{ - zval op1_copy, op2_copy; - - zendi_convert_to_long(op1, op1_copy, result); - zendi_convert_to_long(op2, op2_copy, result); - result->value.lval = op1->value.lval >> op2->value.lval; - result->type = IS_LONG; - return SUCCESS; -} - - - -/* must support result==op1 */ -ZEND_API int add_char_to_string(zval *result, zval *op1, zval *op2) -{ - result->value.str.len = op1->value.str.len + 1; - result->value.str.val = (char *) erealloc(op1->value.str.val, result->value.str.len+1); - result->value.str.val[result->value.str.len - 1] = op2->value.chval; - result->value.str.val[result->value.str.len] = 0; - result->type = IS_STRING; - return SUCCESS; -} - - -/* must support result==op1 */ -ZEND_API int add_string_to_string(zval *result, zval *op1, zval *op2) -{ - int length = op1->value.str.len + op2->value.str.len; - result->value.str.val = (char *) erealloc(op1->value.str.val, length+1); - memcpy(result->value.str.val+op1->value.str.len, op2->value.str.val, op2->value.str.len); - result->value.str.val[length] = 0; - result->value.str.len = length; - result->type = IS_STRING; - return SUCCESS; -} - - -ZEND_API int concat_function(zval *result, zval *op1, zval *op2) -{ - zval op1_copy, op2_copy; - int use_copy1, use_copy2; - - - zend_make_printable_zval(op1, &op1_copy, &use_copy1); - zend_make_printable_zval(op2, &op2_copy, &use_copy2); - - if (use_copy1) { - op1 = &op1_copy; - } - if (use_copy2) { - op2 = &op2_copy; - } - if (result==op1) { /* special case, perform operations on result */ - uint res_len = op1->value.str.len + op2->value.str.len; - - if (result->value.str.len == 0) { /* handle empty_string */ - STR_FREE(result->value.str.val); - result->value.str.val = emalloc(res_len+1); - } else { - result->value.str.val = erealloc(result->value.str.val, res_len+1); - } - memcpy(result->value.str.val+result->value.str.len, op2->value.str.val, op2->value.str.len); - result->value.str.val[res_len]=0; - result->value.str.len = res_len; - } else { - result->value.str.len = op1->value.str.len + op2->value.str.len; - result->value.str.val = (char *) emalloc(result->value.str.len + 1); - memcpy(result->value.str.val, op1->value.str.val, op1->value.str.len); - memcpy(result->value.str.val+op1->value.str.len, op2->value.str.val,op2->value.str.len); - result->value.str.val[result->value.str.len] = 0; - result->type = IS_STRING; - } - if (use_copy1) { - zval_dtor(op1); - } - if (use_copy2) { - zval_dtor(op2); - } - return SUCCESS; -} - - -ZEND_API int compare_function(zval *result, zval *op1, zval *op2) -{ - zval op1_copy, op2_copy; - - if (op1->type == IS_STRING && op2->type == IS_STRING) { - zendi_smart_strcmp(result, op1, op2); - return SUCCESS; - } - - if (op1->type == IS_BOOL || op2->type == IS_BOOL - || op1->type == IS_NULL || op2->type == IS_NULL) { - zendi_convert_to_boolean(op1, op1_copy, result); - zendi_convert_to_boolean(op2, op2_copy, result); - result->type = IS_LONG; - result->value.lval = op1->value.lval - op2->value.lval; - return SUCCESS; - } - - zendi_convert_scalar_to_number(op1, op1_copy, result); - zendi_convert_scalar_to_number(op2, op2_copy, result); - - if (op1->type == IS_LONG && op2->type == IS_LONG) { - result->type = IS_LONG; - result->value.lval = op1->value.lval - op2->value.lval; - return SUCCESS; - } - if ((op1->type == IS_DOUBLE || op1->type == IS_LONG) - && (op2->type == IS_DOUBLE || op2->type == IS_LONG)) { - result->value.dval = (op1->type == IS_LONG ? (double) op1->value.lval : op1->value.dval) - (op2->type == IS_LONG ? (double) op2->value.lval : op2->value.dval); - result->type = IS_DOUBLE; - return SUCCESS; - } - if ((op1->type==IS_ARRAY || op1->type==IS_OBJECT) - && (op2->type==IS_ARRAY || op2->type==IS_OBJECT)) { - zend_error(E_WARNING,"Cannot compare arrays or objects"); - } - var_reset(result); - return FAILURE; -} - - -ZEND_API int is_identical_function(zval *result, zval *op1, zval *op2) -{ - result->type = IS_BOOL; - if (op1->type != op2->type) { - result->value.lval = 0; - return SUCCESS; - } - switch (op1->type) { - case IS_NULL: - result->value.lval = (op2->type==IS_NULL); - return SUCCESS; - break; - case IS_BOOL: - case IS_LONG: - case IS_RESOURCE: - result->value.lval = (op1->value.lval == op2->value.lval); - return SUCCESS; - break; - case IS_DOUBLE: - result->value.lval = (op1->value.dval == op2->value.dval); - return SUCCESS; - break; - case IS_STRING: - if ((op1->value.str.len == op2->value.str.len) - && (!memcmp(op1->value.str.val, op2->value.str.val, op1->value.str.len))) { - result->value.lval = 1; - } else { - result->value.lval = 0; - } - return SUCCESS; - break; - case IS_ARRAY: - case IS_OBJECT: - zend_error(E_WARNING,"Cannot compare arrays or objects"); - break; - } - var_reset(result); - return FAILURE; -} - -ZEND_API int is_equal_function(zval *result, zval *op1, zval *op2) -{ - if (compare_function(result, op1, op2) == FAILURE) { - return FAILURE; - } - convert_to_boolean(result); - if (result->value.lval == 0) { - result->value.lval = 1; - } else { - result->value.lval = 0; - } - return SUCCESS; -} - - -ZEND_API int is_not_equal_function(zval *result, zval *op1, zval *op2) -{ - if (compare_function(result, op1, op2) == FAILURE) { - return FAILURE; - } - convert_to_boolean(result); - if (result->value.lval) { - result->value.lval = 1; - } else { - result->value.lval = 0; - } - return SUCCESS; -} - - -ZEND_API int is_smaller_function(zval *result, zval *op1, zval *op2) -{ - if (compare_function(result, op1, op2) == FAILURE) { - return FAILURE; - } - if (result->type == IS_LONG) { - if (result->value.lval < 0) { - result->value.lval = 1; - } else { - result->value.lval = 0; - } - return SUCCESS; - } - if (result->type == IS_DOUBLE) { - result->type = IS_LONG; - if (result->value.dval < 0) { - result->value.lval = 1; - } else { - result->value.lval = 0; - } - return SUCCESS; - } - zend_error(E_ERROR, "Unsupported operand types"); - return FAILURE; -} - - -ZEND_API int is_smaller_or_equal_function(zval *result, zval *op1, zval *op2) -{ - if (compare_function(result, op1, op2) == FAILURE) { - return FAILURE; - } - if (result->type == IS_LONG) { - if (result->value.lval <= 0) { - result->value.lval = 1; - } else { - result->value.lval = 0; - } - return SUCCESS; - } - if (result->type == IS_DOUBLE) { - result->type = IS_LONG; - if (result->value.dval <= 0) { - result->value.lval = 1; - } else { - result->value.lval = 0; - } - return SUCCESS; - } - zend_error(E_ERROR, "Unsupported operand types"); - return FAILURE; -} - - -#define LOWER_CASE 1 -#define UPPER_CASE 2 -#define NUMERIC 3 - - -static void increment_string(zval *str) -{ - int carry=0; - int pos=str->value.str.len-1; - char *s=str->value.str.val; - char *t; - int last=0; /* Shut up the compiler warning */ - int ch; - - while(pos >= 0) { - ch = s[pos]; - if (ch >= 'a' && ch <= 'z') { - if (ch == 'z') { - s[pos] = 'a'; - carry=1; - } else { - s[pos]++; - carry=0; - } - last=LOWER_CASE; - } else if (ch >= 'A' && ch <= 'Z') { - if (ch == 'Z') { - s[pos] = 'A'; - carry=1; - } else { - s[pos]++; - carry=0; - } - last=UPPER_CASE; - } else if (ch >= '0' && ch <= '9') { - if (ch == '9') { - s[pos] = '0'; - carry=1; - } else { - s[pos]++; - carry=0; - } - last = NUMERIC; - } else { - carry=0; - break; - } - if (carry == 0) { - break; - } - pos--; - } - - if (carry) { - t = (char *) emalloc(str->value.str.len+1+1); - memcpy(t+1,str->value.str.val, str->value.str.len); - str->value.str.len++; - t[str->value.str.len] = '\0'; - switch (last) { - case NUMERIC: - t[0] = '1'; - break; - case UPPER_CASE: - t[0] = 'A'; - break; - case LOWER_CASE: - t[0] = 'a'; - break; - } - STR_FREE(str->value.str.val); - str->value.str.val = t; - } -} - - -ZEND_API int increment_function(zval *op1) -{ - switch (op1->type) { - case IS_LONG: - op1->value.lval++; - break; - case IS_DOUBLE: - op1->value.dval = op1->value.dval + 1; - break; - case IS_NULL: - op1->value.lval = 1; - op1->type = IS_LONG; - break; - case IS_STRING: /* Perl style string increment */ - increment_string(op1); - break; - default: - return FAILURE; - } - return SUCCESS; -} - - -ZEND_API int decrement_function(zval *op1) -{ - long lval; - - switch (op1->type) { - case IS_LONG: - op1->value.lval--; - break; - case IS_DOUBLE: - op1->value.dval = op1->value.dval - 1; - break; - case IS_STRING: /* Like perl we only support string increment */ - if (op1->value.str.len==0) { /* consider as 0 */ - STR_FREE(op1->value.str.val); - op1->value.lval = -1; - op1->type = IS_LONG; - break; - } else if (is_numeric_string(op1->value.str.val, op1->value.str.len, &lval, NULL)==IS_LONG) { /* long */ - STR_FREE(op1->value.str.val); - op1->value.lval = lval-1; - op1->type = IS_LONG; - break; - } - break; - default: - return FAILURE; - } - - return SUCCESS; -} - - -ZEND_API int zval_is_true(zval *op) -{ - convert_to_boolean(op); - return (op->value.lval ? 1 : 0); -} - - -ZEND_API void zend_str_tolower(char *str, unsigned int length) -{ - register char *p=str, *end=p+length; - - while (pvalue.str.val, s1->value.str.len, s2->value.str.val, s2->value.str.len); -} - -ZEND_API int zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3) -{ - return zend_binary_strncmp(s1->value.str.val, s1->value.str.len, s2->value.str.val, s2->value.str.len, s3->value.lval); -} - - -ZEND_API int zend_binary_zval_strcasecmp(zval *s1, zval *s2) -{ - return zend_binary_strcasecmp(s1->value.str.val, s1->value.str.len, s2->value.str.val, s2->value.str.len); -} - - -ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2) -{ - int ret1,ret2; - long lval1, lval2; - double dval1, dval2; - - if ((ret1=is_numeric_string(s1->value.str.val, s1->value.str.len, &lval1, &dval1)) && - (ret2=is_numeric_string(s2->value.str.val, s2->value.str.len, &lval2, &dval2))) { -#if WITH_BCMATH - if ((ret1==FLAG_IS_BC) || (ret2==FLAG_IS_BC)) { - bc_num first, second; - - /* use the BC math library to compare the numbers */ - init_num(&first); - init_num(&second); - str2num(&first,s1->value.str.val,100); /* this scale should do */ - str2num(&second,s2->value.str.val,100); /* ditto */ - result->value.lval = bc_compare(first,second); - result->type = IS_LONG; - free_num(&first); - free_num(&second); - } else -#endif - if ((ret1==IS_DOUBLE) || (ret2==IS_DOUBLE)) { - if (ret1!=IS_DOUBLE) { - dval1 = strtod(s1->value.str.val, NULL); - } else if (ret2!=IS_DOUBLE) { - dval2 = strtod(s2->value.str.val, NULL); - } - result->value.dval = dval1 - dval2; - result->type = IS_DOUBLE; - } else { /* they both have to be long's */ - result->value.lval = lval1 - lval2; - result->type = IS_LONG; - } - } else { - result->value.lval = zend_binary_zval_strcmp(s1, s2); - result->type = IS_LONG; - } - return; -} - - -/* returns 0 for non-numeric string - * returns IS_DOUBLE for floating point string, and assigns the value to *dval (if it's not NULL) - * returns IS_LONG for integer strings, and assigns the value to *lval (if it's not NULL) - * returns FLAG_IS_BC if the number might lose accuracy when converted to a double - */ - -#if 1 -ZEND_API inline int is_numeric_string(char *str, int length, long *lval, double *dval) -{ - long local_lval; - double local_dval; - char *end_ptr; - - if (!length) { - return 0; - } - - errno=0; - local_lval = strtol(str, &end_ptr, 10); - if (errno!=ERANGE && end_ptr == str+length) { /* integer string */ - if (lval) { - *lval = local_lval; - } - return IS_LONG; - } - - errno=0; - local_dval = strtod(str, &end_ptr); - if (errno!=ERANGE && end_ptr == str+length) { /* floating point string */ - if (dval) { - *dval = local_dval; - } -#if WITH_BCMATH - if (length>16) { - register char *ptr=str, *end=str+length; - - while(ptr | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _OPERATORS_H -#define _OPERATORS_H - -#define MAX_LENGTH_OF_LONG 18 -#define MAX_LENGTH_OF_DOUBLE 32 - -ZEND_API int add_function(zval *result, zval *op1, zval *op2); -ZEND_API int sub_function(zval *result, zval *op1, zval *op2); -ZEND_API int mul_function(zval *result, zval *op1, zval *op2); -ZEND_API int div_function(zval *result, zval *op1, zval *op2); -ZEND_API int mod_function(zval *result, zval *op1, zval *op2); -ZEND_API int boolean_or_function(zval *result, zval *op1, zval *op2); -ZEND_API int boolean_xor_function(zval *result, zval *op1, zval *op2); -ZEND_API int boolean_and_function(zval *result, zval *op1, zval *op2); -ZEND_API int boolean_not_function(zval *result, zval *op1); -ZEND_API int bitwise_not_function(zval *result, zval *op1); -ZEND_API int bitwise_or_function(zval *result, zval *op1, zval *op2); -ZEND_API int bitwise_and_function(zval *result, zval *op1, zval *op2); -ZEND_API int bitwise_xor_function(zval *result, zval *op1, zval *op2); -ZEND_API int shift_left_function(zval *result, zval *op1, zval *op2); -ZEND_API int shift_right_function(zval *result, zval *op1, zval *op2); -ZEND_API int concat_function(zval *result, zval *op1, zval *op2); - -ZEND_API int is_equal_function(zval *result, zval *op1, zval *op2); -ZEND_API int is_identical_function(zval *result, zval *op1, zval *op2); -ZEND_API int is_not_equal_function(zval *result, zval *op1, zval *op2); -ZEND_API int is_smaller_function(zval *result, zval *op1, zval *op2); -ZEND_API int is_smaller_or_equal_function(zval *result, zval *op1, zval *op2); -ZEND_API inline int is_numeric_string(char *str, int length, long *lval, double *dval); - -ZEND_API int increment_function(zval *op1); -ZEND_API int decrement_function(zval *op2); - -BEGIN_EXTERN_C() -ZEND_API void convert_scalar_to_number(zval *op); -ZEND_API void convert_to_string(zval *op); -ZEND_API void convert_to_long(zval *op); -ZEND_API void convert_to_long_base(zval *op, int base); -ZEND_API void convert_to_unset(zval *op); -ZEND_API void convert_to_boolean(zval *op); -ZEND_API void convert_to_array(zval *op); -ZEND_API void convert_to_object(zval *op); -ZEND_API int add_char_to_string(zval *result, zval *op1, zval *op2); -ZEND_API int add_string_to_string(zval *result, zval *op1, zval *op2); -ZEND_API void convert_to_double(zval *op); -END_EXTERN_C() - -ZEND_API int zval_is_true(zval *op); -ZEND_API int compare_function(zval *result, zval *op1, zval *op2); - -ZEND_API void zend_str_tolower(char *str, unsigned int length); -ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2); -ZEND_API int zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3); -ZEND_API int zend_binary_zval_strcasecmp(zval *s1, zval *s2); -ZEND_API int zend_binary_strcmp(char *s1, uint len1, char *s2, uint len2); -ZEND_API int zend_binary_strcasecmp(char *s1, uint len1, char *s2, uint len2); - -ZEND_API void zendi_smart_strcmp(zval *result, zval *s1, zval *s2); - -#define convert_to_long_ex(ppzv) \ - if ((*ppzv)->type!=IS_LONG) { \ - if (!(*ppzv)->is_ref) { \ - SEPARATE_ZVAL(ppzv); \ - } \ - convert_to_long(*ppzv); \ - } - -#define convert_to_double_ex(ppzv) \ - if ((*ppzv)->type!=IS_DOUBLE) { \ - if (!(*ppzv)->is_ref) { \ - SEPARATE_ZVAL(ppzv); \ - } \ - convert_to_double(*ppzv); \ - } - -#define convert_to_string_ex(ppzv) \ - if ((*ppzv)->type!=IS_STRING) { \ - if (!(*ppzv)->is_ref) { \ - SEPARATE_ZVAL(ppzv); \ - } \ - convert_to_string(*ppzv); \ - } - -#define convert_to_array_ex(ppzv) \ - if ((*ppzv)->type!=IS_ARRAY) { \ - if (!(*ppzv)->is_ref) { \ - SEPARATE_ZVAL(ppzv); \ - } \ - convert_to_array(*ppzv); \ - } - -#define convert_to_object_ex(ppzv) \ - if ((*ppzv)->type!=IS_OBJECT) { \ - if (!(*ppzv)->is_ref) { \ - SEPARATE_ZVAL(ppzv); \ - } \ - convert_to_object(*ppzv); \ - } - -#define convert_to_boolean_ex(ppzv) \ - if ((*ppzv)->type!=IS_BOOL) { \ - if (!(*ppzv)->is_ref) { \ - SEPARATE_ZVAL(ppzv); \ - } \ - convert_to_boolean(*ppzv); \ - } - -#define convert_scalar_to_number_ex(ppzv) \ - if ((*ppzv)->type!=IS_LONG && (*ppzv)->type!=IS_DOUBLE) { \ - if (!(*ppzv)->is_ref) { \ - SEPARATE_ZVAL(ppzv); \ - } \ - convert_scalar_to_number(*ppzv); \ - } - -#endif diff --git a/Zend/zend_ptr_stack.c b/Zend/zend_ptr_stack.c deleted file mode 100644 index 6c0e7481b3..0000000000 --- a/Zend/zend_ptr_stack.c +++ /dev/null @@ -1,114 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include "zend.h" -#include "zend_ptr_stack.h" -#ifdef HAVE_STDARG_H -# include -#endif - -ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack) -{ - stack->top_element = stack->elements = (void **) emalloc(sizeof(void *)*PTR_STACK_BLOCK_SIZE); - stack->max = PTR_STACK_BLOCK_SIZE; - stack->top = 0; -} - - -ZEND_API inline void zend_ptr_stack_push(zend_ptr_stack *stack, void *ptr) -{ - if (stack->top >= stack->max) { /* we need to allocate more memory */ - stack->elements = (void **) erealloc(stack->elements, (sizeof(void *) * (stack->max *= 2 ))); - stack->top_element = stack->elements+stack->top; - } - stack->top++; - *(stack->top_element++) = ptr; -} - -ZEND_API void zend_ptr_stack_n_push(zend_ptr_stack *stack, int count, ...) -{ - va_list ptr; - void *elem; - - if (stack->top+count > stack->max) { /* we need to allocate more memory */ - stack->max *= 2; - stack->max += count; - stack->elements = (void **) erealloc(stack->elements, (sizeof(void *) * (stack->max))); - stack->top_element = stack->elements+stack->top; - } - va_start(ptr, count); - while (count>0) { - elem = va_arg(ptr, void *); - stack->top++; - *(stack->top_element++) = elem; - count--; - } - va_end(ptr); -} - - -ZEND_API void zend_ptr_stack_n_pop(zend_ptr_stack *stack, int count, ...) -{ - va_list ptr; - void **elem; - - va_start(ptr, count); - while (count>0) { - elem = va_arg(ptr, void **); - *elem = *(--stack->top_element); - stack->top--; - count--; - } - va_end(ptr); -} - -ZEND_API inline void *zend_ptr_stack_pop(zend_ptr_stack *stack) -{ - stack->top--; - return *(--stack->top_element); -} - - -ZEND_API void zend_ptr_stack_destroy(zend_ptr_stack *stack) -{ - if (stack->elements) { - efree(stack->elements); - } -} - - -ZEND_API void zend_ptr_stack_apply(zend_ptr_stack *stack, void (*func)(void *)) -{ - int i = stack->top; - - while (--i >= 0) { - func(stack->elements[i]); - } -} - - -ZEND_API void zend_ptr_stack_clean(zend_ptr_stack *stack, void (*func)(void *)) -{ - zend_ptr_stack_apply(stack, func); - stack->top = 0; - stack->top_element = stack->elements; -} - - diff --git a/Zend/zend_ptr_stack.h b/Zend/zend_ptr_stack.h deleted file mode 100644 index 4b4c417753..0000000000 --- a/Zend/zend_ptr_stack.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _ZEND_PTR_STACK_H -#define _ZEND_PTR_STACK_H - -typedef struct _zend_ptr_stack { - short top, max; - void **elements; - void **top_element; -} zend_ptr_stack; - - -#define PTR_STACK_BLOCK_SIZE 64 - -ZEND_API void zend_ptr_stack_init(zend_ptr_stack *stack); -ZEND_API void zend_ptr_stack_push(zend_ptr_stack *stack, void *ptr); -ZEND_API void zend_ptr_stack_n_push(zend_ptr_stack *stack, int count, ...); -ZEND_API void *zend_ptr_stack_pop(zend_ptr_stack *stack); -ZEND_API void zend_ptr_stack_n_pop(zend_ptr_stack *stack, int count, ...); -ZEND_API void zend_ptr_stack_destroy(zend_ptr_stack *stack); -ZEND_API void zend_ptr_stack_apply(zend_ptr_stack *stack, void (*func)(void *)); -ZEND_API void zend_ptr_stack_clean(zend_ptr_stack *stack, void (*func)(void *)); - -#endif /* _ZEND_PTR_STACK_H */ diff --git a/Zend/zend_sprintf.c b/Zend/zend_sprintf.c deleted file mode 100644 index 57fd0ecfbe..0000000000 --- a/Zend/zend_sprintf.c +++ /dev/null @@ -1,40 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include - -#include "zend.h" - -#ifdef HAVE_STDARG_H -# include -#endif - -#if ZEND_BROKEN_SPRINTF -int zend_sprintf(char *buffer, const char *format, ...) -{ - va_list args; - - va_start(args, format); - vsprintf(buffer, format, args); - va_end(args); - - return strlen(buffer); -} -#endif diff --git a/Zend/zend_stack.c b/Zend/zend_stack.c deleted file mode 100644 index 011e8519c9..0000000000 --- a/Zend/zend_stack.c +++ /dev/null @@ -1,164 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include "zend.h" -#include "zend_stack.h" - -ZEND_API int zend_stack_init(zend_stack *stack) -{ - stack->top = 0; - stack->elements = (void **) emalloc(sizeof(void **) * STACK_BLOCK_SIZE); - if (!stack->elements) { - return FAILURE; - } else { - stack->max = STACK_BLOCK_SIZE; - return SUCCESS; - } -} - -ZEND_API int zend_stack_push(zend_stack *stack, void *element, int size) -{ - if (stack->top >= stack->max) { /* we need to allocate more memory */ - stack->elements = (void **) erealloc(stack->elements, - (sizeof(void **) * (stack->max += STACK_BLOCK_SIZE))); - if (!stack->elements) { - return FAILURE; - } - } - stack->elements[stack->top] = (void *) emalloc(size); - memcpy(stack->elements[stack->top], element, size); - return stack->top++; -} - - -ZEND_API int zend_stack_top(zend_stack *stack, void **element) -{ - if (stack->top > 0) { - *element = stack->elements[stack->top - 1]; - return SUCCESS; - } else { - *element = NULL; - return FAILURE; - } -} - - -ZEND_API int zend_stack_del_top(zend_stack *stack) -{ - if (stack->top > 0) { - efree(stack->elements[--stack->top]); - } - return SUCCESS; -} - - -ZEND_API int zend_stack_int_top(zend_stack *stack) -{ - int *e; - - if (zend_stack_top(stack, (void **) &e) == FAILURE) { - return FAILURE; /* this must be a negative number, since negative numbers can't be address numbers */ - } else { - return *e; - } -} - - -ZEND_API int zend_stack_is_empty(zend_stack *stack) -{ - if (stack->top == 0) { - return 1; - } else { - return 0; - } -} - - -ZEND_API int zend_stack_destroy(zend_stack *stack) -{ - register int i; - - for (i = 0; i < stack->top; i++) { - efree(stack->elements[i]); - } - - if (stack->elements) { - efree(stack->elements); - } - return SUCCESS; -} - - -ZEND_API void **zend_stack_base(zend_stack *stack) -{ - return stack->elements; -} - - -ZEND_API int zend_stack_count(zend_stack *stack) -{ - return stack->top; -} - - -ZEND_API void zend_stack_apply(zend_stack *stack, int (*apply_function)(void *element), int type) -{ - int i; - - switch (type) { - case ZEND_STACK_APPLY_TOPDOWN: - for (i=stack->top-1; i>=0; i--) { - if (apply_function(stack->elements[i])) { - break; - } - } - break; - case ZEND_STACK_APPLY_BOTTOMUP: - for (i=0; itop; i++) { - if (apply_function(stack->elements[i])) { - break; - } - } - break; - } -} - - -ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, int (*apply_function)(void *element, void *arg), int type, void *arg) -{ - int i; - - switch (type) { - case ZEND_STACK_APPLY_TOPDOWN: - for (i=stack->top-1; i>=0; i--) { - if (apply_function(stack->elements[i], arg)) { - break; - } - } - break; - case ZEND_STACK_APPLY_BOTTOMUP: - for (i=0; itop; i++) { - if (apply_function(stack->elements[i], arg)) { - break; - } - } - break; - } -} diff --git a/Zend/zend_stack.h b/Zend/zend_stack.h deleted file mode 100644 index 053d44632d..0000000000 --- a/Zend/zend_stack.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _ZEND_STACK_H -#define _ZEND_STACK_H - -typedef struct _zend_stack { - int top, max; - void **elements; -} zend_stack; - - -#define STACK_BLOCK_SIZE 64 - -ZEND_API int zend_stack_init(zend_stack *stack); -ZEND_API int zend_stack_push(zend_stack *stack, void *element, int size); -ZEND_API int zend_stack_top(zend_stack *stack, void **element); -ZEND_API int zend_stack_del_top(zend_stack *stack); -ZEND_API int zend_stack_int_top(zend_stack *stack); -ZEND_API int zend_stack_is_empty(zend_stack *stack); -ZEND_API int zend_stack_destroy(zend_stack *stack); -ZEND_API void **zend_stack_base(zend_stack *stack); -ZEND_API int zend_stack_count(zend_stack *stack); -ZEND_API void zend_stack_apply(zend_stack *stack, int (*apply_function)(void *element), int type); -ZEND_API void zend_stack_apply_with_argument(zend_stack *stack, int (*apply_function)(void *element, void *arg), int type, void *arg); - -#define ZEND_STACK_APPLY_TOPDOWN 1 -#define ZEND_STACK_APPLY_BOTTOMUP 2 - -#endif /* _ZEND_STACK_H */ diff --git a/Zend/zend_variables.c b/Zend/zend_variables.c deleted file mode 100644 index 640e6e9f72..0000000000 --- a/Zend/zend_variables.c +++ /dev/null @@ -1,190 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#include -#include "zend.h" -#include "zend_API.h" -#include "zend_globals.h" -#include "zend_constants.h" -#include "zend_variables.h" -#include "zend_list.h" - -ZEND_API char *empty_string = ""; /* in order to save emalloc() and efree() time for - * empty strings (usually used to denote empty - * return values in failed functions). - * The macro STR_FREE() will not efree() it. - */ - -/* this function MUST set the value for the variable to an empty string */ -/* and empty strings must be evaluated as FALSE */ -ZEND_API inline void var_reset(zval *var) -{ -#if 0 - var->type = IS_STRING; - var->value.str.val = empty_string; - var->value.str.len = 0; -#else - var->type = IS_BOOL; - var->value.lval = 0; -#endif -} - -ZEND_API inline void var_uninit(zval *var) -{ - var->type = IS_NULL; -} - - -ZEND_API void _zval_dtor(zval *zvalue ZEND_FILE_LINE_DC) -{ - if (zvalue->type==IS_LONG) { - return; - } - switch(zvalue->type) { - case IS_STRING: - case IS_CONSTANT: - STR_FREE_REL(zvalue->value.str.val); - break; - case IS_ARRAY: { - ELS_FETCH(); - - if (zvalue->value.ht && (zvalue->value.ht != &EG(symbol_table))) { - zend_hash_destroy(zvalue->value.ht); - FREE_HASHTABLE(zvalue->value.ht); - } - } - break; - case IS_OBJECT: - zend_hash_destroy(zvalue->value.obj.properties); - FREE_HASHTABLE(zvalue->value.obj.properties); - break; - case IS_RESOURCE: - /* destroy resource */ - zend_list_delete(zvalue->value.lval); - break; - case IS_LONG: - case IS_DOUBLE: - case IS_BOOL: - case IS_NULL: - default: - return; - break; - } -} - - -void zval_del_ref(zval **p) -{ - (*p)->refcount--; - if ((*p)->refcount==0) { - zval_dtor(*p); - FREE_ZVAL(*p); - } -} - - -void zval_add_ref(zval **p) -{ - (*p)->refcount++; -} - - -ZEND_API int _zval_copy_ctor(zval *zvalue ZEND_FILE_LINE_DC) -{ - switch (zvalue->type) { - case IS_RESOURCE: - zend_list_addref(zvalue->value.lval); - break; - case IS_BOOL: - case IS_LONG: - case IS_NULL: - break; - case IS_STRING: - if (zvalue->value.str.val) { - if (zvalue->value.str.len==0) { - zvalue->value.str.val = empty_string; - return SUCCESS; - } - } - zvalue->value.str.val = (char *) estrndup_rel(zvalue->value.str.val, zvalue->value.str.len); - break; - case IS_ARRAY: { - zval *tmp; - HashTable *original_ht = zvalue->value.ht; - ELS_FETCH(); - - if (!zvalue->value.ht) { - var_reset(zvalue); - return FAILURE; - } else if (zvalue->value.ht==&EG(symbol_table)) { - return SUCCESS; /* do nothing */ - } - zvalue->value.ht = (HashTable *) emalloc_rel(sizeof(HashTable)); - zend_hash_init(zvalue->value.ht, 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(zvalue->value.ht, original_ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - } - break; - case IS_OBJECT: { - zval *tmp; - HashTable *original_ht = zvalue->value.obj.properties; - - zvalue->value.obj.properties = (HashTable *) emalloc_rel(sizeof(HashTable)); - zend_hash_init(zvalue->value.obj.properties, 0, NULL, ZVAL_PTR_DTOR, 0); - zend_hash_copy(zvalue->value.obj.properties, original_ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *)); - } - break; - } - return SUCCESS; -} - - -ZEND_API int zend_print_variable(zval *var) -{ - return zend_print_zval(var, 0); -} - - -#if ZEND_DEBUG -ZEND_API int _zval_copy_ctor_wrapper(zval *zvalue) -{ - return zval_copy_ctor(zvalue); -} - - -ZEND_API void _zval_dtor_wrapper(zval *zvalue) -{ - zval_dtor(zvalue); -} - - - -ZEND_API void _zval_ptr_dtor_wrapper(zval **zval_ptr) -{ - zval_ptr_dtor(zval_ptr); -} -#endif - - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - */ diff --git a/Zend/zend_variables.h b/Zend/zend_variables.h deleted file mode 100644 index b2488fb3e0..0000000000 --- a/Zend/zend_variables.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | Zend Engine | - +----------------------------------------------------------------------+ - | Copyright (c) 1998, 1999 Andi Gutmans, Zeev Suraski | - +----------------------------------------------------------------------+ - | This source file is subject to version 0.91 of the Zend license, | - | that is bundled with this package in the file LICENSE, and is | - | available at through the world-wide-web at | - | http://www.zend.com/license/0_91.txt. | - | If you did not receive a copy of the Zend license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@zend.com so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Andi Gutmans | - | Zeev Suraski | - +----------------------------------------------------------------------+ -*/ - - -#ifndef _VARIABLES_H -#define _VARIABLES_H - - -ZEND_API int zend_print_variable(zval *var); - -BEGIN_EXTERN_C() -ZEND_API int _zval_copy_ctor(zval *zvalue ZEND_FILE_LINE_DC); -ZEND_API void _zval_dtor(zval *zvalue ZEND_FILE_LINE_DC); -ZEND_API void _zval_ptr_dtor(zval **zval_ptr ZEND_FILE_LINE_DC); -#define zval_copy_ctor(zvalue) _zval_copy_ctor((zvalue) ZEND_FILE_LINE_CC) -#define zval_dtor(zvalue) _zval_dtor((zvalue) ZEND_FILE_LINE_CC) -#define zval_ptr_dtor(zval_ptr) _zval_ptr_dtor((zval_ptr) ZEND_FILE_LINE_CC) - -#if ZEND_DEBUG -ZEND_API int _zval_copy_ctor_wrapper(zval *zvalue); -ZEND_API void _zval_dtor_wrapper(zval *zvalue); -ZEND_API void _zval_ptr_dtor_wrapper(zval **zval_ptr); -#define zval_copy_ctor_wrapper _zval_copy_ctor_wrapper -#define zval_dtor_wrapper _zval_dtor_wrapper -#define zval_ptr_dtor_wrapper _zval_ptr_dtor_wrapper -#else -#define zval_copy_ctor_wrapper _zval_copy_ctor -#define zval_dtor_wrapper _zval_dtor -#define zval_ptr_dtor_wrapper _zval_ptr_dtor -#endif - -END_EXTERN_C() - - -void zval_add_ref(zval **p); -void zval_del_ref(zval **p); - -#define ZVAL_DESTRUCTOR (void (*)(void *)) zval_dtor_wrapper -#define ZVAL_PTR_DTOR (void (*)(void *)) zval_ptr_dtor_wrapper -#define ZVAL_COPY_CTOR (void (*)(void *)) zval_copy_ctor_wrapper - -ZEND_API void var_reset(zval *var); -ZEND_API void var_uninit(zval *var); - -#endif diff --git a/ext/pcre/config0.m4 b/ext/pcre/config0.m4 deleted file mode 100644 index 9592bc0e2b..0000000000 --- a/ext/pcre/config0.m4 +++ /dev/null @@ -1,64 +0,0 @@ -dnl $Id$ -dnl config.m4 for extension pcre - -dnl By default we'll compile and link against the bundled PCRE library -dnl if DIR is supplied, we'll use that for linking - -AC_MSG_CHECKING(whether to include PCRE support) -AC_ARG_WITH(pcre-regex, -[ --without-pcre-regex Do not include Perl Compatible Regular Expressions - support. Use --with-pcre-regex=DIR to specify DIR - where PCRE's include and library files are located, - if not using bundled library.], -[ - case "$withval" in - no) - AC_MSG_RESULT(no) - ;; - yes) - EXTRA_LIBS="-L$abs_builddir/ext/pcre/pcrelib -lpcre $EXTRA_LIBS" - PCRE_SUBDIR="pcrelib" - AC_DEFINE(HAVE_BUNDLED_PCRE, 1, [ ]) - AC_MSG_RESULT(yes) - PHP_EXTENSION(pcre) - PHP_FAST_OUTPUT(ext/pcre/pcrelib/Makefile) - ;; - *) - if test -f $withval/pcre.h ; then - changequote({,}) - pcre_major=`grep PCRE_MAJOR $withval/pcre.h | sed -e 's/[^0-9]//g'` - pcre_minor=`grep PCRE_MINOR $withval/pcre.h | sed -e 's/[^0-9]//g'` - changequote([,]) - pcre_version=$pcre_major$pcre_minor - if test "$pcre_version" -ge 208; then - AC_ADD_INCLUDE($withval) - else - AC_MSG_ERROR(PCRE extension requires PCRE library version >= 2.08) - fi - else - AC_MSG_ERROR(Could not find pcre.h in $withval) - fi - - if test -f $withval/libpcre.a ; then - AC_ADD_LIBRARY_WITH_PATH(pcre, $withval) - else - AC_MSG_ERROR(Could not find libpcre.a in $withval) - fi - - AC_DEFINE(HAVE_PCRE, 1, [ ]) - AC_MSG_RESULT(yes) - PHP_EXTENSION(pcre) - ;; - esac -],[ - PCRE_LIBADD=pcrelib/libpcre.la - PCRE_SUBDIRS=pcrelib - AC_DEFINE(HAVE_BUNDLED_PCRE, 1, [ ]) - AC_MSG_RESULT(yes) - PHP_EXTENSION(pcre) - PHP_FAST_OUTPUT(ext/pcre/pcrelib/Makefile) -]) -PHP_SUBST(PCRE_LIBADD) -PHP_SUBST(PCRE_SUBDIRS) - -AC_CHECK_FUNC(memmove, [], [AC_DEFINE(USE_BCOPY, 1, [ ])]) diff --git a/strtok_r.c b/strtok_r.c deleted file mode 100644 index fea43bdead..0000000000 --- a/strtok_r.c +++ /dev/null @@ -1,113 +0,0 @@ -#include "php.h" - -#ifndef HAVE_STRTOK_R - -/* - * Copyright (c) 1998 Softweyr LLC. All rights reserved. - * - * strtok_r, from Berkeley strtok - * Oct 13, 1998 by Wes Peters - * - * Copyright (c) 1988, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * - * 1. Redistributions of source code must retain the above copyright - * notices, this list of conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright - * notices, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * - * This product includes software developed by Softweyr LLC, the - * University of California, Berkeley, and its contributors. - * - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY SOFTWEYR LLC, THE REGENTS AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A - * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTWEYR LLC, THE - * REGENTS, OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED - * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include - -char * -strtok_r(char *s, const char *delim, char **last) -{ - char *spanp; - int c, sc; - char *tok; - - if (s == NULL && (s = *last) == NULL) - { - return NULL; - } - - /* - * Skip (span) leading delimiters (s += strspn(s, delim), sort of). - */ -cont: - c = *s++; - for (spanp = (char *)delim; (sc = *spanp++) != 0; ) - { - if (c == sc) - { - goto cont; - } - } - - if (c == 0) /* no non-delimiter characters */ - { - *last = NULL; - return NULL; - } - tok = s - 1; - - /* - * Scan token (scan for delimiters: s += strcspn(s, delim), sort of). - * Note that delim must have one NUL; we stop if we see that, too. - */ - for (;;) - { - c = *s++; - spanp = (char *)delim; - do - { - if ((sc = *spanp++) == c) - { - if (c == 0) - { - s = NULL; - } - else - { - char *w = s - 1; - *w = '\0'; - } - *last = s; - return tok; - } - } - while (sc != 0); - } - /* NOTREACHED */ -} - -#endif -- 2.40.0