Changeset 18
- Timestamp:
- 04/10/06 18:55:09 (7 years ago)
- Files:
-
- trunk/fastxsl.c (modified) (51 diffs)
- trunk/fl_hash.c (modified) (3 diffs)
- trunk/fl_hash.h (modified) (1 diff)
- trunk/php_fastxsl.h (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/fastxsl.c
r17 r18 41 41 #endif 42 42 #include <sys/types.h> 43 #include <sys/file.h> 43 44 #include <unistd.h> 44 45 … … 51 52 ZEND_DECLARE_MODULE_GLOBALS(fastxsl); 52 53 54 static int inshm = 0; 55 53 56 static int le_fastxsl_stylesheet; 54 57 #define le_fastxsl_stylesheet_name "FastXSL Stylesheet" … … 60 63 61 64 void fastxsl_errorfunc(void *ctx, const char *msg, ...); 65 static void ShmCache_Stylesheet_Free(php_ss_wrapper *wrapper TSRMLS_DC); 66 static void _SS_Wrapper_Dtor(php_ss_wrapper *wrapper); 67 static void _XD_Wrapper_Dtor(php_xd_wrapper *wrapper); 68 69 static unsigned int pool_hash(void *ptr) 70 { 71 unsigned long i = (unsigned long) ptr; 72 i /= 8; 73 i *= 99961; 74 return i % 31907; 75 } 76 static void pool_init(zend_fastxsl_globals *globals) 77 { 78 int i; 79 80 globals->pool = calloc(1, sizeof(void **) * 31907); 81 globals->pool_offset = calloc(1, sizeof(int) * 31907); 82 globals->pool_allocd = calloc(1, sizeof(int) * 31907); 83 84 for(i = 0; i < 31907; i++) { 85 globals->pool[i] = calloc(1, sizeof(void *) * 100); 86 globals->pool_allocd[i] = 100; 87 } 88 } 89 90 static void pool_add(void *ptr) 91 { 92 unsigned int slot = pool_hash(ptr); 93 if(FASTXSL_G(pool_offset)[slot] == FASTXSL_G(pool_allocd)[slot] - 1) { 94 FASTXSL_G(pool_allocd)[slot] *= 2; 95 FASTXSL_G(pool)[slot] = realloc(FASTXSL_G(pool)[slot], sizeof(void *) * FASTXSL_G(pool_allocd)[slot]); 96 } 97 FASTXSL_G(pool)[slot][FASTXSL_G(pool_offset)[slot]++] = ptr; 98 } 99 100 static void pool_remove( void *ptr) 101 { 102 int i; 103 unsigned int slot = pool_hash(ptr); 104 for(i = 0; i < FASTXSL_G(pool_offset)[slot]; i++) { 105 if(FASTXSL_G(pool)[slot][i] == ptr) { 106 FASTXSL_G(pool)[slot][i] = NULL; 107 } 108 } 109 } 110 111 static void pool_clear() 112 { 113 int i; 114 for(i = 0; i < 31907; i++) { 115 FASTXSL_G(pool_offset)[i] = 0; 116 } 117 } 118 119 static void pool_destroy( FL_Free free_func ) 120 { 121 int i, j; 122 for(i = 0; i < 31907; i++) { 123 for(j = 0; j < FASTXSL_G(pool_offset)[i]; j++) { 124 if(FASTXSL_G(pool)[i][j]) { 125 free_func(FASTXSL_G(pool)[i][j]); 126 } 127 } 128 } 129 } 62 130 63 131 static php_ss_wrapper * … … 73 141 wrapper = (php_ss_wrapper *) calloc(1, sizeof(php_ss_wrapper)); 74 142 } 143 if(!wrapper) { 144 mm_display_info(FASTXSL_G(cache)->mm); 145 } 75 146 wrapper->persistant = 1; 76 147 #else … … 96 167 static xmlFreeFunc free_ptr; 97 168 static xmlMallocFunc malloc_ptr; 169 static xmlMallocFunc mallocatomic_ptr; 98 170 static xmlReallocFunc realloc_ptr; 99 171 static xmlStrdupFunc strdup_ptr; … … 104 176 { 105 177 TSRMLS_FETCH(); 178 if(!inshm) assert(0); 106 179 FASTXSL_G(tmp_allocated_size) -= mm_sizeof(FASTXSL_G(cache)->mm, ptr); 107 108 180 mm_free(FASTXSL_G(cache)->mm, ptr); 181 //pool_remove(ptr); 109 182 } 110 183 … … 114 187 void *ptr; 115 188 TSRMLS_FETCH(); 116 189 if(!inshm) assert(0); 117 190 ptr = mm_malloc(FASTXSL_G(cache)->mm, size); 118 191 if (!ptr) { 119 192 php_error(E_ERROR, "Ran out of Shared memory to allocate data for FastXSL cache, " 120 "in function %s() cannot allocate % d bytes (%d available, %d allocated)",193 "in function %s() cannot allocate %ld bytes (%ld available, %ld allocated)", 121 194 get_active_function_name(TSRMLS_C), size, mm_available(FASTXSL_G(cache)->mm), 122 195 mm_maxsize() - mm_available(FASTXSL_G(cache)->mm)); … … 125 198 126 199 FASTXSL_G(tmp_allocated_size) += size; 127 200 //pool_add(ptr); 128 201 return ptr; 129 202 } … … 134 207 void *ptr; 135 208 209 if(!inshm) assert(0); 136 210 ptr = ShmCache_Malloc(nmemb * size); 137 211 memset(ptr, 0, nmemb * size); 138 212 //pool_add(ptr); 139 213 return ptr; 140 214 } … … 147 221 TSRMLS_FETCH(); 148 222 223 if(!inshm) assert(0); 149 224 oldsize = mm_sizeof(FASTXSL_G(cache)->mm, ptr); 150 225 newptr = mm_realloc(FASTXSL_G(cache)->mm, ptr, size); … … 158 233 } 159 234 FASTXSL_G(tmp_allocated_size) += (size - oldsize); 160 235 //pool_remove(ptr); 236 //pool_add(newptr); 161 237 return newptr; 162 238 } … … 168 244 int string_length; 169 245 246 if(!inshm) assert(0); 170 247 string_length = strlen(string); 171 newstring = ShmCache_Malloc(string_length );248 newstring = ShmCache_Malloc(string_length + 1); 172 249 memcpy(newstring, string, string_length); 173 250 newstring[string_length] = 0; … … 205 282 ShmCache_UseAllocationFunctions(void) 206 283 { 284 //xmlGcMemSetup(ShmCache_Free, ShmCache_Malloc, ShmCache_Malloc, ShmCache_Realloc, ShmCache_Strdup); 207 285 xmlMemSetup(ShmCache_Free, ShmCache_Malloc, ShmCache_Realloc, ShmCache_Strdup); 208 286 } … … 212 290 Php_UseAllocationFunctions(void) 213 291 { 292 //xmlGcMemSetup(Php_Free, Php_Malloc, Php_Malloc, Php_Realloc, Php_Strdup); 214 293 xmlMemSetup(Php_Free, Php_Malloc, Php_Realloc, Php_Strdup); 215 294 } … … 218 297 Xml_UseAllocationFunctions(void) 219 298 { 220 xmlMemSetup(free_ptr, malloc_ptr, realloc_ptr, strdup_ptr); 299 //xmlGcMemSetup(free_ptr, malloc_ptr, mallocatomic_ptr, realloc_ptr, strdup); 300 xmlMemSetup(free_ptr, malloc_ptr, realloc_ptr, strdup); 221 301 } 222 302 … … 226 306 { 227 307 php_ss_wrapper *wrapper; 228 308 int rv; 229 309 wrapper = SS_Wrapper_Alloc(FASTXSL_SHARED_ALLOC TSRMLS_CC); 230 310 311 //xmlCleanupParserr(); 231 312 ShmCache_UseAllocationFunctions(); 313 wrapper->alloc_type = FASTXSL_SHMALLOC; 232 314 FASTXSL_G(tmp_allocated_size) = 0; 315 inshm = 1; 316 zend_set_timeout(0); 317 //pool_clear(); 233 318 wrapper->ss = xsltParseStylesheetFile(filename); 319 inshm = 0; 320 Xml_UseAllocationFunctions(); 234 321 if (!wrapper->ss) { 235 Xml_UseAllocationFunctions(); 322 //pool_destroy(ShmCache_Free); 323 _SS_Wrapper_Dtor(wrapper); 236 324 return NULL; 237 325 } 238 Xml_UseAllocationFunctions();239 326 wrapper->mtime = mtime; 240 327 wrapper->allocsize = FASTXSL_G(tmp_allocated_size); 241 242 fl_hash_add(FASTXSL_G(cache)->table, filename, filename_len, wrapper); 328 mm_lock(FASTXSL_G(cache)->mm, MM_LOCK_RD); 329 rv = fl_hash_add(FASTXSL_G(cache)->table, filename, filename_len, wrapper); 330 mm_unlock(FASTXSL_G(cache)->mm); 331 if(rv == 0) { 332 /* we failed */ 333 php_ss_wrapper *fallback; 334 mm_lock(FASTXSL_G(cache)->mm, MM_LOCK_RD); 335 fallback = fl_hash_find(FASTXSL_G(cache)->table, filename, filename_len); 336 mm_unlock(FASTXSL_G(cache)->mm); 337 if(fallback) { 338 ShmCache_Stylesheet_Free(wrapper); 339 wrapper = fallback; 340 } else { 341 } 342 } else { 343 } 243 344 244 345 return wrapper; … … 249 350 { 250 351 if (wrapper->ss) { 352 //xmlCleanupParserr(); 251 353 ShmCache_UseAllocationFunctions(); 354 inshm = 1; 252 355 xsltFreeStylesheet(wrapper->ss); 356 inshm = 0; 357 //xmlCleanupParserr(); 253 358 Xml_UseAllocationFunctions(); 254 359 } … … 261 366 php_ss_wrapper *wrapper; 262 367 368 mm_lock(FASTXSL_G(cache)->mm, MM_LOCK_RD); 263 369 wrapper = fl_hash_find(FASTXSL_G(cache)->table, filename, filename_len); 370 mm_unlock(FASTXSL_G(cache)->mm); 264 371 if (wrapper) { 372 mm_lock(FASTXSL_G(cache)->mm, MM_LOCK_RD); 265 373 fl_hash_delete(FASTXSL_G(cache)->table, filename, filename_len); 374 mm_unlock(FASTXSL_G(cache)->mm); 266 375 ShmCache_Stylesheet_Free(wrapper); 267 376 } … … 275 384 276 385 wrapper = (php_ss_wrapper *) SS_Wrapper_Alloc(FASTXSL_PRM_ALLOC TSRMLS_CC); 386 wrapper->alloc_type = FASTXSL_PRMALLOC; 277 387 278 388 wrapper->ss = xsltParseStylesheetFile(filename); 389 ////xmlCleanupParserr(); 279 390 if (!wrapper->ss) { 280 391 return NULL; … … 282 393 wrapper->mtime = mtime; 283 394 284 fl_hash_add(FASTXSL_G(cache)->prmtable, filename, filename_len, wrapper); 395 if(fl_hash_add(FASTXSL_G(cache)->prmtable, filename, filename_len, wrapper) == 0) { 396 /* we failed */ 397 php_ss_wrapper *fallback; 398 mm_lock(FASTXSL_G(cache)->mm, MM_LOCK_RD); 399 fallback = fl_hash_find(FASTXSL_G(cache)->table, filename, filename_len); 400 mm_unlock(FASTXSL_G(cache)->mm); 401 if(fallback) { 402 ShmCache_Stylesheet_Free(wrapper); 403 wrapper = fallback; 404 } 405 } 285 406 286 407 return wrapper; … … 352 473 353 474 add_assoc_long(info_array, "allocated", ss_wrapper->allocsize); 475 add_assoc_long(info_array, "hits", ss_wrapper->hits); 354 476 add_assoc_long(info_array, "mtime", ss_wrapper->mtime); 355 477 … … 361 483 add_assoc_zval(return_value, "files", files_array); 362 484 363 add_assoc_long(return_value, "shm_allocated", allocated_bytes); 485 add_assoc_long(return_value, "apparent_allocated", allocated_bytes); 486 add_assoc_long(return_value, "real_allocated", mm_maxsize() - mm_available(FASTXSL_G(cache)->mm)); 364 487 add_assoc_long(return_value, "shm_maxsize", (long) mm_maxsize()); 365 366 488 mm_unlock(FASTXSL_G(cache)->mm); 489 } 490 491 PHP_FUNCTION(fastxsl_xmlMemoryDump) 492 { 493 chdir("/tmp"); 494 xmlMemDisplay(stderr); 367 495 } 368 496 #endif … … 383 511 384 512 wrapper = (php_ss_wrapper *) SS_Wrapper_Alloc(0 TSRMLS_CC); 513 wrapper->alloc_type = FASTXSL_PRMALLOC; 514 Xml_UseAllocationFunctions(); 385 515 wrapper->ss = xsltParseStylesheetFile(filename); 386 516 if (!wrapper->ss) { … … 405 535 406 536 wrapper = XD_Wrapper_Alloc(); 537 wrapper->alloc_type = FASTXSL_PRMALLOC; 538 Xml_UseAllocationFunctions(); 407 539 wrapper->xd = xmlParseDoc(text); 408 540 if (!wrapper->xd) { 541 _XD_Wrapper_Dtor(wrapper); 409 542 RETURN_FALSE; 410 543 } … … 428 561 429 562 wrapper = XD_Wrapper_Alloc(); 563 wrapper->alloc_type = FASTXSL_PRMALLOC; 430 564 wrapper->xd = xmlParseFile((const xmlChar *) filename); 431 565 if (!wrapper->xd) { 566 _XD_Wrapper_Dtor(wrapper); 432 567 RETURN_FALSE; 433 568 } … … 499 634 zval *z_parameters; 500 635 struct stat sb; 636 int lockfd; 501 637 502 638 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "sz|z", &ss_filename, &ss_filename_len, … … 515 651 516 652 result_wrapper = XD_Wrapper_Alloc(); 517 518 mm_lock(FASTXSL_G(cache)->mm, MM_LOCK_RW); 653 result_wrapper->alloc_type = FASTXSL_PRMALLOC; 654 lockfd = open(ss_filename, O_RDONLY); 655 if(lockfd < 0) { 656 /* FIXME non-existent file */ 657 RETURN_FALSE; 658 } 519 659 if (!FASTXSL_G(nostat)) { 520 if (stat(ss_filename, &sb) == -1) { 660 if (fstat(lockfd, &sb) == -1) { 661 ShmCache_UseAllocationFunctions(); 662 inshm = 1; 521 663 ShmCache_Stylesheet_Delete(ss_filename, ss_filename_len TSRMLS_CC); 522 mm_unlock(FASTXSL_G(cache)->mm); 664 inshm = 0; 665 Xml_UseAllocationFunctions(); 666 _XD_Wrapper_Dtor(result_wrapper); 523 667 free(parameters); 668 close(lockfd); 524 669 RETURN_FALSE; 525 670 } … … 527 672 sb.st_mtime = 0; 528 673 } 529 674 flock(lockfd, LOCK_EX); 675 mm_lock(FASTXSL_G(cache)->mm, MM_LOCK_RW); 530 676 ss_wrapper = fl_hash_find(FASTXSL_G(cache)->table, ss_filename, ss_filename_len); 677 mm_unlock(FASTXSL_G(cache)->mm); 531 678 if (!ss_wrapper) { 679 ShmCache_UseAllocationFunctions(); 680 inshm = 1; 532 681 ss_wrapper = ShmCache_Stylesheet_ParseAndStore(ss_filename, ss_filename_len, sb.st_mtime); 682 inshm = 0; 533 683 if (!ss_wrapper) { 534 mm_unlock(FASTXSL_G(cache)->mm); 684 flock(lockfd, LOCK_UN); 685 close(lockfd); 686 //xmlCleanupParserr(); 687 Xml_UseAllocationFunctions(); 688 _XD_Wrapper_Dtor(result_wrapper); 535 689 free(parameters); 536 690 RETURN_FALSE; … … 539 693 if (!FASTXSL_G(nostat)) { 540 694 if (ss_wrapper->mtime != sb.st_mtime) { 695 //xmlCleanupParserr(); 696 ShmCache_UseAllocationFunctions(); 697 inshm = 1; 541 698 ShmCache_Stylesheet_Delete(ss_filename, ss_filename_len TSRMLS_CC); 542 699 ss_wrapper = ShmCache_Stylesheet_ParseAndStore(ss_filename, ss_filename_len, sb.st_mtime TSRMLS_CC); 700 inshm = 0; 701 //xmlCleanupParserr(); 702 Xml_UseAllocationFunctions(); 543 703 if (!ss_wrapper) { 544 mm_unlock(FASTXSL_G(cache)->mm); 704 flock(lockfd, LOCK_UN); 705 close(lockfd); 706 _XD_Wrapper_Dtor(result_wrapper); 545 707 free(parameters); 546 708 RETURN_FALSE; … … 549 711 } 550 712 } 551 713 ss_wrapper->hits++; 714 //xmlCleanupParserr(); 715 Xml_UseAllocationFunctions(); 716 flock(lockfd, LOCK_UN); 717 close(lockfd); 552 718 result_wrapper->xd = xsltApplyStylesheet(ss_wrapper->ss, xd_wrapper->xd, 553 719 (const char **) parameters); 554 720 555 mm_unlock(FASTXSL_G(cache)->mm);556 721 557 722 if (parameters) … … 595 760 596 761 result_wrapper = XD_Wrapper_Alloc(); 762 result_wrapper->alloc_type = FASTXSL_PRMALLOC; 597 763 598 764 if (!FASTXSL_G(nostat)) { 599 765 if (stat(ss_filename, &sb) == -1) { 600 766 PrmCache_Stylesheet_Delete(ss_filename, ss_filename_len TSRMLS_CC); 767 _XD_Wrapper_Dtor(result_wrapper); 601 768 free(parameters); 602 769 RETURN_FALSE; … … 610 777 ss_wrapper = PrmCache_Stylesheet_ParseAndStore(ss_filename, ss_filename_len, sb.st_mtime TSRMLS_CC); 611 778 if (!ss_wrapper) { 779 _XD_Wrapper_Dtor(result_wrapper); 612 780 free(parameters); 613 781 RETURN_FALSE; … … 619 787 ss_wrapper = PrmCache_Stylesheet_ParseAndStore(ss_filename, ss_filename_len, sb.st_mtime TSRMLS_CC); 620 788 if (!ss_wrapper) { 789 _XD_Wrapper_Dtor(result_wrapper); 621 790 free(parameters); 622 791 RETURN_FALSE; … … 625 794 } 626 795 } 627 796 ss_wrapper->hits++; 628 797 result_wrapper->xd = xsltApplyStylesheet(ss_wrapper->ss, xd_wrapper->xd, 629 798 (const char **) parameters); 799 ////xmlCleanupParserr(); 630 800 631 801 if (parameters) … … 633 803 634 804 if (!result_wrapper->xd) { 805 _XD_Wrapper_Dtor(result_wrapper); 635 806 RETURN_FALSE; 636 807 } … … 667 838 668 839 result_wrapper = XD_Wrapper_Alloc(); 669 840 result_wrapper->alloc_type = FASTXSL_PRMALLOC; 670 841 result_wrapper->xd = xsltApplyStylesheet(ss_wrapper->ss, xd_wrapper->xd, 671 842 (const char **) parameters); … … 674 845 675 846 if (!result_wrapper->xd) { 847 _XD_Wrapper_Dtor(result_wrapper); 676 848 RETURN_FALSE; 677 849 } … … 721 893 722 894 result_wrapper = XD_Wrapper_Alloc(); 895 result_wrapper->alloc_type = FASTXSL_PRMALLOC; 723 896 724 897 result_wrapper->xd = xsltProfileStylesheet(ss_wrapper->ss, xd_wrapper->xd, 725 898 (const char **) parameters, dbgprof); 726 727 899 if (parameters) 728 900 free(parameters); … … 731 903 732 904 if (!result_wrapper->xd) { 905 _XD_Wrapper_Dtor(result_wrapper); 733 906 RETURN_FALSE; 734 907 } … … 788 961 ZEND_FETCH_RESOURCE(xd_wrapper, php_xd_wrapper *, &z_xd_wrapper, -1, "FastXSL XML Document", 789 962 le_fastxsl_document); 790 963 Xml_UseAllocationFunctions(); 791 964 mm_lock(FASTXSL_G(cache)->mm, MM_LOCK_RD); 792 965 ss_wrapper = fl_hash_find(FASTXSL_G(cache)->table, ss_filename, ss_filename_len); 966 mm_unlock(FASTXSL_G(cache)->mm); 793 967 if (!ss_wrapper) { 794 mm_unlock(FASTXSL_G(cache)->mm);795 968 RETURN_FALSE; 796 969 } 970 ss_wrapper->hits++; 797 971 xsltSaveResultToString(&result, &length, xd_wrapper->xd, ss_wrapper->ss); 798 mm_unlock(FASTXSL_G(cache)->mm);799 972 if (result) { 800 973 RETVAL_STRINGL((char *) result, length, 1); 801 974 xmlFree(result); 802 975 } else { 803 RETURN_FALSE; 804 } 976 RETVAL_FALSE; 977 } 978 Xml_UseAllocationFunctions(); 805 979 } 806 980 #endif … … 830 1004 RETURN_FALSE; 831 1005 } 1006 ss_wrapper->hits++; 832 1007 xsltSaveResultToString(&result, &length, xd_wrapper->xd, ss_wrapper->ss); 833 1008 … … 849 1024 PHP_FE(fastxsl_shmcache_tostring, NULL) 850 1025 PHP_FE(fastxsl_shmcache_getstatistics, NULL) 1026 PHP_FE(fastxsl_xmlMemoryDump, NULL) 851 1027 #endif 852 1028 PHP_FE(fastxsl_prmcache_transform, NULL) … … 867 1043 fastxsl_functions, 868 1044 PHP_MINIT(fastxsl), 869 NULL,870 NULL,871 NULL,1045 PHP_MSHUTDOWN(fastxsl), 1046 PHP_RINIT(fastxsl), 1047 PHP_RSHUTDOWN(fastxsl), 872 1048 PHP_MINFO(fastxsl), 873 1049 #if ZEND_MODULE_API_NO >= 20010901 … … 883 1059 884 1060 static void 1061 _SS_Wrapper_Dtor(php_ss_wrapper *wrapper) 1062 { 1063 if(wrapper->ss) { 1064 if(wrapper->alloc_type == FASTXSL_SHMALLOC) { 1065 //xmlCleanupParserr(); 1066 ShmCache_UseAllocationFunctions(); 1067 } else { 1068 Xml_UseAllocationFunctions(); 1069 } 1070 inshm = 1; 1071 xsltFreeStylesheet(wrapper->ss); 1072 inshm = 0; 1073 if(wrapper->alloc_type == FASTXSL_SHMALLOC) { 1074 //xmlCleanupParserr(); 1075 Xml_UseAllocationFunctions(); 1076 } 1077 } 1078 if(wrapper->persistant) { 1079 mm_free(FASTXSL_G(cache)->mm, wrapper); 1080 } else { 1081 free(wrapper); 1082 } 1083 } 1084 1085 static void 885 1086 SS_Wrapper_Dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) 886 1087 { 887 1088 php_ss_wrapper *wrapper = (php_ss_wrapper *) rsrc->ptr; 888 889 1089 if (wrapper->persistant) { 890 1090 return; 891 1091 } 892 893 if (wrapper->ss) 894 xsltFreeStylesheet(wrapper->ss); 895 1092 _SS_Wrapper_Dtor(wrapper); 1093 } 1094 1095 static void _XD_Wrapper_Dtor(php_xd_wrapper *wrapper) { 1096 if (wrapper->xd) { 1097 if(wrapper->alloc_type == FASTXSL_SHMALLOC) { 1098 ShmCache_UseAllocationFunctions(); 1099 } else { 1100 Xml_UseAllocationFunctions(); 1101 } 1102 inshm = 1; 1103 xmlFreeDoc(wrapper->xd); 1104 inshm = 0; 1105 Xml_UseAllocationFunctions(); 1106 } 896 1107 free(wrapper); 897 1108 } … … 901 1112 { 902 1113 php_xd_wrapper *wrapper = (php_xd_wrapper *) rsrc->ptr; 903 904 if (wrapper->xd) 905 xmlFreeDoc(wrapper->xd); 906 free(wrapper); 1114 _XD_Wrapper_Dtor(wrapper); 907 1115 } 908 1116 … … 982 1190 983 1191 globals->cache = calloc(1, sizeof(fl_cache)); 1192 //pool_init(globals); 984 1193 } 985 1194 … … 995 1204 return; 996 1205 } 997 #ifdef FASTXSL_MM998 mm_lock(cache->mm, MM_LOCK_RW);999 fl_hash_free(cache->table);1000 mm_unlock(cache->mm);1001 1002 mm_destroy(cache->mm);1003 #endif1004 1206 fl_hash_free(cache->prmtable); 1005 1207 } 1208 if(globals->pool) { free(globals->pool); } 1006 1209 } 1007 1210 … … 1022 1225 1023 1226 tctxt = (xsltTransformContextPtr) xsltXPathGetTransformContext(ctxt); 1227 ////xmlCleanupParserr(); 1024 1228 if (tctxt == NULL) { 1025 1229 xsltGenericError(xsltGenericErrorContext, … … 1137 1341 le_fastxsl_document = zend_register_list_destructors_ex(XD_Wrapper_Dtor, NULL, 1138 1342 le_fastxsl_document_name, module_number); 1139 1343 #ifdef FASTXSL_MM 1344 if (!sprintf(euid, "%d", geteuid())) { 1345 return FAILURE; 1346 } 1347 1348 shmpath_len = strlen(FASTXSL_G(shmpath)) + strlen(euid); 1349 shmpath = do_alloca(shmpath_len + 1); 1350 1351 strcpy(shmpath, FASTXSL_G(shmpath)); 1352 strcat(shmpath, euid); 1353 1354 FASTXSL_G(cache)->owner = getpid(); 1355 FASTXSL_G(cache)->mm = mm_create(0, shmpath); 1356 free_alloca(shmpath); 1357 if (!FASTXSL_G(cache)->mm) { 1358 return FAILURE; 1359 } 1360 1361 mm_lock(FASTXSL_G(cache)->mm, MM_LOCK_RW); 1362 FASTXSL_G(cache)->table = fl_hash_new(&mm_allocators, NULL); 1363 mm_unlock(FASTXSL_G(cache)->mm); 1364 #endif 1365 FASTXSL_G(cache)->prmtable = fl_hash_new(&normal_allocators, NULL); 1366 //xmlGcMemGet(&free_ptr, &malloc_ptr, &mallocatomic_ptr, &realloc_ptr, &strdup_ptr); 1367 xmlMemGet(&free_ptr, &malloc_ptr, &realloc_ptr, &strdup_ptr); 1368 //xmlCleanupParserr(); 1369 ShmCache_UseAllocationFunctions(); 1370 inshm = 1; 1140 1371 xsltRegisterAllExtras(); 1141 1372 #if HAVE_DOMEXSLT … … 1145 1376 xmlLoadExtDtdDefaultValue = 1; 1146 1377 1147 xmlMemGet(&free_ptr, &malloc_ptr, &realloc_ptr, &strdup_ptr);1148 1378 xmlRegisterOutputCallbacks(Stream_MatchWrapper, Stream_XmlWrite_OpenWrapper, 1149 1379 Stream_XmlWrite_WriteWrapper, Stream_CloseWrapper); 1150 1380 xsltSetGenericErrorFunc(NULL, fastxsl_errorfunc); 1151 1381 xmlSetGenericErrorFunc(NULL, fastxsl_errorfunc); 1152 #ifdef FASTXSL_MM1153 if (!sprintf(euid, "%d", geteuid())) {1154 return FAILURE;1155 }1156 1157 shmpath_len = strlen(FASTXSL_G(shmpath)) + strlen(euid);1158 shmpath = do_alloca(shmpath_len + 1);1159 1160 strcpy(shmpath, FASTXSL_G(shmpath));1161 strcat(shmpath, euid);1162 1163 FASTXSL_G(cache)->owner = getpid();1164 FASTXSL_G(cache)->mm = mm_create(0, shmpath);1165 1166 free_alloca(shmpath);1167 if (!FASTXSL_G(cache)->mm) {1168 return FAILURE;1169 }1170 1171 mm_lock(FASTXSL_G(cache)->mm, MM_LOCK_RW);1172 FASTXSL_G(cache)->table = fl_hash_new(&mm_allocators, NULL);1173 mm_unlock(FASTXSL_G(cache)->mm);1174 #endif1175 FASTXSL_G(cache)->prmtable = fl_hash_new(&normal_allocators, NULL);1176 1382 1177 1383 if(FASTXSL_G(register_functions)) { … … 1180 1386 fastxsl_ext_function); 1181 1387 } 1388 //xmlCleanupParserr(); 1389 inshm = 0; 1390 Xml_UseAllocationFunctions(); 1182 1391 return SUCCESS; 1392 } 1393 1394 PHP_MSHUTDOWN_FUNCTION(fastxsl) 1395 { 1396 UNREGISTER_INI_ENTRIES(); 1397 } 1398 PHP_RINIT_FUNCTION(fastxsl) 1399 { 1400 #ifdef FASTXSL_MM 1401 /* just in case, set back the allocators */ 1402 Xml_UseAllocationFunctions(); 1403 #endif 1404 } 1405 PHP_RSHUTDOWN_FUNCTION(fastxsl) 1406 { 1407 #ifdef FASTXSL_MM 1408 /* just in case, set back the allocators */ 1409 Xml_UseAllocationFunctions(); 1410 #endif 1183 1411 } 1184 1412 trunk/fl_hash.c
r17 r18 74 74 FL_Bucket *b; 75 75 unsigned int hash = hash_hash(key, length) % FL_HASH_SIZE; 76 77 76 for (b = table->buckets[ hash ]; b; b = b->next) { 78 77 if (hash != b->hash) continue; 79 78 if (length != b->length) continue; 80 79 if (memcmp(key, b->key, length)) continue; 81 82 80 return b->data; 83 81 } … … 86 84 } 87 85 88 voidfl_hash_add(FL_Hash *table, char *key, int length, void *data)86 int fl_hash_add(FL_Hash *table, char *key, int length, void *data) 89 87 { 90 FL_Bucket *b ;88 FL_Bucket *b, *ptr; 91 89 unsigned int hash; 92 90 93 91 hash = hash_hash(key, length) % FL_HASH_SIZE; 92 /* check hash for dupes */ 93 ptr = table->buckets[ hash ]; 94 while(ptr) { 95 if(!strcmp(ptr->key, key)) { 96 return 0; 97 } 98 ptr = ptr->next; 99 } 94 100 95 101 b = table->mems->malloc_func(sizeof(FL_Bucket)); … … 100 106 b->hash = hash; 101 107 b->data = data; 102 103 108 b->next = table->buckets[ hash ]; 104 109 105 110 table->buckets[ hash ] = b; 106 111 table->nElements++; 112 return 1; 107 113 } 108 114 trunk/fl_hash.h
r1 r18 53 53 void fl_hash_free(FL_Hash *table); 54 54 void *fl_hash_find(FL_Hash *table, const void *key, int length); 55 voidfl_hash_add(FL_Hash *table, char *key, int length, void *data);55 int fl_hash_add(FL_Hash *table, char *key, int length, void *data); 56 56 void fl_hash_delete(FL_Hash *table, char *key, int length); 57 57 #endif trunk/php_fastxsl.h
r11 r18 65 65 PHP_MINIT_FUNCTION(fastxsl); 66 66 PHP_MSHUTDOWN_FUNCTION(fastxsl); 67 PHP_RINIT_FUNCTION(fastxsl); 68 PHP_RSHUTDOWN_FUNCTION(fastxsl); 67 69 PHP_MINFO_FUNCTION(fastxsl); 70 71 #define FASTXSL_PRMALLOC 0 72 #define FASTXSL_SHMALLOC 1 68 73 69 74 typedef struct { … … 78 83 typedef struct { 79 84 xmlDocPtr xd; 85 int alloc_type; 80 86 } php_xd_wrapper; 81 87 … … 84 90 int allocsize; 85 91 time_t mtime; 92 int hits; 86 93 int persistant; 94 int alloc_type; 87 95 } php_ss_wrapper; 88 96 … … 94 102 long register_functions; 95 103 long tmp_allocated_size; 104 void ***pool; 105 int *pool_offset; 106 int *pool_allocd; 96 107 } zend_fastxsl_globals; 97 108
