Skip to content

Commit 1d5e854

Browse files
author
Sadek Baroudi
authored
Merge pull request #44 from alex-vlasov/BR-6654
BR-6654: 7.3 updates
2 parents 6276525 + b2072a6 commit 1d5e854

35 files changed

+82
-185
lines changed

.travis.yml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
language: php
22
sudo: yes
3-
dist: trusty
3+
dist: bionic
44

55
env:
6-
- PHPVER="7.1.27"
6+
- PHPVER="7.3.8"
77

88
# This replaces the travis supplied phpbuild which defaults to ZTS enabled
99
# builds. Since we are replacing using the same config, we don't have to add
@@ -12,10 +12,7 @@ install:
1212
- rm -rf ~/.phpenv
1313
- sudo apt-get clean
1414
- sudo apt-get update
15-
- sudo apt-get purge --auto-remove mysql-client-5.6 mysql-client-core-5.6 mysql-server-5.6 mysql-server-core-5.6
16-
- sudo rm -rf /var/lib/mysql
17-
- sudo apt-get build-dep php5
18-
- sudo apt-get install git libmcrypt-dev libreadline-dev
15+
- sudo apt-get install libzip-dev
1916
- curl -L http://git.io/phpenv-installer | bash
2017
- travis_wait phpenv install "${PHPVER}"
2118
- phpenv global "${PHPVER}"
@@ -27,7 +24,6 @@ before_script:
2724
- ./configure
2825
- make
2926
- sed -i.stock -r -e 's/!mail_qa_team\(\$[[:alnum:]_]+,[[:space:]]*\$[[:alnum:]_]+,[[:space:]]*\$[[:alnum:]_]+\)/true/' run-tests.php
30-
- 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
3127
- sed -i.stock -e 's/run-tests\.php/run-tests.php --show-diff/' Makefile
3228

3329
script:

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ Configuration parameters
5555

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

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

6565
Debug level
6666
-----------

php_shadow.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ ZEND_BEGIN_MODULE_GLOBALS(shadow)
6060
HashTable cache;
6161
HashTable replaced_function_table;
6262
uint segment_id;
63+
char *shadow_override_copy;
6364
ZEND_END_MODULE_GLOBALS(shadow)
6465

6566
#ifdef ZTS
@@ -68,7 +69,7 @@ ZEND_END_MODULE_GLOBALS(shadow)
6869
#define SHADOW_G(v) (shadow_globals.v)
6970
#endif
7071

71-
#define SHADOW_VERSION "0.8.2"
72+
#define SHADOW_VERSION "0.9.0"
7273

7374
ZEND_EXTERN_MODULE_GLOBALS(shadow)
7475

shadow.c

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
ZEND_DECLARE_MODULE_GLOBALS(shadow)
3030

31-
static char *shadow_override_copy = NULL;
32-
3331
typedef struct _shadow_function {
3432
void (*orig_handler)(INTERNAL_FUNCTION_PARAMETERS);
3533
int argno;
@@ -63,8 +61,8 @@ static php_stream_ops shadow_dirstream_ops = {
6361
NULL /* set_option */
6462
};
6563

66-
static php_stream_wrapper_ops *plain_ops;
67-
zend_string *(*original_zend_resolve_path)(const char *filename, int filename_len);
64+
static const php_stream_wrapper_ops *plain_ops;
65+
zend_string *(*original_zend_resolve_path)(const char *filename, size_t filename_len);
6866
static void (*orig_touch)(INTERNAL_FUNCTION_PARAMETERS);
6967
static void (*orig_chmod)(INTERNAL_FUNCTION_PARAMETERS);
7068
static void (*orig_chdir)(INTERNAL_FUNCTION_PARAMETERS);
@@ -73,7 +71,7 @@ static void (*orig_realpath)(INTERNAL_FUNCTION_PARAMETERS);
7371
static void (*orig_is_writable)(INTERNAL_FUNCTION_PARAMETERS);
7472
static void (*orig_glob)(INTERNAL_FUNCTION_PARAMETERS);
7573

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

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

170+
/* {{{ SHADOW_OVERRIDE
171+
* Use this macros to override php function with shadow analogue. E.g.:
172+
* SHADOW_OVERRIDE(fread);
173+
* It requires shadow_fread() function to be defined and have exactly the same signature as fread() function.
174+
*/
172175
#define SHADOW_OVERRIDE(func) \
173176
orig_##func = NULL; \
174177
zend_string * key_##func = zend_string_init(#func, strlen(#func), 0);\
175178
if ((orig = zend_hash_find_ptr(CG(function_table), key_##func)) != NULL) { \
176179
orig_##func = orig->internal_function.handler; \
177180
orig->internal_function.handler = shadow_##func; \
178181
} \
179-
zend_string_release(key_##func);
182+
zend_string_release_ex(key_##func, 0);
183+
/* }}} */
180184

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

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

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

207211
if ((orig = zend_hash_find_ptr(table, fname_zs)) == NULL) {
208-
zend_string_release(fname_zs);
212+
zend_string_release_ex(fname_zs, 0);
209213
return;
210214
}
211215

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

217221
orig->internal_function.handler = shadow_generic_override;
218222

219-
zend_string_release(fname_zs);
220-
zend_string_release(fname_full);
223+
zend_string_release_ex(fname_zs, 0);
224+
zend_string_release_ex(fname_full, 1);
221225
}
222226

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

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

247251
if ((orig = zend_hash_find_ptr(table, fname_zs)) == NULL) {
248-
zend_string_release(fname_zs);
252+
zend_string_release_ex(fname_zs, 0);
249253
return;
250254
}
251255

252256
if ((override = zend_hash_find_ptr(&SHADOW_G(replaced_function_table), fname_full)) == NULL) {
253-
zend_string_release(fname_zs);
257+
zend_string_release_ex(fname_zs, 0);
254258
return;
255259
}
256260

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

262-
zend_string_release(fname_full);
263-
zend_string_release(fname_zs);
266+
zend_string_release_ex(fname_full, 1);
267+
zend_string_release_ex(fname_zs, 0);
264268
}
265269

266270

@@ -321,7 +325,7 @@ PHP_MINIT_FUNCTION(shadow)
321325
int argno;
322326
int argtype;
323327
/* Save this for shutdown */
324-
shadow_override_copy = estrdup(SHADOW_G(override));
328+
SHADOW_G(shadow_override_copy) = estrdup(SHADOW_G(override));
325329
while(*over) {
326330
char *next = strchr(over, ',');
327331
if(!next) {
@@ -364,9 +368,9 @@ PHP_MINIT_FUNCTION(shadow)
364368
*/
365369
PHP_MSHUTDOWN_FUNCTION(shadow)
366370
{
367-
if (shadow_override_copy != NULL) {
371+
if (SHADOW_G(shadow_override_copy) != NULL) {
368372
/* Cleanup after our user-specified overrides. */
369-
char *over = shadow_override_copy;
373+
char *over = SHADOW_G(shadow_override_copy);
370374
size_t over_len;
371375
char c;
372376
int argno;
@@ -404,7 +408,7 @@ PHP_MSHUTDOWN_FUNCTION(shadow)
404408
break;
405409
}
406410
}
407-
efree(shadow_override_copy);
411+
efree(SHADOW_G(shadow_override_copy));
408412
}
409413
UNREGISTER_INI_ENTRIES();
410414
return SUCCESS;
@@ -417,13 +421,17 @@ PHP_MSHUTDOWN_FUNCTION(shadow)
417421
PHP_RINIT_FUNCTION(shadow)
418422
{
419423
if(SHADOW_G(enabled)) {
420-
php_unregister_url_stream_wrapper_volatile("file");
421-
php_register_url_stream_wrapper_volatile("file", &shadow_wrapper);
424+
zend_string *protocol;
425+
protocol = zend_string_init("file", strlen("file"), 0);
426+
php_unregister_url_stream_wrapper_volatile(protocol);
427+
php_register_url_stream_wrapper_volatile(protocol, &shadow_wrapper);
428+
zend_string_release_ex(protocol, 0);
422429
}
423430
SHADOW_G(template) = NULL;
424431
SHADOW_G(instance) = NULL;
425432
SHADOW_G(curdir) = NULL;
426433
SHADOW_G(segment_id) = 0;
434+
SHADOW_G(shadow_override_copy) = NULL;
427435
return SUCCESS;
428436
}
429437
/* }}} */
@@ -844,7 +852,7 @@ static void ensure_dir_exists(char *pathname, php_stream_wrapper *wrapper, php_s
844852
pathname[dir_len] = '/'; /* restore full path */
845853
}
846854

847-
zend_string *shadow_resolve_path(const char *filename, int filename_len)
855+
zend_string *shadow_resolve_path(const char *filename, size_t filename_len)
848856
{
849857
char *shadow_result = template_to_instance(filename, OPT_CHECK_EXISTS TSRMLS_CC);
850858
zend_string *result = NULL;
@@ -1175,7 +1183,7 @@ static int shadow_call_replace_name_ex(zval *name, char *repname, void (*orig_fu
11751183
Z_STR_P(name) = new_name;
11761184
orig_func(INTERNAL_FUNCTION_PARAM_PASSTHRU);
11771185
Z_STR_P(name) = old_name;
1178-
zend_string_release(new_name);
1186+
zend_string_release_ex(new_name, 1);
11791187
return SUCCESS;
11801188
}
11811189

@@ -1565,7 +1573,7 @@ static void shadow_generic_override(INTERNAL_FUNCTION_PARAMETERS)
15651573
}
15661574
shadow_function *func;
15671575
if ((func = zend_hash_find_ptr(&SHADOW_G(replaced_function_table), fname_full)) == NULL) {
1568-
zend_string_release(fname_full);
1576+
zend_string_release_ex(fname_full, 0);
15691577
return;
15701578
}
15711579
zval *name;
@@ -1574,20 +1582,20 @@ static void shadow_generic_override(INTERNAL_FUNCTION_PARAMETERS)
15741582

15751583
if(!SHADOW_ENABLED()) {
15761584
func->orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
1577-
zend_string_release(fname_full);
1585+
zend_string_release_ex(fname_full, 0);
15781586
return;
15791587
}
15801588

15811589
name = shadow_get_arg(func->argno TSRMLS_CC);
15821590
if (!name || Z_TYPE_P(name) != IS_STRING) {
15831591
func->orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
1584-
zend_string_release(fname_full);
1592+
zend_string_release_ex(fname_full, 0);
15851593
return;
15861594
}
15871595
/* not our path - don't mess with it */
15881596
if (!shadow_stream_check(Z_STRVAL_P(name))) {
15891597
func->orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
1590-
zend_string_release(fname_full);
1598+
zend_string_release_ex(fname_full, 0);
15911599
return;
15921600
}
15931601
/* try to translate */
@@ -1602,11 +1610,11 @@ static void shadow_generic_override(INTERNAL_FUNCTION_PARAMETERS)
16021610
/* we didn't find better name, use original */
16031611
if(!instname) {
16041612
func->orig_handler(INTERNAL_FUNCTION_PARAM_PASSTHRU);
1605-
zend_string_release(fname_full);
1613+
zend_string_release_ex(fname_full, 0);
16061614
return;
16071615
}
16081616
shadow_call_replace_name_ex(name, instname, func->orig_handler, INTERNAL_FUNCTION_PARAM_PASSTHRU);
1609-
zend_string_release(fname_full);
1617+
zend_string_release_ex(fname_full, 0);
16101618
}
16111619

16121620
/*

shadow_cache.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ void shadow_cache_set_id(zend_string *template, zend_string *instance TSRMLS_DC)
4545
} else {
4646
SHADOW_G(segment_id) = Z_LVAL_P(segment_zv);
4747
}
48-
zend_string_release(segname_zs);
48+
zend_string_release_ex(segname_zs, 1);
4949
efree(segname);
5050
}
5151

@@ -65,7 +65,7 @@ int shadow_cache_get(const char *name, char **entry TSRMLS_DC)
6565
namelen = shadow_cache_segmented_name(&segname, name TSRMLS_CC);
6666
zend_string *segname_zs = zend_string_init(segname, namelen, 0);
6767
if ((centry = zend_hash_find(&SHADOW_G(cache), segname_zs)) != NULL) {
68-
zend_string_release(segname_zs);
68+
zend_string_release_ex(segname_zs, 0);
6969
efree(segname);
7070
if(Z_STRLEN_P(centry) == 0){
7171
*entry = NULL;
@@ -75,7 +75,7 @@ int shadow_cache_get(const char *name, char **entry TSRMLS_DC)
7575
return SUCCESS;
7676
} else {
7777
*entry = NULL;
78-
zend_string_release(segname_zs);
78+
zend_string_release_ex(segname_zs, 0);
7979
efree(segname);
8080
return FAILURE;
8181
}
@@ -85,7 +85,6 @@ void shadow_cache_put(const char *name, const char *entry TSRMLS_DC)
8585
{
8686
char *segname;
8787
int namelen;
88-
zend_string * entry_zs;
8988
zval entry_zv;
9089
if(SHADOW_G(cache_size) == 0) {
9190
return;
@@ -96,11 +95,10 @@ void shadow_cache_put(const char *name, const char *entry TSRMLS_DC)
9695
}
9796
namelen = shadow_cache_segmented_name(&segname, name TSRMLS_CC);
9897
zend_string *segname_zs = zend_string_init(segname, namelen, 1);
99-
entry_zs = zend_string_init(entry, strlen(entry), 1);
100-
ZVAL_STR(&entry_zv, entry_zs);
98+
ZVAL_PSTRING(&entry_zv, entry);
10199
zend_hash_update(&SHADOW_G(cache), segname_zs, &entry_zv);
102100
efree(segname);
103-
zend_string_release(segname_zs);
101+
zend_string_release_ex(segname_zs, 1);
104102
}
105103

106104
void shadow_cache_remove(const char *name TSRMLS_DC)
File renamed without changes.

0 commit comments

Comments
 (0)