PostgreSQL Source Code git master
Data Structures | Macros | Functions | Variables
memory.c File Reference
#include "postgres_fe.h"
#include "ecpg-pthread-win32.h"
#include "ecpgerrno.h"
#include "ecpglib.h"
#include "ecpglib_extern.h"
#include "ecpgtype.h"
Include dependency graph for memory.c:

Go to the source code of this file.

Data Structures

struct   auto_mem
 

Macros

 

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, bool *alloc_failed)
 
static void  auto_mem_destructor (void *arg)
 
static void  auto_mem_key_init (void)
 
static struct auto_memget_auto_allocs (void)
 
static void  set_auto_allocs (struct auto_mem *am)
 
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 pthread_once_t  auto_mem_once = PTHREAD_ONCE_INIT
 

Macro Definition Documentation

POSTGRES_ECPG_INTERNAL

#define POSTGRES_ECPG_INTERNAL

Definition at line 3 of file memory.c.

Function Documentation

auto_mem_destructor()

static void auto_mem_destructor ( void *  arg )
static

Definition at line 84 of file memory.c.

85{
86 (void) arg; /* keep the compiler quiet */
88}
void ECPGfree_auto_mem(void)
Definition: memory.c:140
void * arg

References arg, and ECPGfree_auto_mem().

Referenced by auto_mem_key_init().

auto_mem_key_init()

static void auto_mem_key_init ( void  )
static

Definition at line 91 of file memory.c.

92{
93 pthread_key_create(&auto_mem_key, auto_mem_destructor);
94}
static pthread_key_t auto_mem_key
Definition: memory.c:80
static void auto_mem_destructor(void *arg)
Definition: memory.c:84

References auto_mem_destructor(), and auto_mem_key.

Referenced by get_auto_allocs().

ecpg_add_mem()

bool ecpg_add_mem ( void *  ptr,
int  lineno 
)

Definition at line 126 of file memory.c.

127{
128 struct auto_mem *am = (struct auto_mem *) ecpg_alloc(sizeof(struct auto_mem), lineno);
129
130 if (!am)
131 return false;
132
133 am->pointer = ptr;
134 am->next = get_auto_allocs();
135 set_auto_allocs(am);
136 return true;
137}
static struct auto_mem * get_auto_allocs(void)
Definition: memory.c:97
char * ecpg_alloc(long size, int lineno)
Definition: memory.c:19
static void set_auto_allocs(struct auto_mem *am)
Definition: memory.c:104
Definition: memory.c:75
void * pointer
Definition: memory.c:76
struct auto_mem * next
Definition: memory.c:77

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

Referenced by ecpg_auto_alloc().

ecpg_alloc()

char * ecpg_alloc ( long  size,
int  lineno 
)

Definition at line 19 of file memory.c.

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

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

Referenced by AddStmtToCache(), convert_bytea_to_string(), 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_register_prepared_stmt(), ecpg_store_input(), ecpg_type_infocache_push(), ECPGallocate_desc(), ECPGconnect(), ECPGset_desc(), insert_tobeinserted(), prepare_common(), print_param_value(), quote_postgres(), replace_variables(), and store_input_from_desc().

ecpg_auto_alloc()

char * ecpg_auto_alloc ( long  size,
int  lineno 
)

Definition at line 110 of file memory.c.

111{
112 void *ptr = ecpg_alloc(size, lineno);
113
114 if (!ptr)
115 return NULL;
116
117 if (!ecpg_add_mem(ptr, lineno))
118 {
119 ecpg_free(ptr);
120 return NULL;
121 }
122 return ptr;
123}
bool ecpg_add_mem(void *ptr, int lineno)
Definition: memory.c:126
void ecpg_free(void *ptr)
Definition: memory.c:13

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

Referenced by ecpg_store_result(), and ECPGget_desc().

ecpg_clear_auto_mem()

void ecpg_clear_auto_mem ( void  )

Definition at line 160 of file memory.c.

161{
162 struct auto_mem *am = get_auto_allocs();
163
164 /* only free our own structure */
165 if (am)
166 {
167 do
168 {
169 struct auto_mem *act = am;
170
171 am = am->next;
172 ecpg_free(act);
173 } while (am);
174 set_auto_allocs(NULL);
175 }
176}

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

Referenced by ecpg_do_prologue(), and ECPGconnect().

ecpg_free()

void ecpg_free ( void *  ptr )

Definition at line 13 of file memory.c.

14{
15 free(ptr);
16}
#define free(a)
Definition: header.h:65

References free.

Referenced by deallocate_one(), descriptor_free(), ecpg_auto_alloc(), ecpg_auto_prepare(), ecpg_build_params(), ecpg_clear_auto_mem(), ecpg_do_prologue(), ecpg_finish(), ecpg_free_params(), ecpg_freeStmtCacheEntry(), ecpg_is_type_an_array(), ecpg_register_prepared_stmt(), ecpg_store_input(), ECPGallocate_desc(), ECPGconnect(), ECPGfree_auto_mem(), ECPGget_desc(), ECPGset_desc(), free_statement(), free_variable(), insert_tobeinserted(), prepare_common(), print_param_value(), quote_postgres(), replace_variables(), and set_desc_attr().

ecpg_realloc()

char * ecpg_realloc ( void *  ptr,
long  size,
int  lineno 
)

Definition at line 33 of file memory.c.

34{
35 char *new = (char *) realloc(ptr, size);
36
37 if (!new)
38 {
40 return NULL;
41 }
42
43 return new;
44}
#define realloc(a, b)
Definition: header.h:60

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

Referenced by ecpg_build_params(), and ecpg_store_input().

ecpg_strdup()

char * ecpg_strdup ( const char *  string,
int  lineno,
bool *  alloc_failed 
)

Definition at line 54 of file memory.c.

55{
56 char *new;
57
58 if (string == NULL)
59 return NULL;
60
61 new = strdup(string);
62 if (!new)
63 {
64 if (alloc_failed)
65 *alloc_failed = true;
67 return NULL;
68 }
69
70 return new;
71}

References ECPG_OUT_OF_MEMORY, ecpg_raise(), and ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY.

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

ECPGfree_auto_mem()

void ECPGfree_auto_mem ( void  )

Definition at line 140 of file memory.c.

141{
142 struct auto_mem *am = get_auto_allocs();
143
144 /* free all memory we have allocated for the user */
145 if (am)
146 {
147 do
148 {
149 struct auto_mem *act = am;
150
151 am = am->next;
152 ecpg_free(act->pointer);
153 ecpg_free(act);
154 } while (am);
155 set_auto_allocs(NULL);
156 }
157}

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

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

get_auto_allocs()

static struct auto_mem * get_auto_allocs ( void  )
static

Definition at line 97 of file memory.c.

98{
99 pthread_once(&auto_mem_once, auto_mem_key_init);
100 return (struct auto_mem *) pthread_getspecific(auto_mem_key);
101}
static void auto_mem_key_init(void)
Definition: memory.c:91
static pthread_once_t auto_mem_once
Definition: memory.c:81
void * pthread_getspecific(pthread_key_t key)
Definition: pthread-win32.c:29

References auto_mem_key, auto_mem_key_init(), auto_mem_once, and pthread_getspecific().

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

set_auto_allocs()

static void set_auto_allocs ( struct auto_memam )
static

Definition at line 104 of file memory.c.

105{
107}
void pthread_setspecific(pthread_key_t key, void *val)
Definition: pthread-win32.c:24

References auto_mem_key, and pthread_setspecific().

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

Variable Documentation

auto_mem_key

pthread_key_t auto_mem_key
static

Definition at line 80 of file memory.c.

Referenced by auto_mem_key_init(), get_auto_allocs(), and set_auto_allocs().

auto_mem_once

pthread_once_t auto_mem_once = PTHREAD_ONCE_INIT
static

Definition at line 81 of file memory.c.

Referenced by get_auto_allocs().

AltStyle によって変換されたページ (->オリジナル) /