[postgis-tickets] r16390 - Drop cstring2text/text2cstring in favor of PostgreSQL functions

Darafei komzpa at gmail.com
Tue Feb 20 08:16:45 PST 2018


Author: komzpa
Date: 2018-02-20 08:16:45 -0800 (Tue, 20 Feb 2018)
New Revision: 16390

Modified:
   trunk/libpgcommon/lwgeom_pg.c
   trunk/libpgcommon/lwgeom_pg.h
   trunk/postgis/geography_inout.c
   trunk/postgis/gserialized_estimate.c
   trunk/postgis/gserialized_typmod.c
   trunk/postgis/lwgeom_export.c
   trunk/postgis/lwgeom_functions_basic.c
   trunk/postgis/lwgeom_geos.c
   trunk/postgis/lwgeom_geos_relatematch.c
   trunk/postgis/lwgeom_in_encoded_polyline.c
   trunk/postgis/lwgeom_in_geohash.c
   trunk/postgis/lwgeom_in_geojson.c
   trunk/postgis/lwgeom_in_gml.c
   trunk/postgis/lwgeom_in_kml.c
   trunk/postgis/lwgeom_inout.c
   trunk/postgis/lwgeom_ogc.c
   trunk/postgis/lwgeom_sfcgal.c
   trunk/postgis/lwgeom_transform.c
   trunk/postgis/postgis_libprotobuf.c
   trunk/raster/rt_pg/rtpg_spatial_relationship.c
   trunk/raster/rt_pg/rtpg_utility.c
   trunk/topology/postgis_topology.c
Log:
Drop cstring2text/text2cstring in favor of PostgreSQL functions

Patch by Raúl Marín Rodríguez

Closes https://github.com/postgis/postgis/pull/213
Closes #4022



Modified: trunk/libpgcommon/lwgeom_pg.c
===================================================================
--- trunk/libpgcommon/lwgeom_pg.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/libpgcommon/lwgeom_pg.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -31,40 +31,6 @@
 
 #define PGC_ERRMSG_MAXLEN 2048 //256
 
-/**
-* Utility to convert cstrings to textp pointers
-*/
-text*
-cstring2text(const char *cstring)
-{
-	text *output;
-	size_t sz;
-
-	/* Guard against null input */
-	if( !cstring )
-		return NULL;
-
-	sz = strlen(cstring);
-	output = palloc(sz + VARHDRSZ);
-	if ( ! output )
-		return NULL;
-	SET_VARSIZE(output, sz + VARHDRSZ);
-	if ( sz )
-		memcpy(VARDATA(output),cstring,sz);
-	return output;
-}
-
-char*
-text2cstring(const text *textptr)
-{
-	size_t size = VARSIZE(textptr) - VARHDRSZ;
-	char *str = lwalloc(size+1);
-	memcpy(str, VARDATA(textptr), size);
-	str[size]='\0';
-	return str;
-}
-
-
 /*
  * Error message parsing functions
  *

Modified: trunk/libpgcommon/lwgeom_pg.h
===================================================================
--- trunk/libpgcommon/lwgeom_pg.h	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/libpgcommon/lwgeom_pg.h	2018-02-20 16:16:45 UTC (rev 16390)
@@ -124,18 +124,6 @@
 */
 int gserialized_datum_get_gbox_p(Datum gsdatum, GBOX *gbox);
 
-/**
-* Convert cstrings (null-terminated byte array) to textp pointers
-* (PgSQL varlena structure with VARSIZE header).
-*/
-text* cstring2text(const char *cstring);
-
-/**
-* Convert textp (PgSQL varlena structure with VARSIZE header) to
-* cstrings (null-terminated byte array).
-*/
-char* text2cstring(const text *textptr);
-
 /*
  * For PostgreSQL >= 8.5 redefine the STATRELATT macro to its
  * new value of STATRELATTINH

Modified: trunk/postgis/geography_inout.c
===================================================================
--- trunk/postgis/geography_inout.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/geography_inout.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -336,7 +336,7 @@
 		PG_RETURN_NULL();
 
 	/* Turn string result into text for return */
-	result = cstring2text(gml);
+	result = cstring_to_text(gml);
 	lwfree(gml);
 
 	PG_RETURN_TEXT_P(result);
@@ -415,7 +415,7 @@
 	if ( ! kml )
 		PG_RETURN_NULL();
 
-	result = cstring2text(kml);
+	result = cstring_to_text(kml);
 	lwfree(kml);
 
 	PG_RETURN_TEXT_P(result);
@@ -460,7 +460,7 @@
     lwgeom_free(lwgeom);
 	PG_FREE_IF_COPY(g, 0);
 
-	result = cstring2text(svg);
+	result = cstring_to_text(svg);
 	lwfree(svg);
 
 	PG_RETURN_TEXT_P(result);
@@ -537,7 +537,7 @@
 	PG_FREE_IF_COPY(g, 1);
 	if (srs) pfree(srs);
 
-	result = cstring2text(geojson);
+	result = cstring_to_text(geojson);
 	lwfree(geojson);
 
 	PG_RETURN_TEXT_P(result);
@@ -557,7 +557,7 @@
 	text *wkt_text = PG_GETARG_TEXT_P(0);
 
 	/* Extract the cstring from the varlena */
-	char *wkt = text2cstring(wkt_text);
+	char *wkt = text_to_cstring(wkt_text);
 
 	/* Pass the cstring to the input parser, and magic occurs! */
 	if ( lwgeom_parse_wkt(&lwg_parser_result, wkt, LW_PARSER_CHECK_ALL) == LW_FAILURE )

Modified: trunk/postgis/gserialized_estimate.c
===================================================================
--- trunk/postgis/gserialized_estimate.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/gserialized_estimate.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -976,7 +976,7 @@
 static ND_STATS*
 pg_get_nd_stats_by_name(const Oid table_oid, const text *att_text, int mode, bool only_parent)
 {
-	const char *att_name = text2cstring(att_text);
+	const char *att_name = text_to_cstring(att_text);
 	AttrNumber att_num;
 
 	/* We know the name? Look up the num */
@@ -2052,11 +2052,11 @@
 	/* Retrieve the stats object */
 	nd_stats = pg_get_nd_stats_by_name(table_oid, att_text, mode, only_parent);
 	if ( ! nd_stats )
-		elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid), text2cstring(att_text));
+		elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid), text_to_cstring(att_text));
 
 	/* Convert to JSON */
 	str = nd_stats_to_json(nd_stats);
-	json = cstring2text(str);
+	json = cstring_to_text(str);
 	pfree(str);
 	pfree(nd_stats);
 	PG_RETURN_TEXT_P(json);
@@ -2086,7 +2086,7 @@
 	nd_stats = pg_get_nd_stats_by_name(table_oid, att_text, mode, false);
 
 	if ( ! nd_stats )
-		elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid), text2cstring(att_text));
+		elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid), text_to_cstring(att_text));
 
 	/* Calculate the gbox */
 	if ( ! gserialized_datum_get_gbox_p(geom_datum, &gbox) )
@@ -2123,16 +2123,16 @@
 	nd_stats2 = pg_get_nd_stats_by_name(table_oid2, att_text2, mode, false);
 
 	if ( ! nd_stats1 )
-		elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid1), text2cstring(att_text1));
+		elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid1), text_to_cstring(att_text1));
 
 	if ( ! nd_stats2 )
-		elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid2), text2cstring(att_text2));
+		elog(ERROR, "stats for \"%s.%s\" do not exist", get_rel_name(table_oid2), text_to_cstring(att_text2));
 
 	/* Check if we've been asked to not use 2d mode */
 	if ( ! PG_ARGISNULL(4) )
 	{
 		text *modetxt = PG_GETARG_TEXT_P(4);
-		char *modestr = text2cstring(modetxt);
+		char *modestr = text_to_cstring(modetxt);
 		if ( modestr[0] == 'N' )
 			mode = 0;
 	}
@@ -2294,8 +2294,8 @@
 
 	if ( PG_NARGS() == 4 )
 	{
-		nsp = text2cstring(PG_GETARG_TEXT_P(0));
-		tbl = text2cstring(PG_GETARG_TEXT_P(1));
+		nsp = text_to_cstring(PG_GETARG_TEXT_P(0));
+		tbl = text_to_cstring(PG_GETARG_TEXT_P(1));
 		col = PG_GETARG_TEXT_P(2);
 		only_parent = PG_GETARG_BOOL(3);
 		nsp_tbl = palloc(strlen(nsp) + strlen(tbl) + 6);
@@ -2305,8 +2305,8 @@
 	}
 	else if ( PG_NARGS() == 3 )
 	{
-		nsp = text2cstring(PG_GETARG_TEXT_P(0));
-		tbl = text2cstring(PG_GETARG_TEXT_P(1));
+		nsp = text_to_cstring(PG_GETARG_TEXT_P(0));
+		tbl = text_to_cstring(PG_GETARG_TEXT_P(1));
 		col = PG_GETARG_TEXT_P(2);
 		nsp_tbl = palloc(strlen(nsp) + strlen(tbl) + 6);
 		sprintf(nsp_tbl, "\"%s\".\"%s\"", nsp, tbl);
@@ -2315,7 +2315,7 @@
 	}
 	else if ( PG_NARGS() == 2 )
 	{
-		tbl = text2cstring(PG_GETARG_TEXT_P(0));
+		tbl = text_to_cstring(PG_GETARG_TEXT_P(0));
 		col = PG_GETARG_TEXT_P(1);
 		nsp_tbl = palloc(strlen(tbl) + 3);
 		sprintf(nsp_tbl, "\"%s\"", tbl);
@@ -2332,7 +2332,7 @@
 	/* Read the extent from the head of the spatial index, if there is one */
 	idx_oid = table_get_spatial_index(tbl_oid, col, &key_type);
 	if (!idx_oid)
-		elog(DEBUG2, "index for \"%s.%s\" does not exist", tbl, text2cstring(col));
+		elog(DEBUG2, "index for \"%s.%s\" does not exist", tbl, text_to_cstring(col));
 	gbox = spatial_index_read_extent(idx_oid, key_type);
 #endif
 
@@ -2344,7 +2344,7 @@
 
 		/* Error out on no stats */
 		if ( ! nd_stats ) {
-			elog(WARNING, "stats for \"%s.%s\" do not exist", tbl, text2cstring(col));
+			elog(WARNING, "stats for \"%s.%s\" do not exist", tbl, text_to_cstring(col));
 			PG_RETURN_NULL();
 		}
 
@@ -2411,7 +2411,7 @@
 	ListCell *lc;
 	List *idx_list;
 	Oid result = InvalidOid;
-	char *colname = text2cstring(col);
+	char *colname = text_to_cstring(col);
 
 	/* Lookup our spatial index key types */
 	Oid b2d_oid = typname_to_oid(INDEX_KEY_2D);

Modified: trunk/postgis/gserialized_typmod.c
===================================================================
--- trunk/postgis/gserialized_typmod.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/gserialized_typmod.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -379,7 +379,7 @@
 	if ( typmod >= 0 && TYPMOD_GET_M(typmod) )
 		ptr += sprintf(ptr, "%s", "M");
 
-	stext = cstring2text(s);
+	stext = cstring_to_text(s);
 	pfree(s);
 	PG_RETURN_TEXT_P(stext);
 }

Modified: trunk/postgis/lwgeom_export.c
===================================================================
--- trunk/postgis/lwgeom_export.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/lwgeom_export.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -31,6 +31,7 @@
 #include "float.h" /* for DBL_DIG */
 #include "postgres.h"
 #include "executor/spi.h"
+#include "utils/builtins.h"
 
 #include "../postgis_config.h"
 #include "lwgeom_pg.h"
@@ -304,7 +305,7 @@
 	if ( ! gml )
 		PG_RETURN_NULL();
 
-	result = cstring2text(gml);
+	result = cstring_to_text(gml);
 	lwfree(gml);
 	PG_RETURN_TEXT_P(result);
 }
@@ -379,7 +380,7 @@
 	if( ! kml )
 		PG_RETURN_NULL();
 
-	result = cstring2text(kml);
+	result = cstring_to_text(kml);
 	lwfree(kml);
 
 	PG_RETURN_POINTER(result);
@@ -480,7 +481,7 @@
 
 	if (srs) pfree(srs);
 
-	result = cstring2text(geojson);
+	result = cstring_to_text(geojson);
 	lwfree(geojson);
 
 	PG_FREE_IF_COPY(geom, 0);
@@ -520,7 +521,7 @@
 
 	lwgeom = lwgeom_from_gserialized(geom);
 	svg = lwgeom_to_svg(lwgeom, precision, relative);
-	result = cstring2text(svg);
+	result = cstring_to_text(svg);
 	lwgeom_free(lwgeom);
 	pfree(svg);
 	PG_FREE_IF_COPY(geom, 0);
@@ -619,7 +620,7 @@
 	lwgeom_free(lwgeom);
 	PG_FREE_IF_COPY(geom, 1);
 
-	result = cstring2text(x3d);
+	result = cstring_to_text(x3d);
 	lwfree(x3d);
 
 	PG_RETURN_TEXT_P(result);
@@ -657,7 +658,7 @@
 	lwgeom_free(lwgeom);
 	PG_FREE_IF_COPY(geom, 0);
 
-	result = cstring2text(encodedpolyline);
+	result = cstring_to_text(encodedpolyline);
 	lwfree(encodedpolyline);
 
 	PG_RETURN_TEXT_P(result);

Modified: trunk/postgis/lwgeom_functions_basic.c
===================================================================
--- trunk/postgis/lwgeom_functions_basic.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/lwgeom_functions_basic.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -25,8 +25,9 @@
 
 #include "postgres.h"
 #include "fmgr.h"
+#include "utils/array.h"
+#include "utils/builtins.h"
 #include "utils/elog.h"
-#include "utils/array.h"
 #include "utils/geo_decls.h"
 
 #include "../postgis_config.h"
@@ -140,7 +141,7 @@
 	lwgeom_free(lwgeom);
 
 	/* create a text obj to return */
-	mytext = cstring2text(result);
+	mytext = cstring_to_text(result);
 	pfree(result);
 
 	PG_FREE_IF_COPY(geom,0);
@@ -151,7 +152,7 @@
 Datum postgis_version(PG_FUNCTION_ARGS)
 {
 	char *ver = POSTGIS_VERSION;
-	text *result = cstring2text(ver);
+	text *result = cstring_to_text(ver);
 	PG_RETURN_TEXT_P(result);
 }
 
@@ -159,7 +160,7 @@
 Datum postgis_liblwgeom_version(PG_FUNCTION_ARGS)
 {
 	const char *ver = lwgeom_version();
-	text *result = cstring2text(ver);
+	text *result = cstring_to_text(ver);
 	PG_RETURN_TEXT_P(result);
 }
 
@@ -167,7 +168,7 @@
 Datum postgis_lib_version(PG_FUNCTION_ARGS)
 {
 	char *ver = POSTGIS_LIB_VERSION;
-	text *result = cstring2text(ver);
+	text *result = cstring_to_text(ver);
 	PG_RETURN_TEXT_P(result);
 }
 
@@ -179,7 +180,7 @@
 	if ( rev > 0 )
 	{
 		snprintf(ver, 32, "%d", rev);
-		PG_RETURN_TEXT_P(cstring2text(ver));
+		PG_RETURN_TEXT_P(cstring_to_text(ver));
 	}
 	else
 		PG_RETURN_NULL();
@@ -189,7 +190,7 @@
 Datum postgis_lib_build_date(PG_FUNCTION_ARGS)
 {
 	char *ver = POSTGIS_BUILD_DATE;
-	text *result = cstring2text(ver);
+	text *result = cstring_to_text(ver);
 	PG_RETURN_TEXT_P(result);
 }
 
@@ -202,7 +203,7 @@
 	snprintf(ver, 64, "%s r%d", POSTGIS_LIB_VERSION, POSTGIS_SVN_REVISION);
 	ver[63] = '\0';
 
-	result = cstring2text(ver);
+	result = cstring_to_text(ver);
 	PG_RETURN_TEXT_P(result);
 }
 
@@ -227,7 +228,7 @@
 Datum postgis_libxml_version(PG_FUNCTION_ARGS)
 {
 	char *ver = POSTGIS_LIBXML2_VERSION;
-	text *result = cstring2text(ver);
+	text *result = cstring_to_text(ver);
 	PG_RETURN_TEXT_P(result);
 }
 
@@ -2345,7 +2346,7 @@
 	lwgeom_free(lwgeom);
 
 	/* Write to text and free the WKT */
-	result = cstring2text(wkt);
+	result = cstring_to_text(wkt);
 	pfree(wkt);
 
 	/* Return the text */
@@ -2676,7 +2677,7 @@
 	if ( ! geohash )
 		PG_RETURN_NULL();
 
-	result = cstring2text(geohash);
+	result = cstring_to_text(geohash);
 	pfree(geohash);
 
 	PG_RETURN_TEXT_P(result);

Modified: trunk/postgis/lwgeom_geos.c
===================================================================
--- trunk/postgis/lwgeom_geos.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/lwgeom_geos.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -113,7 +113,7 @@
 Datum postgis_geos_version(PG_FUNCTION_ARGS)
 {
 	const char *ver = lwgeom_geos_version();
-	text *result = cstring2text(ver);
+	text *result = cstring_to_text(ver);
 	PG_RETURN_POINTER(result);
 }
 
@@ -1140,7 +1140,7 @@
 	if ( nargs > 2 )
 	{
 		text *wkttext = PG_GETARG_TEXT_P(2);
-		paramstr = text2cstring(wkttext);
+		paramstr = text_to_cstring(wkttext);
 
 		POSTGIS_DEBUGF(3, "paramstr: %s", paramstr);
 
@@ -1204,7 +1204,7 @@
 			}
 		}
 		POSTGIS_DEBUGF(3, "joinStyle:%d mitreLimit:%g", joinStyle, mitreLimit);
-		pfree(paramstr); /* alloc'ed in text2cstring */
+		pfree(paramstr); /* alloc'ed in text_to_cstring */
 	}
 
 	lwgeom_result = lwgeom_offsetcurve(lwgeom_as_lwline(lwgeom_input), size, quadsegs, joinStyle, mitreLimit);
@@ -1600,12 +1600,12 @@
 		reason_str = GEOSisValidReason(g1);
 		GEOSGeom_destroy((GEOSGeometry *)g1);
 		if (!reason_str) HANDLE_GEOS_ERROR("GEOSisValidReason");
-		result = cstring2text(reason_str);
+		result = cstring_to_text(reason_str);
 		GEOSFree(reason_str);
 	}
 	else
 	{
-		result = cstring2text(lwgeom_geos_errmsg);
+		result = cstring_to_text(lwgeom_geos_errmsg);
 	}
 
 	PG_FREE_IF_COPY(geom, 0);
@@ -2677,7 +2677,7 @@
 
 	if (!relate_str) HANDLE_GEOS_ERROR("GEOSRelate");
 
-	result = cstring2text(relate_str);
+	result = cstring_to_text(relate_str);
 	GEOSFree(relate_str);
 
 	PG_FREE_IF_COPY(geom1, 0);

Modified: trunk/postgis/lwgeom_geos_relatematch.c
===================================================================
--- trunk/postgis/lwgeom_geos_relatematch.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/lwgeom_geos_relatematch.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -26,6 +26,7 @@
 #include "postgres.h"
 #include "fmgr.h"
 #include "funcapi.h"
+#include "utils/builtins.h"
 
 #include "../postgis_config.h"
 #include "lwgeom_geos.h"
@@ -49,8 +50,8 @@
         pat_text = (PG_GETARG_TEXT_P(1));
 
         /* Convert from text to cstring */
-        mat = text2cstring(mat_text);
-        pat = text2cstring(pat_text);
+        mat = text_to_cstring(mat_text);
+        pat = text_to_cstring(pat_text);
 
 	initGEOS(lwpgnotice, lwgeom_geos_error);
 

Modified: trunk/postgis/lwgeom_in_encoded_polyline.c
===================================================================
--- trunk/postgis/lwgeom_in_encoded_polyline.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/lwgeom_in_encoded_polyline.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -26,6 +26,7 @@
 #include <assert.h>
 
 #include "postgres.h"
+#include "utils/builtins.h"
 
 #include "../postgis_config.h"
 #include "lwgeom_pg.h"
@@ -45,7 +46,7 @@
   if (PG_ARGISNULL(0)) PG_RETURN_NULL();
 
   encodedpolyline_input = PG_GETARG_TEXT_P(0);
-  encodedpolyline = text2cstring(encodedpolyline_input);
+  encodedpolyline = text_to_cstring(encodedpolyline_input);
 
   if (PG_NARGS() > 1 && !PG_ARGISNULL(1))
   {

Modified: trunk/postgis/lwgeom_in_geohash.c
===================================================================
--- trunk/postgis/lwgeom_in_geohash.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/lwgeom_in_geohash.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -26,6 +26,7 @@
 #include <assert.h>
 
 #include "postgres.h"
+#include "utils/builtins.h"
 
 #include "../postgis_config.h"
 #include "lwgeom_pg.h"
@@ -92,7 +93,7 @@
 	}
 
 	geohash_input = PG_GETARG_TEXT_P(0);
-	geohash = text2cstring(geohash_input);
+	geohash = text_to_cstring(geohash_input);
 
 	box = parse_geohash(geohash, precision);
 
@@ -121,7 +122,7 @@
 	}
 
 	geohash_input = PG_GETARG_TEXT_P(0);
-	geohash = text2cstring(geohash_input);
+	geohash = text_to_cstring(geohash_input);
 
 	box = parse_geohash(geohash, precision);
 

Modified: trunk/postgis/lwgeom_in_geojson.c
===================================================================
--- trunk/postgis/lwgeom_in_geojson.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/lwgeom_in_geojson.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -38,6 +38,28 @@
 # else
 #  include <json/json.h>
 # endif
+
+/* We don't include <utils/builtins.h> to avoid collisions with json-c/json.h */
+static text*
+cstring2text(const char *cstring)
+{
+	size_t len = strlen(cstring);
+	text *result = (text *) palloc(len + VARHDRSZ);
+	SET_VARSIZE(result, len + VARHDRSZ);
+	memcpy(VARDATA(result), cstring, len);
+
+	return result;
+}
+
+static char*
+text2cstring(const text *textptr)
+{
+	size_t size = VARSIZE(textptr) - VARHDRSZ;
+	char *str = lwalloc(size+1);
+	memcpy(str, VARDATA(textptr), size);
+	str[size]='\0';
+	return str;
+}
 #endif
 
 Datum geom_from_geojson(PG_FUNCTION_ARGS);

Modified: trunk/postgis/lwgeom_in_gml.c
===================================================================
--- trunk/postgis/lwgeom_in_gml.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/lwgeom_in_gml.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -54,6 +54,7 @@
 
 #include "postgres.h"
 #include "executor/spi.h"
+#include "utils/builtins.h"
 
 #include "../postgis_config.h"
 #include "lwgeom_pg.h"
@@ -106,7 +107,7 @@
 	/* Get the GML stream */
 	if (PG_ARGISNULL(0)) PG_RETURN_NULL();
 	xml_input = PG_GETARG_TEXT_P(0);
-	xml = text2cstring(xml_input);
+	xml = text_to_cstring(xml_input);
 
 	/* Zero for undefined */
 	root_srid = PG_GETARG_INT32(1);

Modified: trunk/postgis/lwgeom_in_kml.c
===================================================================
--- trunk/postgis/lwgeom_in_kml.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/lwgeom_in_kml.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -45,6 +45,7 @@
 #include <string.h>
 
 #include "postgres.h"
+#include "utils/builtins.h"
 
 #include "../postgis_config.h"
 #include "lwgeom_pg.h"
@@ -86,7 +87,7 @@
 	/* Get the KML stream */
 	if (PG_ARGISNULL(0)) PG_RETURN_NULL();
 	xml_input = PG_GETARG_TEXT_P(0);
-	xml = text2cstring(xml_input);
+	xml = text_to_cstring(xml_input);
 	xml_size = VARSIZE(xml_input) - VARHDRSZ;
 
 	/* Begin to Parse XML doc */

Modified: trunk/postgis/lwgeom_inout.c
===================================================================
--- trunk/postgis/lwgeom_inout.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/lwgeom_inout.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -39,8 +39,9 @@
 #include "fmgr.h"
 #include "utils/elog.h"
 #include "mb/pg_wchar.h"
-# include "lib/stringinfo.h" /* for binary input */
+#include "lib/stringinfo.h" /* for binary input */
 #include "utils/array.h"
+#include "utils/builtins.h"
 #include "utils/lsyscache.h"
 #include "funcapi.h"
 
@@ -222,7 +223,7 @@
     PG_RETURN_NULL();
   }
 
-	format_str = text2cstring(format_text);
+	format_str = text_to_cstring(format_text);
   assert(format_str != NULL);
 
   /* The input string supposedly will be in the database encoding,
@@ -251,7 +252,7 @@
   }
 
 	/* Convert to the postgres output string type. */
-	formatted_text = cstring2text(formatted_str);
+	formatted_text = cstring_to_text(formatted_str);
   pfree(formatted_str);
 
 	PG_RETURN_POINTER(formatted_text);
@@ -350,7 +351,7 @@
 	lwgeom_free(lwgeom);
 
 	/* Copy into text obect */
-	result = cstring2text(hexwkb);
+	result = cstring_to_text(hexwkb);
 	pfree(hexwkb);
 
 	/* Clean up and return */
@@ -731,7 +732,7 @@
 	Datum result;
 
 	/* Unwrap the PgSQL text type into a cstring */
-	wkt = text2cstring(wkt_text);
+	wkt = text_to_cstring(wkt_text);
 
 	/* Now we call over to the geometry_in function */
 	result = DirectFunctionCall1(LWGEOM_in, CStringGetDatum(wkt));

Modified: trunk/postgis/lwgeom_ogc.c
===================================================================
--- trunk/postgis/lwgeom_ogc.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/lwgeom_ogc.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -35,6 +35,7 @@
 #include "access/itup.h"
 
 #include "fmgr.h"
+#include "utils/builtins.h"
 #include "utils/elog.h"
 
 #include "../postgis_config.h"
@@ -191,7 +192,7 @@
 	strncat(type_str, lwtype_name(gserialized_get_type(gser)), type_str_len - 3);
 
 	/* Build a text type to store things in */
-	type_text = cstring2text(type_str);
+	type_text = cstring_to_text(type_str);
 
 	PG_FREE_IF_COPY(gser, 0);
 	PG_RETURN_TEXT_P(type_text);
@@ -784,7 +785,7 @@
 Datum LWGEOM_from_text(PG_FUNCTION_ARGS)
 {
 	text *wkttext = PG_GETARG_TEXT_P(0);
-	char *wkt = text2cstring(wkttext);
+	char *wkt = text_to_cstring(wkttext);
 	LWGEOM_PARSER_RESULT lwg_parser_result;
 	GSERIALIZED *geom_result = NULL;
 	LWGEOM *lwgeom;
@@ -878,7 +879,7 @@
 	POSTGIS_DEBUGF(3, "WKT size = %u, WKT length = %u", (unsigned int)wkt_size, (unsigned int)strlen(wkt));
 
 	/* Write to text and free the WKT */
-	result = cstring2text(wkt);
+	result = cstring_to_text(wkt);
 	pfree(wkt);
 
 	/* Return the text */

Modified: trunk/postgis/lwgeom_sfcgal.c
===================================================================
--- trunk/postgis/lwgeom_sfcgal.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/lwgeom_sfcgal.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -25,6 +25,7 @@
 
 #include "postgres.h"
 #include "fmgr.h"
+#include "utils/builtins.h"
 #include "../liblwgeom/liblwgeom.h"
 
 #include "lwgeom_pg.h"
@@ -62,7 +63,7 @@
 
 
 GSERIALIZED *geometry_serialize(LWGEOM *lwgeom);
-char* text2cstring(const text *textptr);
+char* text_to_cstring(const text *textptr);
 
 static int __sfcgal_init = 0;
 
@@ -143,7 +144,7 @@
 	GSERIALIZED* result;
 	sfcgal_prepared_geometry_t* g;
 	text *wkttext = PG_GETARG_TEXT_P(0);
-	char *cstring = text2cstring(wkttext);
+	char *cstring = text_to_cstring(wkttext);
 
 	sfcgal_postgis_init();
 
@@ -721,7 +722,7 @@
 Datum postgis_sfcgal_version(PG_FUNCTION_ARGS)
 {
         const char *ver = lwgeom_sfcgal_version();
-        text *result = cstring2text(ver);
+        text *result = cstring_to_text(ver);
         PG_RETURN_POINTER(result);
 }
 

Modified: trunk/postgis/lwgeom_transform.c
===================================================================
--- trunk/postgis/lwgeom_transform.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/lwgeom_transform.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -25,6 +25,7 @@
 
 #include "postgres.h"
 #include "fmgr.h"
+#include "utils/builtins.h"
 
 #include "../postgis_config.h"
 #include "liblwgeom.h"
@@ -130,8 +131,8 @@
 	output_proj4_text = (PG_GETARG_TEXT_P(2));
 
 	/* Convert from text to cstring for libproj */
-	input_proj4 = text2cstring(input_proj4_text);
-	output_proj4 = text2cstring(output_proj4_text);
+	input_proj4 = text_to_cstring(input_proj4_text);
+	output_proj4 = text_to_cstring(output_proj4_text);
 
 	/* make input and output projection objects */
 	input_pj = lwproj_from_string(input_proj4);
@@ -199,6 +200,6 @@
 Datum postgis_proj_version(PG_FUNCTION_ARGS)
 {
 	const char *ver = pj_get_release();
-	text *result = cstring2text(ver);
+	text *result = cstring_to_text(ver);
 	PG_RETURN_POINTER(result);
 }

Modified: trunk/postgis/postgis_libprotobuf.c
===================================================================
--- trunk/postgis/postgis_libprotobuf.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/postgis/postgis_libprotobuf.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -14,7 +14,7 @@
 	PG_RETURN_NULL();
 #else /* HAVE_LIBPROTOBUF  */
 	const char *ver = protobuf_c_version();
-	text *result = cstring2text(ver);
+	text *result = cstring_to_text(ver);
 	PG_RETURN_POINTER(result);
 #endif
 }
\ No newline at end of file

Modified: trunk/raster/rt_pg/rtpg_spatial_relationship.c
===================================================================
--- trunk/raster/rt_pg/rtpg_spatial_relationship.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/raster/rt_pg/rtpg_spatial_relationship.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -29,6 +29,7 @@
 
 #include <postgres.h> /* for palloc */
 #include <fmgr.h>
+#include <utils/builtins.h>
 
 #include "../../postgis_config.h"
 
@@ -1309,6 +1310,6 @@
 		PG_RETURN_NULL();
 	}
 
-	result = cstring2text(reason);
+	result = cstring_to_text(reason);
 	PG_RETURN_TEXT_P(result);
 }

Modified: trunk/raster/rt_pg/rtpg_utility.c
===================================================================
--- trunk/raster/rt_pg/rtpg_utility.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/raster/rt_pg/rtpg_utility.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -50,7 +50,7 @@
     snprintf(ver, 64, "%s r%d", POSTGIS_LIB_VERSION, POSTGIS_SVN_REVISION);
     ver[63] = '\0';
 
-    result = cstring2text(ver);
+    result = cstring_to_text(ver);
     PG_RETURN_TEXT_P(result);
 }
 
@@ -76,15 +76,15 @@
 		char *rtn = NULL;
 		rtn = palloc(strlen(ver) + strlen(" GDAL_DATA not found") + 1);
 		if (!rtn)
-			result = cstring2text(ver);
+			result = cstring_to_text(ver);
 		else {
 			sprintf(rtn, "%s GDAL_DATA not found", ver);
-			result = cstring2text(rtn);
+			result = cstring_to_text(rtn);
 			pfree(rtn);
 		}
 	}
 	else
-		result = cstring2text(ver);
+		result = cstring_to_text(ver);
 
 	PG_RETURN_POINTER(result);
 }

Modified: trunk/topology/postgis_topology.c
===================================================================
--- trunk/topology/postgis_topology.c	2018-02-20 14:35:50 UTC (rev 16389)
+++ trunk/topology/postgis_topology.c	2018-02-20 16:16:45 UTC (rev 16390)
@@ -13,6 +13,7 @@
 #include "postgres.h"
 #include "fmgr.h"
 #include "c.h" /* for UINT64_FORMAT and uint64 */
+#include "utils/builtins.h"
 #include "utils/elog.h"
 #include "utils/memutils.h" /* for TopMemoryContext */
 #include "utils/array.h" /* for ArrayType */
@@ -3011,7 +3012,7 @@
   }
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   edge_id = PG_GETARG_INT32(1) ;
@@ -3076,7 +3077,7 @@
   }
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   edge_id = PG_GETARG_INT32(1) ;
@@ -3141,7 +3142,7 @@
   }
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   if ( PG_ARGISNULL(1) ) containing_face = -1;
@@ -3221,7 +3222,7 @@
   }
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   start_node = PG_GETARG_INT32(1);
@@ -3292,7 +3293,7 @@
   }
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   startnode_id = PG_GETARG_INT32(1) ;
@@ -3358,7 +3359,7 @@
   }
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   startnode_id = PG_GETARG_INT32(1) ;
@@ -3423,7 +3424,7 @@
   }
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   face_id = PG_GETARG_INT32(1) ;
@@ -3508,7 +3509,7 @@
     }
 
     toponame_text = PG_GETARG_TEXT_P(0);
-    toponame = text2cstring(toponame_text);
+    toponame = text_to_cstring(toponame_text);
     PG_FREE_IF_COPY(toponame_text, 0);
 
     face_id = PG_GETARG_INT32(1) ;
@@ -3618,7 +3619,7 @@
   }
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   edge_id = PG_GETARG_INT32(1) ;
@@ -3665,7 +3666,7 @@
   {
     buf[63] = '\0';
   }
-  PG_RETURN_TEXT_P(cstring2text(buf));
+  PG_RETURN_TEXT_P(cstring_to_text(buf));
 }
 
 /*  ST_RemoveIsoNode(atopology, anode) */
@@ -3686,7 +3687,7 @@
   }
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   node_id = PG_GETARG_INT32(1) ;
@@ -3725,7 +3726,7 @@
   {
     buf[63] = '\0';
   }
-  PG_RETURN_TEXT_P(cstring2text(buf));
+  PG_RETURN_TEXT_P(cstring_to_text(buf));
 }
 
 /*  ST_RemIsoEdge(atopology, anedge) */
@@ -3746,7 +3747,7 @@
   }
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   node_id = PG_GETARG_INT32(1) ;
@@ -3785,7 +3786,7 @@
   {
     buf[63] = '\0';
   }
-  PG_RETURN_TEXT_P(cstring2text(buf));
+  PG_RETURN_TEXT_P(cstring_to_text(buf));
 }
 
 /*  ST_MoveIsoNode(atopology, anode, apoint) */
@@ -3810,7 +3811,7 @@
   }
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   node_id = PG_GETARG_INT32(1) ;
@@ -3869,7 +3870,7 @@
   {
     buf[63] = '\0';
   }
-  PG_RETURN_TEXT_P(cstring2text(buf));
+  PG_RETURN_TEXT_P(cstring_to_text(buf));
 }
 
 /*  ST_RemEdgeModFace(atopology, anedge) */
@@ -3889,7 +3890,7 @@
   }
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   node_id = PG_GETARG_INT32(1) ;
@@ -3940,7 +3941,7 @@
   }
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   node_id = PG_GETARG_INT32(1) ;
@@ -3989,7 +3990,7 @@
   }
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   eid1 = PG_GETARG_INT32(1) ;
@@ -4039,7 +4040,7 @@
   }
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   eid1 = PG_GETARG_INT32(1) ;
@@ -4087,7 +4088,7 @@
   LWT_TOPOLOGY *topo;
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   geom = PG_GETARG_GSERIALIZED_P(1);
@@ -4153,7 +4154,7 @@
   LWT_TOPOLOGY *topo;
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   geom = PG_GETARG_GSERIALIZED_P(1);
@@ -4219,7 +4220,7 @@
   LWT_TOPOLOGY *topo;
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   geom = PG_GETARG_GSERIALIZED_P(1);
@@ -4285,7 +4286,7 @@
   LWT_TOPOLOGY *topo;
 
   toponame_text = PG_GETARG_TEXT_P(0);
-  toponame = text2cstring(toponame_text);
+  toponame = text_to_cstring(toponame_text);
 	PG_FREE_IF_COPY(toponame_text, 0);
 
   geom = PG_GETARG_GSERIALIZED_P(1);
@@ -4376,7 +4377,7 @@
     }
 
     toponame_text = PG_GETARG_TEXT_P(0);
-    toponame = text2cstring(toponame_text);
+    toponame = text_to_cstring(toponame_text);
     PG_FREE_IF_COPY(toponame_text, 0);
 
     geom = PG_GETARG_GSERIALIZED_P(1);
@@ -4500,7 +4501,7 @@
     }
 
     toponame_text = PG_GETARG_TEXT_P(0);
-    toponame = text2cstring(toponame_text);
+    toponame = text_to_cstring(toponame_text);
     PG_FREE_IF_COPY(toponame_text, 0);
 
     geom = PG_GETARG_GSERIALIZED_P(1);



More information about the postgis-tickets mailing list