From: Dmitry Stogov Date: Fri, 2 Mar 2018 08:02:21 +0000 (+0300) Subject: GC API cleanup X-Git-Tag: php-7.3.0alpha1~270^2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f844d40fdc3450e33a6c95d5d3486b239ea7f545;p=php GC API cleanup --- diff --git a/Zend/zend.c b/Zend/zend.c index a714f04786..d8ed9bcd35 100644 --- a/Zend/zend.c +++ b/Zend/zend.c @@ -113,7 +113,7 @@ static ZEND_INI_MH(OnUpdateGCEnabled) /* {{{ */ val = (zend_bool) atoi(ZSTR_VAL(new_value)); } - gc_set_enabled(val); + gc_enable(val); return SUCCESS; } @@ -1019,6 +1019,7 @@ ZEND_API ZEND_COLD void _zend_bailout(const char *filename, uint32_t lineno) /* zend_output_debug_string(1, "%s(%d) : Bailed out without a bailout address!", filename, lineno); exit(-1); } + gc_protect(1); CG(unclean_shutdown) = 1; CG(active_class_entry) = NULL; CG(in_compilation) = 0; diff --git a/Zend/zend_gc.c b/Zend/zend_gc.c index 26a60a68d9..7bc4b23560 100644 --- a/Zend/zend_gc.c +++ b/Zend/zend_gc.c @@ -368,7 +368,7 @@ static void gc_globals_ctor_ex(zend_gc_globals *gc_globals) #endif } -ZEND_API void gc_globals_ctor(void) +void gc_globals_ctor(void) { #ifdef ZTS ts_allocate_id(&gc_globals_id, sizeof(zend_gc_globals), (ts_allocate_ctor) gc_globals_ctor_ex, (ts_allocate_dtor) root_buffer_dtor); @@ -377,14 +377,14 @@ ZEND_API void gc_globals_ctor(void) #endif } -ZEND_API void gc_globals_dtor(void) +void gc_globals_dtor(void) { #ifndef ZTS root_buffer_dtor(&gc_globals); #endif } -ZEND_API void gc_reset(void) +void gc_reset(void) { if (GC_G(buf)) { GC_G(gc_active) = 0; @@ -408,7 +408,7 @@ ZEND_API void gc_reset(void) } } -ZEND_API zend_bool gc_set_enabled(zend_bool enable) +ZEND_API zend_bool gc_enable(zend_bool enable) { zend_bool old_enabled = GC_G(gc_enabled); GC_G(gc_enabled) = enable; @@ -426,6 +426,18 @@ ZEND_API zend_bool gc_enabled(void) return GC_G(gc_enabled); } +ZEND_API zend_bool gc_protect(zend_bool protect) +{ + zend_bool old_protected = GC_G(gc_protected); + GC_G(gc_protected) = protect; + return old_protected; +} + +ZEND_API zend_bool gc_protected(void) +{ + return GC_G(gc_protected); +} + static void gc_grow_root_buffer(void) { size_t new_size; @@ -433,11 +445,9 @@ static void gc_grow_root_buffer(void) if (GC_G(buf_size) >= GC_MAX_BUF_SIZE) { if (!GC_G(gc_full)) { zend_error(E_WARNING, "GC buffer overflow (GC disabled)\n"); - //???GC_G(gc_enabled) = 0; GC_G(gc_active) = 1; GC_G(gc_protected) = 1; GC_G(gc_full) = 1; - CG(unclean_shutdown) = 1; return; } } @@ -530,7 +540,7 @@ ZEND_API void ZEND_FASTCALL gc_possible_root(zend_refcounted *ref) uint32_t addr; gc_root_buffer *newRoot; - if (UNEXPECTED(GC_G(gc_protected)) || UNEXPECTED(CG(unclean_shutdown))) { + if (UNEXPECTED(GC_G(gc_protected))) { return; } @@ -1354,6 +1364,11 @@ ZEND_API int zend_gc_collect_cycles(void) } pefree(refcounts, 1); + + if (GC_G(gc_protected)) { + /* something went wrong */ + return 0; + } } /* Destroy zvals */ diff --git a/Zend/zend_gc.h b/Zend/zend_gc.h index cf327e2d06..9328e2c59c 100644 --- a/Zend/zend_gc.h +++ b/Zend/zend_gc.h @@ -27,14 +27,22 @@ ZEND_API extern int (*gc_collect_cycles)(void); ZEND_API void ZEND_FASTCALL gc_possible_root(zend_refcounted *ref); ZEND_API void ZEND_FASTCALL gc_remove_from_buffer(zend_refcounted *ref); -ZEND_API void gc_globals_ctor(void); -ZEND_API void gc_globals_dtor(void); -ZEND_API void gc_reset(void); -ZEND_API zend_bool gc_set_enabled(zend_bool enable); + +/* enable/disable automatic start of GC collection */ +ZEND_API zend_bool gc_enable(zend_bool enable); ZEND_API zend_bool gc_enabled(void); +/* enable/disable possible root additions */ +ZEND_API zend_bool gc_protect(zend_bool protect); +ZEND_API zend_bool gc_protected(void); + /* The default implementation of the gc_collect_cycles callback. */ ZEND_API int zend_gc_collect_cycles(void); + +void gc_globals_ctor(void); +void gc_globals_dtor(void); +void gc_reset(void); + END_EXTERN_C() #define GC_REMOVE_FROM_BUFFER(p) do { \