diff options
author | Michael Meskes <meskes@postgresql.org> | 2003-03-16 10:42:54 +0000 |
---|---|---|
committer | Michael Meskes <meskes@postgresql.org> | 2003-03-16 10:42:54 +0000 |
commit | a4f25b6a9c2dbf5f38e498922e3761cb3bf46ba0 (patch) | |
tree | 54ff23d698b18c898c8fd7903df29b76e95df9fb /src/interfaces/ecpg/ecpglib/memory.c | |
parent | 48dfa0d057e0d9b2244ff1706dd72e91a0b45064 (diff) |
Started working on a seperate pgtypes library. First test work. PLEASE test compilation on iother systems.
Diffstat (limited to 'src/interfaces/ecpg/ecpglib/memory.c')
-rw-r--r-- | src/interfaces/ecpg/ecpglib/memory.c | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/src/interfaces/ecpg/ecpglib/memory.c b/src/interfaces/ecpg/ecpglib/memory.c new file mode 100644 index 00000000000..a94b293de45 --- /dev/null +++ b/src/interfaces/ecpg/ecpglib/memory.c @@ -0,0 +1,109 @@ +/* $Header: /cvsroot/pgsql/src/interfaces/ecpg/ecpglib/memory.c,v 1.1 2003/03/16 10:42:53 meskes Exp $ */ + +#include "postgres_fe.h" + +#include "ecpgtype.h" +#include "ecpglib.h" +#include "ecpgerrno.h" +#include "extern.h" + +void +ECPGfree(void *ptr) +{ + free(ptr); +} + +char * +ECPGalloc(long size, int lineno) +{ + char *new = (char *) calloc(1L, size); + + if (!new) + { + ECPGraise(lineno, ECPG_OUT_OF_MEMORY, NULL); + return NULL; + } + + memset(new, '\0', size); + return (new); +} + +char * +ECPGrealloc(void *ptr, long size, int lineno) +{ + char *new = (char *) realloc(ptr, size); + + if (!new) + { + ECPGraise(lineno, ECPG_OUT_OF_MEMORY, NULL); + return NULL; + } + + return (new); +} + +char * +ECPGstrdup(const char *string, int lineno) +{ + char *new = strdup(string); + + if (!new) + { + ECPGraise(lineno, ECPG_OUT_OF_MEMORY, NULL); + return NULL; + } + + return (new); +} + +/* keep a list of memory we allocated for the user */ +static struct auto_mem +{ + void *pointer; + struct auto_mem *next; +} *auto_allocs = NULL; + +void +ECPGadd_mem(void *ptr, int lineno) +{ + struct auto_mem *am = (struct auto_mem *) ECPGalloc(sizeof(struct auto_mem), lineno); + + am->pointer = ptr; + am->next = auto_allocs; + auto_allocs = am; +} + +void +ECPGfree_auto_mem(void) +{ + struct auto_mem *am; + + /* free all memory we have allocated for the user */ + for (am = auto_allocs; am;) + { + struct auto_mem *act = am; + + am = am->next; + ECPGfree(act->pointer); + ECPGfree(act); + } + + auto_allocs = NULL; +} + +void +ECPGclear_auto_mem(void) +{ + struct auto_mem *am; + + /* free just our own structure */ + for (am = auto_allocs; am;) + { + struct auto_mem *act = am; + + am = am->next; + ECPGfree(act); + } + + auto_allocs = NULL; +} |