--- parser3/src/include/pa_memory.h 2017/12/03 23:36:23 1.35 +++ parser3/src/include/pa_memory.h 2023/09/26 20:49:07 1.44 @@ -1,15 +1,15 @@ /** @file Parser: memory reference counting classes decls. - Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com) + Copyright (c) 2001-2023 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.35 2017/12/03 23:36:23 moko Exp $" +#define IDENT_PA_MEMORY_H "$Id: pa_memory.h,v 1.44 2023/09/26 20:49:07 moko Exp $" // include @@ -19,7 +19,7 @@ // define destructors use for Array, Hash and VMethodFrame #define USE_DESTRUCTORS -// std::basic_stringstream used in ^table.csv-string[] is compatible with delete usage check only under Debian 9 +// std::basic_stringstream used in ^table.csv-string[] is compatible with delete usage check only under Debian 9/10, FreeBSD 12 // #define CHECK_DELETE_USAGE // forwards @@ -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,14 +113,16 @@ typedef PA_Allocated PA_Object; #define PA_THROW(what) throw(what) #endif -#ifndef _MSC_VER +#if !defined(_MSC_VER) && !defined(FREEBSD1X) // 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(); inline void *operator new[] (std::size_t) PA_THROW(std::bad_alloc){ return new_disabled(); } inline void operator delete[](void *) throw(){ delete_disabled(); } +inline void operator delete[](void *, std::size_t) throw(){ delete_disabled(); } inline void *operator new(std::size_t) PA_THROW(std::bad_alloc){ return new_disabled(); } #ifdef CHECK_DELETE_USAGE @@ -144,4 +147,7 @@ inline char *strdup(const char*, size_t) #endif // _MSC_VER +void pa_gc_collect(bool forced=false); +void pa_gc_set_free_space_divisor(int); + #endif