PostgreSQL Source Code  git master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
memory.c File Reference
#include "postgres_fe.h"
#include "ecpg-pthread-win32.h"
#include "ecpgtype.h"
#include "ecpglib.h"
#include "ecpgerrno.h"
#include "extern.h"
Include dependency graph for memory.c:

Go to the source code of this file.

Data Structures

struct  auto_mem
 

Macros

#define POSTGRES_ECPG_INTERNAL
 
#define get_auto_allocs()   (auto_allocs)
 
#define set_auto_allocs(am)   do { auto_allocs = (am); } while(0)
 

Functions

void ecpg_free (void *ptr)
 
char * ecpg_alloc (long size, int lineno)
 
char * ecpg_realloc (void *ptr, long size, int lineno)
 
char * ecpg_strdup (const char *string, int lineno)
 
char * ecpg_auto_alloc (long size, int lineno)
 
bool ecpg_add_mem (void *ptr, int lineno)
 
void ECPGfree_auto_mem (void)
 
void ecpg_clear_auto_mem (void)
 

Variables

static struct auto_memauto_allocs = NULL
 

Macro Definition Documentation

#define get_auto_allocs ( )    (auto_allocs)

Definition at line 103 of file memory.c.

Referenced by ecpg_add_mem(), ecpg_clear_auto_mem(), and ECPGfree_auto_mem().

#define POSTGRES_ECPG_INTERNAL

Definition at line 3 of file memory.c.

#define set_auto_allocs (   am)    do { auto_allocs = (am); } while(0)

Definition at line 104 of file memory.c.

Referenced by ecpg_add_mem(), ecpg_clear_auto_mem(), and ECPGfree_auto_mem().

Function Documentation

bool ecpg_add_mem ( void *  ptr,
int  lineno 
)

Definition at line 124 of file memory.c.

References ecpg_alloc(), get_auto_allocs, auto_mem::next, auto_mem::pointer, and set_auto_allocs.

Referenced by ecpg_auto_alloc().

125 {
126  struct auto_mem *am = (struct auto_mem *) ecpg_alloc(sizeof(struct auto_mem), lineno);
127 
128  if (!am)
129  return false;
130 
131  am->pointer = ptr;
132  am->next = get_auto_allocs();
133  set_auto_allocs(am);
134  return true;
135 }
void * pointer
Definition: memory.c:67
#define get_auto_allocs()
Definition: memory.c:103
#define set_auto_allocs(am)
Definition: memory.c:104
char * ecpg_alloc(long size, int lineno)
Definition: memory.c:19
struct auto_mem * next
Definition: memory.c:68
char* ecpg_alloc ( long  size,
int  lineno 
)

Definition at line 19 of file memory.c.

References calloc, ECPG_OUT_OF_MEMORY, ecpg_raise(), ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, and NULL.

Referenced by deallocate_one(), ecpg_add_mem(), ecpg_auto_alloc(), ecpg_build_compat_sqlda(), ecpg_build_native_sqlda(), ecpg_build_params(), ecpg_do_prologue(), ecpg_get_data(), ecpg_is_type_an_array(), ecpg_store_input(), ecpg_type_infocache_push(), ECPGallocate_desc(), ECPGconnect(), ECPGset_desc(), insert_tobeinserted(), prepare_common(), quote_postgres(), and replace_variables().

20 {
21  char *new = (char *) calloc(1L, size);
22 
23  if (!new)
24  {
26  return NULL;
27  }
28 
29  return (new);
30 }
#define calloc(a, b)
Definition: header.h:50
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
Definition: extern.h:221
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define NULL
Definition: c.h:226
char* ecpg_auto_alloc ( long  size,
int  lineno 
)

Definition at line 108 of file memory.c.

References ecpg_add_mem(), ecpg_alloc(), ecpg_free(), and NULL.

Referenced by ecpg_store_result(), and ECPGget_desc().

109 {
110  void *ptr = (void *) ecpg_alloc(size, lineno);
111 
112  if (!ptr)
113  return NULL;
114 
115  if (!ecpg_add_mem(ptr, lineno))
116  {
117  ecpg_free(ptr);
118  return NULL;
119  }
120  return ptr;
121 }
char * ecpg_alloc(long size, int lineno)
Definition: memory.c:19
void ecpg_free(void *ptr)
Definition: memory.c:13
#define NULL
Definition: c.h:226
bool ecpg_add_mem(void *ptr, int lineno)
Definition: memory.c:124
void ecpg_clear_auto_mem ( void  )

Definition at line 158 of file memory.c.

References ecpg_free(), get_auto_allocs, auto_mem::next, NULL, and set_auto_allocs.

Referenced by ecpg_do_prologue(), and ECPGconnect().

159 {
160  struct auto_mem *am = get_auto_allocs();
161 
162  /* only free our own structure */
163  if (am)
164  {
165  do
166  {
167  struct auto_mem *act = am;
168 
169  am = am->next;
170  ecpg_free(act);
171  } while (am);
173  }
174 }
#define get_auto_allocs()
Definition: memory.c:103
#define set_auto_allocs(am)
Definition: memory.c:104
void ecpg_free(void *ptr)
Definition: memory.c:13
#define NULL
Definition: c.h:226
struct auto_mem * next
Definition: memory.c:68
char* ecpg_realloc ( void *  ptr,
long  size,
int  lineno 
)

Definition at line 33 of file memory.c.

References ECPG_OUT_OF_MEMORY, ecpg_raise(), ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL, and realloc.

Referenced by ecpg_build_params(), and ecpg_store_input().

34 {
35  char *new = (char *) realloc(ptr, size);
36 
37  if (!new)
38  {
40  return NULL;
41  }
42 
43  return (new);
44 }
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
Definition: extern.h:221
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define NULL
Definition: c.h:226
#define realloc(a, b)
Definition: header.h:55
char* ecpg_strdup ( const char *  string,
int  lineno 
)

Definition at line 47 of file memory.c.

References ECPG_OUT_OF_MEMORY, ecpg_raise(), ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, and NULL.

Referenced by AddStmtToCache(), ecpg_auto_prepare(), ecpg_do_prologue(), ecpg_store_input(), ECPGconnect(), ECPGget_desc(), and prepare_common().

48 {
49  char *new;
50 
51  if (string == NULL)
52  return NULL;
53 
54  new = strdup(string);
55  if (!new)
56  {
58  return NULL;
59  }
60 
61  return (new);
62 }
#define ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY
Definition: extern.h:221
#define ECPG_OUT_OF_MEMORY
Definition: ecpgerrno.h:15
void ecpg_raise(int line, int code, const char *sqlstate, const char *str)
Definition: error.c:13
#define NULL
Definition: c.h:226
void ECPGfree_auto_mem ( void  )

Definition at line 138 of file memory.c.

References ecpg_free(), get_auto_allocs, auto_mem::next, NULL, auto_mem::pointer, and set_auto_allocs.

Referenced by ecpg_raise(), ecpg_raise_backend(), ECPGset_var(), and main().

139 {
140  struct auto_mem *am = get_auto_allocs();
141 
142  /* free all memory we have allocated for the user */
143  if (am)
144  {
145  do
146  {
147  struct auto_mem *act = am;
148 
149  am = am->next;
150  ecpg_free(act->pointer);
151  ecpg_free(act);
152  } while (am);
154  }
155 }
void * pointer
Definition: memory.c:67
#define get_auto_allocs()
Definition: memory.c:103
#define set_auto_allocs(am)
Definition: memory.c:104
void ecpg_free(void *ptr)
Definition: memory.c:13
#define NULL
Definition: c.h:226
struct auto_mem * next
Definition: memory.c:68

Variable Documentation

struct auto_mem* auto_allocs = NULL
static

Definition at line 101 of file memory.c.