]> granicus.if.org Git - php/commitdiff
Change indexing scheme for symtable_cache
authorNikita Popov <nikita.ppv@gmail.com>
Thu, 20 Jun 2019 08:52:18 +0000 (10:52 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Thu, 20 Jun 2019 14:21:39 +0000 (16:21 +0200)
symtable_cache_ptr now points to the first unused symtable_cache
entry, rahter than the last used one. This avoids taking a pointer
to the minus first element of the array, which is UB. Instead we
take a pointer to the end plus one, which is not UB.

Zend/zend_execute.c
Zend/zend_execute_API.c
Zend/zend_globals.h

index 5588ada56aa108204846fe64b9850b7fe9b4ec95..95a63e9bcf2691d3034fe9a6cf6e97e0accd481c 100644 (file)
@@ -3337,7 +3337,7 @@ ZEND_API void zend_clean_and_cache_symbol_table(zend_array *symbol_table) /* {{{
                /* clean before putting into the cache, since clean
                   could call dtors, which could use cached hash */
                zend_symtable_clean(symbol_table);
-               *(++EG(symtable_cache_ptr)) = symbol_table;
+               *(EG(symtable_cache_ptr)++) = symbol_table;
        }
 }
 /* }}} */
index e0cc560d4bed1d9737bd935e2980df4f5eee7ed6..4117b48baffb77bb7676c11aae1f568f532a9a76 100644 (file)
@@ -132,8 +132,8 @@ void init_executor(void) /* {{{ */
        original_sigsegv_handler = signal(SIGSEGV, zend_handle_sigsegv);
 #endif
 
-       EG(symtable_cache_ptr) = EG(symtable_cache) - 1;
-       EG(symtable_cache_limit) = EG(symtable_cache) + SYMTABLE_CACHE_SIZE - 1;
+       EG(symtable_cache_ptr) = EG(symtable_cache);
+       EG(symtable_cache_limit) = EG(symtable_cache) + SYMTABLE_CACHE_SIZE;
        EG(no_extensions) = 0;
 
        EG(function_table) = CG(function_table);
@@ -400,10 +400,10 @@ void shutdown_executor(void) /* {{{ */
 
                zend_cleanup_internal_classes();
 
-               while (EG(symtable_cache_ptr)>=EG(symtable_cache)) {
+               while (EG(symtable_cache_ptr) > EG(symtable_cache)) {
+                       EG(symtable_cache_ptr)--;
                        zend_hash_destroy(*EG(symtable_cache_ptr));
                        FREE_HASHTABLE(*EG(symtable_cache_ptr));
-                       EG(symtable_cache_ptr)--;
                }
 
                zend_hash_destroy(&EG(included_files));
@@ -1476,9 +1476,8 @@ ZEND_API zend_array *zend_rebuild_symbol_table(void) /* {{{ */
        }
 
        ZEND_ADD_CALL_FLAG(ex, ZEND_CALL_HAS_SYMBOL_TABLE);
-       if (EG(symtable_cache_ptr) >= EG(symtable_cache)) {
-               /*printf("Cache hit!  Reusing %x\n", symtable_cache[symtable_cache_ptr]);*/
-               symbol_table = ex->symbol_table = *(EG(symtable_cache_ptr)--);
+       if (EG(symtable_cache_ptr) > EG(symtable_cache)) {
+               symbol_table = ex->symbol_table = *(--EG(symtable_cache_ptr));
                if (!ex->func->op_array.last_var) {
                        return symbol_table;
                }
index d88fdabcf7f2cd4f36abdf28f094932f14c66bf4..a64e4beac2a70a7a5a938e127f93400650265584 100644 (file)
@@ -136,7 +136,9 @@ struct _zend_executor_globals {
 
        /* symbol table cache */
        zend_array *symtable_cache[SYMTABLE_CACHE_SIZE];
+       /* Pointer to one past the end of the symtable_cache */
        zend_array **symtable_cache_limit;
+       /* Pointer to first unused symtable_cache slot */
        zend_array **symtable_cache_ptr;
 
        zend_array symbol_table;                /* main symbol table */