From b8a8c7822d4125f5eb658634d2a9ffb96853aeaa Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 4 Nov 2013 14:48:33 +0100 Subject: [PATCH 1/2] Fix issue #147: allow to work with phar build shared --- ZendAccelerator.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/ZendAccelerator.c b/ZendAccelerator.c index 51bc3da..a3dd28d 100644 --- a/ZendAccelerator.c +++ b/ZendAccelerator.c @@ -148,9 +148,33 @@ static inline int is_cacheable_stream_path(const char *filename) } #ifdef HAVE_PHAR_HEADER +#ifdef COMPILE_DL_PHAR +static typeof(phar_resolve_alias) *opcache_phar_resolve_alias; +#else +# define opcache_phar_resolve_alias phar_resolve_alias +#endif + static inline int is_phar_relative_alias_path(const char *filename, char **alias, int *alias_len) { - if (memcmp(filename, "phar://", sizeof("phar://") - 1) == 0 +#ifdef COMPILE_DL_PHAR + static int pharloaded = -1; + + /* Only once, retrieve phar_resolve_alias from phar module if loaded */ + if (pharloaded < 0) { + zend_module_entry *phar; + + if (zend_hash_find(&module_registry, "phar", 5, (void**)&phar) == SUCCESS) { + opcache_phar_resolve_alias = DL_FETCH_SYMBOL(phar->handle, "phar_resolve_alias"); + pharloaded = (opcache_phar_resolve_alias ? 1 : 0); + } else { + pharloaded = 0; + } + } + if (pharloaded && +#else + if ( +#endif + memcmp(filename, "phar://", sizeof("phar://") - 1) == 0 && filename[sizeof("phar://") - 1] != '\0' && filename[sizeof("phar://") - 1] != '/') { char *slash; *alias = (char*)filename + sizeof("phar://") - 1; @@ -1062,7 +1086,7 @@ char *accel_make_persistent_key_ex(zend_file_handle *file_handle, int path_lengt if (is_phar_relative_alias_path(file_handle->filename, &alias, &alias_len)) { char *phar_path; int phar_path_len; - if (phar_resolve_alias(alias, alias_len, &phar_path, &phar_path_len TSRMLS_CC) == SUCCESS) { + if (opcache_phar_resolve_alias(alias, alias_len, &phar_path, &phar_path_len TSRMLS_CC) == SUCCESS) { int filename_len = strlen(file_handle->filename); memcpy(ZCG(key), "phar://", sizeof("phar://") -1); memcpy(ZCG(key) + sizeof("phar://") - 1, phar_path, phar_path_len); From 4b0a10fac171f4450aacb0597a7d847253ae94d8 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Mon, 4 Nov 2013 15:53:31 +0100 Subject: [PATCH 2/2] typeof is not really portable --- ZendAccelerator.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/ZendAccelerator.c b/ZendAccelerator.c index a3dd28d..d6ac679 100644 --- a/ZendAccelerator.c +++ b/ZendAccelerator.c @@ -148,10 +148,13 @@ static inline int is_cacheable_stream_path(const char *filename) } #ifdef HAVE_PHAR_HEADER -#ifdef COMPILE_DL_PHAR -static typeof(phar_resolve_alias) *opcache_phar_resolve_alias; -#else + +#ifndef COMPILE_DL_PHAR # define opcache_phar_resolve_alias phar_resolve_alias +#elif defined(__GNUC__) +static __typeof__(phar_resolve_alias) *opcache_phar_resolve_alias; +#else +static int (*opcache_phar_resolve_alias)(char *alias, int alias_len, char **filename, int *filename_len TSRMLS_DC); #endif static inline int is_phar_relative_alias_path(const char *filename, char **alias, int *alias_len)