mirror of
https://git.osgeo.org/gitea/postgis/postgis
synced 2024-10-25 09:32:46 +00:00
d745e459b8
git-svn-id: http://svn.osgeo.org/postgis/trunk@923 b70326c6-7e19-0410-871a-916f4a2858ee
102 lines
1.4 KiB
C
102 lines
1.4 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <stdarg.h>
|
|
#include "postgres.h"
|
|
#include "liblwgeom.h"
|
|
#include "lwgeom_pg.h"
|
|
|
|
#undef DEBUG
|
|
|
|
void *
|
|
pg_alloc(size_t size)
|
|
{
|
|
void * result;
|
|
#ifdef DEBUG
|
|
lwnotice(" pg_alloc(%d) called", size);
|
|
#endif
|
|
result = palloc(size);
|
|
#ifdef DEBUG
|
|
lwnotice(" pg_alloc(%d) returning %p", size, result);
|
|
#endif
|
|
if ( ! result )
|
|
{
|
|
elog(ERROR, "Out of virtual memory");
|
|
return NULL;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
void *
|
|
pg_realloc(void *mem, size_t size)
|
|
{
|
|
void * result;
|
|
#ifdef DEBUG
|
|
lwnotice(" pg_realloc(%p, %d) called", mem, size);
|
|
#endif
|
|
result = repalloc(mem, size);
|
|
#ifdef DEBUG
|
|
lwnotice(" pg_realloc(%p, %d) returning %p", mem, size, result);
|
|
#endif
|
|
return result;
|
|
}
|
|
|
|
void
|
|
pg_free(void *ptr)
|
|
{
|
|
pfree(ptr);
|
|
}
|
|
|
|
void
|
|
pg_error(const char *fmt, ...)
|
|
{
|
|
char *msg;
|
|
va_list ap;
|
|
|
|
va_start (ap, fmt);
|
|
|
|
/*
|
|
* This is a GNU extension.
|
|
* Dunno how to handle errors here.
|
|
*/
|
|
if (!vasprintf (&msg, fmt, ap))
|
|
{
|
|
va_end (ap);
|
|
return;
|
|
}
|
|
elog(ERROR, "%s", msg);
|
|
va_end(ap);
|
|
free(msg);
|
|
}
|
|
|
|
void
|
|
pg_notice(const char *fmt, ...)
|
|
{
|
|
char *msg;
|
|
va_list ap;
|
|
|
|
va_start (ap, fmt);
|
|
|
|
/*
|
|
* This is a GNU extension.
|
|
* Dunno how to handle errors here.
|
|
*/
|
|
if (!vasprintf (&msg, fmt, ap))
|
|
{
|
|
va_end (ap);
|
|
return;
|
|
}
|
|
elog(NOTICE, "%s", msg);
|
|
va_end(ap);
|
|
free(msg);
|
|
}
|
|
|
|
void
|
|
init_pg_func()
|
|
{
|
|
lwalloc = pg_alloc;
|
|
lwrealloc = pg_realloc;
|
|
lwfree = pg_free;
|
|
lwerror = pg_error;
|
|
lwnotice = pg_notice;
|
|
}
|