Changeset 95 in svn
Legend:
- Unmodified
- Added
- Removed
-
trunk/config.m4
r87 r95 18 18 19 19 if test "$PHP_XCACHE" != "no"; then 20 PHP_ARG_ENABLE(xcache-constant, for XCache handle of compile time constant, 21 [ --enable-xcache-constant XCache: Handle new constants made by php compiler (e.g.: for __halt_compiler)], yes, no) 22 if test "$PHP_XCACHE_CONSTANT" != "no"; then 23 AC_DEFINE([HAVE_XCACHE_CONSTANT], 1, [Define to enable XCache handling of compile time constants]) 24 fi 25 20 26 xcache_sources="processor.c \ 21 27 xcache.c \ -
trunk/config.w32
r37 r95 5 5 6 6 if (PHP_XCACHE != "no") { 7 // {{{ check for xcache-constant 8 ARG_ENABLE("xcache-constant", "XCache: Handle new constants made by php compiler (e.g.: for __halt_compiler)", "yes"); 9 if (PHP_XCACHE_CONSTANT != "no") { 10 AC_DEFINE("HAVE_XCACHE_CONSTANT", 1, "Define to enable XCache handling of compile time constants"); 11 } 12 // }}} 13 7 14 var xcache_sources = "processor.c \ 8 15 xcache.c \ -
trunk/processor/processor.m4
r94 r95 5 5 DECL_STRUCT_P_FUNC(`zend_op_array') 6 6 DECL_STRUCT_P_FUNC(`zend_class_entry') 7 #ifdef HAVE_XCACHE_CONSTANT 8 DECL_STRUCT_P_FUNC(`zend_constant') 9 #endif 7 10 DECL_STRUCT_P_FUNC(`zend_function') 8 11 DECL_STRUCT_P_FUNC(`xc_entry_t') … … 59 62 dnl }}} 60 63 DEF_HASH_TABLE_FUNC(`HashTable_zval_ptr', `zval_ptr') 64 #ifdef HAVE_XCACHE_CONSTANT 65 DEF_HASH_TABLE_FUNC(`HashTable_zend_constant', `zend_constant') 66 #endif 61 67 DEF_HASH_TABLE_FUNC(`HashTable_zend_function', `zend_function') 62 68 #ifdef ZEND_ENGINE_2 … … 205 211 #endif 206 212 dnl }}} 213 #ifdef HAVE_XCACHE_CONSTANT 214 DEF_STRUCT_P_FUNC(`zend_constant', , `dnl {{{ 215 STRUCT(zval, value) 216 DISPATCH(int, flags) 217 DISPATCH(uint, name_len) 218 PROC_STRING_L(name, name_len) 219 zstr name; 220 DISPATCH(int, module_number) 221 ') 222 dnl }}} 223 #endif 207 224 DEF_STRUCT_P_FUNC(`zend_function', , `dnl {{{ 208 225 DISABLECHECK(` … … 599 616 STRUCT_P(HashTable, static_variables, HashTable_zval_ptr) 600 617 601 IFCOPY(`dst->start_op = src->start_op;') 602 DONE(start_op) 618 COPY(start_op) 603 619 DISPATCH(int, backpatch_count) 604 620 … … 628 644 dnl }}} 629 645 646 #ifdef HAVE_XCACHE_CONSTANT 647 DEF_STRUCT_P_FUNC(`xc_constinfo_t', , `dnl {{{ 648 DISPATCH(zend_uint, key_size) 649 #ifdef IS_UNICODE 650 DISPATCH(zend_uchar, type) 651 #endif 652 IFRESTORE(`COPY(key)', ` 653 PROC_USTRING_N(type, key, key_size) 654 ') 655 STRUCT(zend_constant, constant) 656 ') 657 dnl }}} 658 #endif 630 659 DEF_STRUCT_P_FUNC(`xc_funcinfo_t', , `dnl {{{ 631 660 DISPATCH(zend_uint, key_size) … … 666 695 667 696 STRUCT_P(zend_op_array, op_array) 697 698 #ifdef HAVE_XCACHE_CONSTANT 699 DISPATCH(zend_uint, constinfo_cnt) 700 STRUCT_ARRAY(constinfo_cnt, xc_constinfo_t, constinfos) 701 #endif 668 702 669 703 DISPATCH(zend_uint, funcinfo_cnt) -
trunk/utils.c
r88 r95 265 265 #endif 266 266 267 #ifdef HAVE_XCACHE_CONSTANT 268 void xc_install_constant(char *filename, zend_constant *constant, zend_uchar type, void *key, uint len TSRMLS_DC) /* {{{ */ 269 { 270 if (zend_u_hash_add(EG(zend_constants), type, key, len, 271 constant, sizeof(zend_constant), 272 NULL 273 ) == FAILURE) { 274 CG(in_compilation) = 1; 275 CG(compiled_filename) = filename; 276 CG(zend_lineno) = 0; 277 zend_error(E_NOTICE, "Constant %s already defined", key); 278 free(constant->name); 279 if (!(constant->flags & CONST_PERSISTENT)) { 280 zval_dtor(&constant->value); 281 } 282 } 283 } 284 /* }}} */ 285 #endif 267 286 void xc_install_function(char *filename, zend_function *func, zend_uchar type, void *key, uint len TSRMLS_DC) /* {{{ */ 268 287 { … … 316 335 #define OG(x) (sandbox->orig_##x) 317 336 /* }}} */ 337 #ifdef HAVE_XCACHE_CONSTANT 338 static void xc_constant_copy_ctor(zend_constant *c) /* {{{ */ 339 { 340 c->name = zend_strndup(c->name, c->name_len - 1); 341 if (!(c->flags & CONST_PERSISTENT)) { 342 zval_copy_ctor(&c->value); 343 } 344 } 345 /* }}} */ 346 #endif 318 347 xc_sandbox_t *xc_sandbox_init(xc_sandbox_t *sandbox, char *filename TSRMLS_DC) /* {{{ */ 319 348 { … … 325 354 sandbox->alloc = 1; 326 355 } 356 327 357 memcpy(&OG(included_files), &EG(included_files), sizeof(EG(included_files))); 328 358 memcpy(&OG(open_files), &CG(open_files), sizeof(CG(open_files))); 359 360 #ifdef HAVE_XCACHE_CONSTANT 361 OG(zend_constants) = EG(zend_constants); 362 EG(zend_constants) = &TG(zend_constants); 363 #endif 329 364 330 365 OG(function_table) = CG(function_table); … … 342 377 zend_llist_init(TG(open_files), sizeof(zend_file_handle), (void (*)(void *)) zend_file_handle_dtor, 0); 343 378 zend_hash_init_ex(TG(included_files), 5, NULL, NULL, 0, 1); 379 #ifdef HAVE_XCACHE_CONSTANT 380 zend_hash_init_ex(&TG(zend_constants), 20, NULL, ZEND_CONSTANT_DTOR, 1, 0); 381 #endif 344 382 zend_hash_init_ex(&TG(function_table), 128, NULL, ZEND_FUNCTION_DTOR, 0, 0); 345 383 zend_hash_init_ex(&TG(class_table), 16, NULL, ZEND_CLASS_DTOR, 0, 0); … … 356 394 zend_llist_position lpos; 357 395 zend_file_handle *handle; 396 397 #ifdef HAVE_XCACHE_CONSTANT 398 b = TG(zend_constants).pListHead; 399 /* install constants */ 400 while (b != NULL) { 401 zend_constant *c = (zend_constant*) b->pData; 402 xc_install_constant(sandbox->filename, c, 403 BUCKET_KEY_TYPE(b), BUCKET_KEY(b), b->nKeyLength TSRMLS_CC); 404 b = b->pListNext; 405 } 406 #endif 358 407 359 408 b = TG(function_table).pListHead; … … 386 435 { 387 436 /* restore first first install function/class */ 437 #ifdef HAVE_XCACHE_CONSTANT 438 EG(zend_constants) = OG(zend_constants); 439 #endif 388 440 CG(function_table) = OG(function_table); 389 441 CG(class_table) = OG(class_table); … … 394 446 395 447 /* no free as it's installed */ 448 #ifdef HAVE_XCACHE_CONSTANT 449 TG(zend_constants).pDestructor = NULL; 450 #endif 396 451 TG(function_table).pDestructor = NULL; 397 452 TG(class_table).pDestructor = NULL; … … 400 455 401 456 /* destroy all the tmp */ 457 #ifdef HAVE_XCACHE_CONSTANT 458 zend_hash_destroy(&TG(zend_constants)); 459 #endif 402 460 zend_hash_destroy(&TG(function_table)); 403 461 zend_hash_destroy(&TG(class_table)); -
trunk/utils.h
r88 r95 26 26 27 27 /* installer */ 28 #ifdef HAVE_XCACHE_CONSTANT 29 void xc_install_constant(char *filename, zend_constant *constant, zend_uchar type, void *key, uint len TSRMLS_DC); 30 #endif 28 31 void xc_install_function(char *filename, zend_function *func, zend_uchar type, void *key, uint len TSRMLS_DC); 29 32 ZESW(xc_cest_t *, void) xc_install_class(char *filename, xc_cest_t *cest, zend_uchar type, void *key, uint len TSRMLS_DC); … … 39 42 zend_llist *tmp_open_files; 40 43 44 #ifdef HAVE_XCACHE_CONSTANT 45 HashTable *orig_zend_constants; 46 HashTable tmp_zend_constants; 47 #endif 41 48 HashTable *orig_function_table; 42 49 HashTable *orig_class_table; -
trunk/xcache.c
r92 r95 301 301 case XC_TYPE_PHP: 302 302 php = entry->data.php; 303 add_assoc_long_ex(ei, ZEND_STRS("sourcesize"), php->sourcesize);303 add_assoc_long_ex(ei, ZEND_STRS("sourcesize"), php->sourcesize); 304 304 #ifdef HAVE_INODE 305 add_assoc_long_ex(ei, ZEND_STRS("device"), php->device); 306 add_assoc_long_ex(ei, ZEND_STRS("inode"), php->inode); 307 #endif 308 add_assoc_long_ex(ei, ZEND_STRS("mtime"), php->mtime); 309 310 add_assoc_long_ex(ei, ZEND_STRS("function_cnt"), php->funcinfo_cnt); 311 add_assoc_long_ex(ei, ZEND_STRS("class_cnt"), php->classinfo_cnt); 305 add_assoc_long_ex(ei, ZEND_STRS("device"), php->device); 306 add_assoc_long_ex(ei, ZEND_STRS("inode"), php->inode); 307 #endif 308 add_assoc_long_ex(ei, ZEND_STRS("mtime"), php->mtime); 309 310 #ifdef HAVE_XCACHE_CONSTANT 311 add_assoc_long_ex(ei, ZEND_STRS("constinfo_cnt"), php->constinfo_cnt); 312 #endif 313 add_assoc_long_ex(ei, ZEND_STRS("function_cnt"), php->funcinfo_cnt); 314 add_assoc_long_ex(ei, ZEND_STRS("class_cnt"), php->classinfo_cnt); 312 315 break; 313 316 case XC_TYPE_VAR: … … 354 357 /* new ptr which is stored inside CG(class_table) */ 355 358 xc_cest_t **new_cest_ptrs = (xc_cest_t **)do_alloca(sizeof(xc_cest_t*) * p->classinfo_cnt); 359 #endif 360 361 #ifdef HAVE_XCACHE_CONSTANT 362 /* install constant */ 363 for (i = 0; i < p->constinfo_cnt; i ++) { 364 xc_constinfo_t *ci = &p->constinfos[i]; 365 xc_install_constant(xce->name.str.val, &ci->constant, 366 UNISW(0, ci->type), ci->key, ci->key_size TSRMLS_CC); 367 } 356 368 #endif 357 369 … … 594 606 zend_bool catched = 0; 595 607 char *filename; 608 int old_constinfo_cnt, old_funcinfo_cnt, old_classinfo_cnt; 596 609 597 610 if (!xc_initized) { … … 675 688 xc_sandbox_init(&sandbox, filename TSRMLS_CC); 676 689 690 old_classinfo_cnt = zend_hash_num_elements(CG(class_table)); 691 old_funcinfo_cnt = zend_hash_num_elements(CG(function_table)); 692 old_constinfo_cnt = zend_hash_num_elements(EG(zend_constants)); 693 677 694 zend_try { 678 695 op_array = origin_compile_file(h, type TSRMLS_CC); … … 703 720 php.op_array = op_array; 704 721 705 php.funcinfo_cnt = zend_hash_num_elements(CG(function_table)); 706 php.classinfo_cnt = zend_hash_num_elements(CG(class_table)); 707 708 php.funcinfos = ECALLOC_N(php.funcinfos, php.funcinfo_cnt); 709 if (!php.funcinfos) { 710 goto err_func; 711 } 712 php.classinfos = ECALLOC_N(php.classinfos, php.classinfo_cnt); 713 if (!php.classinfos) { 714 goto err_class; 715 } 722 #ifdef HAVE_XCACHE_CONSTANT 723 php.constinfo_cnt = zend_hash_num_elements(EG(zend_constants)) - old_constinfo_cnt; 724 #endif 725 php.funcinfo_cnt = zend_hash_num_elements(CG(function_table)) - old_funcinfo_cnt; 726 php.classinfo_cnt = zend_hash_num_elements(CG(class_table)) - old_classinfo_cnt; 727 728 #define X_ALLOC_N(var, cnt) do { \ 729 if (php.cnt) { \ 730 ECALLOC_N(php.var, php.cnt); \ 731 if (!php.var) { \ 732 goto err_##var; \ 733 } \ 734 } \ 735 else { \ 736 php.var = NULL; \ 737 } \ 738 } while (0) 739 740 #ifdef HAVE_XCACHE_CONSTANT 741 X_ALLOC_N(constinfos, constinfo_cnt); 742 #endif 743 X_ALLOC_N(funcinfos, funcinfo_cnt); 744 X_ALLOC_N(classinfos, classinfo_cnt); 745 #undef X_ALLOC 716 746 /* }}} */ 717 747 /* {{{ shallow copy, pointers only */ { … … 719 749 unsigned int i; 720 750 721 b = CG(function_table)->pListHead; 722 for (i = 0; b; i ++, b = b->pListNext) { 723 xc_funcinfo_t *fi = &php.funcinfos[i]; 724 725 assert(i < php.funcinfo_cnt); 726 assert(b->pData); 727 memcpy(&fi->func, b->pData, sizeof(zend_function)); 728 UNISW(NOTHING, fi->type = b->key.type;) 729 fi->key = BUCKET_KEY(b); 730 fi->key_size = b->nKeyLength; 731 } 732 733 b = CG(class_table)->pListHead; 734 for (i = 0; b; i ++, b = b->pListNext) { 735 xc_classinfo_t *ci = &php.classinfos[i]; 736 737 assert(i < php.classinfo_cnt); 738 assert(b->pData); 739 memcpy(&ci->cest, b->pData, sizeof(xc_cest_t)); 740 UNISW(NOTHING, ci->type = b->key.type;) 741 ci->key = BUCKET_KEY(b); 742 ci->key_size = b->nKeyLength; 743 /* need to fix inside store */ 744 } 751 #define COPY_H(vartype, var, cnt, name, datatype) do { \ 752 for (i = 0; b; i ++, b = b->pListNext) { \ 753 vartype *data = &php.var[i]; \ 754 \ 755 if (i < old_##cnt) { \ 756 continue; \ 757 } \ 758 \ 759 assert(i < old_##cnt + php.cnt); \ 760 assert(b->pData); \ 761 memcpy(&data->name, b->pData, sizeof(datatype)); \ 762 UNISW(NOTHING, data->type = b->key.type;) \ 763 data->key = BUCKET_KEY(b); \ 764 data->key_size = b->nKeyLength; \ 765 } \ 766 } while(0) 767 768 #ifdef HAVE_XCACHE_CONSTANT 769 b = EG(zend_constants)->pListHead; COPY_H(xc_constinfo_t, constinfos, constinfo_cnt, constant, zend_constant); 770 #endif 771 b = CG(function_table)->pListHead; COPY_H(xc_funcinfo_t, funcinfos, funcinfo_cnt, func, zend_function); 772 b = CG(class_table)->pListHead; COPY_H(xc_classinfo_t, classinfos, classinfo_cnt, cest, xc_cest_t); 773 774 #undef COPY_H 775 /* for ZE1, cest need to fix inside store */ 745 776 } 746 777 /* }}} */ … … 754 785 #endif 755 786 756 efree(xce.data.php->classinfos); 757 err_class: 758 efree(xce.data.php->funcinfos); 759 err_func: 787 #define X_FREE(var) \ 788 if (xce.data.php->var) { \ 789 efree(xce.data.php->var); \ 790 } \ 791 err_##var: 792 793 X_FREE(classinfos) 794 X_FREE(funcinfos) 795 #ifdef HAVE_XCACHE_CONSTANT 796 X_FREE(constinfos) 797 #endif 798 #undef X_FREE 799 760 800 err_oparray: 761 801 err_bailout: … … 790 830 #endif 791 831 xc_processor_restore_xc_entry_t(&xce, stored_xce, xc_readonly_protection TSRMLS_CC); 792 op_array = xc_entry_install(&xce, h TSRMLS_CC); 793 794 efree(xce.data.php->funcinfos); 795 efree(xce.data.php->classinfos); 832 833 catched = 0; 834 zend_try { 835 op_array = xc_entry_install(&xce, h TSRMLS_CC); 836 } zend_catch { 837 catched = 1; 838 } zend_end_try(); 839 840 #define X_FREE(var) \ 841 if (xce.data.php->var) { \ 842 efree(xce.data.php->var); \ 843 } 844 X_FREE(classinfos) 845 X_FREE(funcinfos) 846 #ifdef HAVE_XCACHE_CONSTANT 847 X_FREE(constinfos) 848 #endif 849 #undef X_FREE 796 850 efree(xce.data.php); 851 852 if (catched) { 853 zend_bailout(); 854 } 797 855 #ifdef DEBUG 798 856 fprintf(stderr, "restored\n"); -
trunk/xcache.h
r88 r95 154 154 } xc_classinfo_t; 155 155 /* }}} */ 156 #ifdef HAVE_XCACHE_CONSTANT 157 /* {{{ xc_constinfo_t */ 158 typedef struct { 159 #ifdef IS_UNICODE 160 zend_uchar type; 161 #endif 162 char *key; 163 zend_uint key_size; 164 zend_constant constant; 165 } xc_constinfo_t; 166 /* }}} */ 167 #endif 156 168 /* {{{ xc_funcinfo_t */ 157 169 typedef struct { … … 175 187 176 188 zend_op_array *op_array; 189 190 #ifdef HAVE_XCACHE_CONSTANT 191 zend_uint constinfo_cnt; 192 xc_constinfo_t *constinfos; 193 #endif 177 194 178 195 zend_uint funcinfo_cnt;
Note: See TracChangeset
for help on using the changeset viewer.