[postgis-tickets] r16958 - Use TupleDescAttr instead of its internal representation
Raul
raul at rmr.ninja
Mon Oct 29 06:52:42 PDT 2018
Author: algunenano
Date: 2018-10-29 06:52:42 -0700 (Mon, 29 Oct 2018)
New Revision: 16958
Modified:
trunk/libpgcommon/pgsql_compat.h
trunk/postgis/geobuf.c
trunk/postgis/mvt.c
trunk/topology/postgis_topology.c
Log:
Use TupleDescAttr instead of its internal representation
Closes https://trac.osgeo.org/postgis/ticket/4213
Closes https://github.com/postgis/postgis/pull/322
Modified: trunk/libpgcommon/pgsql_compat.h
===================================================================
--- trunk/libpgcommon/pgsql_compat.h 2018-10-29 04:10:46 UTC (rev 16957)
+++ trunk/libpgcommon/pgsql_compat.h 2018-10-29 13:52:42 UTC (rev 16958)
@@ -1,9 +1,11 @@
#ifndef _PGSQL_COMPAT_H
#define _PGSQL_COMPAT_H 1
-/* Make sure PG_NARGS is defined for older PostgreSQL versions */
-#ifndef PG_NARGS
-#define PG_NARGS() (fcinfo->nargs)
+#include "access/tupdesc.h"
+
+/* TupleDescAttr was backported into 9.6.5 but we support any 9.6.X */
+#ifndef TupleDescAttr
+#define TupleDescAttr(tupdesc, i) ((tupdesc)->attrs[(i)])
#endif
#endif /* _PGSQL_COMPAT_H */
Modified: trunk/postgis/geobuf.c
===================================================================
--- trunk/postgis/geobuf.c 2018-10-29 04:10:46 UTC (rev 16957)
+++ trunk/postgis/geobuf.c 2018-10-29 13:52:42 UTC (rev 16958)
@@ -24,6 +24,7 @@
#include <math.h>
#include "geobuf.h"
+#include "pgsql_compat.h"
#ifdef HAVE_LIBPROTOBUF
@@ -57,13 +58,8 @@
uint32_t i, k = 0;
bool geom_found = false;
for (i = 0; i < natts; i++) {
-#if POSTGIS_PGSQL_VERSION < 110
- Oid typoid = getBaseType(tupdesc->attrs[i]->atttypid);
- char *tkey = tupdesc->attrs[i]->attname.data;
-#else
- Oid typoid = getBaseType(tupdesc->attrs[i].atttypid);
- char *tkey = tupdesc->attrs[i].attname.data;
-#endif
+ Oid typoid = getBaseType(TupleDescAttr(tupdesc, i)->atttypid);
+ char *tkey = TupleDescAttr(tupdesc, i)->attname.data;
char *key = pstrdup(tkey);
if (ctx->geom_name == NULL) {
if (!geom_found && typoid == TypenameGetTypid("geometry")) {
@@ -127,11 +123,9 @@
datum = GetAttributeByNum(ctx->row, i + 1, &isnull);
if (isnull)
continue;
-#if POSTGIS_PGSQL_VERSION < 110
- typoid = getBaseType(tupdesc->attrs[i]->atttypid);
-#else
- typoid = getBaseType(tupdesc->attrs[i].atttypid);
-#endif
+
+ typoid = getBaseType(TupleDescAttr(tupdesc, i)->atttypid);
+
if (strcmp(type, "int2") == 0) {
set_int_value(value, DatumGetInt16(datum));
} else if (strcmp(type, "int4") == 0) {
Modified: trunk/postgis/mvt.c
===================================================================
--- trunk/postgis/mvt.c 2018-10-29 04:10:46 UTC (rev 16957)
+++ trunk/postgis/mvt.c 2018-10-29 13:52:42 UTC (rev 16958)
@@ -25,6 +25,7 @@
#include <string.h>
#include "mvt.h"
+#include "pgsql_compat.h"
#ifdef HAVE_LIBPROTOBUF
@@ -334,13 +335,8 @@
for (i = 0; i < natts; i++)
{
-#if POSTGIS_PGSQL_VERSION < 110
- Oid typoid = getBaseType(ctx->column_cache.tupdesc->attrs[i]->atttypid);
- char *tkey = ctx->column_cache.tupdesc->attrs[i]->attname.data;
-#else
- Oid typoid = getBaseType(ctx->column_cache.tupdesc->attrs[i].atttypid);
- char *tkey = ctx->column_cache.tupdesc->attrs[i].attname.data;
-#endif
+ Oid typoid = getBaseType(TupleDescAttr(ctx->column_cache.tupdesc, i)->atttypid);
+ char *tkey = TupleDescAttr(ctx->column_cache.tupdesc, i)->attname.data;
ctx->column_cache.column_oid[i] = typoid;
#if POSTGIS_PGSQL_VERSION >= 94
@@ -726,11 +722,7 @@
continue;
}
-#if POSTGIS_PGSQL_VERSION < 110
- key = cc.tupdesc->attrs[i]->attname.data;
-#else
- key = cc.tupdesc->attrs[i].attname.data;
-#endif
+ key = TupleDescAttr(cc.tupdesc, i)->attname.data;
k = cc.column_keys_index[i];
typoid = cc.column_oid[i];
Modified: trunk/topology/postgis_topology.c
===================================================================
--- trunk/topology/postgis_topology.c 2018-10-29 04:10:46 UTC (rev 16957)
+++ trunk/topology/postgis_topology.c 2018-10-29 13:52:42 UTC (rev 16958)
@@ -32,6 +32,7 @@
/*#define POSTGIS_DEBUG_LEVEL 1*/
#include "lwgeom_log.h"
#include "lwgeom_pg.h"
+#include "pgsql_compat.h"
#include <stdarg.h>
@@ -257,11 +258,7 @@
}
/* we're dynamically querying geometry type here */
-#if POSTGIS_PGSQL_VERSION < 110
- topo->geometryOID = SPI_tuptable->tupdesc->attrs[3]->atttypid;
-#else
- topo->geometryOID = SPI_tuptable->tupdesc->attrs[3].atttypid;
-#endif
+ topo->geometryOID = TupleDescAttr(SPI_tuptable->tupdesc, 3)->atttypid;
POSTGIS_DEBUGF(1, "cb_loadTopologyByName: topo '%s' has "
"id %d, srid %d, precision %g",
More information about the postgis-tickets
mailing list