diff options
Diffstat (limited to 'Zend/zend_extensions.c')
-rw-r--r-- | Zend/zend_extensions.c | 94 |
1 files changed, 84 insertions, 10 deletions
diff --git a/Zend/zend_extensions.c b/Zend/zend_extensions.c index 65d215d5eb..2cf68293ec 100644 --- a/Zend/zend_extensions.c +++ b/Zend/zend_extensions.c @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | Zend Engine | +----------------------------------------------------------------------+ - | Copyright (c) 1998-2015 Zend Technologies Ltd. (http://www.zend.com) | + | Copyright (c) 1998-2016 Zend Technologies Ltd. (http://www.zend.com) | +----------------------------------------------------------------------+ | This source file is subject to version 2.00 of the Zend license, | | that is bundled with this package in the file LICENSE, and is | @@ -22,6 +22,7 @@ #include "zend_extensions.h" ZEND_API zend_llist zend_extensions; +ZEND_API uint32_t zend_extension_flags = 0; static int last_resource_number; int zend_load_extension(const char *path) @@ -35,12 +36,10 @@ int zend_load_extension(const char *path) if (!handle) { #ifndef ZEND_WIN32 fprintf(stderr, "Failed loading %s: %s\n", path, DL_ERROR()); -/* See http://support.microsoft.com/kb/190351 */ -#ifdef PHP_WIN32 - fflush(stderr); -#endif #else fprintf(stderr, "Failed loading %s\n", path); + /* See http://support.microsoft.com/kb/190351 */ + fflush(stderr); #endif return FAILURE; } @@ -56,7 +55,7 @@ int zend_load_extension(const char *path) if (!extension_version_info || !new_extension) { fprintf(stderr, "%s doesn't appear to be a valid Zend extension\n", path); /* See http://support.microsoft.com/kb/190351 */ -#ifdef PHP_WIN32 +#ifdef ZEND_WIN32 fflush(stderr); #endif DL_UNLOAD(handle); @@ -73,7 +72,7 @@ int zend_load_extension(const char *path) extension_version_info->zend_extension_api_no, ZEND_EXTENSION_API_NO); /* See http://support.microsoft.com/kb/190351 */ -#ifdef PHP_WIN32 +#ifdef ZEND_WIN32 fflush(stderr); #endif DL_UNLOAD(handle); @@ -89,7 +88,7 @@ int zend_load_extension(const char *path) new_extension->URL, new_extension->name); /* See http://support.microsoft.com/kb/190351 */ -#ifdef PHP_WIN32 +#ifdef ZEND_WIN32 fflush(stderr); #endif DL_UNLOAD(handle); @@ -100,7 +99,7 @@ int zend_load_extension(const char *path) fprintf(stderr, "Cannot load %s - it was built with configuration %s, whereas running engine is %s\n", new_extension->name, extension_version_info->build_id, ZEND_EXTENSION_BUILD_ID); /* See http://support.microsoft.com/kb/190351 */ -#ifdef PHP_WIN32 +#ifdef ZEND_WIN32 fflush(stderr); #endif DL_UNLOAD(handle); @@ -108,6 +107,14 @@ int zend_load_extension(const char *path) } else if (zend_get_extension(new_extension->name)) { fprintf(stderr, "Cannot load %s - it was already loaded\n", new_extension->name); /* See http://support.microsoft.com/kb/190351 */ +#ifdef ZEND_WIN32 + fflush(stderr); +#endif + DL_UNLOAD(handle); + return FAILURE; + } else if (zend_get_extension(new_extension->name)) { + fprintf(stderr, "Cannot load %s - extension already loaded\n", new_extension->name); +/* See http://support.microsoft.com/kb/190351 */ #ifdef PHP_WIN32 fflush(stderr); #endif @@ -119,7 +126,7 @@ int zend_load_extension(const char *path) #else fprintf(stderr, "Extensions are not supported on this platform.\n"); /* See http://support.microsoft.com/kb/190351 */ -#ifdef PHP_WIN32 +#ifdef ZEND_WIN32 fflush(stderr); #endif return FAILURE; @@ -139,6 +146,21 @@ int zend_register_extension(zend_extension *new_extension, DL_HANDLE handle) zend_llist_add_element(&zend_extensions, &extension); + if (extension.op_array_ctor) { + zend_extension_flags |= ZEND_EXTENSIONS_HAVE_OP_ARRAY_CTOR; + } + if (extension.op_array_dtor) { + zend_extension_flags |= ZEND_EXTENSIONS_HAVE_OP_ARRAY_DTOR; + } + if (extension.op_array_handler) { + zend_extension_flags |= ZEND_EXTENSIONS_HAVE_OP_ARRAY_HANDLER; + } + if (extension.op_array_persist_calc) { + zend_extension_flags |= ZEND_EXTENSIONS_HAVE_OP_ARRAY_PERSIST_CALC; + } + if (extension.op_array_persist) { + zend_extension_flags |= ZEND_EXTENSIONS_HAVE_OP_ARRAY_PERSIST; + } /*fprintf(stderr, "Loaded %s, version %s\n", extension.name, extension.version);*/ #endif @@ -247,6 +269,58 @@ ZEND_API zend_extension *zend_get_extension(const char *extension_name) return NULL; } +typedef struct _zend_extension_persist_data { + zend_op_array *op_array; + size_t size; + char *mem; +} zend_extension_persist_data; + +static void zend_extension_op_array_persist_calc_handler(zend_extension *extension, zend_extension_persist_data *data) +{ + if (extension->op_array_persist_calc) { + data->size += extension->op_array_persist_calc(data->op_array); + } +} + +static void zend_extension_op_array_persist_handler(zend_extension *extension, zend_extension_persist_data *data) +{ + if (extension->op_array_persist) { + size_t size = extension->op_array_persist(data->op_array, data->mem); + if (size) { + data->mem = (void*)((char*)data->mem + size); + data->size += size; + } + } +} + +ZEND_API size_t zend_extensions_op_array_persist_calc(zend_op_array *op_array) +{ + if (zend_extension_flags & ZEND_EXTENSIONS_HAVE_OP_ARRAY_PERSIST_CALC) { + zend_extension_persist_data data; + + data.op_array = op_array; + data.size = 0; + data.mem = NULL; + zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) zend_extension_op_array_persist_calc_handler, &data); + return data.size; + } + return 0; +} + +ZEND_API size_t zend_extensions_op_array_persist(zend_op_array *op_array, void *mem) +{ + if (zend_extension_flags & ZEND_EXTENSIONS_HAVE_OP_ARRAY_PERSIST) { + zend_extension_persist_data data; + + data.op_array = op_array; + data.size = 0; + data.mem = mem; + zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) zend_extension_op_array_persist_handler, &data); + return data.size; + } + return 0; +} + /* * Local variables: * tab-width: 4 |