--- parser3/src/include/pa_memory.h 2020/12/15 17:10:31 1.41 +++ parser3/src/include/pa_memory.h 2025/12/08 01:15:39 1.46 @@ -1,15 +1,15 @@ /** @file Parser: memory reference counting classes decls. - Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2024 Art. Lebedev Studio (http://www.artlebedev.com) - Author: Alexandr Petrosian (http://paf.design.ru) + Authors: Konstantin Morshnev , Alexandr Petrosian */ #ifndef PA_MEMORY_H #define PA_MEMORY_H -#define IDENT_PA_MEMORY_H "$Id: pa_memory.h,v 1.41 2020/12/15 17:10:31 moko Exp $" +#define IDENT_PA_MEMORY_H "$Id: pa_memory.h,v 1.46 2025/12/08 01:15:39 moko Exp $" // include @@ -42,18 +42,19 @@ inline void *pa_malloc_atomic(size_t siz return pa_fail_alloc("allocate clean", size); } -/// @a length may be null, which mean "autocalc it" -inline char *pa_strdup(const char* auto_variable_never_null, size_t helper_length=0) { - size_t known_length= helper_length ? helper_length : strlen(auto_variable_never_null); - - size_t size=known_length+1; - if(char *result=static_cast(GC_MALLOC_ATOMIC(size))) { +/// length may be zero, and this is normal +inline char *pa_strdup(const char* auto_variable_never_null, size_t known_length) { + if(char *result=static_cast(GC_MALLOC_ATOMIC(known_length+1))) { memcpy(result, auto_variable_never_null, known_length); result[known_length]=0; return result; } - return static_cast(pa_fail_alloc("allocate clean", size)); + return static_cast(pa_fail_alloc("allocate clean", known_length+1)); +} + +inline char *pa_strdup(const char* auto_variable_never_null) { + return pa_strdup(auto_variable_never_null, strlen(auto_variable_never_null)); } inline void pa_free(void *ptr) { @@ -112,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(); @@ -146,10 +152,7 @@ inline char *strdup(const char*, size_t) #endif // _MSC_VER -#ifdef PA_DEBUG_DISABLE_GC -#define PA_GC_GCOLLECT -#else -#define PA_GC_GCOLLECT { GC_enable(); GC_gcollect(); GC_disable(); } -#endif +void pa_gc_collect(bool forced=false); +void pa_gc_set_free_space_divisor(int); #endif