--- parser3/src/include/pa_memory.h 2025/12/08 01:15:39 1.46 +++ parser3/src/include/pa_memory.h 2026/10/18 22:42:42 1.48 @@ -1,7 +1,7 @@ /** @file Parser: memory reference counting classes decls. - Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com) Authors: Konstantin Morshnev , Alexandr Petrosian */ @@ -9,7 +9,7 @@ #ifndef PA_MEMORY_H #define PA_MEMORY_H -#define IDENT_PA_MEMORY_H "$Id: pa_memory.h,v 1.46 2025/12/08 01:15:39 moko Exp $" +#define IDENT_PA_MEMORY_H "$Id: pa_memory.h,v 1.48 2026/10/18 22:42:42 moko Exp $" // include @@ -155,4 +155,26 @@ inline char *strdup(const char*, size_t) void pa_gc_collect(bool forced=false); void pa_gc_set_free_space_divisor(int); +class String; + +/** + Keeps the pointer GC does not see and returns it. The first case is the exception: C++ runtime keeps the exception in flight + in malloc memory, which GC does not scan. To avoid collection, exception fields are passed through pa_gc_reference(). +*/ + +const String* pa_gc_reference(const String*); +const char* pa_gc_reference(const char*); + +/// for the pointers GC does not see: should be created on the stack at the very start of every thread and live until its end +class Temp_gc_references { + enum { SIZE=32 }; + const void* items[SIZE]; + unsigned index; + Temp_gc_references* previous; +public: + Temp_gc_references(); + ~Temp_gc_references(); + void keep(const void* data) { items[index++ % SIZE]=data; } +}; + #endif