Diff for /parser3/src/include/pa_memory.h between versions 1.33 and 1.47

version 1.33, 2017/11/16 22:50:25 version 1.47, 2026/04/25 13:38:46
Line 1 Line 1
 /** @file  /** @file
         Parser: memory reference counting classes decls.          Parser: memory reference counting classes decls.
   
         Copyright (c) 2001-2017 Art. Lebedev Studio (http://www.artlebedev.com)          Copyright (c) 2001-2026 Art. Lebedev Studio (https://www.artlebedev.com)
   
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Authors: Konstantin Morshnev <moko@design.ru>, Alexandr Petrosian <paf@design.ru>
 */  */
   
 #ifndef PA_MEMORY_H  #ifndef PA_MEMORY_H
Line 14 Line 14
 // include  // include
   
 #include "pa_config_includes.h"  #include "pa_config_includes.h"
 #include "gc.h"  
 #include <new>  #include <new>
   
 // define destructors use for Array, Hash and VMethodFrame  // define destructors use for Array, Hash and VMethodFrame
 #define USE_DESTRUCTORS  #define USE_DESTRUCTORS
 // std::basic_stringstream used in ^table.csv-string[] is compatible with delete usage check only under Debian 9  
 // #define CHECK_DELETE_USAGE  
   
 inline void* pa_gc_malloc(size_t size) { return GC_MALLOC(size); }  // std::basic_stringstream used in ^table.csv-string[] is compatible with delete usage check only under Debian 9/10, FreeBSD 12
 inline void* pa_gc_malloc_atomic(size_t size) { return GC_MALLOC_ATOMIC(size); }  // #define CHECK_DELETE_USAGE
 inline void* pa_gc_realloc(void* ptr, size_t size) { return GC_REALLOC(ptr, size); }  
 inline void pa_gc_free(void* ptr) { GC_FREE(ptr); }  
   
 // forwards  // forwards
   
Line 34  void *pa_fail_alloc(const char* what, si Line 29  void *pa_fail_alloc(const char* what, si
 // inlines  // inlines
   
 inline void *pa_malloc(size_t size) {  inline void *pa_malloc(size_t size) {
         if(void *result=pa_gc_malloc(size))          if(void *result=GC_MALLOC(size))
                 return result;                  return result;
   
         return pa_fail_alloc("allocate", size);          return pa_fail_alloc("allocate", size);
 }  }
   
 inline void *pa_malloc_atomic(size_t size) {  inline void *pa_malloc_atomic(size_t size) {
         if(void *result=pa_gc_malloc_atomic(size))          if(void *result=GC_MALLOC_ATOMIC(size))
                 return result;                  return result;
   
         return pa_fail_alloc("allocate clean", size);          return pa_fail_alloc("allocate clean", size);
 }  }
   
 /// @a length may be null, which mean "autocalc it"  /// length may be zero, and this is normal
 inline char *pa_strdup(const char* auto_variable_never_null, size_t helper_length=0) {  inline char *pa_strdup(const char* auto_variable_never_null, size_t known_length) {
         size_t known_length= helper_length ? helper_length : strlen(auto_variable_never_null);          if(char *result=static_cast<char*>(GC_MALLOC_ATOMIC(known_length+1))) {
   
         size_t size=known_length+1;  
         if(char *result=static_cast<char*>(pa_gc_malloc_atomic(size))) {  
                 memcpy(result, auto_variable_never_null, known_length);                  memcpy(result, auto_variable_never_null, known_length);
                 result[known_length]=0;                  result[known_length]=0;
                 return result;                  return result;
         }          }
   
         return static_cast<char*>(pa_fail_alloc("allocate clean", size));          return static_cast<char*>(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) {  inline void pa_free(void *ptr) {
         pa_gc_free(ptr);          GC_FREE(ptr);
 }  }
   
 inline void *pa_realloc(void *ptr, size_t size) {  inline void *pa_realloc(void *ptr, size_t size) {
         if(void *result=pa_gc_realloc(ptr, size))          if(void *result=GC_REALLOC(ptr, size))
                 return result;                  return result;
   
         return pa_fail_alloc("reallocate to", size);          return pa_fail_alloc("reallocate to", size);
Line 117  typedef PA_Allocated PA_Object; Line 113  typedef PA_Allocated PA_Object;
 #define PA_THROW(what) throw(what)  #define PA_THROW(what) throw(what)
 #endif  #endif
   
 #ifndef _MSC_VER  #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  // regular new/delete are disabled from accidental use
   
 void *new_disabled();  void *new_disabled();
 void delete_disabled();  void delete_disabled();
   
 inline void *operator new[] (std::size_t size) PA_THROW(std::bad_alloc){ return new_disabled(); }  inline void *operator new[] (std::size_t) PA_THROW(std::bad_alloc){ return new_disabled(); }
 inline void operator delete[](void *ptr) throw(){ delete_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 size) PA_THROW(std::bad_alloc){ return new_disabled(); }  inline void *operator new(std::size_t) PA_THROW(std::bad_alloc){ return new_disabled(); }
 #ifdef CHECK_DELETE_USAGE  #ifdef CHECK_DELETE_USAGE
 inline void operator delete(void *ptr) throw(){ delete_disabled(); }  inline void operator delete(void *) throw(){ delete_disabled(); }
 #endif  #endif
   
   #ifndef PA_DEBUG_DISABLE_GC
 // other regular allocators as disabled from accidental use as well  // other regular allocators as disabled from accidental use as well
   
 void *calloc_disabled();  void *calloc_disabled();
Line 145  inline void *malloc(size_t) { return mal Line 148  inline void *malloc(size_t) { return mal
 inline void *realloc(void *, size_t) { return realloc_disabled(); }  inline void *realloc(void *, size_t) { return realloc_disabled(); }
 inline void free(void *) { free_disabled(); }  inline void free(void *) { free_disabled(); }
 inline char *strdup(const char*, size_t){ return strdup_disabled(); }  inline char *strdup(const char*, size_t){ return strdup_disabled(); }
   #endif // PA_DEBUG_DISABLE_GC
   
 #endif  #endif // _MSC_VER
   
   void pa_gc_collect(bool forced=false);
   void pa_gc_set_free_space_divisor(int);
   
 #endif  #endif

Removed from v.1.33  
changed lines
  Added in v.1.47


E-mail: