[postgis-tickets] r15655 - Remove use of lwerror in postgis/ directory, replace

Paul Ramsey pramsey at cleverelephant.ca
Thu Sep 7 06:40:42 PDT 2017


Author: pramsey
Date: 2017-09-07 06:40:42 -0700 (Thu, 07 Sep 2017)
New Revision: 15655

Modified:
   trunk/postgis/geobuf.c
   trunk/postgis/lwgeom_out_geobuf.c
   trunk/postgis/lwgeom_out_mvt.c
   trunk/postgis/lwgeom_sfcgal.c
   trunk/postgis/mvt.c
Log:
Remove use of lwerror in postgis/ directory, replace
with PgSQL elog() calls instead.


Modified: trunk/postgis/geobuf.c
===================================================================
--- trunk/postgis/geobuf.c	2017-09-07 13:00:13 UTC (rev 15654)
+++ trunk/postgis/geobuf.c	2017-09-07 13:40:42 UTC (rev 15655)
@@ -72,7 +72,7 @@
 		keys[k++] = key;
 	}
 	if (!geom_name_found)
-		lwerror("encode_keys: no column with specificed geom_name found");
+		elog(ERROR, "encode_keys: no column with specificed geom_name found");
 	ctx->data->n_keys = k;
 	ctx->data->keys = keys;
 	ReleaseTupleDesc(tupdesc);
@@ -422,7 +422,7 @@
 	case COLLECTIONTYPE:
 		return encode_collection(ctx, (LWCOLLECTION*)lwgeom);
 	default:
-		lwerror("encode_geometry: '%s' geometry type not supported",
+		elog(ERROR, "encode_geometry: '%s' geometry type not supported",
 				lwtype_name(type));
 	}
 	return NULL;
@@ -477,7 +477,7 @@
 			analyze_geometry(ctx, lwcollection->geoms[i]);
 		break;
 	default:
-		lwerror("analyze_geometry: '%s' geometry type not supported",
+		elog(ERROR, "analyze_geometry: '%s' geometry type not supported",
 			lwtype_name(type));
 	}
 }
@@ -571,7 +571,7 @@
 
 	datum = GetAttributeByNum(ctx->row, ctx->geom_index + 1, &isnull);
 	if (!datum)
-		lwerror("geobuf_agg_transfn: geometry column cannot be null");
+		elog(ERROR, "geobuf_agg_transfn: geometry column cannot be null");
 	gs = (GSERIALIZED *) PG_DETOAST_DATUM_COPY(datum);
 	lwgeom = lwgeom_from_gserialized(gs);
 

Modified: trunk/postgis/lwgeom_out_geobuf.c
===================================================================
--- trunk/postgis/lwgeom_out_geobuf.c	2017-09-07 13:00:13 UTC (rev 15654)
+++ trunk/postgis/lwgeom_out_geobuf.c	2017-09-07 13:40:42 UTC (rev 15655)
@@ -46,20 +46,20 @@
 Datum pgis_asgeobuf_transfn(PG_FUNCTION_ARGS)
 {
 #ifndef HAVE_LIBPROTOBUF
-	lwerror("Missing libprotobuf-c");
+	elog(ERROR, "Missing libprotobuf-c");
 	PG_RETURN_NULL();
 #else
 	MemoryContext aggcontext;
 	struct geobuf_agg_context *ctx;
 
 	if (!AggCheckCallContext(fcinfo, &aggcontext))
-		lwerror("pgis_asmvt_transfn: called in non-aggregate context");
+		elog(ERROR, "pgis_asmvt_transfn: called in non-aggregate context");
 	MemoryContextSwitchTo(aggcontext);
 
 	if (PG_ARGISNULL(0)) {
 		ctx = palloc(sizeof(*ctx));
 		if (PG_ARGISNULL(1))
-			lwerror("pgis_asgeobuf_transfn: parameter geom_name cannot be null");
+			elog(ERROR, "pgis_asgeobuf_transfn: parameter geom_name cannot be null");
 		ctx->geom_name = text_to_cstring(PG_GETARG_TEXT_P(1));
 		geobuf_agg_init_context(ctx);
 	} else {
@@ -67,7 +67,7 @@
 	}
 
 	if (!type_is_rowtype(get_fn_expr_argtype(fcinfo->flinfo, 2)))
-		lwerror("pgis_asgeobuf_transfn: parameter row cannot be other than a rowtype");
+		elog(ERROR, "pgis_asgeobuf_transfn: parameter row cannot be other than a rowtype");
 	ctx->row = PG_GETARG_HEAPTUPLEHEADER(2);
 
 	geobuf_agg_transfn(ctx);
@@ -82,12 +82,12 @@
 Datum pgis_asgeobuf_finalfn(PG_FUNCTION_ARGS)
 {
 #ifndef HAVE_LIBPROTOBUF
-	lwerror("Missing libprotobuf-c");
+	elog(ERROR, "Missing libprotobuf-c");
 	PG_RETURN_NULL();
 #else
 	struct geobuf_agg_context *ctx;
 	if (!AggCheckCallContext(fcinfo, NULL))
-		lwerror("pgis_asmvt_finalfn called in non-aggregate context");
+		elog(ERROR, "pgis_asmvt_finalfn called in non-aggregate context");
 
 	if (PG_ARGISNULL(0))
 		PG_RETURN_NULL();

Modified: trunk/postgis/lwgeom_out_mvt.c
===================================================================
--- trunk/postgis/lwgeom_out_mvt.c	2017-09-07 13:00:13 UTC (rev 15654)
+++ trunk/postgis/lwgeom_out_mvt.c	2017-09-07 13:40:42 UTC (rev 15655)
@@ -42,7 +42,7 @@
 Datum ST_AsMVTGeom(PG_FUNCTION_ARGS)
 {
 #ifndef HAVE_LIBPROTOBUF
-	lwerror("Missing libprotobuf-c");
+	elog(ERROR, "Missing libprotobuf-c");
 	PG_RETURN_NULL();
 #else
 	LWGEOM *lwgeom_in, *lwgeom_out;
@@ -51,11 +51,11 @@
 	int extent, buffer;
 	bool clip_geom;
 	if (PG_ARGISNULL(0))
-		lwerror("ST_AsMVTGeom: geom cannot be null");
+		elog(ERROR, "ST_AsMVTGeom: geom cannot be null");
 	geom_in = PG_GETARG_GSERIALIZED_P(0);
 	lwgeom_in = lwgeom_from_gserialized(geom_in);
 	if (PG_ARGISNULL(1))
-		lwerror("ST_AsMVTGeom: parameter bounds cannot be null");
+		elog(ERROR, "ST_AsMVTGeom: parameter bounds cannot be null");
 	bounds = (GBOX *) PG_GETARG_POINTER(1);
 	extent = PG_ARGISNULL(2) ? 4096 : PG_GETARG_INT32(2);
 	buffer = PG_ARGISNULL(3) ? 0 : PG_GETARG_INT32(3);
@@ -78,26 +78,26 @@
 Datum pgis_asmvt_transfn(PG_FUNCTION_ARGS)
 {
 #ifndef HAVE_LIBPROTOBUF
-	lwerror("Missing libprotobuf-c");
+	elog(ERROR, "Missing libprotobuf-c");
 	PG_RETURN_NULL();
 #else
 	MemoryContext aggcontext;
 	struct mvt_agg_context *ctx;
 
 	if (!AggCheckCallContext(fcinfo, &aggcontext))
-		lwerror("pgis_asmvt_transfn: called in non-aggregate context");
+		elog(ERROR, "pgis_asmvt_transfn: called in non-aggregate context");
 	MemoryContextSwitchTo(aggcontext);
 
 	if (PG_ARGISNULL(0)) {
 		ctx = palloc(sizeof(*ctx));
 		if (PG_ARGISNULL(1))
-			lwerror("pgis_asmvt_transfn: parameter name cannot be null");
+			elog(ERROR, "pgis_asmvt_transfn: parameter name cannot be null");
 		text *name = PG_GETARG_TEXT_P(1);
 		ctx->name = text_to_cstring(name);
 		PG_FREE_IF_COPY(name, 1);
 		ctx->extent = PG_ARGISNULL(2) ? 4096 : PG_GETARG_INT32(2);
 		if (PG_ARGISNULL(3))
-			lwerror("pgis_asmvt_transfn: parameter geom_name cannot be null");
+			elog(ERROR, "pgis_asmvt_transfn: parameter geom_name cannot be null");
 		text *geom_name = PG_GETARG_TEXT_P(3);
 		ctx->geom_name = text_to_cstring(geom_name);
 		PG_FREE_IF_COPY(geom_name, 3);
@@ -107,7 +107,7 @@
 	}
 
 	if (!type_is_rowtype(get_fn_expr_argtype(fcinfo->flinfo, 4)))
-		lwerror("pgis_asmvt_transfn: parameter row cannot be other than a rowtype");
+		elog(ERROR, "pgis_asmvt_transfn: parameter row cannot be other than a rowtype");
 	ctx->row = PG_GETARG_HEAPTUPLEHEADER(4);
 
 	mvt_agg_transfn(ctx);
@@ -123,12 +123,12 @@
 Datum pgis_asmvt_finalfn(PG_FUNCTION_ARGS)
 {
 #ifndef HAVE_LIBPROTOBUF
-	lwerror("Missing libprotobuf-c");
+	elog(ERROR, "Missing libprotobuf-c");
 	PG_RETURN_NULL();
 #else
 	struct mvt_agg_context *ctx;
 	if (!AggCheckCallContext(fcinfo, NULL))
-		lwerror("pgis_asmvt_finalfn called in non-aggregate context");
+		elog(ERROR, "pgis_asmvt_finalfn called in non-aggregate context");
 
 	if (PG_ARGISNULL(0))
 		PG_RETURN_NULL();

Modified: trunk/postgis/lwgeom_sfcgal.c
===================================================================
--- trunk/postgis/lwgeom_sfcgal.c	2017-09-07 13:00:13 UTC (rev 15654)
+++ trunk/postgis/lwgeom_sfcgal.c	2017-09-07 13:40:42 UTC (rev 15655)
@@ -734,7 +734,7 @@
 	PG_FREE_IF_COPY(input, 0);
 	if (! lwgeom)
 	{
-		lwerror("sfcgal_is_solid: Unable to deserialize input");
+		elog(ERROR, "sfcgal_is_solid: Unable to deserialize input");
 	}
         result = FLAGS_GET_SOLID( lwgeom->flags );
 
@@ -752,7 +752,7 @@
 	PG_FREE_IF_COPY(input, 0);
 	if (! lwgeom)
 	{
-		lwerror("sfcgal_make_solid: Unable to deserialize input");
+		elog(ERROR, "sfcgal_make_solid: Unable to deserialize input");
 	}
 
         FLAGS_SET_SOLID( lwgeom->flags, 1);

Modified: trunk/postgis/mvt.c
===================================================================
--- trunk/postgis/mvt.c	2017-09-07 13:00:13 UTC (rev 15654)
+++ trunk/postgis/mvt.c	2017-09-07 13:40:42 UTC (rev 15655)
@@ -262,7 +262,7 @@
 		return encode_mline(ctx, (LWMLINE*)lwgeom);
 	case MULTIPOLYGONTYPE:
 		return encode_mpoly(ctx, (LWMPOLY*)lwgeom);
-	default: lwerror("encode_geometry: '%s' geometry type not supported",
+	default: elog(ERROR, "encode_geometry: '%s' geometry type not supported",
 		lwtype_name(type));
 	}
 }
@@ -325,7 +325,7 @@
 		add_key(ctx, key);
 	}
 	if (!geom_name_found)
-		lwerror("parse_column_keys: no column '%s' found", ctx->geom_name);
+		elog(ERROR, "parse_column_keys: no column '%s' found", ctx->geom_name);
 	ReleaseTupleDesc(tupdesc);
 }
 
@@ -570,17 +570,16 @@
 		}
 #if POSTGIS_PGSQL_VERSION >= 94
 		if (k == -1 && typoid != JSONBOID)
-#else
-		if (k == -1)
-#endif
-			lwerror("parse_values: unexpectedly could not find parsed key name",
-				key);
-#if POSTGIS_PGSQL_VERSION >= 94
+			elog(ERROR, "parse_values: unexpectedly could not find parsed key name '%s'", key);
 		if (typoid == JSONBOID) {
 			tags = parse_jsonb(ctx, DatumGetJsonb(datum), tags);
 			continue;
 		}
+#else
+		if (k == -1)
+			elog(ERROR, "parse_values: unexpectedly could not find parsed key name '%s'", key);
 #endif
+
 		switch (typoid) {
 		case BOOLOID:
 			MVT_PARSE_DATUM(protobuf_c_boolean, mvt_kv_bool_value,
@@ -655,10 +654,10 @@
 	const GBOX *ggbox = lwgeom_get_bbox(lwgeom);
 
 	if (width == 0 || height == 0)
-		lwerror("mvt_geom: bounds width or height cannot be 0");
+		elog(ERROR, "mvt_geom: bounds width or height cannot be 0");
 
 	if (extent == 0)
-		lwerror("mvt_geom: extent cannot be 0");
+		elog(ERROR, "mvt_geom: extent cannot be 0");
 
 	if (clip_geom) {
 		GBOX *bgbox = gbox_copy(gbox);
@@ -744,7 +743,7 @@
 	VectorTile__Tile__Layer *layer;
 
 	if (ctx->extent == 0)
-		lwerror("mvt_agg_init_context: extent cannot be 0");
+		elog(ERROR, "mvt_agg_init_context: extent cannot be 0");
 
 	ctx->features_capacity = FEATURES_CAPACITY_INITIAL;
 	ctx->keys_hash = NULL;
@@ -800,7 +799,7 @@
 	bool isnull;
 	Datum datum = GetAttributeByNum(ctx->row, ctx->geom_index + 1, &isnull);
 	if (!datum)
-		lwerror("mvt_agg_transfn: geometry column cannot be null");
+		elog(ERROR, "mvt_agg_transfn: geometry column cannot be null");
 	GSERIALIZED *gs = (GSERIALIZED *) PG_DETOAST_DATUM(datum);
 	LWGEOM *lwgeom = lwgeom_from_gserialized(gs);
 



More information about the postgis-tickets mailing list