Browse Source

merge changes from trunk

git-svn-id: svn://svn.lighttpd.net/xcache/branches/1.3@766 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
1.3
Xuefer 11 years ago
parent
commit
e02b80790e
  1. 2
      ChangeLog
  2. 683
      Decompiler.class.php
  3. 2
      NEWS
  4. 305
      decompilesample.php
  5. 30
      disassembler.c
  6. 12
      phpdop.phpr
  7. 2
      processor/struct.m4
  8. 6
      utils.c
  9. 4
      xcache.c

2
ChangeLog

@ -1,5 +1,7 @@
1.3.2 2011-??-??
========
* adds 30 seconds timeout to "compiling" flag
* decompiler: improves decompiling
* disassembler: DECLARE_INHERITED_CLASS/DELAYED class not found
* disassembler: don't dump builtin functions
* fix win32 build against win32 native gnu tools

683
Decompiler.class.php

File diff suppressed because it is too large

2
NEWS

@ -1,5 +1,7 @@
1.3.2 2011-??-??
========
* adds 30 seconds timeout to "compiling" flag
* improves decompiling
* memory leak on recompile
* disassembler fixes and updates for new PHP
* win32 build fix

305
decompilesample.php

@ -1,7 +1,13 @@
<?php
class ClassName
//* >= PHP 5.3
namespace ns;
// */
abstract class ClassName
{
const CONST_VALUE = 'A constant value';
/** doc */
static public $static = array(
array('array'),
@ -28,8 +34,24 @@ class ClassName
/** doc */
public function __construct($a, $b)
{
echo CONST_VALUE;
echo ClassName::CONST_VALUE;
unset(ClassName::$classProp);
unset($obj->objProp);
unset($this->thisProp);
unset($array['index']->valueProp);
unset($obj->array['index']);
unset($this->array['index']);
$obj->objProp = 1;
$this->thisProp = 1;
$array['index']->valueProp = 1;
$array['index'] = 1;
$array[1] = 1;
}
/** doc */
abstract public function abastractMethod();
/** doc */
public function method(array $a = NULL, $b = NULL)
{
@ -64,5 +86,286 @@ class ClassName
}
}
interface IInterface
{
public function nothing();
}
function f1($f)
{
echo __FUNCTION__;
echo $f;
}
final class Child extends ClassName implements IInterface
{
public function __construct()
{
parent::__construct();
ClassName::__construct();
echo __CLASS__;
echo __METHOD__;
throw new Exception();
$this->methodCall();
}
public function __destruct()
{
parent::__destruct();
functionCall();
}
static public function __callStatic($name, $args)
{
}
public function __toString()
{
}
public function __set($name, $value)
{
}
public function __get($name)
{
}
public function __isset($name)
{
}
public function __unset($name)
{
}
public function __sleep()
{
}
public function __wakeup()
{
}
public function __clone()
{
return array();
}
}
if ($late) {
class LateBindingClass
{}
function lateBindingFunction($arg)
{
echo 'lateFunction';
}
}
echo "\r\n";
echo "\r";
echo "\n";
echo str_replace(array('a' => 'a', 'b' => 'c'), 'b');
$object = new ClassName();
$object = new $className();
$result = $object instanceof ClassName;
$cloned = clone $object;
$a = 1;
$a = $b + $c;
$a = $b + 1;
$a = 1 + $b;
$a = $b - $c;
$a = $b * $c;
$a = $b / $c;
$a = $b % $c;
$a = $b . $c;
$a = $b = $c;
$a = $b & $c;
$a = $b | $c;
$a = $b ^ $c;
$a = ~$b;
$a = -$b;
$a = +$b;
$a = $b >> $c;
$a = $b >> $c;
$a = $b == $c;
$a = $b === $c;
$a = $b != $c;
$a = $b < $c;
$a = $b <= $c;
$a = $b <= $c;
$a = $b++;
$a = ++$b;
$a = $obj->b++;
$a = ++$obj->b;
$a = $b--;
$a = --$b;
$a = $obj->b--;
$a = --$obj->b;
$a = $b xor $c;
$a = !$b;
$a = $b === $c;
$a = $b !== $c;
$a = $b << 2;
$a = $b >> 3;
$a += $b;
$a -= $b;
$a *= $b;
$a /= $b;
$a <<= $b;
$a >>= $b;
$a &= $b;
$a |= $b;
$a .= $b;
$a %= $b;
$a ^= $b;
$a = 'a' . 'b';
$a = 'a' . 'abc';
@f1();
print('1');
ref(&$a);
$a = $array['index'];
$a = $object->prop;
$a = $this->prop;
$array['index'] = 1;
$object->prop = 1;
$this->prop = 1;
$a = isset($b);
$a = empty($b);
$a = isset($array['index']);
$a = empty($array['index']);
$a = isset($object->prop);
$a = empty($object->prop);
$a = isset($this->prop);
$a = empty($this->prop);
$a = (int) $b;
$a = (double) $b;
$a = (string) $b;
$a = (array) $b;
$a = (object) $b;
$a = (bool) $b;
$a = (unset) $b;
$a = (array) $b;
$a = (object) $b;
// PHP6+ $a = (scalar) $b;
$a = $b ? $c : $d;
$a = f1() ? f2() : f3();
$a = $b and $c;
$a = $b or $c;
$a = $b && $c;
$a = $b || $c;
try {
echo 'outer try 1';
try {
echo 'inner try';
}
catch (InnerException $e) {
echo $e;
}
echo 'outer try 2';
}
catch (OuterException $e) {
echo $e;
}
if ($a) {
echo 'if ($a)';
}
else if ($b) {
echo 'else if ($b)';
}
else {
echo 'else';
}
while (false) {
echo 'while';
}
do {
echo 'do/while';
} while (false);
for ($i = 1; $i < 10; ++$i) {
echo $i;
break;
}
foreach ($array as $key => $value) {
foreach ($array as $key => $value) {
echo $key . ' = ' . $value . "\n";
break 2;
continue;
}
}
switch ($switch) {
case 'case1':
echo 'case1';
break;
case 'case2':
echo 'case2';
break;
default:
echo 'default';
break;
}
declare (ticks=1) {
echo 1;
echo 2;
}
require 'require.php';
require_once 'require_once.php';
include 'include.php';
include_once 'include_once.php';
echo __FILE__;
echo __LINE__;
//*
echo 'PHP 5.3+ code testing';
const CONST_VALUE = 1;
echo $this::CONST_VALUE;
echo $a::CONST_VALUE;
echo CONST_VALUE;
$this::__construct();
$obj::__construct();
$a = $b ?: $d;
$a = ($b ?: $d) + $c;
$a = f1() ?: f2();
echo 'goto a';
goto a;
for ($i = 1; $i <= 2; ++$i) {
goto a;
}
a:
echo 'label a';
echo preg_replace_callback('~-([a-z])~', function ($match) {
return strtoupper($match[1]);
}, 'hello-world');
$greet = function ($name) {
printf("Hello %s\r\n", $name);
};
$greet('World');
$greet('PHP');
$total = 0;
$tax = 1;
$callback = function ($quantity, $product) use ($tax, &$total) {
static $static = array(1);
$tax = 'tax';
$pricePerItem = constant('PRICE_' . strtoupper($product));
$total += $pricePerItem * $quantity * ($tax + 1);
};
// */
exit();
?>

30
disassembler.c

@ -36,19 +36,45 @@ static void xc_dasm(xc_sandbox_t *sandbox, zval *dst, zend_op_array *op_array TS
xc_dasm_zend_op_array(zv, op_array TSRMLS_CC);
add_assoc_zval_ex(dst, ZEND_STRS("op_array"), zv);
buf = emalloc(bufsize);
ALLOC_INIT_ZVAL(list);
array_init(list);
b = TG(internal_function_tail) ? TG(internal_function_tail)->pListNext : TG(function_table).pListHead;
for (; b; b = b->pListNext) {
int keysize, keyLength;
ALLOC_INIT_ZVAL(zv);
array_init(zv);
xc_dasm_zend_function(zv, b->pData TSRMLS_CC);
add_u_assoc_zval_ex(list, BUCKET_KEY_TYPE(b), ZSTR(BUCKET_KEY_S(b)), b->nKeyLength, zv);
keysize = BUCKET_KEY_SIZE(b) + 2;
if (keysize > bufsize) {
do {
bufsize *= 2;
} while (keysize > bufsize);
buf = erealloc(buf, bufsize);
}
memcpy(buf, BUCKET_KEY_S(b), keysize);
buf[keysize - 2] = buf[keysize - 1] = ""[0];
keyLength = b->nKeyLength;
#ifdef IS_UNICODE
if (BUCKET_KEY_TYPE(b) == IS_UNICODE) {
if (buf[0] == ""[0] && buf[1] == ""[0]) {
keyLength ++;
}
} else
#endif
{
if (buf[0] == ""[0]) {
keyLength ++;
}
}
add_u_assoc_zval_ex(list, BUCKET_KEY_TYPE(b), ZSTR(buf), keyLength, zv);
}
add_assoc_zval_ex(dst, ZEND_STRS("function_table"), list);
buf = emalloc(bufsize);
ALLOC_INIT_ZVAL(list);
array_init(list);
b = TG(internal_class_tail) ? TG(internal_class_tail)->pListNext : TG(class_table).pListHead;

12
phpdop.phpr

@ -109,17 +109,17 @@ if (isset($pk['class_table'])) {
unset($pk['class_table']);
}
var_dump($pk);
if (isset($op_array)) {
dump_opcodes($op_array['opcodes']);
if (isset($classes)) {
foreach ($classes as $name => $class) {
dump_class($name, $class);
}
}
if (isset($funcs)) {
foreach ($funcs as $name => $func) {
dump_function($name, $func);
}
}
if (isset($classes)) {
foreach ($classes as $name => $class) {
dump_class($name, $class);
}
if (isset($op_array)) {
dump_opcodes($op_array['opcodes']);
}

2
processor/struct.m4

@ -32,7 +32,7 @@ DECL_STRUCT_P_FUNC(`$1', `$2', 1)
IFASSERT(`
/* {{{ init assert */
ifdef(`SIZEOF_$1', , `m4_errprint(`missing SIZEOF_$1, safe to ignore')')
ifdef(`COUNTOF_$1', , `m4_errprint(`missing COUNTOF_$1, safe to ignore'))')
ifdef(`COUNTOF_$1', , `m4_errprint(`missing COUNTOF_$1, safe to ignore')')
dnl SIZEOF_x COUNTOF_x can be both defined or both not
ifdef(`SIZEOF_$1', `
ifdef(`COUNTOF_$1', , `m4_errprint(`AUTOCHECK WARN: missing COUNTOF_$1')')

6
utils.c

@ -244,6 +244,12 @@ static void xc_fix_opcode_ex_znode(int tofix, xc_op_spec_t spec, zend_uchar *op_
case IS_TMP_VAR:
break;
case IS_CONST:
if (spec == OPSPEC_UCLASS) {
break;
}
/* fall */
default:
/* TODO: data lost, find a way to keep it */
/* assert(*op_type == IS_CONST); */

4
xcache.c

@ -1000,7 +1000,7 @@ static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /
/* }}} */
/* {{{ restore */
/* stale precheck */
if (cache->compiling) {
if (XG(request_time) - cache->compiling < 30) {
cache->clogs ++; /* is it safe here? */
return old_compile_file(h, type TSRMLS_CC);
}
@ -1009,7 +1009,7 @@ static zend_op_array *xc_compile_file(zend_file_handle *h, int type TSRMLS_DC) /
op_array = NULL;
ENTER_LOCK_EX(cache) {
/* clogged */
if (cache->compiling) {
if (XG(request_time) - cache->compiling < 30) {
cache->clogs ++;
op_array = NULL;
clogged = 1;

Loading…
Cancel
Save