]> granicus.if.org Git - php/commitdiff
GC API cleanup
authorDmitry Stogov <dmitry@zend.com>
Fri, 2 Mar 2018 08:02:21 +0000 (11:02 +0300)
committerDmitry Stogov <dmitry@zend.com>
Fri, 2 Mar 2018 08:02:21 +0000 (11:02 +0300)
Zend/zend.c
Zend/zend_gc.c
Zend/zend_gc.h

index a714f04786ec3c032fadad16f03a95a8a79faa8f..d8ed9bcd35111c98251b125aa0b71b90d48515a2 100644 (file)
@@ -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;
index 26a60a68d9acab9143ee6d273afcc9273aaf6969..7bc4b235603cc46cdf0522c66037a5c4586c5f9d 100644 (file)
@@ -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 */
index cf327e2d063db8986f4b8b7a186469da68d80be6..9328e2c59cedb910c335f9d30b1ccd1668917520 100644 (file)
@@ -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 { \