Skip to content

Commit

Permalink
Merge pull request #44 from alex-vlasov/BR-6654
Browse files Browse the repository at this point in the history
BR-6654: 7.3 updates
  • Loading branch information
Sadek Baroudi authored Aug 16, 2019
2 parents 6276525 + b2072a6 commit 1d5e854
Show file tree
Hide file tree
Showing 35 changed files with 82 additions and 185 deletions.
10 changes: 3 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: php
sudo: yes
dist: trusty
dist: bionic

env:
- PHPVER="7.1.27"
- PHPVER="7.3.8"

# This replaces the travis supplied phpbuild which defaults to ZTS enabled
# builds. Since we are replacing using the same config, we don't have to add
Expand All @@ -12,10 +12,7 @@ install:
- rm -rf ~/.phpenv
- sudo apt-get clean
- sudo apt-get update
- sudo apt-get purge --auto-remove mysql-client-5.6 mysql-client-core-5.6 mysql-server-5.6 mysql-server-core-5.6
- sudo rm -rf /var/lib/mysql
- sudo apt-get build-dep php5
- sudo apt-get install git libmcrypt-dev libreadline-dev
- sudo apt-get install libzip-dev
- curl -L http://git.io/phpenv-installer | bash
- travis_wait phpenv install "${PHPVER}"
- phpenv global "${PHPVER}"
Expand All @@ -27,7 +24,6 @@ before_script:
- ./configure
- make
- sed -i.stock -r -e 's/!mail_qa_team\(\$[[:alnum:]_]+,[[:space:]]*\$[[:alnum:]_]+,[[:space:]]*\$[[:alnum:]_]+\)/true/' run-tests.php
- sed -i.stock -e "s/\$ini_settings\['extension'\]\[\] = \$ext_dir \. DIRECTORY_SEPARATOR \. \$req_ext \. '\.' \. PHP_SHLIB_SUFFIX;/array_unshift\(\$ini_settings\['extension'\], \$ext_dir \. DIRECTORY_SEPARATOR \. \$req_ext \. '\.' \. PHP_SHLIB_SUFFIX\);/" run-tests.php
- sed -i.stock -e 's/run-tests\.php/run-tests.php --show-diff/' Makefile

script:
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ Configuration parameters

php.ini parameters for shadow. Default is fine for most cases.

| Name | Default | Meaning |
|--------------------|---------|------------------------------------------------------|
| shadow.enabled | 1 | Shadowing enabled? |
| shadow.mkdir\_mask | 0755 | Mask used when creating new directories on instances |
| shadow.debug | 0 | Debug level (bitmask) |
| shadow.cache\_size | 10000 | Shadow cache size (in bytes, per process) |
| Name | Default | Meaning |
|--------------------|---------|-----------------------------------------------------------------|
| shadow.enabled | 1 | Shadowing enabled? |
| shadow.mkdir\_mask | 0755 | Mask used when creating implicitly new directories on instances |
| shadow.debug | 0 | Debug level (bitmask) |
| shadow.cache\_size | 10000 | Shadow cache size (in bytes, per process) |

Debug level
-----------
Expand Down
3 changes: 2 additions & 1 deletion php_shadow.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ ZEND_BEGIN_MODULE_GLOBALS(shadow)
HashTable cache;
HashTable replaced_function_table;
uint segment_id;
char *shadow_override_copy;
ZEND_END_MODULE_GLOBALS(shadow)

#ifdef ZTS
Expand All @@ -68,7 +69,7 @@ ZEND_END_MODULE_GLOBALS(shadow)
#define SHADOW_G(v) (shadow_globals.v)
#endif

#define SHADOW_VERSION "0.8.2"
#define SHADOW_VERSION "0.9.0"

ZEND_EXTERN_MODULE_GLOBALS(shadow)

Expand Down
68 changes: 38 additions & 30 deletions shadow.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

ZEND_DECLARE_MODULE_GLOBALS(shadow)

static char *shadow_override_copy = NULL;

typedef struct _shadow_function {
void (*orig_handler)(INTERNAL_FUNCTION_PARAMETERS);
int argno;
Expand Down Expand Up @@ -63,8 +61,8 @@ static php_stream_ops shadow_dirstream_ops = {
NULL /* set_option */
};

static php_stream_wrapper_ops *plain_ops;
zend_string *(*original_zend_resolve_path)(const char *filename, int filename_len);
static const php_stream_wrapper_ops *plain_ops;
zend_string *(*original_zend_resolve_path)(const char *filename, size_t filename_len);
static void (*orig_touch)(INTERNAL_FUNCTION_PARAMETERS);
static void (*orig_chmod)(INTERNAL_FUNCTION_PARAMETERS);
static void (*orig_chdir)(INTERNAL_FUNCTION_PARAMETERS);
Expand All @@ -73,7 +71,7 @@ static void (*orig_realpath)(INTERNAL_FUNCTION_PARAMETERS);
static void (*orig_is_writable)(INTERNAL_FUNCTION_PARAMETERS);
static void (*orig_glob)(INTERNAL_FUNCTION_PARAMETERS);

zend_string *shadow_resolve_path(const char *filename, int filename_len);
zend_string *shadow_resolve_path(const char *filename, size_t filename_len);
static php_stream *shadow_stream_opener(php_stream_wrapper *wrapper, const char *filename, const char *mode,
int options, zend_string **opened_path, php_stream_context *context STREAMS_DC);
static int shadow_stat(php_stream_wrapper *wrapper, const char *url, int flags, php_stream_statbuf *ssb,
Expand Down Expand Up @@ -115,7 +113,7 @@ const zend_function_entry shadow_functions[] = {
static PHP_GINIT_FUNCTION(shadow)
{
memset(shadow_globals, 0, sizeof(zend_shadow_globals));
zend_hash_init(&shadow_globals->cache, 10, NULL, ZVAL_PTR_DTOR, 1); // persistent!
zend_hash_init(&shadow_globals->cache, 10, NULL, ZVAL_INTERNAL_PTR_DTOR, 1); // persistent!
zend_hash_init(&shadow_globals->replaced_function_table, 10, NULL, ZVAL_PTR_DTOR, 1);
// initial size 10 here is a common sense - look at the number of overriden functions
}
Expand Down Expand Up @@ -169,14 +167,20 @@ PHP_INI_END()

#define SHADOW_CONSTANT(C) REGISTER_LONG_CONSTANT(#C, C, CONST_CS | CONST_PERSISTENT)

/* {{{ SHADOW_OVERRIDE
* Use this macros to override php function with shadow analogue. E.g.:
* SHADOW_OVERRIDE(fread);
* It requires shadow_fread() function to be defined and have exactly the same signature as fread() function.
*/
#define SHADOW_OVERRIDE(func) \
orig_##func = NULL; \
zend_string * key_##func = zend_string_init(#func, strlen(#func), 0);\
if ((orig = zend_hash_find_ptr(CG(function_table), key_##func)) != NULL) { \
orig_##func = orig->internal_function.handler; \
orig->internal_function.handler = shadow_##func; \
} \
zend_string_release(key_##func);
zend_string_release_ex(key_##func, 0);
/* }}} */

#define SHADOW_ENABLED() (SHADOW_G(enabled) != 0 && SHADOW_G(instance) != NULL && SHADOW_G(template) != NULL)

Expand All @@ -196,7 +200,7 @@ static void shadow_override_function(char *fname, size_t fname_len, int argno, i
return;
}

zend_string_release(fname_zs);
zend_string_release_ex(fname_zs, 0);
table = &cls->function_table;
fname = col+2;
fname_len = strlen(fname);
Expand All @@ -205,7 +209,7 @@ static void shadow_override_function(char *fname, size_t fname_len, int argno, i
zend_string *fname_zs = zend_string_init(fname, strlen(fname), 0);

if ((orig = zend_hash_find_ptr(table, fname_zs)) == NULL) {
zend_string_release(fname_zs);
zend_string_release_ex(fname_zs, 0);
return;
}

Expand All @@ -216,8 +220,8 @@ static void shadow_override_function(char *fname, size_t fname_len, int argno, i

orig->internal_function.handler = shadow_generic_override;

zend_string_release(fname_zs);
zend_string_release(fname_full);
zend_string_release_ex(fname_zs, 0);
zend_string_release_ex(fname_full, 1);
}

static void shadow_undo_override(char *fname, size_t fname_len, int argno, int argtype)
Expand All @@ -236,7 +240,7 @@ static void shadow_undo_override(char *fname, size_t fname_len, int argno, int a
return;
}

zend_string_release(fname_zs);
zend_string_release_ex(fname_zs, 0);
table = &cls->function_table;
fname = col+2;
fname_len = strlen(fname);
Expand All @@ -245,12 +249,12 @@ static void shadow_undo_override(char *fname, size_t fname_len, int argno, int a
zend_string *fname_zs = zend_string_init(fname, strlen(fname), 0);

if ((orig = zend_hash_find_ptr(table, fname_zs)) == NULL) {
zend_string_release(fname_zs);
zend_string_release_ex(fname_zs, 0);
return;
}

if ((override = zend_hash_find_ptr(&SHADOW_G(replaced_function_table), fname_full)) == NULL) {
zend_string_release(fname_zs);
zend_string_release_ex(fname_zs, 0);
return;
}

Expand All @@ -259,8 +263,8 @@ static void shadow_undo_override(char *fname, size_t fname_len, int argno, int a
zend_hash_del(&SHADOW_G(replaced_function_table), fname_full);
pefree(override, 1);

zend_string_release(fname_full);
zend_string_release(fname_zs);
zend_string_release_ex(fname_full, 1);
zend_string_release_ex(fname_zs, 0);
}


Expand Down Expand Up @@ -321,7 +325,7 @@ PHP_MINIT_FUNCTION(shadow)
int argno;
int argtype;
/* Save this for shutdown */
shadow_override_copy = estrdup(SHADOW_G(override));
SHADOW_G(shadow_override_copy) = estrdup(SHADOW_G(override));
while(*over) {
char *next = strchr(over, ',');
if(!next) {
Expand Down Expand Up @@ -364,9 +368,9 @@ PHP_MINIT_FUNCTION(shadow)
*/
PHP_MSHUTDOWN_FUNCTION(shadow)
{
if (shadow_override_copy != NULL) {
if (SHADOW_G(shadow_override_copy) != NULL) {
/* Cleanup after our user-specified overrides. */
char *over = shadow_override_copy;
char *over = SHADOW_G(shadow_override_copy);
size_t over_len;
char c;
int argno;
Expand Down Expand Up @@ -404,7 +408,7 @@ PHP_MSHUTDOWN_FUNCTION(shadow)
break;
}
}
efree(shadow_override_copy);
efree(SHADOW_G(shadow_override_copy));
}
UNREGISTER_INI_ENTRIES();
return SUCCESS;
Expand All @@ -417,13 +421,17 @@ PHP_MSHUTDOWN_FUNCTION(shadow)
PHP_RINIT_FUNCTION(shadow)
{
if(SHADOW_G(enabled)) {
php_unregister_url_stream_wrapper_volatile("file");
php_register_url_stream_wrapper_volatile("file", &shadow_wrapper);
zend_string *protocol;
protocol = zend_string_init("file", strlen("file"), 0);
php_unregister_url_stream_wrapper_volatile(protocol);
php_register_url_stream_wrapper_volatile(protocol, &shadow_wrapper);
zend_string_release_ex(protocol, 0);
}
SHADOW_G(template) = NULL;
SHADOW_G(instance) = NULL;
SHADOW_G(curdir) = NULL;
SHADOW_G(segment_id) = 0;
SHADOW_G(shadow_override_copy) = NULL;
return SUCCESS;
}
/* }}} */
Expand Down Expand Up @@ -844,7 +852,7 @@ static void ensure_dir_exists(char *pathname, php_stream_wrapper *wrapper, php_s
pathname[dir_len] = '/'; /* restore full path */
}

zend_string *shadow_resolve_path(const char *filename, int filename_len)
zend_string *shadow_resolve_path(const char *filename, size_t filename_len)
{
char *shadow_result = template_to_instance(filename, OPT_CHECK_EXISTS TSRMLS_CC);
zend_string *result = NULL;
Expand Down Expand Up @@ -1175,7 +1183,7 @@ static int shadow_call_replace_name_ex(zval *name, char *repname, void (*orig_fu
Z_STR_P(name) = new_name;
orig_func(INTERNAL_FUNCTION_PARAM_PASSTHRU);
Z_STR_P(name) = old_name;
zend_string_release(new_name);
zend_string_release_ex(new_name, 1);
return SUCCESS;
}

Expand Down Expand Up @@ -1565,7 +1573,7 @@ static void shadow_generic_override(INTERNAL_FUNCTION_PARAMETERS)
}
shadow_function *func;
if ((func = zend_hash_find_ptr(&SHADOW_G(replaced_function_table), fname_full)) == NULL) {
zend_string_release(fname_full);
zend_string_release_ex(fname_full, 0);
return;
}
zval *name;
Expand All @@ -1574,20 +1582,20 @@ static void shadow_generic_override(INTERNAL_FUNCTION_PARAMETERS)

if(!SHADOW_ENABLED()) {
func->orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
zend_string_release(fname_full);
zend_string_release_ex(fname_full, 0);
return;
}

name = shadow_get_arg(func->argno TSRMLS_CC);
if (!name || Z_TYPE_P(name) != IS_STRING) {
func->orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
zend_string_release(fname_full);
zend_string_release_ex(fname_full, 0);
return;
}
/* not our path - don't mess with it */
if (!shadow_stream_check(Z_STRVAL_P(name))) {
func->orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
zend_string_release(fname_full);
zend_string_release_ex(fname_full, 0);
return;
}
/* try to translate */
Expand All @@ -1602,11 +1610,11 @@ static void shadow_generic_override(INTERNAL_FUNCTION_PARAMETERS)
/* we didn't find better name, use original */
if(!instname) {
func->orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
zend_string_release(fname_full);
zend_string_release_ex(fname_full, 0);
return;
}
shadow_call_replace_name_ex(name, instname, func->orig_handler, INTERNAL_FUNCTION_PARAM_PASSTHRU);
zend_string_release(fname_full);
zend_string_release_ex(fname_full, 0);
}

/*
Expand Down
12 changes: 5 additions & 7 deletions shadow_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void shadow_cache_set_id(zend_string *template, zend_string *instance TSRMLS_DC)
} else {
SHADOW_G(segment_id) = Z_LVAL_P(segment_zv);
}
zend_string_release(segname_zs);
zend_string_release_ex(segname_zs, 1);
efree(segname);
}

Expand All @@ -65,7 +65,7 @@ int shadow_cache_get(const char *name, char **entry TSRMLS_DC)
namelen = shadow_cache_segmented_name(&segname, name TSRMLS_CC);
zend_string *segname_zs = zend_string_init(segname, namelen, 0);
if ((centry = zend_hash_find(&SHADOW_G(cache), segname_zs)) != NULL) {
zend_string_release(segname_zs);
zend_string_release_ex(segname_zs, 0);
efree(segname);
if(Z_STRLEN_P(centry) == 0){
*entry = NULL;
Expand All @@ -75,7 +75,7 @@ int shadow_cache_get(const char *name, char **entry TSRMLS_DC)
return SUCCESS;
} else {
*entry = NULL;
zend_string_release(segname_zs);
zend_string_release_ex(segname_zs, 0);
efree(segname);
return FAILURE;
}
Expand All @@ -85,7 +85,6 @@ void shadow_cache_put(const char *name, const char *entry TSRMLS_DC)
{
char *segname;
int namelen;
zend_string * entry_zs;
zval entry_zv;
if(SHADOW_G(cache_size) == 0) {
return;
Expand All @@ -96,11 +95,10 @@ void shadow_cache_put(const char *name, const char *entry TSRMLS_DC)
}
namelen = shadow_cache_segmented_name(&segname, name TSRMLS_CC);
zend_string *segname_zs = zend_string_init(segname, namelen, 1);
entry_zs = zend_string_init(entry, strlen(entry), 1);
ZVAL_STR(&entry_zv, entry_zs);
ZVAL_PSTRING(&entry_zv, entry);
zend_hash_update(&SHADOW_G(cache), segname_zs, &entry_zv);
efree(segname);
zend_string_release(segname_zs);
zend_string_release_ex(segname_zs, 1);
}

void shadow_cache_remove(const char *name TSRMLS_DC)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 1d5e854

Please sign in to comment.