diff -ur E:\source\c\bcompiler_orig/bcompiler.c E:\source\c\bcompiler_fixed/bcompiler.c --- E:\source\c\bcompiler_orig/bcompiler.c 2008-05-02 10:31:58.655340900 +0200 +++ E:\source\c\bcompiler_fixed/bcompiler.c 2008-06-05 14:18:46.631997400 +0200 @@ -43,6 +43,9 @@ #define ZEND_ENGINE_2_2 #endif +#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 2) || PHP_MAJOR_VERSION >= 6 +#define ZEND_ENGINE_2_3 +#endif #include "php_bcompiler.h" @@ -76,7 +79,10 @@ /* Bytecode version parameters */ #if PHP_MAJOR_VERSION >= 6 -#define BCOMPILER_CUR_VER 0x0013 /* current bytecode version: 0.19 */ +#define BCOMPILER_CUR_VER 0x0014 /* current bytecode version: 0.20 */ +#define BCOMPILER_CAN_READ 10, 15, 19 /* can read bytecodes: 0.10, 0.15, 0.19, 0.20 */ +#elif defined(ZEND_ENGINE_2_3) +#define BCOMPILER_CUR_VER 0x0013 /* current bytecode version 0.19 */ #define BCOMPILER_CAN_READ 10, 15, 19 /* can read bytecodes: 0.10, 0.15, 0.19 */ #elif defined(ZEND_ENGINE_2_1) #define BCOMPILER_CUR_VER 0x0012 /* current bytecode version: 0.18 */ @@ -437,7 +443,12 @@ file_handle->opened_path = estrdup(file_handle->filename); /* read bytecodes */ BCOMPILERG(current_include) = 1; + /* daniel: added currentfile to set the real filename/path when running a compiled script */ + BCOMPILERG(currentfile) = (char *) emalloc(strlen(file_handle->filename)); + BCOMPILERG(currentfile) = estrdup(file_handle->filename); op_array = bcompiler_read(TSRMLS_C); + BCOMPILERG(currentfile) = NULL; + efree(BCOMPILERG(currentfile)); if (!op_array) op_array = dummy_op_array(TSRMLS_C); #if 0 /* val: buffer allocation changed, so it can't be used anymore */ BCOMPILERG(buffer) = (char *) emalloc(1); /* avoid 1 byte memory leak */ @@ -1435,6 +1446,11 @@ char *key = NULL; int key_len; + /* daniel: This may should be done only if needed when restoring op_array */ + zend_is_auto_global("_SERVER", sizeof("_SERVER")-1 TSRMLS_CC); + zend_is_auto_global("_REQUEST", sizeof("_REQUEST")-1 TSRMLS_CC); + zend_is_auto_global("_ENV", sizeof("_ENV")-1 TSRMLS_CC); + BCOMPILERG(parsing_error) = 0; DESERIALIZE_SCALAR_V(&item, char, BCOMPILER_READ_RESULT); @@ -1882,9 +1898,12 @@ } #endif -#if VAL_0 /* val: disabled since all PHP versions work without it */ +//#if VAL_0 /* val: disabled since all PHP versions work without it */ /* inherit: recursively inherit methods from base to all the children * of parent, the children of parent's children, and so on */ +/* daniel: put it back in so old styled classes work better + maybe it can be thrown out in later versions +*/ static void bcompiler_inherit(zend_class_entry* base TSRMLS_DC) { @@ -1908,7 +1927,7 @@ } } -#endif +//#endif @@ -2305,9 +2324,13 @@ #ifdef ZEND_ENGINE_2_1 if (zc->__unset == old) zc->__unset = act; if (zc->__isset == old) zc->__isset = act; + if (zc->__tostring == old) zc->__tostring = act; /* daniel: Added __tostring */ if (zc->serialize_func == old) zc->serialize_func = act; if (zc->unserialize_func == old) zc->unserialize_func = act; #endif +#ifdef ZEND_ENGINE_2_3 + if (zc->__callstatic == old) zc->__callstatic = act; +#endif } } #endif @@ -2657,9 +2680,10 @@ /* type is the switch for serializing zvalue_value */ SERIALIZE_SCALAR(zv->type, zend_uchar); apc_serialize_zvalue_value(&zv->value, zv->type, zn TSRMLS_CC); -#if PHP_MAJOR_VERSION >= 6 + //daniel: Changes in PHP5.3 requires this +#ifdef ZEND_ENGINE_2_3 SERIALIZE_SCALAR(zv->is_ref__gc, zend_uchar); - SERIALIZE_SCALAR(zv->refcount__gc, zend_ushort); + SERIALIZE_SCALAR(zv->refcount__gc, zend_uint); #else SERIALIZE_SCALAR(zv->is_ref, zend_uchar); SERIALIZE_SCALAR(zv->refcount, zend_ushort); @@ -2671,9 +2695,10 @@ /* type is the switch for deserializing zvalue_value */ DESERIALIZE_SCALAR(&zv->type, zend_uchar); apc_deserialize_zvalue_value(&zv->value, zv->type, zn TSRMLS_CC); -#if PHP_MAJOR_VERSION >= 6 - DESERIALIZE_SCALAR(&zv->is_ref__gc, zend_uchar); - DESERIALIZE_SCALAR(&zv->refcount__gc, zend_ushort); + //daniel: Changes in PHP5.3 requires this +#ifdef ZEND_ENGINE_2_3 + DESERIALIZE_SCALAR(&zv->is_ref__gc, zend_uchar); + DESERIALIZE_SCALAR(&zv->refcount__gc, zend_uint); #else DESERIALIZE_SCALAR(&zv->is_ref, zend_uchar); DESERIALIZE_SCALAR(&zv->refcount, zend_ushort); @@ -2682,8 +2707,16 @@ void apc_create_zval(zval** zv TSRMLS_DC) { + /* daniel: refernce cycle garbage collector... new in 5.3 */ + /* Maybe one should check if is enabled? */ +#ifdef ZEND_ENGINE_2_3 + *zv = (zval*) emalloc(sizeof(zval_gc_info)); + memset(*zv, 0, sizeof(zval_gc_info)); + GC_ZVAL_INIT(zv); +#else *zv = (zval*) emalloc(sizeof(zval)); memset(*zv, 0, sizeof(zval)); +#endif apc_deserialize_zval(*zv, NULL TSRMLS_CC); } @@ -2692,7 +2725,7 @@ /* type: zend_function_entry */ -void apc_serialize_zend_function_entry(zend_function_entry* zfe TSRMLS_DC) +void apc_serialize_zend_function_entry(zend_function_entry *zfe TSRMLS_DC) { #ifdef ZEND_ENGINE_2 int i, len; @@ -2973,7 +3006,10 @@ apc_serialize_zstring(force_key, UBYTES(-force_key_len) TSRMLS_CC); } else { #endif - SERIALIZE_SCALAR(force_key_len, char); + /* daniel: one can't use char at this point since there are hash keys which are are longer + then 127 Characters. When restored, the opcode gets changed (ZEND_DECLARE_INHERITED_CLASS was + missing in that cases) */ + SERIALIZE_SCALAR(force_key_len, int); apc_serialize_zstring(force_key, force_key_len TSRMLS_CC); #if PHP_MAJOR_VERSION >= 6 } @@ -3070,6 +3106,7 @@ (void*) NULL, (int) sizeof(zval *), (char)exists TSRMLS_CC); + //zce->default_properties.pDestructor = (dtor_func_t)& #ifdef ZEND_ENGINE_2 BCOMPILERG(cur_zc) = zce; BCOMPILER_DEBUG(("-----------------------------\nPROP INFO:\n")); @@ -3080,7 +3117,7 @@ (void*) apc_free_zend_property_info, (int) sizeof(zend_property_info) , (char) exists TSRMLS_CC); - zce->properties_info.pDestructor = (dtor_func_t)&zend_destroy_property_info; + //zce->properties_info.pDestructor = (dtor_func_t)&zend_destroy_property_info; BCOMPILERG(cur_zc) = NULL; #ifdef ZEND_ENGINE_2_1 @@ -3168,7 +3205,8 @@ if (key_len) *key_len = 0; if (key) *key = NULL; if (BCOMPILERG(current_version) >= 0x0005) { - DESERIALIZE_SCALAR(&exists, char); + /* daniel: See apc_serialize_zend_class_entry why this must be int*/ + DESERIALIZE_SCALAR(&exists, int); if (exists > 0 && key_len && key) { *key_len = exists; apc_create_string2(key, -1 TSRMLS_CC); @@ -3187,11 +3225,14 @@ Since we now can do inheritance by striping - this is usefull.. */ -#if VAL_0 /* val: all PHP versions work fine without it */ +//#if VAL_0 /* val: all PHP versions work fine without it */ +/* daniel: No they doesn't. Old styled classes in PHP5 seems to need it. + Otherwise calling parent constructor with $this->parentClassName() wont be + resolved */ if (zce->parent) { - bcompiler_inherit(zce TSRMLS_CC); + bcompiler_inherit(zce TSRMLS_CC); } -#endif +//#endif if (parent_name) { apclib_free_string(&parent_name); } @@ -3230,6 +3271,7 @@ case IS_VAR: case IS_TMP_VAR: case IS_UNUSED: + case IS_CV: /* daniel: new in 5.3 */ default: if (BCOMPILERG(current_write) >= 0x0005) { @@ -3411,7 +3453,12 @@ assert(zoa->start_op == NULL); SERIALIZE_SCALAR(zoa->return_reference, zend_bool); SERIALIZE_SCALAR(zoa->done_pass_two, zend_bool); - apc_serialize_string(zoa->filename TSRMLS_CC); + /* daniel: Throwed away storing of filename and ...*/ + //apc_serialize_string(zoa->filename TSRMLS_CC); + /* daniel: ... serialize only string. So compatibility to erlier versions is given. + filename op_array filename will be set during deserialisation so the real path will + be shown if an error occours */ + apc_serialize_string("string" TSRMLS_CC); #ifdef ZEND_ENGINE_2 if (BCOMPILERG(current_write) >= 0x0005) { @@ -3430,7 +3477,11 @@ SERIALIZE_SCALAR(zoa->pass_rest_by_reference, zend_bool); SERIALIZE_SCALAR(zoa->backpatch_count, int); +#ifdef ZEND_ENGINE_2_3 //daniel: changed in 5.3 + SERIALIZE_SCALAR(zoa->this_var, zend_uint); +#else SERIALIZE_SCALAR(zoa->uses_this, zend_bool); +#endif } #endif @@ -3670,8 +3721,9 @@ DESERIALIZE_SCALAR(&zoa->return_reference, zend_bool); DESERIALIZE_SCALAR(&zoa->done_pass_two, zend_bool); - apc_create_string2(&fname, -1 TSRMLS_CC); - zoa->filename = zend_set_compiled_filename(fname TSRMLS_CC); + apc_create_string2(&fname, -1 TSRMLS_CC); /* daniel: returns 'string' now */ + /* daniel: setting the real filename */ + zoa->filename = zend_set_compiled_filename(BCOMPILERG(currentfile) TSRMLS_CC); apclib_free_string(&fname); #ifdef ZEND_ENGINE_2 if (BCOMPILERG(current_version) >= 0x0005) { @@ -3706,7 +3758,11 @@ DESERIALIZE_SCALAR(&zoa->required_num_args, zend_uint); DESERIALIZE_SCALAR(&zoa->pass_rest_by_reference, zend_bool); DESERIALIZE_SCALAR(&zoa->backpatch_count, int); +#ifdef ZEND_ENGINE_2_3 //daniel: changed in 5.3 + DESERIALIZE_SCALAR(&zoa->this_var, zend_uint); +#else DESERIALIZE_SCALAR(&zoa->uses_this, zend_bool); +#endif } #endif @@ -3861,6 +3917,10 @@ BCOMPILER_DEBUG(("> it's an __isset handler\n")); ftype |= 0x80; } + if (zf == zc->__tostring) { /* daniel: Added __tostring */ + BCOMPILER_DEBUG(("> it's a __tostring handler\n")); + ftype |= 0x90; + } if (zf == zc->serialize_func) { BCOMPILER_DEBUG(("> it's a serialize_func handler\n")); ftype |= 0x100; @@ -3869,6 +3929,12 @@ BCOMPILER_DEBUG(("> it's a unserialize_func handler\n")); ftype |= 0x200; } +#ifdef ZEND_ENGINE_2_3 + if (zf == zc->__callstatic) { + BCOMPILER_DEBUG(("> it's a __callstatic handler\n")); + ftype |= 0x300; + } +#endif } #endif if (BCOMPILERG(current_write) >= 0x000a) { @@ -3927,9 +3993,13 @@ #ifdef ZEND_ENGINE_2_1 if (ftype & 0x40) zc->__unset = zf; if (ftype & 0x80) zc->__isset = zf; + if (ftype & 0x90) zc->__tostring = zf; /* daniel: Added __tostring */ if (ftype & 0x100) zc->serialize_func = zf; if (ftype & 0x200) zc->unserialize_func = zf; #endif +#ifdef ZEND_ENGINE_2_3 + if (ftype & 0x300) zc->__callstatic = zf; +#endif } #endif switch(zf->type) diff -ur E:\source\c\bcompiler_orig/php_bcompiler.h E:\source\c\bcompiler_fixed/php_bcompiler.h --- E:\source\c\bcompiler_orig/php_bcompiler.h 2008-05-02 10:32:12.139111800 +0200 +++ E:\source\c\bcompiler_fixed/php_bcompiler.h 2008-05-02 10:45:07.726353000 +0200 @@ -85,6 +85,7 @@ int current_include; /* read file after bcompiler_write_file() */ int parsing_error; /* i/o error while parsing, skip file */ const size_t *bcompiler_stdsize; /* array of standard data sizes */ + char *currentfile; /* daniel: the current (compiled)file */ zend_class_entry *cur_zc; /* current class entry */ ZEND_END_MODULE_GLOBALS(bcompiler)