From ffde636dc0484b1f08b1feadfe09a42335c638b5 Mon Sep 17 00:00:00 2001 From: Mark Cave-Ayland Date: Sun, 29 Jun 2008 19:11:48 +0000 Subject: [PATCH] Split the basic geometry accessors into a separate static library liblwgeom.a; this potentially allows re-use of the liblwgeom functions from within PostGIS, or could be extended at a later date to include databases other than MySQL. This patch includes a change to the liblwgeom handler functions; instead of sprinkling init_pg_func()s around the source, I have changed the default liblwgeom handlers to make use of a callback to allow linked libraries to set their own handlers the first time any of them are called. I have also tidied up the parser API a little in liblwgeom.h, which means wktparse.h can be removed from all of the headers in the lwgeom/ directory, plus renamed wktunparse.c to lwgunparse.c to keep things similar to lwgparse.c. Finally, I renamed liblwgeom.c to lwutil.c to avoid confusion within the new interface. TODO: the liblwgeom Makefile has some gcc-specific options, but these can be fixed later - it seemed more important to make the warnings visible to developers. git-svn-id: http://svn.osgeo.org/postgis/trunk@2815 b70326c6-7e19-0410-871a-916f4a2858ee --- GNUmakefile | 24 ++-- configure.ac | 2 +- liblwgeom/Makefile.in | 51 ++++++++ {lwgeom => liblwgeom}/box2d.c | 0 {lwgeom => liblwgeom}/lex.yy.c | 0 {lwgeom => liblwgeom}/liblwgeom.h | 10 +- {lwgeom => liblwgeom}/lwcollection.c | 2 +- {lwgeom => liblwgeom}/lwcompound.c | 0 {lwgeom => liblwgeom}/lwcurve.c | 0 {lwgeom => liblwgeom}/lwcurvepoly.c | 0 {lwgeom => liblwgeom}/lwgeom.c | 2 +- {lwgeom => liblwgeom}/lwgeom_api.c | 0 {lwgeom => liblwgeom}/lwgparse.c | 0 lwgeom/wktunparse.c => liblwgeom/lwgunparse.c | 2 +- {lwgeom => liblwgeom}/lwline.c | 2 +- {lwgeom => liblwgeom}/lwmcurve.c | 0 {lwgeom => liblwgeom}/lwmline.c | 2 +- {lwgeom => liblwgeom}/lwmpoint.c | 2 +- {lwgeom => liblwgeom}/lwmpoly.c | 2 +- {lwgeom => liblwgeom}/lwmsurface.c | 0 {lwgeom => liblwgeom}/lwpoint.c | 2 +- {lwgeom => liblwgeom}/lwpoly.c | 2 +- lwgeom/liblwgeom.c => liblwgeom/lwutil.c | 121 ++++++++++++++---- {lwgeom => liblwgeom}/measures.c | 2 +- {lwgeom => liblwgeom}/ptarray.c | 2 +- {lwgeom => liblwgeom}/vsprintf.c | 0 {lwgeom => liblwgeom}/wktparse.h | 0 {lwgeom => liblwgeom}/wktparse.lex | 0 {lwgeom => liblwgeom}/wktparse.tab.c | 0 {lwgeom => liblwgeom}/wktparse.tab.h | 0 {lwgeom => liblwgeom}/wktparse.y | 0 lwgeom/Makefile.in | 32 +---- lwgeom/lwgeom_dump.c | 2 - lwgeom/lwgeom_functions_basic.c | 10 +- lwgeom/lwgeom_geos_c.c | 2 +- lwgeom/lwgeom_gist.c | 4 - lwgeom/lwgeom_inout.c | 13 +- lwgeom/lwgeom_ogc.c | 9 -- lwgeom/lwgeom_pg.c | 6 +- lwgeom/lwgeom_pg.h | 3 - lwgeom/lwgeom_sqlmm.c | 2 +- 41 files changed, 192 insertions(+), 121 deletions(-) create mode 100644 liblwgeom/Makefile.in rename {lwgeom => liblwgeom}/box2d.c (100%) rename {lwgeom => liblwgeom}/lex.yy.c (100%) rename {lwgeom => liblwgeom}/liblwgeom.h (99%) rename {lwgeom => liblwgeom}/lwcollection.c (99%) rename {lwgeom => liblwgeom}/lwcompound.c (100%) rename {lwgeom => liblwgeom}/lwcurve.c (100%) rename {lwgeom => liblwgeom}/lwcurvepoly.c (100%) rename {lwgeom => liblwgeom}/lwgeom.c (99%) rename {lwgeom => liblwgeom}/lwgeom_api.c (100%) rename {lwgeom => liblwgeom}/lwgparse.c (100%) rename lwgeom/wktunparse.c => liblwgeom/lwgunparse.c (99%) rename {lwgeom => liblwgeom}/lwline.c (99%) rename {lwgeom => liblwgeom}/lwmcurve.c (100%) rename {lwgeom => liblwgeom}/lwmline.c (98%) rename {lwgeom => liblwgeom}/lwmpoint.c (97%) rename {lwgeom => liblwgeom}/lwmpoly.c (97%) rename {lwgeom => liblwgeom}/lwmsurface.c (100%) rename {lwgeom => liblwgeom}/lwpoint.c (99%) rename {lwgeom => liblwgeom}/lwpoly.c (99%) rename lwgeom/liblwgeom.c => liblwgeom/lwutil.c (59%) rename {lwgeom => liblwgeom}/measures.c (99%) rename {lwgeom => liblwgeom}/ptarray.c (99%) rename {lwgeom => liblwgeom}/vsprintf.c (100%) rename {lwgeom => liblwgeom}/wktparse.h (100%) rename {lwgeom => liblwgeom}/wktparse.lex (100%) rename {lwgeom => liblwgeom}/wktparse.tab.c (100%) rename {lwgeom => liblwgeom}/wktparse.tab.h (100%) rename {lwgeom => liblwgeom}/wktparse.y (100%) diff --git a/GNUmakefile b/GNUmakefile index 55baf36c0..119b31148 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -4,13 +4,13 @@ # #----------------------------------------------------- -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 @@ -35,16 +35,24 @@ test check: 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: diff --git a/configure.ac b/configure.ac index 7d50a312d..bd9697a9a 100644 --- a/configure.ac +++ b/configure.ac @@ -357,5 +357,5 @@ AC_SUBST([SHLIB_LINK]) 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]) diff --git a/liblwgeom/Makefile.in b/liblwgeom/Makefile.in new file mode 100644 index 000000000..ffbbbb41b --- /dev/null +++ b/liblwgeom/Makefile.in @@ -0,0 +1,51 @@ +# ********************************************************************** +# * $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 $@ $< + diff --git a/lwgeom/box2d.c b/liblwgeom/box2d.c similarity index 100% rename from lwgeom/box2d.c rename to liblwgeom/box2d.c diff --git a/lwgeom/lex.yy.c b/liblwgeom/lex.yy.c similarity index 100% rename from lwgeom/lex.yy.c rename to liblwgeom/lex.yy.c diff --git a/lwgeom/liblwgeom.h b/liblwgeom/liblwgeom.h similarity index 99% rename from lwgeom/liblwgeom.h rename to liblwgeom/liblwgeom.h index b9ca41cce..4067b871f 100644 --- a/lwgeom/liblwgeom.h +++ b/liblwgeom/liblwgeom.h @@ -3,7 +3,7 @@ #include "../postgis_config.h" #include -#include "compat.h" +/* #include "compat.h" */ #define INTEGRITY_CHECKS 1 @@ -24,6 +24,8 @@ /* * 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); @@ -1111,8 +1113,12 @@ extern LWCOLLECTION *lwcollection_segmentize2d(LWCOLLECTION *coll, double dist); 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); diff --git a/lwgeom/lwcollection.c b/liblwgeom/lwcollection.c similarity index 99% rename from lwgeom/lwcollection.c rename to liblwgeom/lwcollection.c index 6cb8515fa..9f7374b62 100644 --- a/lwgeom/lwcollection.c +++ b/liblwgeom/lwcollection.c @@ -1,5 +1,5 @@ /********************************************************************** - * $Id$ + * $Id: lwcollection.c 2797 2008-05-31 09:56:44Z mcayland $ * * PostGIS - Spatial Types for PostgreSQL * http://postgis.refractions.net diff --git a/lwgeom/lwcompound.c b/liblwgeom/lwcompound.c similarity index 100% rename from lwgeom/lwcompound.c rename to liblwgeom/lwcompound.c diff --git a/lwgeom/lwcurve.c b/liblwgeom/lwcurve.c similarity index 100% rename from lwgeom/lwcurve.c rename to liblwgeom/lwcurve.c diff --git a/lwgeom/lwcurvepoly.c b/liblwgeom/lwcurvepoly.c similarity index 100% rename from lwgeom/lwcurvepoly.c rename to liblwgeom/lwcurvepoly.c diff --git a/lwgeom/lwgeom.c b/liblwgeom/lwgeom.c similarity index 99% rename from lwgeom/lwgeom.c rename to liblwgeom/lwgeom.c index cb492c562..a6972b581 100644 --- a/lwgeom/lwgeom.c +++ b/liblwgeom/lwgeom.c @@ -1,5 +1,5 @@ /********************************************************************** - * $Id$ + * $Id: lwgeom.c 2797 2008-05-31 09:56:44Z mcayland $ * * PostGIS - Spatial Types for PostgreSQL * http://postgis.refractions.net diff --git a/lwgeom/lwgeom_api.c b/liblwgeom/lwgeom_api.c similarity index 100% rename from lwgeom/lwgeom_api.c rename to liblwgeom/lwgeom_api.c diff --git a/lwgeom/lwgparse.c b/liblwgeom/lwgparse.c similarity index 100% rename from lwgeom/lwgparse.c rename to liblwgeom/lwgparse.c diff --git a/lwgeom/wktunparse.c b/liblwgeom/lwgunparse.c similarity index 99% rename from lwgeom/wktunparse.c rename to liblwgeom/lwgunparse.c index b6dffed31..c68ecf82a 100644 --- a/lwgeom/wktunparse.c +++ b/liblwgeom/lwgunparse.c @@ -4,7 +4,7 @@ * Copyright Telogis 2004 * www.telogis.com * - * $Id$ + * $Id: wktunparse.c 2781 2008-05-22 20:43:00Z mcayland $ */ diff --git a/lwgeom/lwline.c b/liblwgeom/lwline.c similarity index 99% rename from lwgeom/lwline.c rename to liblwgeom/lwline.c index 6078c2e68..69a063d94 100644 --- a/lwgeom/lwline.c +++ b/liblwgeom/lwline.c @@ -1,5 +1,5 @@ /********************************************************************** - * $Id$ + * $Id: lwline.c 2797 2008-05-31 09:56:44Z mcayland $ * * PostGIS - Spatial Types for PostgreSQL * http://postgis.refractions.net diff --git a/lwgeom/lwmcurve.c b/liblwgeom/lwmcurve.c similarity index 100% rename from lwgeom/lwmcurve.c rename to liblwgeom/lwmcurve.c diff --git a/lwgeom/lwmline.c b/liblwgeom/lwmline.c similarity index 98% rename from lwgeom/lwmline.c rename to liblwgeom/lwmline.c index 7f8d45568..ba6a86166 100644 --- a/lwgeom/lwmline.c +++ b/liblwgeom/lwmline.c @@ -1,5 +1,5 @@ /********************************************************************** - * $Id$ + * $Id: lwmline.c 2369 2006-05-30 08:38:58Z strk $ * * PostGIS - Spatial Types for PostgreSQL * http://postgis.refractions.net diff --git a/lwgeom/lwmpoint.c b/liblwgeom/lwmpoint.c similarity index 97% rename from lwgeom/lwmpoint.c rename to liblwgeom/lwmpoint.c index 1faa3724a..7421454e9 100644 --- a/lwgeom/lwmpoint.c +++ b/liblwgeom/lwmpoint.c @@ -1,5 +1,5 @@ /********************************************************************** - * $Id$ + * $Id: lwmpoint.c 2369 2006-05-30 08:38:58Z strk $ * * PostGIS - Spatial Types for PostgreSQL * http://postgis.refractions.net diff --git a/lwgeom/lwmpoly.c b/liblwgeom/lwmpoly.c similarity index 97% rename from lwgeom/lwmpoly.c rename to liblwgeom/lwmpoly.c index 3673c16ae..b94baa62b 100644 --- a/lwgeom/lwmpoly.c +++ b/liblwgeom/lwmpoly.c @@ -1,5 +1,5 @@ /********************************************************************** - * $Id$ + * $Id: lwmpoly.c 2797 2008-05-31 09:56:44Z mcayland $ * * PostGIS - Spatial Types for PostgreSQL * http://postgis.refractions.net diff --git a/lwgeom/lwmsurface.c b/liblwgeom/lwmsurface.c similarity index 100% rename from lwgeom/lwmsurface.c rename to liblwgeom/lwmsurface.c diff --git a/lwgeom/lwpoint.c b/liblwgeom/lwpoint.c similarity index 99% rename from lwgeom/lwpoint.c rename to liblwgeom/lwpoint.c index bf6e2b995..6557e2760 100644 --- a/lwgeom/lwpoint.c +++ b/liblwgeom/lwpoint.c @@ -1,5 +1,5 @@ /********************************************************************** - * $Id$ + * $Id: lwpoint.c 2797 2008-05-31 09:56:44Z mcayland $ * * PostGIS - Spatial Types for PostgreSQL * http://postgis.refractions.net diff --git a/lwgeom/lwpoly.c b/liblwgeom/lwpoly.c similarity index 99% rename from lwgeom/lwpoly.c rename to liblwgeom/lwpoly.c index adb681ac6..80b1aec4e 100644 --- a/lwgeom/lwpoly.c +++ b/liblwgeom/lwpoly.c @@ -1,5 +1,5 @@ /********************************************************************** - * $Id$ + * $Id: lwpoly.c 2797 2008-05-31 09:56:44Z mcayland $ * * PostGIS - Spatial Types for PostgreSQL * http://postgis.refractions.net diff --git a/lwgeom/liblwgeom.c b/liblwgeom/lwutil.c similarity index 59% rename from lwgeom/liblwgeom.c rename to liblwgeom/lwutil.c index 1253577b3..5ed070236 100644 --- a/lwgeom/liblwgeom.c +++ b/liblwgeom/lwutil.c @@ -1,39 +1,24 @@ #include #include #include +#include -#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", @@ -54,6 +39,74 @@ static char *lwgeomTypeName[] = { "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) { @@ -119,6 +172,22 @@ default_errorreporter(const char *fmt, ...) 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) { diff --git a/lwgeom/measures.c b/liblwgeom/measures.c similarity index 99% rename from lwgeom/measures.c rename to liblwgeom/measures.c index 3cffc3eb4..2b860975d 100644 --- a/lwgeom/measures.c +++ b/liblwgeom/measures.c @@ -1,5 +1,5 @@ /********************************************************************** - * $Id$ + * $Id: measures.c 2797 2008-05-31 09:56:44Z mcayland $ * * PostGIS - Spatial Types for PostgreSQL * http://postgis.refractions.net diff --git a/lwgeom/ptarray.c b/liblwgeom/ptarray.c similarity index 99% rename from lwgeom/ptarray.c rename to liblwgeom/ptarray.c index 3b3ef6c7b..02e5b6b1d 100644 --- a/lwgeom/ptarray.c +++ b/liblwgeom/ptarray.c @@ -1,5 +1,5 @@ /********************************************************************** - * $Id$ + * $Id: ptarray.c 2797 2008-05-31 09:56:44Z mcayland $ * * PostGIS - Spatial Types for PostgreSQL * http://postgis.refractions.net diff --git a/lwgeom/vsprintf.c b/liblwgeom/vsprintf.c similarity index 100% rename from lwgeom/vsprintf.c rename to liblwgeom/vsprintf.c diff --git a/lwgeom/wktparse.h b/liblwgeom/wktparse.h similarity index 100% rename from lwgeom/wktparse.h rename to liblwgeom/wktparse.h diff --git a/lwgeom/wktparse.lex b/liblwgeom/wktparse.lex similarity index 100% rename from lwgeom/wktparse.lex rename to liblwgeom/wktparse.lex diff --git a/lwgeom/wktparse.tab.c b/liblwgeom/wktparse.tab.c similarity index 100% rename from lwgeom/wktparse.tab.c rename to liblwgeom/wktparse.tab.c diff --git a/lwgeom/wktparse.tab.h b/liblwgeom/wktparse.tab.h similarity index 100% rename from lwgeom/wktparse.tab.h rename to liblwgeom/wktparse.tab.h diff --git a/lwgeom/wktparse.y b/liblwgeom/wktparse.y similarity index 100% rename from lwgeom/wktparse.y rename to liblwgeom/wktparse.y diff --git a/lwgeom/Makefile.in b/lwgeom/Makefile.in index 1cd0a8296..076f89cdd 100644 --- a/lwgeom/Makefile.in +++ b/lwgeom/Makefile.in @@ -20,33 +20,8 @@ DATA=../spatial_ref_sys.sql # 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 \ @@ -75,10 +50,11 @@ PG_OBJS=liblwgeom.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) diff --git a/lwgeom/lwgeom_dump.c b/lwgeom/lwgeom_dump.c index f37225c23..e3f4d28ba 100644 --- a/lwgeom/lwgeom_dump.c +++ b/lwgeom/lwgeom_dump.c @@ -17,8 +17,6 @@ #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); diff --git a/lwgeom/lwgeom_functions_basic.c b/lwgeom/lwgeom_functions_basic.c index 2ee46a143..474dc786b 100644 --- a/lwgeom/lwgeom_functions_basic.c +++ b/lwgeom/lwgeom_functions_basic.c @@ -25,8 +25,6 @@ #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); @@ -112,8 +110,6 @@ Datum LWGEOM_summary(PG_FUNCTION_ARGS) text *mytext; LWGEOM *lwgeom; - init_pg_func(); - lwgeom = lwgeom_deserialize(SERIALIZED_FORM(geom)); result = lwgeom_summary(lwgeom, 0); @@ -2910,11 +2906,9 @@ Datum LWGEOM_asEWKT(PG_FUNCTION_ARGS) 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); @@ -2954,8 +2948,6 @@ Datum LWGEOM_azimuth(PG_FUNCTION_ARGS) 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)); diff --git a/lwgeom/lwgeom_geos_c.c b/lwgeom/lwgeom_geos_c.c index cb210b68d..06f8d514a 100644 --- a/lwgeom/lwgeom_geos_c.c +++ b/lwgeom/lwgeom_geos_c.c @@ -8,7 +8,7 @@ #include "lwgeom_pg.h" #include "liblwgeom.h" #include "profile.h" -#include "wktparse.h" + #include "geos_c.h" #include "lwgeom_rtree.h" diff --git a/lwgeom/lwgeom_gist.c b/lwgeom/lwgeom_gist.c index 01d3c2d05..c69666026 100644 --- a/lwgeom/lwgeom_gist.c +++ b/lwgeom/lwgeom_gist.c @@ -19,10 +19,6 @@ #include "lwgeom_pg.h" #include "stringBuffer.h" -#if POSTGIS_DEBUG_LEVEL > 0 -#include "wktparse.h" -#endif - /* * implementation GiST support and basic LWGEOM operations (like &&) diff --git a/lwgeom/lwgeom_inout.c b/lwgeom/lwgeom_inout.c index e981a1c41..8e75a7f63 100644 --- a/lwgeom/lwgeom_inout.c +++ b/lwgeom/lwgeom_inout.c @@ -24,7 +24,6 @@ #include "lwgeom_pg.h" -#include "wktparse.h" #include "profile.h" void elog_ERROR(const char* string); @@ -97,8 +96,6 @@ Datum LWGEOM_out(PG_FUNCTION_ARGS) 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); @@ -118,8 +115,6 @@ Datum LWGEOM_asHEXEWKB(PG_FUNCTION_ARGS) 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)) ) @@ -169,8 +164,6 @@ Datum LWGEOM_to_text(PG_FUNCTION_ARGS) 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); @@ -250,8 +243,6 @@ Datum WKBFromLWGEOM(PG_FUNCTION_ARGS) profstart(PROF_QRUN); #endif - init_pg_func(); - if ( (PG_NARGS()>1) && (!PG_ARGISNULL(1)) ) { type = PG_GETARG_TEXT_P(1); @@ -479,8 +470,6 @@ Datum parse_WKT_lwgeom(PG_FUNCTION_ARGS) char *wkt; int wkt_size ; - init_pg_func(); - wkt_size = VARSIZE(wkt_input)-VARHDRSZ; /* actual letters */ wkt = palloc( wkt_size+1); /* +1 for null */ @@ -490,7 +479,7 @@ Datum parse_WKT_lwgeom(PG_FUNCTION_ARGS) 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); diff --git a/lwgeom/lwgeom_ogc.c b/lwgeom/lwgeom_ogc.c index d0f1bd421..51195282d 100644 --- a/lwgeom/lwgeom_ogc.c +++ b/lwgeom/lwgeom_ogc.c @@ -28,9 +28,6 @@ #include "lwgeom_pg.h" - -#include "wktparse.h" - /* ---- SRID(geometry) */ Datum LWGEOM_getSRID(PG_FUNCTION_ARGS); /* ---- SetSRID(geometry, integer) */ @@ -121,8 +118,6 @@ Datum LWGEOM_getTYPE(PG_FUNCTION_ARGS) 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; @@ -1077,8 +1072,6 @@ Datum LWGEOM_asText(PG_FUNCTION_ARGS) POSTGIS_DEBUG(2, "LWGEOM_asText called."); - init_pg_func(); - lwgeom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); /* Force to 2d */ @@ -1113,8 +1106,6 @@ Datum LWGEOM_asBinary(PG_FUNCTION_ARGS) PG_LWGEOM *ogclwgeom; char *result; - init_pg_func(); - /* Force to 2d */ ogclwgeom = (PG_LWGEOM *)DatumGetPointer(DirectFunctionCall1( LWGEOM_force_2d, PG_GETARG_DATUM(0))); diff --git a/lwgeom/lwgeom_pg.c b/lwgeom/lwgeom_pg.c index d89c1f1a1..febf88fef 100644 --- a/lwgeom/lwgeom_pg.c +++ b/lwgeom/lwgeom_pg.c @@ -8,8 +8,6 @@ #include #include "liblwgeom.h" #include "lwgeom_pg.h" -#include "wktparse.h" - #define PARANOIA_LEVEL 1 @@ -17,7 +15,6 @@ /* * This is required for builds against pgsql 8.2 */ -/*#include "pgmagic.h"*/ #ifdef PG_MODULE_MAGIC PG_MODULE_MAGIC; #endif @@ -100,8 +97,9 @@ pg_notice(const char *fmt, ...) } 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; diff --git a/lwgeom/lwgeom_pg.h b/lwgeom/lwgeom_pg.h index c82f87e1f..67873174d 100644 --- a/lwgeom/lwgeom_pg.h +++ b/lwgeom/lwgeom_pg.h @@ -67,9 +67,6 @@ extern int pglwgeom_getSRID(PG_LWGEOM *pglwgeom); 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); diff --git a/lwgeom/lwgeom_sqlmm.c b/lwgeom/lwgeom_sqlmm.c index 442d45498..9390ccaf1 100644 --- a/lwgeom/lwgeom_sqlmm.c +++ b/lwgeom/lwgeom_sqlmm.c @@ -19,7 +19,7 @@ #include "postgres.h" #include "liblwgeom.h" #include "fmgr.h" -#include "wktparse.h" + #include "lwgeom_pg.h" -- 2.50.1