summaryrefslogtreecommitdiff
path: root/support/util/newalloc.h
diff options
context:
space:
mode:
authorXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
committerXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
commit268a53de823a6750d6256ee1fb1e7707b4b45740 (patch)
tree42c1799a9a82b2f7d9790ee9fe181d72a7274751 /support/util/newalloc.h
downloadsdcc-gas-268a53de823a6750d6256ee1fb1e7707b4b45740.tar.gz
sdcc-3.9.0 fork implementing GNU assembler syntax
This fork aims to provide better support for stm8-binutils
Diffstat (limited to 'support/util/newalloc.h')
-rw-r--r--support/util/newalloc.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/support/util/newalloc.h b/support/util/newalloc.h
new file mode 100644
index 0000000..4da6932
--- /dev/null
+++ b/support/util/newalloc.h
@@ -0,0 +1,99 @@
+/*-------------------------------------------------------------------------
+ newalloc.h - SDCC Memory allocation functions
+
+ These functions are wrappers for the standard malloc, realloc and free
+ functions.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published by the
+ Free Software Foundation; either version 2, or (at your option) any
+ later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+-------------------------------------------------------------------------*/
+
+#if !defined(_NewAlloc_H)
+
+#define _NewAlloc_H
+
+#include <memory.h>
+
+typedef struct _allocTrace
+{
+ int num;
+ int max;
+ void **palloced;
+} allocTrace;
+
+/*
+-------------------------------------------------------------------------------
+Clear_realloc - Reallocate a memory block and clear any memory added with
+out of memory error detection
+
+-------------------------------------------------------------------------------
+*/
+
+void *Clear_realloc (void *OldPtr, size_t OldSize, size_t NewSize);
+
+/*
+-------------------------------------------------------------------------------
+Safe_realloc - Reallocate a memory block with out of memory error detection
+
+-------------------------------------------------------------------------------
+*/
+
+void *Safe_realloc (void *OldPtr, size_t NewSize);
+
+/*
+-------------------------------------------------------------------------------
+Safe_calloc - Allocate a block of memory from the application heap, clearing
+all data to zero and checking for out or memory errors.
+
+-------------------------------------------------------------------------------
+*/
+
+void *Safe_calloc (size_t Elements, size_t Size);
+
+/*
+-------------------------------------------------------------------------------
+Safe_malloc - Allocate a block of memory from the application heap
+and checking for out or memory errors.
+
+-------------------------------------------------------------------------------
+*/
+
+void *Safe_malloc (size_t Size);
+
+/** Replacement for Safe_malloc that also zeros memory. To make it interchangable.
+ */
+void *Safe_alloc (size_t Size);
+
+/** Function to make the replacements complete.
+ */
+void Safe_free (void *p);
+
+/** Creates a copy of a string with specified length in a safe way.
+ */
+char *Safe_strndup (const char *sz, size_t len);
+
+/** Creates a copy of a string in a safe way.
+ */
+char *Safe_strdup (const char *sz);
+
+/** Logs the allocated memory 'p' in the given trace for batch freeing
+ later using freeTrace.
+*/
+void *traceAlloc (allocTrace * ptrace, void *p);
+
+/** Frees all the memory logged in the trace and resets the trace.
+ */
+void freeTrace (allocTrace * ptrace);
+
+#endif