--- parser3/src/include/pa_memory.h 2023/09/26 20:49:07 1.44 +++ 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-2023 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.44 2023/09/26 20:49:07 moko Exp $" +#define IDENT_PA_MEMORY_H "$Id: pa_memory.h,v 1.48 2026/10/18 22:42:42 moko Exp $" // include @@ -113,9 +113,14 @@ typedef PA_Allocated PA_Object; #define PA_THROW(what) throw(what) #endif -#if !defined(_MSC_VER) && !defined(FREEBSD1X) +#if defined(_MSC_VER) || defined(FREEBSD1X) || defined(__APPLE__) +// no checks for FreeBSD1X.X and OS X due to https://bugs.llvm.org/show_bug.cgi?id=40161 bug +#define PA_CHECK_REGULAR_ALLOC_UNAVAILABLE +#endif + +// #define PA_CHECK_REGULAR_ALLOC_UNAVAILABLE +#if !defined(PA_CHECK_REGULAR_ALLOC_UNAVAILABLE) // regular new/delete are disabled from accidental use -// no checks for FreeBSD1X.X due to https://bugs.llvm.org/show_bug.cgi?id=40161 bug void *new_disabled(); void delete_disabled(); @@ -150,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