#
#-----------------------------------------------------
-all: liblwgeom loaderdumper utils
+all: postgis loaderdumper utils
-install: all liblwgeom-install loaderdumper-install
+install: all postgis-install loaderdumper-install
-uninstall: liblwgeom-uninstall loaderdumper-uninstall docs-uninstall
+uninstall: postgis-uninstall loaderdumper-uninstall docs-uninstall
-clean: liblwgeom-clean loaderdumper-clean docs-clean test-clean
+clean: liblwgeom-clean postgis-clean loaderdumper-clean docs-clean test-clean
rm -f lwpostgis.sql lwpostgis_upgrade.sql
distclean: clean
test-clean:
$(MAKE) -C regress clean
-liblwgeom:
- $(MAKE) -C lwgeom
+liblwgeom/liblwgeom.a:
+ $(MAKE) -C liblwgeom
+
+liblwgeom: liblwgeom/liblwgeom.a
liblwgeom-clean:
+ $(MAKE) -C liblwgeom clean
+
+postgis: liblwgeom/liblwgeom.a
+ $(MAKE) -C lwgeom
+
+postgis-clean:
$(MAKE) -C lwgeom clean
-liblwgeom-install:
+postgis-install:
$(MAKE) -C lwgeom install
-liblwgeom-uninstall:
+postgis-uninstall:
$(MAKE) -C lwgeom uninstall
loaderdumper:
dnl AC_MSG_RESULT([SHLIB_LINK: $SHLIB_LINK])
dnl Output the relevant files
-AC_OUTPUT([lwgeom/Makefile lwgeom/sqldefines.h loader/Makefile.pgsql2shp loader/Makefile.shp2pgsql regress/Makefile doc/Makefile])
+AC_OUTPUT([liblwgeom/Makefile lwgeom/Makefile lwgeom/sqldefines.h loader/Makefile.pgsql2shp loader/Makefile.shp2pgsql regress/Makefile doc/Makefile])
--- /dev/null
+# **********************************************************************
+# * $Id: Makefile.in
+# *
+# * PostGIS - Spatial Types for PostgreSQL
+# * http://postgis.refractions.net
+# * Copyright 2008 Mark Cave-Ayland
+# *
+# * This is free software; you can redistribute and/or modify it under
+# * the terms of the GNU General Public Licence. See the COPYING file.
+# *
+# **********************************************************************
+
+CC=@CC@
+CFLAGS=@CFLAGS@ -Wall -Wmissing-prototypes -fPIC
+
+# Standalone LWGEOM objects
+SA_OBJS=measures.o \
+ box2d.o \
+ ptarray.o \
+ lwgeom_api.o \
+ lwgeom.o \
+ lwpoint.o \
+ lwline.o \
+ lwpoly.o \
+ lwmpoint.o \
+ lwmline.o \
+ lwmpoly.o \
+ lwcollection.o \
+ lwcurve.o \
+ lwcompound.o \
+ lwcurvepoly.o \
+ lwmcurve.o \
+ lwmsurface.o \
+ lwutil.o \
+ lwgunparse.o \
+ lwgparse.o \
+ wktparse.tab.o \
+ lex.yy.o \
+ vsprintf.o
+
+all: $(SA_OBJS)
+ ar rs liblwgeom.a $(SA_OBJS)
+
+clean:
+ rm -f $(SA_OBJS)
+ rm -f liblwgeom.a
+
+# Command to build each of the .o files
+$(SA_OBJS): %.o: %.c
+ $(CC) $(CFLAGS) -c -o $@ $<
+
#include "../postgis_config.h"
#include <stdio.h>
-#include "compat.h"
+/* #include "compat.h" */
#define INTEGRITY_CHECKS 1
/*
* Memory management function types
*/
+extern void lwgeom_init_allocators(void);
+
typedef void* (*lwallocator)(size_t size);
typedef void* (*lwreallocator)(void *mem, size_t size);
typedef void (*lwfreeor)(void* mem);
extern uchar parse_hex(char *str);
extern void deparse_hex(uchar str, char *result);
-extern SERIALIZED_LWGEOM *parse_lwgeom_wkt(char *wkt_input);
+/* Parser access routines */
+extern char *unparse_WKT(uchar* serialized, lwallocator alloc, lwfreeor free);
+extern char *unparse_WKB(uchar* serialized, lwallocator alloc, lwfreeor free, char endian, size_t *outsize, uchar hex);
+
+extern SERIALIZED_LWGEOM *parse_lwgeom_wkt(char *wkt_input);
extern char *lwgeom_to_ewkt(LWGEOM *lwgeom);
extern char *lwgeom_to_hexwkb(LWGEOM *lwgeom, unsigned int byteorder);
extern LWGEOM *lwgeom_from_ewkb(uchar *ewkb, size_t ewkblen);
/**********************************************************************
- * $Id$
+ * $Id: lwcollection.c 2797 2008-05-31 09:56:44Z mcayland $
*
* PostGIS - Spatial Types for PostgreSQL
* http://postgis.refractions.net
/**********************************************************************
- * $Id$
+ * $Id: lwgeom.c 2797 2008-05-31 09:56:44Z mcayland $
*
* PostGIS - Spatial Types for PostgreSQL
* http://postgis.refractions.net
* Copyright Telogis 2004
* www.telogis.com
*
- * $Id$
+ * $Id: wktunparse.c 2781 2008-05-22 20:43:00Z mcayland $
*/
/**********************************************************************
- * $Id$
+ * $Id: lwline.c 2797 2008-05-31 09:56:44Z mcayland $
*
* PostGIS - Spatial Types for PostgreSQL
* http://postgis.refractions.net
/**********************************************************************
- * $Id$
+ * $Id: lwmline.c 2369 2006-05-30 08:38:58Z strk $
*
* PostGIS - Spatial Types for PostgreSQL
* http://postgis.refractions.net
/**********************************************************************
- * $Id$
+ * $Id: lwmpoint.c 2369 2006-05-30 08:38:58Z strk $
*
* PostGIS - Spatial Types for PostgreSQL
* http://postgis.refractions.net
/**********************************************************************
- * $Id$
+ * $Id: lwmpoly.c 2797 2008-05-31 09:56:44Z mcayland $
*
* PostGIS - Spatial Types for PostgreSQL
* http://postgis.refractions.net
/**********************************************************************
- * $Id$
+ * $Id: lwpoint.c 2797 2008-05-31 09:56:44Z mcayland $
*
* PostGIS - Spatial Types for PostgreSQL
* http://postgis.refractions.net
/**********************************************************************
- * $Id$
+ * $Id: lwpoly.c 2797 2008-05-31 09:56:44Z mcayland $
*
* PostGIS - Spatial Types for PostgreSQL
* http://postgis.refractions.net
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
+#include <string.h>
-#define CONTEXT_PG 0
-#define CONTEXT_SA 1
-
-
-
-#ifdef STANDALONE
-#define DEFAULT_CONTEXT CONTEXT_SA
-#else
-#define DEFAULT_CONTEXT CONTEXT_PG
-#endif
/* Global variables */
#include "../postgis_config.h"
-
-#if DEFAULT_CONTEXT == CONTEXT_SA
-#include "liblwgeom.h"
-lwallocator lwalloc_var = default_allocator;
-lwreallocator lwrealloc_var = default_reallocator;
-lwfreeor lwfree_var = default_freeor;
-lwreporter lwerror = default_errorreporter;
-lwreporter lwnotice = default_noticereporter;
-#else
-#include "lwgeom_pg.h"
#include "liblwgeom.h"
-lwallocator lwalloc_var = pg_alloc;
-lwreallocator lwrealloc_var = pg_realloc;
-lwfreeor lwfree_var = pg_free;
-lwreporter lwerror = pg_error;
-lwreporter lwnotice = pg_notice;
-#endif
+void *init_allocator(size_t size);
+void init_freeor(void *mem);
+void *init_reallocator(void *mem, size_t size);
+void init_noticereporter(const char *fmt, ...);
+void init_errorreporter(const char *fmt, ...);
+lwallocator lwalloc_var = init_allocator;
+lwreallocator lwrealloc_var = init_reallocator;
+lwfreeor lwfree_var = init_freeor;
+lwreporter lwerror = init_errorreporter;
+lwreporter lwnotice = init_noticereporter;
static char *lwgeomTypeName[] = {
"Unknown",
"MultiSurface"
};
+
+/*
+ * Initialisation allocators
+ *
+ * These are used the first time any of the allocators are called
+ * to enable executables/libraries that link into liblwgeom to
+ * be able to set up their own allocators. This is mainly useful
+ * for older PostgreSQL versions that don't have functions that
+ * are called upon startup.
+ */
+
+void *
+init_allocator(size_t size)
+{
+ lwgeom_init_allocators();
+
+ return lwalloc_var(size);
+}
+
+void
+init_freeor(void *mem)
+{
+ lwgeom_init_allocators();
+
+ lwfree_var(mem);
+}
+
+void *
+init_reallocator(void *mem, size_t size)
+{
+ lwgeom_init_allocators();
+
+ return lwrealloc_var(mem, size);
+}
+
+void
+init_noticereporter(const char *fmt, ...)
+{
+ va_list ap;
+
+ lwgeom_init_allocators();
+
+ va_start(ap, fmt);
+ lwnotice(fmt, ap);
+ va_end(ap);
+}
+
+void
+init_errorreporter(const char *fmt, ...)
+{
+ va_list ap;
+
+ lwgeom_init_allocators();
+
+ va_start(ap, fmt);
+ lwerror(fmt, ap);
+ va_end(ap);
+}
+
+
+/*
+ * Default allocators
+ *
+ * We include some default allocators that use malloc/free/realloc
+ * along with stdout/stderr since this is the most common use case
+ *
+ */
+
void *
default_allocator(size_t size)
{
exit(1);
}
+
+/*
+ * This function should be called from lwgeom_init_allocators() by programs
+ * which wish to use the default allocators above
+ */
+
+void lwgeom_install_default_allocators()
+{
+ lwalloc_var = default_allocator;
+ lwrealloc_var = default_reallocator;
+ lwfree_var = default_freeor;
+ lwerror = default_errorreporter;
+ lwnotice = default_noticereporter;
+}
+
+
const char *
lwgeom_typename(int type)
{
/**********************************************************************
- * $Id$
+ * $Id: measures.c 2797 2008-05-31 09:56:44Z mcayland $
*
* PostGIS - Spatial Types for PostgreSQL
* http://postgis.refractions.net
/**********************************************************************
- * $Id$
+ * $Id: ptarray.c 2797 2008-05-31 09:56:44Z mcayland $
*
* PostGIS - Spatial Types for PostgreSQL
* http://postgis.refractions.net
# SQL objects (files requiring C pre-processing)
SQL_OBJS=lwpostgis.sql.in
-# Standalone LWGEOM objects
-SA_OBJS=measures.o \
- box2d.o \
- ptarray.o \
- lwgeom_api.o \
- lwgeom.o \
- lwpoint.o \
- lwline.o \
- lwpoly.o \
- lwmpoint.o \
- lwmline.o \
- lwmpoly.o \
- lwcollection.o \
- lwcurve.o \
- lwcompound.o \
- lwcurvepoly.o \
- lwmcurve.o \
- lwmsurface.o \
- wktunparse.o \
- lwgparse.o \
- wktparse.tab.o \
- lex.yy.o \
- vsprintf.o
-
# PostgreSQL objects
-PG_OBJS=liblwgeom.o \
- lwgeom_pg.o \
+PG_OBJS=lwgeom_pg.o \
lwgeom_debug.o \
lwgeom_spheroid.o \
lwgeom_ogc.o \
lwgeom_rtree.o
# Objects to build using PGXS
-OBJS=$(SA_OBJS) $(PG_OBJS)
+OBJS=$(PG_OBJS)
# Libraries to link into the module (proj, geos)
-SHLIB_LINK=@SHLIB_LINK@
+PG_CPPFLAGS=@CPPFLAGS@ -I../liblwgeom
+SHLIB_LINK=@SHLIB_LINK@ -L../liblwgeom -llwgeom
# Extra files to remove during 'make clean'
EXTRA_CLEAN=$(SQL_OBJS)
#include "liblwgeom.h"
#include "lwgeom_pg.h"
#include "profile.h"
-#include "wktparse.h"
-
Datum LWGEOM_dump(PG_FUNCTION_ARGS);
Datum LWGEOM_dump_rings(PG_FUNCTION_ARGS);
#include "liblwgeom.h"
#include "lwgeom_pg.h"
#include "profile.h"
-#include "wktparse.h"
-
Datum LWGEOM_mem_size(PG_FUNCTION_ARGS);
Datum LWGEOM_summary(PG_FUNCTION_ARGS);
text *mytext;
LWGEOM *lwgeom;
- init_pg_func();
-
lwgeom = lwgeom_deserialize(SERIALIZED_FORM(geom));
result = lwgeom_summary(lwgeom, 0);
PG_LWGEOM *lwgeom;
char *result_cstring;
int len;
- char *result,*loc_wkt;
+ char *result,*loc_wkt;
/*char *semicolonLoc; */
- init_pg_func();
-
lwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
result_cstring = unparse_WKT(SERIALIZED_FORM(lwgeom),lwalloc,lwfree);
double result;
int SRID;
- init_pg_func();
-
/* Extract first point */
geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
lwpoint = lwpoint_deserialize(SERIALIZED_FORM(geom));
#include "lwgeom_pg.h"
#include "liblwgeom.h"
#include "profile.h"
-#include "wktparse.h"
+
#include "geos_c.h"
#include "lwgeom_rtree.h"
#include "lwgeom_pg.h"
#include "stringBuffer.h"
-#if POSTGIS_DEBUG_LEVEL > 0
-#include "wktparse.h"
-#endif
-
/*
* implementation GiST support and basic LWGEOM operations (like &&)
#include "lwgeom_pg.h"
-#include "wktparse.h"
#include "profile.h"
void elog_ERROR(const char* string);
PG_LWGEOM *lwgeom;
char *result;
- init_pg_func();
-
lwgeom = (PG_LWGEOM *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
result = unparse_WKB(SERIALIZED_FORM(lwgeom),lwalloc,lwfree,-1,NULL,1);
text *type;
unsigned int byteorder=-1;
- init_pg_func();
-
lwgeom = (PG_LWGEOM *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) )
text *text_result;
size_t size;
- init_pg_func();
-
lwgeom = (PG_LWGEOM *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
result = unparse_WKB(SERIALIZED_FORM(lwgeom),lwalloc,lwfree,-1,&size,1);
profstart(PROF_QRUN);
#endif
- init_pg_func();
-
if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) )
{
type = PG_GETARG_TEXT_P(1);
char *wkt;
int wkt_size ;
- init_pg_func();
-
wkt_size = VARSIZE(wkt_input)-VARHDRSZ; /* actual letters */
wkt = palloc( wkt_size+1); /* +1 for null */
POSTGIS_DEBUGF(3, "in parse_WKT_lwgeom with input: '%s'",wkt);
- serialized_lwgeom = parse_lwg((const char *)wkt, (allocator)lwalloc, (report_error)elog_ERROR);
+ serialized_lwgeom = parse_lwgeom_wkt(wkt);
lwgeom = lwgeom_deserialize(serialized_lwgeom->lwgeom);
ret = pglwgeom_serialize(lwgeom);
#include "lwgeom_pg.h"
-
-#include "wktparse.h"
-
/* ---- SRID(geometry) */
Datum LWGEOM_getSRID(PG_FUNCTION_ARGS);
/* ---- SetSRID(geometry, integer) */
int32 size;
uchar type;
- init_pg_func();
-
lwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
text_ob = lwalloc(20+VARHDRSZ);
result = text_ob+VARHDRSZ;
POSTGIS_DEBUG(2, "LWGEOM_asText called.");
- init_pg_func();
-
lwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
/* Force to 2d */
PG_LWGEOM *ogclwgeom;
char *result;
- init_pg_func();
-
/* Force to 2d */
ogclwgeom = (PG_LWGEOM *)DatumGetPointer(DirectFunctionCall1(
LWGEOM_force_2d, PG_GETARG_DATUM(0)));
#include <executor/spi.h>
#include "liblwgeom.h"
#include "lwgeom_pg.h"
-#include "wktparse.h"
-
#define PARANOIA_LEVEL 1
/*
* This is required for builds against pgsql 8.2
*/
-/*#include "pgmagic.h"*/
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
}
void
-init_pg_func(void)
+lwgeom_init_allocators(void)
{
+ /* liblwgeom callback - install PostgreSQL handlers */
lwalloc_var = pg_alloc;
lwrealloc_var = pg_realloc;
lwfree_var = pg_free;
extern Oid getGeometryOID(void);
-/* call this as first thing of any PG function */
-void init_pg_func(void);
-
/* PG-dependant */
/* BOX is postgresql standard type */
extern void box_to_box2df_p(BOX *box, BOX2DFLOAT4 *out);
#include "postgres.h"
#include "liblwgeom.h"
#include "fmgr.h"
-#include "wktparse.h"
+
#include "lwgeom_pg.h"