Skip to content

Commit

Permalink
Merge branch 'master' of git.php.net:php-src
Browse files Browse the repository at this point in the history
  • Loading branch information
faizshukri committed Jan 13, 2014
2 parents 73008bb + 5980e98 commit bbc37e7
Show file tree
Hide file tree
Showing 9 changed files with 121 additions and 35 deletions.
4 changes: 4 additions & 0 deletions ext/opcache/Optimizer/block_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -1909,7 +1909,9 @@ static void zend_t_usage(zend_code_block *block, zend_op_array *op_array, char *
if (RESULT_USED(opline)) {
if (!defined_here[VAR_NUM(ZEND_RESULT(opline).var)] && !used_ext[VAR_NUM(ZEND_RESULT(opline).var)] &&
(opline->opcode == ZEND_RECV || opline->opcode == ZEND_RECV_INIT ||
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
opline->opcode == ZEND_RECV_VARIADIC ||
#endif
(opline->opcode == ZEND_OP_DATA && ZEND_RESULT_TYPE(opline) == IS_TMP_VAR) ||
opline->opcode == ZEND_ADD_ARRAY_ELEMENT)) {
/* these opcodes use the result as argument */
Expand Down Expand Up @@ -1994,7 +1996,9 @@ static void zend_t_usage(zend_code_block *block, zend_op_array *op_array, char *

if (opline->opcode == ZEND_RECV ||
opline->opcode == ZEND_RECV_INIT ||
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
opline->opcode == ZEND_RECV_VARIADIC ||
#endif
opline->opcode == ZEND_ADD_ARRAY_ELEMENT) {
if (ZEND_OP1_TYPE(opline) == IS_VAR || ZEND_OP1_TYPE(opline) == IS_TMP_VAR) {
usage[VAR_NUM(ZEND_RESULT(opline).var)] = 1;
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/Optimizer/pass1_5.c
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ if (ZEND_OPTIMIZER_PASS_1 & OPTIMIZATION_LEVEL) {
zval t;

if (zend_get_persistent_constant(Z_STRVAL(ZEND_OP1_LITERAL(opline - 1)),
Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)), &t, 0 TSRMLS_CC)) {
Z_STRLEN(ZEND_OP1_LITERAL(opline - 1)), &t, 1 TSRMLS_CC)) {
if (replace_var_by_const(op_array, opline + 1, ZEND_RESULT(opline).var, &t TSRMLS_CC)) {
literal_dtor(&ZEND_OP1_LITERAL(opline - 1));
MAKE_NOP((opline - 1));
Expand Down
76 changes: 44 additions & 32 deletions ext/opcache/ZendAccelerator.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@
#include "main/php_open_temporary_file.h"
#include "zend_API.h"
#include "zend_ini.h"
#include "zend_virtual_cwd.h"
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
# include "zend_virtual_cwd.h"
#else
# include "TSRM/tsrm_virtual_cwd.h"
#endif
#include "zend_accelerator_util_funcs.h"
#include "zend_accelerator_hash.h"

Expand Down Expand Up @@ -387,8 +391,10 @@ static void accel_use_shm_interned_strings(TSRMLS_D)
{
Bucket *p, *q;

#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
/* empty string */
CG(interned_empty_string) = accel_new_interned_string("", sizeof(""), 0 TSRMLS_CC);
#endif

/* function table hash keys */
p = CG(function_table)->pListHead;
Expand Down Expand Up @@ -2135,7 +2141,9 @@ static void accel_activate(void)
}

#if (ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO) && !defined(ZTS)
accel_interned_strings_restore_state(TSRMLS_C);
if (ZCG(accel_directives).interned_strings_buffer) {
accel_interned_strings_restore_state(TSRMLS_C);
}
#endif

zend_shared_alloc_restore_state();
Expand Down Expand Up @@ -2453,36 +2461,39 @@ static int zend_accel_init_shm(TSRMLS_D)

#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO

ZCSG(interned_strings_start) = ZCSG(interned_strings_end) = NULL;
# ifndef ZTS
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);
ZCSG(interned_strings).nTableMask = ZCSG(interned_strings).nTableSize - 1;
ZCSG(interned_strings).arBuckets = zend_shared_alloc(ZCSG(interned_strings).nTableSize * sizeof(Bucket *));
ZCSG(interned_strings_start) = zend_shared_alloc((ZCG(accel_directives).interned_strings_buffer * 1024 * 1024));
if (!ZCSG(interned_strings).arBuckets || !ZCSG(interned_strings_start)) {
zend_accel_error(ACCEL_LOG_FATAL, ACCELERATOR_PRODUCT_NAME " cannot allocate buffer for interned strings");
return FAILURE;
if (ZCG(accel_directives).interned_strings_buffer) {
ZCSG(interned_strings).nTableMask = ZCSG(interned_strings).nTableSize - 1;
ZCSG(interned_strings).arBuckets = zend_shared_alloc(ZCSG(interned_strings).nTableSize * sizeof(Bucket *));
ZCSG(interned_strings_start) = zend_shared_alloc((ZCG(accel_directives).interned_strings_buffer * 1024 * 1024));
if (!ZCSG(interned_strings).arBuckets || !ZCSG(interned_strings_start)) {
zend_accel_error(ACCEL_LOG_FATAL, ACCELERATOR_PRODUCT_NAME " cannot allocate buffer for interned strings");
return FAILURE;
}
ZCSG(interned_strings_end) = ZCSG(interned_strings_start) + (ZCG(accel_directives).interned_strings_buffer * 1024 * 1024);
ZCSG(interned_strings_top) = ZCSG(interned_strings_start);

orig_interned_strings_start = CG(interned_strings_start);
orig_interned_strings_end = CG(interned_strings_end);
CG(interned_strings_start) = ZCSG(interned_strings_start);
CG(interned_strings_end) = ZCSG(interned_strings_end);
}
ZCSG(interned_strings_end) = ZCSG(interned_strings_start) + (ZCG(accel_directives).interned_strings_buffer * 1024 * 1024);
ZCSG(interned_strings_top) = ZCSG(interned_strings_start);
# else
ZCSG(interned_strings_start) = ZCSG(interned_strings_end) = NULL;
# endif

orig_interned_strings_start = CG(interned_strings_start);
orig_interned_strings_end = CG(interned_strings_end);
orig_new_interned_string = zend_new_interned_string;
orig_interned_strings_snapshot = zend_interned_strings_snapshot;
orig_interned_strings_restore = zend_interned_strings_restore;

CG(interned_strings_start) = ZCSG(interned_strings_start);
CG(interned_strings_end) = ZCSG(interned_strings_end);
zend_new_interned_string = accel_new_interned_string_for_php;
zend_interned_strings_snapshot = accel_interned_strings_snapshot_for_php;
zend_interned_strings_restore = accel_interned_strings_restore_for_php;

# ifndef ZTS
accel_use_shm_interned_strings(TSRMLS_C);
accel_interned_strings_save_state(TSRMLS_C);
if (ZCG(accel_directives).interned_strings_buffer) {
accel_use_shm_interned_strings(TSRMLS_C);
accel_interned_strings_save_state(TSRMLS_C);
}
# endif

#endif
Expand Down Expand Up @@ -2711,27 +2722,28 @@ void accel_shutdown(TSRMLS_D)
return;
}

accel_free_ts_resources();
zend_shared_alloc_shutdown();
zend_compile_file = accelerator_orig_compile_file;

if (zend_hash_find(EG(ini_directives), "include_path", sizeof("include_path"), (void **) &ini_entry) == SUCCESS) {
ini_entry->on_modify = orig_include_path_on_modify;
}

#if ZEND_EXTENSION_API_NO > PHP_5_3_X_API_NO
if (ZCG(accel_directives).interned_strings_buffer) {
# ifndef ZTS
zend_hash_clean(CG(function_table));
zend_hash_clean(CG(class_table));
zend_hash_clean(EG(zend_constants));
zend_hash_clean(CG(function_table));
zend_hash_clean(CG(class_table));
zend_hash_clean(EG(zend_constants));
# endif
CG(interned_strings_start) = orig_interned_strings_start;
CG(interned_strings_end) = orig_interned_strings_end;
CG(interned_strings_start) = orig_interned_strings_start;
CG(interned_strings_end) = orig_interned_strings_end;
}
zend_new_interned_string = orig_new_interned_string;
zend_interned_strings_snapshot = orig_interned_strings_snapshot;
zend_interned_strings_restore = orig_interned_strings_restore;
#endif

accel_free_ts_resources();
zend_shared_alloc_shutdown();
zend_compile_file = accelerator_orig_compile_file;

if (zend_hash_find(EG(ini_directives), "include_path", sizeof("include_path"), (void **) &ini_entry) == SUCCESS) {
ini_entry->on_modify = orig_include_path_on_modify;
}
}

void zend_accel_schedule_restart(zend_accel_restart_reason reason TSRMLS_DC)
Expand Down
2 changes: 1 addition & 1 deletion ext/opcache/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ AC_TRY_RUN([
if test "$flock_type" == "unknown"; then
AC_MSG_ERROR([Don't know how to define struct flock on this system[,] set --enable-opcache=no])
fi

PHP_NEW_EXTENSION(opcache,
ZendAccelerator.c \
zend_accelerator_blacklist.c \
Expand Down
34 changes: 34 additions & 0 deletions ext/opcache/tests/blacklist-win32.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
Blacklist (with glob, quote and comments)
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.blacklist_filename={PWD}/opcache-*.blacklist
opcache.file_update_protection=0
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php if (substr(PHP_OS, 0, 3) != 'WIN') { die('skip only for Windows'); } ?>
--FILE--
<?php
$conf = opcache_get_configuration();
$conf = $conf['blacklist'];
$conf[3] = preg_replace("!^\\Q".dirname(__FILE__)."\\E!", "__DIR__", $conf[3]);
$conf[4] = preg_replace("!^\\Q".dirname(__FILE__)."\\E!", "__DIR__", $conf[4]);
print_r($conf);
include("blacklist.inc");
$status = opcache_get_status();
print_r(count($status['scripts']));
?>
--EXPECTF--
Array
(
[0] => C:\path\to\foo
[1] => C:\path\to\foo2
[2] => C:\path\to\bar
[3] => __DIR__\blacklist.inc
[4] => __DIR__\current.php
[5] => %scurrent.php
[6] => %scurrent.php
)
ok
1
1 change: 1 addition & 0 deletions ext/opcache/tests/blacklist.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ opcache.blacklist_filename={PWD}/opcache-*.blacklist
opcache.file_update_protection=0
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php if (substr(PHP_OS, 0, 3) == 'WIN') { die('skip not for Windows'); } ?>
--FILE--
<?php
$conf = opcache_get_configuration();
Expand Down
16 changes: 16 additions & 0 deletions ext/opcache/tests/bug66440.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
Bug #66440 (Optimisation of conditional JMPs based on pre-evaluate constant function calls)
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
opcache.file_update_protection=0
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
if(constant('PHP_BINARY')) {
echo "OK\n";
}
--EXPECT--
OK
15 changes: 15 additions & 0 deletions ext/opcache/tests/bug66461.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--TEST--
Bug #66461 (PHP crashes if opcache.interned_strings_buffer=0)
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
opcache.file_update_protection=0
opcache.interned_strings_buffer=0
--SKIPIF--
<?php require_once('skipif.inc'); ?>
--FILE--
<?php
echo "ok\n";
--EXPECT--
ok
6 changes: 5 additions & 1 deletion ext/opcache/zend_accelerator_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@
#include "zend_accelerator_blacklist.h"
#include "php_ini.h"
#include "SAPI.h"
#include "zend_virtual_cwd.h"
#if ZEND_EXTENSION_API_NO > PHP_5_5_X_API_NO
# include "zend_virtual_cwd.h"
#else
# include "TSRM/tsrm_virtual_cwd.h"
#endif
#include "ext/standard/info.h"
#include "ext/standard/php_filestat.h"

Expand Down

0 comments on commit bbc37e7

Please sign in to comment.