Header And Logo

PostgreSQL
| The world's most advanced open source database.

Data Structures | Defines | Functions | Variables

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

Defines

#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)
void 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

Define 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

void ecpg_add_mem ( void *  ptr,
int  lineno 
)

Definition at line 108 of file memory.c.

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

Referenced by ecpg_store_result(), and ECPGget_desc().

{
    struct auto_mem *am = (struct auto_mem *) ecpg_alloc(sizeof(struct auto_mem), lineno);

    am->pointer = ptr;
    am->next = get_auto_allocs();
    set_auto_allocs(am);
}

char* ecpg_alloc ( long  size,
int  lineno 
)
void ecpg_clear_auto_mem ( void   ) 

Definition at line 138 of file memory.c.

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

Referenced by ECPGconnect(), and ECPGdo().

{
    struct auto_mem *am = get_auto_allocs();

    /* only free our own structure */
    if (am)
    {
        do
        {
            struct auto_mem *act = am;

            am = am->next;
            ecpg_free(act);
        } while (am);
        set_auto_allocs(NULL);
    }
}

void ecpg_free ( void *  ptr  ) 
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_execute(), and ecpg_store_input().

{
    char       *new = (char *) realloc(ptr, size);

    if (!new)
    {
        ecpg_raise(lineno, ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
        return NULL;
    }

    return (new);
}

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_store_input(), ECPGconnect(), ECPGdo(), ECPGget_desc(), and prepare_common().

{
    char       *new;

    if (string == NULL)
        return NULL;

    new = strdup(string);
    if (!new)
    {
        ecpg_raise(lineno, ECPG_OUT_OF_MEMORY, ECPG_SQLSTATE_ECPG_OUT_OF_MEMORY, NULL);
        return NULL;
    }

    return (new);
}

void ECPGfree_auto_mem ( void   ) 

Definition at line 118 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().

{
    struct auto_mem *am = get_auto_allocs();

    /* free all memory we have allocated for the user */
    if (am)
    {
        do
        {
            struct auto_mem *act = am;

            am = am->next;
            ecpg_free(act->pointer);
            ecpg_free(act);
        } while (am);
        set_auto_allocs(NULL);
    }
}


Variable Documentation

struct auto_mem* auto_allocs = NULL [static]

Definition at line 101 of file memory.c.