diff --git a/include/gc/gc.h b/include/gc/gc.h index b985caa4d..ad2f054c4 100644 --- a/include/gc/gc.h +++ b/include/gc/gc.h @@ -1492,6 +1492,13 @@ GC_API int GC_CALL GC_invoke_finalizers(void); /* analysis. */ GC_API void GC_CALL GC_noop1(GC_word); +/* Explicitly tell the collector that an object is reachable */ +/* at a particular program point. This prevents the argument */ +/* pointer from being optimized away, even it is otherwise no */ +/* longer needed. Used to prevent finalizers from running when */ +/* the associated object is still in use. */ +GC_API void GC_CALL GC_keep_alive(GC_word); + /* Same as GC_noop1() but for a pointer. */ GC_API void GC_CALL GC_noop1_ptr(volatile void *); diff --git a/mark.c b/mark.c index 2d1280ca0..ce353e561 100644 --- a/mark.c +++ b/mark.c @@ -60,6 +60,11 @@ GC_API void GC_CALL GC_noop1_ptr(volatile void *p) # endif } +GC_API void GC_keep_alive(GC_word x) +{ + GC_reachable_here(x); +} + /* Initialize GC_obj_kinds properly and standard free lists properly. */ /* This must be done statically since they may be accessed before */ /* GC_init is called. It is done here, since we need to deal with mark */