Skip to content

Commit bbc37e7

Browse files
committed
Merge branch 'master' of git.php.net:php-src
2 parents 73008bb + 5980e98 commit bbc37e7

9 files changed

+121
-35
lines changed

ext/opcache/Optimizer/block_pass.c

+4
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,9 @@ static void zend_t_usage(zend_code_block *block, zend_op_array *op_array, char *
19091909
if (RESULT_USED(opline)) {
19101910
if (!defined_here[VAR_NUM(ZEND_RESULT(opline).var)] && !used_ext[VAR_NUM(ZEND_RESULT(opline).var)] &&
19111911
(opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT ||
1912+
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
19121913
opline->opcode == ZEND_RECV_VARIADIC ||
1914+
#endif
19131915
(opline->opcode == ZEND_OP_DATA && ZEND_RESULT_TYPE(opline) == IS_TMP_VAR) ||
19141916
opline->opcode == ZEND_ADD_ARRAY_ELEMENT)) {
19151917
/* these opcodes use the result as argument */
@@ -1994,7 +1996,9 @@ static void zend_t_usage(zend_code_block *block, zend_op_array *op_array, char *
19941996

19951997
if (opline->opcode == ZEND_RECV ||
19961998
opline->opcode == ZEND_RECV_INIT ||
1999+
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
19972000
opline->opcode == ZEND_RECV_VARIADIC ||
2001+
#endif
19982002
opline->opcode == ZEND_ADD_ARRAY_ELEMENT) {
19992003
if (ZEND_OP1_TYPE(opline) == IS_VAR || ZEND_OP1_TYPE(opline) == IS_TMP_VAR) {
20002004
usage[VAR_NUM(ZEND_RESULT(opline).var)] = 1;

ext/opcache/Optimizer/pass1_5.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
433433
zval t;
434434

435435
if (zend_get_persistent_constant(Z_STRVAL(ZEND_OP1_LITERAL(opline - 1)),
436-
Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)), &t, 0 TSRMLS_CC)) {
436+
Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)), &t, 1 TSRMLS_CC)) {
437437
if (replace_var_by_const(op_array, opline + 1, ZEND_RESULT(opline).var, &t TSRMLS_CC)) {
438438
literal_dtor(&ZEND_OP1_LITERAL(opline - 1));
439439
MAKE_NOP((opline - 1));

ext/opcache/ZendAccelerator.c

+44-32
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,11 @@
3636
#include "main/php_open_temporary_file.h"
3737
#include "zend_API.h"
3838
#include "zend_ini.h"
39-
#include "zend_virtual_cwd.h"
39+
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
40+
# include "zend_virtual_cwd.h"
41+
#else
42+
# include "TSRM/tsrm_virtual_cwd.h"
43+
#endif
4044
#include "zend_accelerator_util_funcs.h"
4145
#include "zend_accelerator_hash.h"
4246

@@ -387,8 +391,10 @@ static void accel_use_shm_interned_strings(TSRMLS_D)
387391
{
388392
Bucket *p, *q;
389393

394+
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
390395
/* empty string */
391396
CG(interned_empty_string) = accel_new_interned_string("", sizeof(""), 0 TSRMLS_CC);
397+
#endif
392398

393399
/* function table hash keys */
394400
p = CG(function_table)->pListHead;
@@ -2135,7 +2141,9 @@ static void accel_activate(void)
21352141
}
21362142

21372143
#if (ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO) && !defined(ZTS)
2138-
accel_interned_strings_restore_state(TSRMLS_C);
2144+
if (ZCG(accel_directives).interned_strings_buffer) {
2145+
accel_interned_strings_restore_state(TSRMLS_C);
2146+
}
21392147
#endif
21402148

21412149
zend_shared_alloc_restore_state();
@@ -2453,36 +2461,39 @@ static int zend_accel_init_shm(TSRMLS_D)
24532461

24542462
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
24552463

2464+
ZCSG(interned_strings_start) = ZCSG(interned_strings_end) = NULL;
24562465
# ifndef ZTS
24572466
zend_hash_init(&ZCSG(interned_strings), (ZCG(accel_directives).interned_strings_buffer * 1024 * 1024) / (sizeof(Bucket) + sizeof(Bucket*) + 8 /* average string length */), NULL, NULL, 1);
2458-
ZCSG(interned_strings).nTableMask = ZCSG(interned_strings).nTableSize - 1;
2459-
ZCSG(interned_strings).arBuckets = zend_shared_alloc(ZCSG(interned_strings).nTableSize * sizeof(Bucket *));
2460-
ZCSG(interned_strings_start) = zend_shared_alloc((ZCG(accel_directives).interned_strings_buffer * 1024 * 1024));
2461-
if (!ZCSG(interned_strings).arBuckets || !ZCSG(interned_strings_start)) {
2462-
zend_accel_error(ACCEL_LOG_FATAL, ACCELERATOR_PRODUCT_NAME " cannot allocate buffer for interned strings");
2463-
return FAILURE;
2467+
if (ZCG(accel_directives).interned_strings_buffer) {
2468+
ZCSG(interned_strings).nTableMask = ZCSG(interned_strings).nTableSize - 1;
2469+
ZCSG(interned_strings).arBuckets = zend_shared_alloc(ZCSG(interned_strings).nTableSize * sizeof(Bucket *));
2470+
ZCSG(interned_strings_start) = zend_shared_alloc((ZCG(accel_directives).interned_strings_buffer * 1024 * 1024));
2471+
if (!ZCSG(interned_strings).arBuckets || !ZCSG(interned_strings_start)) {
2472+
zend_accel_error(ACCEL_LOG_FATAL, ACCELERATOR_PRODUCT_NAME " cannot allocate buffer for interned strings");
2473+
return FAILURE;
2474+
}
2475+
ZCSG(interned_strings_end) = ZCSG(interned_strings_start) + (ZCG(accel_directives).interned_strings_buffer * 1024 * 1024);
2476+
ZCSG(interned_strings_top) = ZCSG(interned_strings_start);
2477+
2478+
orig_interned_strings_start = CG(interned_strings_start);
2479+
orig_interned_strings_end = CG(interned_strings_end);
2480+
CG(interned_strings_start) = ZCSG(interned_strings_start);
2481+
CG(interned_strings_end) = ZCSG(interned_strings_end);
24642482
}
2465-
ZCSG(interned_strings_end) = ZCSG(interned_strings_start) + (ZCG(accel_directives).interned_strings_buffer * 1024 * 1024);
2466-
ZCSG(interned_strings_top) = ZCSG(interned_strings_start);
2467-
# else
2468-
ZCSG(interned_strings_start) = ZCSG(interned_strings_end) = NULL;
24692483
# endif
24702484

2471-
orig_interned_strings_start = CG(interned_strings_start);
2472-
orig_interned_strings_end = CG(interned_strings_end);
24732485
orig_new_interned_string = zend_new_interned_string;
24742486
orig_interned_strings_snapshot = zend_interned_strings_snapshot;
24752487
orig_interned_strings_restore = zend_interned_strings_restore;
2476-
2477-
CG(interned_strings_start) = ZCSG(interned_strings_start);
2478-
CG(interned_strings_end) = ZCSG(interned_strings_end);
24792488
zend_new_interned_string = accel_new_interned_string_for_php;
24802489
zend_interned_strings_snapshot = accel_interned_strings_snapshot_for_php;
24812490
zend_interned_strings_restore = accel_interned_strings_restore_for_php;
24822491

24832492
# ifndef ZTS
2484-
accel_use_shm_interned_strings(TSRMLS_C);
2485-
accel_interned_strings_save_state(TSRMLS_C);
2493+
if (ZCG(accel_directives).interned_strings_buffer) {
2494+
accel_use_shm_interned_strings(TSRMLS_C);
2495+
accel_interned_strings_save_state(TSRMLS_C);
2496+
}
24862497
# endif
24872498

24882499
#endif
@@ -2711,27 +2722,28 @@ void accel_shutdown(TSRMLS_D)
27112722
return;
27122723
}
27132724

2714-
accel_free_ts_resources();
2715-
zend_shared_alloc_shutdown();
2716-
zend_compile_file = accelerator_orig_compile_file;
2717-
2718-
if (zend_hash_find(EG(ini_directives), "include_path", sizeof("include_path"), (void **) &ini_entry) == SUCCESS) {
2719-
ini_entry->on_modify = orig_include_path_on_modify;
2720-
}
2721-
27222725
#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
2726+
if (ZCG(accel_directives).interned_strings_buffer) {
27232727
# ifndef ZTS
2724-
zend_hash_clean(CG(function_table));
2725-
zend_hash_clean(CG(class_table));
2726-
zend_hash_clean(EG(zend_constants));
2728+
zend_hash_clean(CG(function_table));
2729+
zend_hash_clean(CG(class_table));
2730+
zend_hash_clean(EG(zend_constants));
27272731
# endif
2728-
CG(interned_strings_start) = orig_interned_strings_start;
2729-
CG(interned_strings_end) = orig_interned_strings_end;
2732+
CG(interned_strings_start) = orig_interned_strings_start;
2733+
CG(interned_strings_end) = orig_interned_strings_end;
2734+
}
27302735
zend_new_interned_string = orig_new_interned_string;
27312736
zend_interned_strings_snapshot = orig_interned_strings_snapshot;
27322737
zend_interned_strings_restore = orig_interned_strings_restore;
27332738
#endif
27342739

2740+
accel_free_ts_resources();
2741+
zend_shared_alloc_shutdown();
2742+
zend_compile_file = accelerator_orig_compile_file;
2743+
2744+
if (zend_hash_find(EG(ini_directives), "include_path", sizeof("include_path"), (void **) &ini_entry) == SUCCESS) {
2745+
ini_entry->on_modify = orig_include_path_on_modify;
2746+
}
27352747
}
27362748

27372749
void zend_accel_schedule_restart(zend_accel_restart_reason reason TSRMLS_DC)

ext/opcache/config.m4

+1-1
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ AC_TRY_RUN([
362362
if test "$flock_type" == "unknown"; then
363363
AC_MSG_ERROR([Don't know how to define struct flock on this system[,] set --enable-opcache=no])
364364
fi
365-
365+
366366
PHP_NEW_EXTENSION(opcache,
367367
ZendAccelerator.c \
368368
zend_accelerator_blacklist.c \
+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
Blacklist (with glob, quote and comments)
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.blacklist_filename={PWD}/opcache-*.blacklist
7+
opcache.file_update_protection=0
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
<?php if (substr(PHP_OS, 0, 3) != 'WIN') { die('skip only for Windows'); } ?>
11+
--FILE--
12+
<?php
13+
$conf = opcache_get_configuration();
14+
$conf = $conf['blacklist'];
15+
$conf[3] = preg_replace("!^\\Q".dirname(__FILE__)."\\E!", "__DIR__", $conf[3]);
16+
$conf[4] = preg_replace("!^\\Q".dirname(__FILE__)."\\E!", "__DIR__", $conf[4]);
17+
print_r($conf);
18+
include("blacklist.inc");
19+
$status = opcache_get_status();
20+
print_r(count($status['scripts']));
21+
?>
22+
--EXPECTF--
23+
Array
24+
(
25+
[0] => C:\path\to\foo
26+
[1] => C:\path\to\foo2
27+
[2] => C:\path\to\bar
28+
[3] => __DIR__\blacklist.inc
29+
[4] => __DIR__\current.php
30+
[5] => %scurrent.php
31+
[6] => %scurrent.php
32+
)
33+
ok
34+
1

ext/opcache/tests/blacklist.phpt

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ opcache.blacklist_filename={PWD}/opcache-*.blacklist
77
opcache.file_update_protection=0
88
--SKIPIF--
99
<?php require_once('skipif.inc'); ?>
10+
<?php if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip not for Windows'); } ?>
1011
--FILE--
1112
<?php
1213
$conf = opcache_get_configuration();

ext/opcache/tests/bug66440.phpt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Bug #66440 (Optimisation of conditional JMPs based on pre-evaluate constant function calls)
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.file_update_protection=0
8+
--SKIPIF--
9+
<?php require_once('skipif.inc'); ?>
10+
--FILE--
11+
<?php
12+
if(constant('PHP_BINARY')) {
13+
echo "OK\n";
14+
}
15+
--EXPECT--
16+
OK

ext/opcache/tests/bug66461.phpt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--TEST--
2+
Bug #66461 (PHP crashes if opcache.interned_strings_buffer=0)
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.file_update_protection=0
8+
opcache.interned_strings_buffer=0
9+
--SKIPIF--
10+
<?php require_once('skipif.inc'); ?>
11+
--FILE--
12+
<?php
13+
echo "ok\n";
14+
--EXPECT--
15+
ok

ext/opcache/zend_accelerator_module.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@
2828
#include "zend_accelerator_blacklist.h"
2929
#include "php_ini.h"
3030
#include "SAPI.h"
31-
#include "zend_virtual_cwd.h"
31+
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
32+
# include "zend_virtual_cwd.h"
33+
#else
34+
# include "TSRM/tsrm_virtual_cwd.h"
35+
#endif
3236
#include "ext/standard/info.h"
3337
#include "ext/standard/php_filestat.h"
3438

0 commit comments

Comments
 (0)