From b18e8b7bd739aa2a5ee7f20fe18e0d11aedc3bf2 Mon Sep 17 00:00:00 2001
From: Olivier Courtin <olivier.courtin@camptocamp.com>
Date: Mon, 22 Feb 2010 19:16:00 +0000
Subject: [PATCH] merge all export functions in a same file. remove useless old
 ones. rename SVG one to LWGEOM_asSVG for consistancy.

git-svn-id: http://svn.osgeo.org/postgis/trunk@5294 b70326c6-7e19-0410-871a-916f4a2858ee
---
 postgis/Makefile.in       |   4 -
 postgis/geography_inout.c |   1 -
 postgis/lwgeom_export.c   | 252 +++++++++++++++++++++++++++++++++++++-
 postgis/lwgeom_export.h   |  16 ---
 postgis/lwgeom_geojson.c  | 105 ----------------
 postgis/lwgeom_gml.c      |  94 --------------
 postgis/lwgeom_kml.c      |  80 ------------
 postgis/lwgeom_svg.c      |  70 -----------
 postgis/postgis.sql.in.c  |  12 +-
 9 files changed, 257 insertions(+), 377 deletions(-)
 delete mode 100644 postgis/lwgeom_export.h
 delete mode 100644 postgis/lwgeom_geojson.c
 delete mode 100644 postgis/lwgeom_gml.c
 delete mode 100644 postgis/lwgeom_kml.c
 delete mode 100644 postgis/lwgeom_svg.c

diff --git a/postgis/Makefile.in b/postgis/Makefile.in
index 3a22bb514..e9fa5c1c0 100644
--- a/postgis/Makefile.in
+++ b/postgis/Makefile.in
@@ -41,10 +41,6 @@ PG_OBJS=lwgeom_pg.o \
 	lwgeom_geos_prepared.o \
 	lwgeom_geos_clean.o \
 	lwgeom_export.o \
-	lwgeom_svg.o \
-	lwgeom_gml.o \
-	lwgeom_kml.o \
-	lwgeom_geojson.o \
 	lwgeom_in_gml.o \
 	lwgeom_in_kml.o \
 	lwgeom_triggers.o \
diff --git a/postgis/geography_inout.c b/postgis/geography_inout.c
index faa1a2fdd..4ae609c62 100644
--- a/postgis/geography_inout.c
+++ b/postgis/geography_inout.c
@@ -28,7 +28,6 @@
 #include "libgeom.h"         /* For standard geometry types. */
 #include "lwgeom_pg.h"       /* For debugging macros. */
 #include "geography.h"	     /* For utility functions. */
-#include "lwgeom_export.h"   /* For exports functions. */
 
 Datum geography_in(PG_FUNCTION_ARGS);
 Datum geography_out(PG_FUNCTION_ARGS);
diff --git a/postgis/lwgeom_export.c b/postgis/lwgeom_export.c
index af35b3b63..1e3a8c84d 100644
--- a/postgis/lwgeom_export.c
+++ b/postgis/lwgeom_export.c
@@ -20,7 +20,11 @@
 #include "lwgeom_pg.h"
 #include "liblwgeom.h"
 
-#include "lwgeom_export.h"
+Datum LWGEOM_asGML(PG_FUNCTION_ARGS);
+Datum LWGEOM_asKML(PG_FUNCTION_ARGS);
+Datum LWGEOM_asGeoJson(PG_FUNCTION_ARGS);
+Datum LWGEOM_asSVG(PG_FUNCTION_ARGS);
+
 
 /*
  * Retrieve an SRS from a given SRID
@@ -84,3 +88,249 @@ char * getSRSbySRID(int SRID, bool short_crs)
 
 	return srscopy;
 }
+
+
+/**
+ * Encode feature in GML
+ */
+PG_FUNCTION_INFO_V1(LWGEOM_asGML);
+Datum LWGEOM_asGML(PG_FUNCTION_ARGS)
+{
+	PG_LWGEOM *geom;
+	char *gml;
+	text *result;
+	int len;
+	int version;
+	char *srs;
+	int SRID;
+	int option = 0;
+	int is_deegree = 0;
+	int precision = OUT_MAX_DOUBLE_PRECISION;
+
+	/* Get the version */
+	version = PG_GETARG_INT32(0);
+	if ( version != 2 && version != 3 )
+	{
+		elog(ERROR, "Only GML 2 and GML 3 are supported");
+		PG_RETURN_NULL();
+	}
+
+	/* Get the geometry */
+	if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
+	geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+
+	/* Retrieve precision if any (default is max) */
+	if (PG_NARGS() >2 && !PG_ARGISNULL(2))
+	{
+		precision = PG_GETARG_INT32(2);
+		if ( precision > OUT_MAX_DOUBLE_PRECISION )
+			precision = OUT_MAX_DOUBLE_PRECISION;
+		else if ( precision < 0 ) precision = 0;
+	}
+
+	/* retrieve option */
+	if (PG_NARGS() >3 && !PG_ARGISNULL(3))
+		option = PG_GETARG_INT32(3);
+
+	SRID = lwgeom_getsrid(SERIALIZED_FORM(geom));
+	if (SRID == -1)      srs = NULL;
+	else if (option & 1) srs = getSRSbySRID(SRID, false);
+	else                 srs = getSRSbySRID(SRID, true);
+
+	if (option & 16) is_deegree = 1;
+
+	if (version == 2)
+		gml = lwgeom_to_gml2(SERIALIZED_FORM(geom), srs, precision);
+	else
+		gml = lwgeom_to_gml3(SERIALIZED_FORM(geom), srs, precision, is_deegree);
+
+	PG_FREE_IF_COPY(geom, 1);
+
+	len = strlen(gml) + VARHDRSZ;
+
+	result = palloc(len);
+	SET_VARSIZE(result, len);
+
+	memcpy(VARDATA(result), gml, len-VARHDRSZ);
+
+	lwfree(gml);
+
+	PG_RETURN_POINTER(result);
+}
+
+
+/**
+ * Encode feature in KML
+ */
+PG_FUNCTION_INFO_V1(LWGEOM_asKML);
+Datum LWGEOM_asKML(PG_FUNCTION_ARGS)
+{
+	PG_LWGEOM *geom;
+	char *kml;
+	text *result;
+	int len;
+	int version;
+	int precision = OUT_MAX_DOUBLE_PRECISION;
+
+
+	/* Get the version */
+	version = PG_GETARG_INT32(0);
+	if ( version != 2)
+	{
+		elog(ERROR, "Only KML 2 is supported");
+		PG_RETURN_NULL();
+	}
+
+	/* Get the geometry */
+	if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
+	geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+
+	/* Retrieve precision if any (default is max) */
+	if (PG_NARGS() >2 && !PG_ARGISNULL(2))
+	{
+		precision = PG_GETARG_INT32(2);
+		if ( precision > OUT_MAX_DOUBLE_PRECISION )
+			precision = OUT_MAX_DOUBLE_PRECISION;
+		else if ( precision < 0 ) precision = 0;
+	}
+
+	kml = lwgeom_to_kml2(SERIALIZED_FORM(geom), precision);
+
+	PG_FREE_IF_COPY(geom, 1);
+
+	len = strlen(kml) + VARHDRSZ;
+
+	result = palloc(len);
+	SET_VARSIZE(result, len);
+
+	memcpy(VARDATA(result), kml, len-VARHDRSZ);
+
+	lwfree(kml);
+
+	PG_RETURN_POINTER(result);
+}
+
+
+/**
+ * Encode Feature in GeoJson
+ */
+PG_FUNCTION_INFO_V1(LWGEOM_asGeoJson);
+Datum LWGEOM_asGeoJson(PG_FUNCTION_ARGS)
+{
+	PG_LWGEOM *geom;
+	char *geojson;
+	text *result;
+	int SRID;
+	int len;
+	int version;
+	int option = 0;
+	int has_bbox = 0;
+	int precision = OUT_MAX_DOUBLE_PRECISION;
+	char * srs = NULL;
+
+	/* Get the version */
+	version = PG_GETARG_INT32(0);
+	if ( version != 1)
+	{
+		elog(ERROR, "Only GeoJSON 1 is supported");
+		PG_RETURN_NULL();
+	}
+
+	/* Get the geometry */
+	if (PG_ARGISNULL(1) ) PG_RETURN_NULL();
+	geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
+
+	/* Retrieve precision if any (default is max) */
+	if (PG_NARGS() >2 && !PG_ARGISNULL(2))
+	{
+		precision = PG_GETARG_INT32(2);
+		if ( precision > OUT_MAX_DOUBLE_PRECISION )
+			precision = OUT_MAX_DOUBLE_PRECISION;
+		else if ( precision < 0 ) precision = 0;
+	}
+
+	/* Retrieve output option
+	 * 0 = without option (default)
+	 * 1 = bbox
+	 * 2 = short crs
+	 * 4 = long crs
+	 */
+	if (PG_NARGS() >3 && !PG_ARGISNULL(3))
+		option = PG_GETARG_INT32(3);
+
+	if (option & 2 || option & 4)
+	{
+		SRID = lwgeom_getsrid(SERIALIZED_FORM(geom));
+		if ( SRID != -1 )
+		{
+			if (option & 2) srs = getSRSbySRID(SRID, true);
+			if (option & 4) srs = getSRSbySRID(SRID, false);
+			if (!srs)
+			{
+				elog(	ERROR, 
+					"SRID %i unknown in spatial_ref_sys table",
+					SRID);
+				PG_RETURN_NULL();
+			}
+		}
+	}
+
+	if (option & 1) has_bbox = 1;
+
+	geojson = lwgeom_to_geojson(SERIALIZED_FORM(geom), srs, precision, has_bbox);
+
+	PG_FREE_IF_COPY(geom, 1);
+	if (srs) pfree(srs);
+
+	len = strlen(geojson) + VARHDRSZ;
+	result = palloc(len);
+	SET_VARSIZE(result, len);
+	memcpy(VARDATA(result), geojson, len-VARHDRSZ);
+
+	lwfree(geojson);
+
+	PG_RETURN_POINTER(result);
+}
+
+
+/**
+ * SVG features
+ */
+PG_FUNCTION_INFO_V1(LWGEOM_asSVG);
+Datum LWGEOM_asSVG(PG_FUNCTION_ARGS)
+{
+	PG_LWGEOM *geom;
+	char *svg;
+	text *result;
+	int len;
+	int relative = 0;
+	int precision=OUT_MAX_DOUBLE_PRECISION;
+
+	if ( PG_ARGISNULL(0) ) PG_RETURN_NULL();
+
+	geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
+
+	/* check for relative path notation */
+	if ( PG_NARGS() > 1 && ! PG_ARGISNULL(1) )
+		relative = PG_GETARG_INT32(1) ? 1:0;
+
+	if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
+	{
+		precision = PG_GETARG_INT32(2);
+		if ( precision > OUT_MAX_DOUBLE_PRECISION )
+			precision = OUT_MAX_DOUBLE_PRECISION;
+		else if ( precision < 0 ) precision = 0;
+	}
+
+	svg = lwgeom_to_svg(SERIALIZED_FORM(geom), precision, relative);
+	PG_FREE_IF_COPY(geom, 0);
+
+	len = strlen(svg) + VARHDRSZ;
+	result = palloc(len);
+	SET_VARSIZE(result, len);
+	memcpy(VARDATA(result), svg, len-VARHDRSZ);
+
+	lwfree(svg);
+
+	PG_RETURN_POINTER(result);
+}
diff --git a/postgis/lwgeom_export.h b/postgis/lwgeom_export.h
deleted file mode 100644
index c21a995be..000000000
--- a/postgis/lwgeom_export.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/**********************************************************************
- * $Id:$
- *
- * PostGIS - Export functions for PostgreSQL/PostGIS
- * Copyright 2009 Olivier Courtin <olivier.courtin@oslandia.com>
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of the GNU General Public Licence. See the COPYING file.
- *
- **********************************************************************/
-
-/**
- * Commons define and prototype function for all export functions
- */
-
-char * getSRSbySRID(int SRID, bool short_crs);
diff --git a/postgis/lwgeom_geojson.c b/postgis/lwgeom_geojson.c
deleted file mode 100644
index 746d3e7f6..000000000
--- a/postgis/lwgeom_geojson.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/**********************************************************************
- * $Id$
- *
- * PostGIS - Spatial Types for PostgreSQL
- * http://postgis.refractions.net
- * Copyright 2001-2003 Refractions Research Inc.
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of hte GNU General Public Licence. See the COPYING file.
- *
- **********************************************************************/
-/** @file
-* GeoJSON output routines.
-* Originally written by Olivier Courtin (Camptocamp)
-* 
-**********************************************************************/
-
-#include "postgres.h"
-
-#include "lwgeom_pg.h"
-#include "liblwgeom.h"
-#include "lwgeom_export.h"
-
-Datum LWGEOM_asGeoJson(PG_FUNCTION_ARGS);
-
-/**
- * Encode Feature in GeoJson
- */
-PG_FUNCTION_INFO_V1(LWGEOM_asGeoJson);
-Datum LWGEOM_asGeoJson(PG_FUNCTION_ARGS)
-{
-	PG_LWGEOM *geom;
-	char *geojson;
-	text *result;
-	int SRID;
-	int len;
-	int version;
-	int option = 0;
-	int has_bbox = 0;
-	int precision = OUT_MAX_DOUBLE_PRECISION;
-	char * srs = NULL;
-
-	/* Get the version */
-	version = PG_GETARG_INT32(0);
-	if ( version != 1)
-	{
-		elog(ERROR, "Only GeoJSON 1 is supported");
-		PG_RETURN_NULL();
-	}
-
-	/* Get the geometry */
-	if (PG_ARGISNULL(1) ) PG_RETURN_NULL();
-	geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
-
-	/* Retrieve precision if any (default is max) */
-	if (PG_NARGS() >2 && !PG_ARGISNULL(2))
-	{
-		precision = PG_GETARG_INT32(2);
-		if ( precision > OUT_MAX_DOUBLE_PRECISION )
-			precision = OUT_MAX_DOUBLE_PRECISION;
-		else if ( precision < 0 ) precision = 0;
-	}
-
-	/* Retrieve output option
-	 * 0 = without option (default)
-	 * 1 = bbox
-	 * 2 = short crs
-	 * 4 = long crs
-	 */
-	if (PG_NARGS() >3 && !PG_ARGISNULL(3))
-		option = PG_GETARG_INT32(3);
-
-	if (option & 2 || option & 4)
-	{
-		SRID = lwgeom_getsrid(SERIALIZED_FORM(geom));
-		if ( SRID != -1 )
-		{
-			if (option & 2) srs = getSRSbySRID(SRID, true);
-			if (option & 4) srs = getSRSbySRID(SRID, false);
-			if (!srs)
-			{
-				elog(	ERROR, 
-					"SRID %i unknown in spatial_ref_sys table",
-					SRID);
-				PG_RETURN_NULL();
-			}
-		}
-	}
-
-	if (option & 1) has_bbox = 1;
-
-	geojson = lwgeom_to_geojson(SERIALIZED_FORM(geom), srs, precision, has_bbox);
-
-	PG_FREE_IF_COPY(geom, 1);
-	if (srs) pfree(srs);
-
-	len = strlen(geojson) + VARHDRSZ;
-	result = palloc(len);
-	SET_VARSIZE(result, len);
-	memcpy(VARDATA(result), geojson, len-VARHDRSZ);
-
-	lwfree(geojson);
-
-	PG_RETURN_POINTER(result);
-}
diff --git a/postgis/lwgeom_gml.c b/postgis/lwgeom_gml.c
deleted file mode 100644
index 35f6b2f36..000000000
--- a/postgis/lwgeom_gml.c
+++ /dev/null
@@ -1,94 +0,0 @@
-/**********************************************************************
- * $Id$
- *
- * PostGIS - Spatial Types for PostgreSQL
- * http://postgis.refractions.net
- * Copyright 2001-2003 Refractions Research Inc.
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of hte GNU General Public Licence. See the COPYING file.
- *
- **********************************************************************/
-
-/**
-* @file GML output routines.
-*
-**********************************************************************/
-
-
-#include "postgres.h"
-
-#include "lwgeom_pg.h"
-#include "liblwgeom.h"
-#include "lwgeom_export.h"
-
-
-Datum LWGEOM_asGML(PG_FUNCTION_ARGS);
-
-/**
- * Encode feature in GML
- */
-PG_FUNCTION_INFO_V1(LWGEOM_asGML);
-Datum LWGEOM_asGML(PG_FUNCTION_ARGS)
-{
-	PG_LWGEOM *geom;
-	char *gml;
-	text *result;
-	int len;
-	int version;
-	char *srs;
-	int SRID;
-	int option = 0;
-	int is_deegree = 0;
-	int precision = OUT_MAX_DOUBLE_PRECISION;
-
-	/* Get the version */
-	version = PG_GETARG_INT32(0);
-	if ( version != 2 && version != 3 )
-	{
-		elog(ERROR, "Only GML 2 and GML 3 are supported");
-		PG_RETURN_NULL();
-	}
-
-	/* Get the geometry */
-	if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
-	geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
-
-	/* Retrieve precision if any (default is max) */
-	if (PG_NARGS() >2 && !PG_ARGISNULL(2))
-	{
-		precision = PG_GETARG_INT32(2);
-		if ( precision > OUT_MAX_DOUBLE_PRECISION )
-			precision = OUT_MAX_DOUBLE_PRECISION;
-		else if ( precision < 0 ) precision = 0;
-	}
-
-	/* retrieve option */
-	if (PG_NARGS() >3 && !PG_ARGISNULL(3))
-		option = PG_GETARG_INT32(3);
-
-	SRID = lwgeom_getsrid(SERIALIZED_FORM(geom));
-	if (SRID == -1)      srs = NULL;
-	else if (option & 1) srs = getSRSbySRID(SRID, false);
-	else                 srs = getSRSbySRID(SRID, true);
-
-	if (option & 16) is_deegree = 1;
-
-	if (version == 2)
-		gml = lwgeom_to_gml2(SERIALIZED_FORM(geom), srs, precision);
-	else
-		gml = lwgeom_to_gml3(SERIALIZED_FORM(geom), srs, precision, is_deegree);
-
-	PG_FREE_IF_COPY(geom, 1);
-
-	len = strlen(gml) + VARHDRSZ;
-
-	result = palloc(len);
-	SET_VARSIZE(result, len);
-
-	memcpy(VARDATA(result), gml, len-VARHDRSZ);
-
-	lwfree(gml);
-
-	PG_RETURN_POINTER(result);
-}
diff --git a/postgis/lwgeom_kml.c b/postgis/lwgeom_kml.c
deleted file mode 100644
index 774b1bb0d..000000000
--- a/postgis/lwgeom_kml.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/**********************************************************************
- * $Id$
- *
- * PostGIS - Spatial Types for PostgreSQL
- * http://postgis.refractions.net
- * Copyright 2001-2003 Refractions Research Inc.
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of hte GNU General Public Licence. See the COPYING file.
- *
- **********************************************************************/
-
-/**
-* @file
-* KML output routines based on lwgeom_gml.c
-* Written by: Eduin Carrillo <yecarrillo@cas.gov.co>
-*             © 2006 Corporacion Autonoma Regional de Santander - CAS
-*
-**********************************************************************/
-
-
-#include "postgres.h"
-#include "executor/spi.h"
-
-#include "lwgeom_pg.h"
-#include "liblwgeom.h"
-#include "lwgeom_export.h"
-
-Datum LWGEOM_asKML(PG_FUNCTION_ARGS);
-
-/**
- * Encode feature in KML
- */
-PG_FUNCTION_INFO_V1(LWGEOM_asKML);
-Datum LWGEOM_asKML(PG_FUNCTION_ARGS)
-{
-	PG_LWGEOM *geom;
-	char *kml;
-	text *result;
-	int len;
-	int version;
-	int precision = OUT_MAX_DOUBLE_PRECISION;
-
-
-	/* Get the version */
-	version = PG_GETARG_INT32(0);
-	if ( version != 2)
-	{
-		elog(ERROR, "Only KML 2 is supported");
-		PG_RETURN_NULL();
-	}
-
-	/* Get the geometry */
-	if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
-	geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
-
-	/* Retrieve precision if any (default is max) */
-	if (PG_NARGS() >2 && !PG_ARGISNULL(2))
-	{
-		precision = PG_GETARG_INT32(2);
-		if ( precision > OUT_MAX_DOUBLE_PRECISION )
-			precision = OUT_MAX_DOUBLE_PRECISION;
-		else if ( precision < 0 ) precision = 0;
-	}
-
-	kml = lwgeom_to_kml2(SERIALIZED_FORM(geom), precision);
-
-	PG_FREE_IF_COPY(geom, 1);
-
-	len = strlen(kml) + VARHDRSZ;
-
-	result = palloc(len);
-	SET_VARSIZE(result, len);
-
-	memcpy(VARDATA(result), kml, len-VARHDRSZ);
-
-	lwfree(kml);
-
-	PG_RETURN_POINTER(result);
-}
diff --git a/postgis/lwgeom_svg.c b/postgis/lwgeom_svg.c
deleted file mode 100644
index f10c607e5..000000000
--- a/postgis/lwgeom_svg.c
+++ /dev/null
@@ -1,70 +0,0 @@
-/**********************************************************************
- * $Id$
- *
- * PostGIS - Spatial Types for PostgreSQL
- * http://postgis.refractions.net
- * Copyright 2001-2003 Refractions Research Inc.
- *
- * This is free software; you can redistribute and/or modify it under
- * the terms of hte GNU General Public Licence. See the COPYING file.
- *
- **********************************************************************/
-
-/** @file
-*
-* SVG output routines.
-* Originally written by: Klaus Förster <klaus@svg.cc>
-* Refactored by: Olivier Courtin (Camptocamp)
-*
-* BNF SVG Path: <http://www.w3.org/TR/SVG/paths.html#PathDataBNF>
-**********************************************************************/
-
-
-#include "postgres.h"
-#include "liblwgeom.h"
-#include "lwgeom_pg.h"
-#include "lwgeom_export.h"
-
-Datum assvg_geometry(PG_FUNCTION_ARGS);
-
-/**
- * SVG features
- */
-PG_FUNCTION_INFO_V1(assvg_geometry);
-Datum assvg_geometry(PG_FUNCTION_ARGS)
-{
-	PG_LWGEOM *geom;
-	char *svg;
-	text *result;
-	int len;
-	int relative = 0;
-	int precision=OUT_MAX_DOUBLE_PRECISION;
-
-	if ( PG_ARGISNULL(0) ) PG_RETURN_NULL();
-
-	geom = (PG_LWGEOM *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
-
-	/* check for relative path notation */
-	if ( PG_NARGS() > 1 && ! PG_ARGISNULL(1) )
-		relative = PG_GETARG_INT32(1) ? 1:0;
-
-	if ( PG_NARGS() > 2 && ! PG_ARGISNULL(2) )
-	{
-		precision = PG_GETARG_INT32(2);
-		if ( precision > OUT_MAX_DOUBLE_PRECISION )
-			precision = OUT_MAX_DOUBLE_PRECISION;
-		else if ( precision < 0 ) precision = 0;
-	}
-
-	svg = lwgeom_to_svg(SERIALIZED_FORM(geom), precision, relative);
-	PG_FREE_IF_COPY(geom, 0);
-
-	len = strlen(svg) + VARHDRSZ;
-	result = palloc(len);
-	SET_VARSIZE(result, len);
-	memcpy(VARDATA(result), svg, len-VARHDRSZ);
-
-	lwfree(svg);
-
-	PG_RETURN_POINTER(result);
-}
diff --git a/postgis/postgis.sql.in.c b/postgis/postgis.sql.in.c
index 00506d894..69a078405 100644
--- a/postgis/postgis.sql.in.c
+++ b/postgis/postgis.sql.in.c
@@ -4625,37 +4625,37 @@ CREATE OR REPLACE FUNCTION ST_GeomFromKML(text)
 -- Deprecation in 1.2.3
 CREATE OR REPLACE FUNCTION AsSVG(geometry,int4,int4)
 	RETURNS TEXT
-	AS 'MODULE_PATHNAME','assvg_geometry'
+	AS 'MODULE_PATHNAME','LWGEOM_asSVG'
 	LANGUAGE 'C' IMMUTABLE STRICT;
 
 -- Availability: 1.2.2
 CREATE OR REPLACE FUNCTION ST_AsSVG(geometry,int4,int4)
 	RETURNS TEXT
-	AS 'MODULE_PATHNAME','assvg_geometry'
+	AS 'MODULE_PATHNAME','LWGEOM_asSVG'
 	LANGUAGE 'C' IMMUTABLE STRICT;
 
 -- Deprecation in 1.2.3
 CREATE OR REPLACE FUNCTION AsSVG(geometry,int4)
 	RETURNS TEXT
-	AS 'MODULE_PATHNAME','assvg_geometry'
+	AS 'MODULE_PATHNAME','LWGEOM_asSVG'
 	LANGUAGE 'C' IMMUTABLE STRICT;
 
 -- Availability: 1.2.2
 CREATE OR REPLACE FUNCTION ST_AsSVG(geometry,int4)
 	RETURNS TEXT
-	AS 'MODULE_PATHNAME','assvg_geometry'
+	AS 'MODULE_PATHNAME','LWGEOM_asSVG'
 	LANGUAGE 'C' IMMUTABLE STRICT;
 
 -- Deprecation in 1.2.3
 CREATE OR REPLACE FUNCTION AsSVG(geometry)
 	RETURNS TEXT
-	AS 'MODULE_PATHNAME','assvg_geometry'
+	AS 'MODULE_PATHNAME','LWGEOM_asSVG'
 	LANGUAGE 'C' IMMUTABLE STRICT;
 
 -- Availability: 1.2.2
 CREATE OR REPLACE FUNCTION ST_AsSVG(geometry)
 	RETURNS TEXT
-	AS 'MODULE_PATHNAME','assvg_geometry'
+	AS 'MODULE_PATHNAME','LWGEOM_asSVG'
 	LANGUAGE 'C' IMMUTABLE STRICT;
 
 -----------------------------------------------------------------------
-- 
2.40.0