]> granicus.if.org Git - postgis/commitdiff
Replace VARSIZE(foo)-VARHDRSZ pattern with VARSIZE_ANY_EXHDR(foo)
authorPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 22 Feb 2019 16:51:34 +0000 (16:51 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Fri, 22 Feb 2019 16:51:34 +0000 (16:51 +0000)
macro from standard Pg.

git-svn-id: http://svn.osgeo.org/postgis/trunk@17271 b70326c6-7e19-0410-871a-916f4a2858ee

15 files changed:
extensions/address_standardizer/address_parser.c
extensions/address_standardizer/address_standardizer.c
postgis/geography_inout.c
postgis/gserialized_estimate.c
postgis/gserialized_gist_nd.c
postgis/lwgeom_export.c
postgis/lwgeom_in_geojson.c
postgis/lwgeom_in_gml.c
postgis/lwgeom_in_kml.c
postgis/lwgeom_inout.c
postgis/lwgeom_ogc.c
postgis/mvt.c
raster/rt_pg/rtpg_gdal.c
raster/rt_pg/rtpg_inout.c
raster/rt_pg/rtpg_wkb.c

index c6c597625ba051904eea0e26400c5e76b1d9ad77..184cfc8cfdb39394e143d2b9d27f857bccf2150a 100644 (file)
 
 Datum parse_address(PG_FUNCTION_ARGS);
 
-static char *text2char(text *in)
-{
-    char *out = palloc(VARSIZE(in));
-    memcpy(out, VARDATA(in), VARSIZE(in) - VARHDRSZ);
-    out[VARSIZE(in) - VARHDRSZ] = '\0';
-    return out;
-}
-
 PG_FUNCTION_INFO_V1(parse_address);
 
 Datum parse_address(PG_FUNCTION_ARGS)
@@ -47,7 +39,7 @@ Datum parse_address(PG_FUNCTION_ARGS)
 
     DBG("Start standardize_address");
 
-    str = text2char(PG_GETARG_TEXT_P(0));
+    str = text_to_cstring(PG_GETARG_TEXT_P(0));
 
     DBG("str='%s'", str);
 
index b1703995c12ce623993222fe638afe25664359d3..dbfd21ed61ae737ae29ac93da2d569f060361bc8 100644 (file)
@@ -19,14 +19,6 @@ Datum standardize_address(PG_FUNCTION_ARGS);
 Datum standardize_address1(PG_FUNCTION_ARGS);
 
 
-static char *text2char(text *in)
-{
-    char *out = palloc(VARSIZE(in));
-    memcpy(out, VARDATA(in), VARSIZE(in) - VARHDRSZ);
-    out[VARSIZE(in) - VARHDRSZ] = '\0';
-    return out;
-}
-
 /*
  * The signature for standardize_address follows. The lextab, gaztab and
  * rultab should not change once the reference has been standardized and
@@ -80,11 +72,11 @@ Datum standardize_address(PG_FUNCTION_ARGS)
 
     DBG("Start standardize_address");
 
-    lextab = text2char(PG_GETARG_TEXT_P(0));
-    gaztab = text2char(PG_GETARG_TEXT_P(1));
-    rultab = text2char(PG_GETARG_TEXT_P(2));
-    micro  = text2char(PG_GETARG_TEXT_P(3));
-    macro  = text2char(PG_GETARG_TEXT_P(4));
+    lextab = text_to_cstring(PG_GETARG_TEXT_P(0));
+    gaztab = text_to_cstring(PG_GETARG_TEXT_P(1));
+    rultab = text_to_cstring(PG_GETARG_TEXT_P(2));
+    micro  = text_to_cstring(PG_GETARG_TEXT_P(3));
+    macro  = text_to_cstring(PG_GETARG_TEXT_P(4));
 
     DBG("calling RelationNameGetTupleDesc");
     if (get_call_result_type( fcinfo, NULL, &tuple_desc ) != TYPEFUNC_COMPOSITE ) {
@@ -167,10 +159,10 @@ Datum standardize_address1(PG_FUNCTION_ARGS)
 
     DBG("Start standardize_address");
 
-    lextab = text2char(PG_GETARG_TEXT_P(0));
-    gaztab = text2char(PG_GETARG_TEXT_P(1));
-    rultab = text2char(PG_GETARG_TEXT_P(2));
-    addr   = text2char(PG_GETARG_TEXT_P(3));
+    lextab = text_to_cstring(PG_GETARG_TEXT_P(0));
+    gaztab = text_to_cstring(PG_GETARG_TEXT_P(1));
+    rultab = text_to_cstring(PG_GETARG_TEXT_P(2));
+    addr   = text_to_cstring(PG_GETARG_TEXT_P(3));
 
     DBG("calling RelationNameGetTupleDesc");
     if (get_call_result_type( fcinfo, NULL, &tuple_desc ) != TYPEFUNC_COMPOSITE ) {
index 844e828d8bfa8f6d2219d375a34b69c7e89a1535..ad0deb838b690ef4d7a423d4a7ca8c120ddce9d3 100644 (file)
@@ -260,19 +260,19 @@ Datum geography_as_gml(PG_FUNCTION_ARGS)
        if (PG_NARGS() >4 && !PG_ARGISNULL(4))
        {
                prefix_text = PG_GETARG_TEXT_P(4);
-               if ( VARSIZE(prefix_text)-VARHDRSZ == 0 )
+               if ( VARSIZE_ANY_EXHDR(prefix_text) == 0 )
                {
                        prefix = "";
                }
                else
                {
                        /* +2 is one for the ':' and one for term null */
-                       prefix_buf = palloc(VARSIZE(prefix_text)-VARHDRSZ+2);
-                       memcpy(prefix_buf, VARDATA(prefix_text),
-                              VARSIZE(prefix_text)-VARHDRSZ);
+                       prefix_buf = palloc(VARSIZE_ANY_EXHDR(prefix_text)+2);
+                       memcpy(prefix_buf, VARDATA_ANY(prefix_text),
+                              VARSIZE_ANY_EXHDR(prefix_text));
                        /* add colon and null terminate */
-                       prefix_buf[VARSIZE(prefix_text)-VARHDRSZ] = ':';
-                       prefix_buf[VARSIZE(prefix_text)-VARHDRSZ+1] = '\0';
+                       prefix_buf[VARSIZE_ANY_EXHDR(prefix_text)] = ':';
+                       prefix_buf[VARSIZE_ANY_EXHDR(prefix_text)+1] = '\0';
                        prefix = prefix_buf;
                }
        }
@@ -281,15 +281,15 @@ Datum geography_as_gml(PG_FUNCTION_ARGS)
        if (PG_NARGS() >5 && !PG_ARGISNULL(5))
        {
                id_text = PG_GETARG_TEXT_P(5);
-               if ( VARSIZE(id_text)-VARHDRSZ == 0 )
+               if ( VARSIZE_ANY_EXHDR(id_text) == 0 )
                {
                        id = "";
                }
                else
                {
-                       id_buf = palloc(VARSIZE(id_text)-VARHDRSZ+1);
-                       memcpy(id_buf, VARDATA(id_text), VARSIZE(id_text)-VARHDRSZ);
-                       prefix_buf[VARSIZE(id_text)-VARHDRSZ+1] = '\0';
+                       id_buf = palloc(VARSIZE_ANY_EXHDR(id_text)+1);
+                       memcpy(id_buf, VARDATA(id_text), VARSIZE_ANY_EXHDR(id_text));
+                       prefix_buf[VARSIZE_ANY_EXHDR(id_text)+1] = '\0';
                        id = id_buf;
                }
        }
@@ -389,19 +389,19 @@ Datum geography_as_kml(PG_FUNCTION_ARGS)
        if (PG_NARGS() >3 && !PG_ARGISNULL(3))
        {
                prefix_text = PG_GETARG_TEXT_P(3);
-               if ( VARSIZE(prefix_text)-VARHDRSZ == 0 )
+               if ( VARSIZE_ANY_EXHDR(prefix_text) == 0 )
                {
                        prefix = "";
                }
                else
                {
                        /* +2 is one for the ':' and one for term null */
-                       prefixbuf = palloc(VARSIZE(prefix_text)-VARHDRSZ+2);
+                       prefixbuf = palloc(VARSIZE_ANY_EXHDR(prefix_text)+2);
                        memcpy(prefixbuf, VARDATA(prefix_text),
-                              VARSIZE(prefix_text)-VARHDRSZ);
+                              VARSIZE_ANY_EXHDR(prefix_text));
                        /* add colon and null terminate */
-                       prefixbuf[VARSIZE(prefix_text)-VARHDRSZ] = ':';
-                       prefixbuf[VARSIZE(prefix_text)-VARHDRSZ+1] = '\0';
+                       prefixbuf[VARSIZE_ANY_EXHDR(prefix_text)] = ':';
+                       prefixbuf[VARSIZE_ANY_EXHDR(prefix_text)+1] = '\0';
                        prefix = prefixbuf;
                }
        }
index 93ba45abf698b4ef87b31d59517a8c05e9df290e..b273cdcb489f5f962e7cbc9e2038c431e35607d2 100644 (file)
@@ -304,7 +304,7 @@ text_p_get_mode(const text *txt)
 {
        int mode = 2;
        char *modestr;
-       if (VARSIZE(txt) - VARHDRSZ <= 0)
+       if (VARSIZE_ANY_EXHDR(txt) <= 0)
                return mode;
        modestr = (char*)VARDATA(txt);
        if ( modestr[0] == 'N' )
index e65060c9ac2538ce919ca73055f184554d9cb7ea..b9dc2649b7cb7855eaf80473b694d527f3680e36 100644 (file)
@@ -141,7 +141,7 @@ gidx_validate(GIDX *b)
 inline bool
 gidx_is_unknown(const GIDX *a)
 {
-       size_t size = VARSIZE(a) - VARHDRSZ;
+       size_t size = VARSIZE_ANY_EXHDR(a);
        /* "unknown" gidx objects have a too-small size of one float */
        if (size <= 0.0)
                return true;
index 248f383f86202c7518e2a3adcd8df0ab4de06f1a..a1bfb50da9ec86e6dd290483610629252168e266 100644 (file)
@@ -233,7 +233,7 @@ Datum LWGEOM_asGML(PG_FUNCTION_ARGS)
                }
                else
                {
-                       len = VARSIZE(prefix_text)-VARHDRSZ;
+                       len = VARSIZE_ANY_EXHDR(prefix_text);
                        prefix_buf = palloc(len + 2); /* +2 is one for the ':' and one for term null */
                        memcpy(prefix_buf, VARDATA(prefix_text), len);
                        /* add colon and null terminate */
@@ -252,7 +252,7 @@ Datum LWGEOM_asGML(PG_FUNCTION_ARGS)
                }
                else
                {
-                       len = VARSIZE(gml_id_text)-VARHDRSZ;
+                       len = VARSIZE_ANY_EXHDR(gml_id_text);
                        gml_id_buf = palloc(len+1);
                        memcpy(gml_id_buf, VARDATA(gml_id_text), len);
                        gml_id_buf[len] = '\0';
@@ -355,19 +355,19 @@ Datum LWGEOM_asKML(PG_FUNCTION_ARGS)
        if (PG_NARGS() >3 && !PG_ARGISNULL(3))
        {
                prefix_text = PG_GETARG_TEXT_P(3);
-               if ( VARSIZE(prefix_text)-VARHDRSZ == 0 )
+               if ( VARSIZE_ANY_EXHDR(prefix_text) == 0 )
                {
                        prefix = "";
                }
                else
                {
                        /* +2 is one for the ':' and one for term null */
-                       prefixbuf = palloc(VARSIZE(prefix_text)-VARHDRSZ+2);
+                       prefixbuf = palloc(VARSIZE_ANY_EXHDR(prefix_text)+2);
                        memcpy(prefixbuf, VARDATA(prefix_text),
-                              VARSIZE(prefix_text)-VARHDRSZ);
+                              VARSIZE_ANY_EXHDR(prefix_text));
                        /* add colon and null terminate */
-                       prefixbuf[VARSIZE(prefix_text)-VARHDRSZ] = ':';
-                       prefixbuf[VARSIZE(prefix_text)-VARHDRSZ+1] = '\0';
+                       prefixbuf[VARSIZE_ANY_EXHDR(prefix_text)] = ':';
+                       prefixbuf[VARSIZE_ANY_EXHDR(prefix_text)+1] = '\0';
                        prefix = prefixbuf;
                }
        }
@@ -581,19 +581,19 @@ Datum LWGEOM_asX3D(PG_FUNCTION_ARGS)
        if (PG_NARGS() >4 && !PG_ARGISNULL(4))
        {
                defid_text = PG_GETARG_TEXT_P(4);
-               if ( VARSIZE(defid_text)-VARHDRSZ == 0 )
+               if ( VARSIZE_ANY_EXHDR(defid_text) == 0 )
                {
                        defid = "";
                }
                else
                {
                        /* +2 is one for the ':' and one for term null */
-                       defidbuf = palloc(VARSIZE(defid_text)-VARHDRSZ+2);
+                       defidbuf = palloc(VARSIZE_ANY_EXHDR(defid_text)+2);
                        memcpy(defidbuf, VARDATA(defid_text),
-                              VARSIZE(defid_text)-VARHDRSZ);
+                              VARSIZE_ANY_EXHDR(defid_text));
                        /* add colon and null terminate */
-                       defidbuf[VARSIZE(defid_text)-VARHDRSZ] = ':';
-                       defidbuf[VARSIZE(defid_text)-VARHDRSZ+1] = '\0';
+                       defidbuf[VARSIZE_ANY_EXHDR(defid_text)] = ':';
+                       defidbuf[VARSIZE_ANY_EXHDR(defid_text)+1] = '\0';
                        defid = defidbuf;
                }
        }
index c4d454d626839920829dc7c5057bd7bf7d10f9b7..c39d9dd5e41f0966af4b624ddf395f85e84d7324 100644 (file)
@@ -51,7 +51,7 @@ cstring2text(const char *cstring)
 static char*
 text2cstring(const text *textptr)
 {
-       size_t size = VARSIZE(textptr) - VARHDRSZ;
+       size_t size = VARSIZE_ANY_EXHDR(textptr);
        char *str = lwalloc(size+1);
        memcpy(str, VARDATA(textptr), size);
        str[size]='\0';
index 6603a177cca53b64ebeddb0a4b44c1424933455d..cf9bd259bec3974bcb1a6c48b422aa191e8a87b9 100644 (file)
@@ -108,7 +108,7 @@ Datum geom_from_gml(PG_FUNCTION_ARGS)
        if (PG_ARGISNULL(0)) PG_RETURN_NULL();
        xml_input = PG_GETARG_TEXT_P(0);
        xml = text_to_cstring(xml_input);
-       xml_size = VARSIZE(xml_input) - VARHDRSZ;
+       xml_size = VARSIZE_ANY_EXHDR(xml_input);
 
        /* Zero for undefined */
        root_srid = PG_GETARG_INT32(1);
index 52a7820ef874c4ecd85a82f4ea9421d1d3f4d1d6..06889181969c7c4c11891214c61ccab2c3ed5c7d 100644 (file)
@@ -86,7 +86,7 @@ Datum geom_from_kml(PG_FUNCTION_ARGS)
        if (PG_ARGISNULL(0)) PG_RETURN_NULL();
        xml_input = PG_GETARG_TEXT_P(0);
        xml = text_to_cstring(xml_input);
-       xml_size = VARSIZE(xml_input) - VARHDRSZ;
+       xml_size = VARSIZE_ANY_EXHDR(xml_input);
 
        /* Begin to Parse XML doc */
        xmlInitParser();
index d822fc8029127823c2075b4759962cabf8742f8a..9a86c1f215349e8e389c8bf89285d9c1d8288fa0 100644 (file)
@@ -374,7 +374,7 @@ Datum LWGEOMFromEWKB(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom;
        uint8_t *wkb = (uint8_t*)VARDATA(bytea_wkb);
 
-       lwgeom = lwgeom_from_wkb(wkb, VARSIZE(bytea_wkb)-VARHDRSZ, LW_PARSER_CHECK_ALL);
+       lwgeom = lwgeom_from_wkb(wkb, VARSIZE_ANY_EXHDR(bytea_wkb), LW_PARSER_CHECK_ALL);
 
        if (  ( PG_NARGS()>1) && ( ! PG_ARGISNULL(1) ))
        {
@@ -403,7 +403,7 @@ Datum LWGEOMFromTWKB(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom;
        uint8_t *twkb = (uint8_t*)VARDATA(bytea_twkb);
 
-       lwgeom = lwgeom_from_twkb(twkb, VARSIZE(bytea_twkb)-VARHDRSZ, LW_PARSER_CHECK_ALL);
+       lwgeom = lwgeom_from_twkb(twkb, VARSIZE_ANY_EXHDR(bytea_twkb), LW_PARSER_CHECK_ALL);
 
        if ( lwgeom_needs_bbox(lwgeom) )
                lwgeom_add_bbox(lwgeom);
@@ -443,7 +443,7 @@ Datum WKBFromLWGEOM(PG_FUNCTION_ARGS)
                        variant = variant | WKB_NDR;
                }
        }
-       wkb_size= VARSIZE(geom) - VARHDRSZ;
+       wkb_size= VARSIZE_ANY_EXHDR(geom);
        /* Create WKB hex string */
        lwgeom = lwgeom_from_gserialized(geom);
 
index 8cdc5fcc7af0b6230e2ddcb1e5279818e71e0e2e..de294dae2e470f554ebf68c7890ecce28034148e 100644 (file)
@@ -830,7 +830,7 @@ Datum LWGEOM_from_WKB(PG_FUNCTION_ARGS)
        LWGEOM *lwgeom;
        uint8_t *wkb = (uint8_t*)VARDATA(bytea_wkb);
 
-       lwgeom = lwgeom_from_wkb(wkb, VARSIZE(bytea_wkb)-VARHDRSZ, LW_PARSER_CHECK_ALL);
+       lwgeom = lwgeom_from_wkb(wkb, VARSIZE_ANY_EXHDR(bytea_wkb), LW_PARSER_CHECK_ALL);
 
        if ( lwgeom_needs_bbox(lwgeom) )
                lwgeom_add_bbox(lwgeom);
index 5c4be1eb1d72082e609c1c2990a784dcf4dc7100..ce206c38af26efdc985abe0749ad4b371c9ad139 100644 (file)
@@ -1183,7 +1183,7 @@ mvt_agg_context * mvt_ctx_deserialize(const bytea *ba)
                NULL
        };
 
-       size_t len = VARSIZE(ba) - VARHDRSZ;
+       size_t len = VARSIZE_ANY_EXHDR(ba);
        VectorTile__Tile *tile = vector_tile__tile__unpack(&allocator, len, (uint8_t*)VARDATA(ba));
        mvt_agg_context *ctx = palloc(sizeof(mvt_agg_context));
        memset(ctx, 0, sizeof(mvt_agg_context));
index 94f0bc151b81f8e0c99acec5bdbec7df8a298b69..31263a5e7451a1ffd61627f38ad88dd984ff8f46 100644 (file)
@@ -77,7 +77,7 @@ Datum RASTER_fromGDALRaster(PG_FUNCTION_ARGS)
        /* get data */
        bytea_data = (bytea *) PG_GETARG_BYTEA_P(0);
        data = (uint8_t *) VARDATA(bytea_data);
-       data_len = VARSIZE(bytea_data) - VARHDRSZ;
+       data_len = VARSIZE_ANY_EXHDR(bytea_data);
 
        /* process srid */
        /* NULL srid means try to determine SRID from bytea */
@@ -321,7 +321,7 @@ Datum RASTER_asGDALRaster(PG_FUNCTION_ARGS)
                PG_RETURN_NULL();
        }
        SET_VARSIZE(result, result_size);
-       memcpy(VARDATA(result), gdal, VARSIZE(result) - VARHDRSZ);
+       memcpy(VARDATA(result), gdal, VARSIZE_ANY_EXHDR(result));
 
        /* free gdal mem buffer */
        CPLFree(gdal);
index 5d0dce49757e28e6a2ea70d6b5f0020786c01217..b959cf204c1211700625e07f05c3662e212bfde0 100644 (file)
@@ -142,7 +142,7 @@ Datum RASTER_to_bytea(PG_FUNCTION_ARGS)
        result_size = wkb_size + VARHDRSZ;
        result = (bytea *)palloc(result_size);
        SET_VARSIZE(result, result_size);
-       memcpy(VARDATA(result), wkb, VARSIZE(result) - VARHDRSZ);
+       memcpy(VARDATA(result), wkb, VARSIZE_ANY_EXHDR(result));
 
        /* Free raster objects used */
        rt_raster_destroy(raster);
index c43d446c186443a547d3d9d3772d52f3aa1604ef..6cf2b8a95bb4e7d25247af432002f07a994d8554 100644 (file)
@@ -81,7 +81,7 @@ Datum RASTER_asWKB(PG_FUNCTION_ARGS)
        result_size = wkb_size + VARHDRSZ;
        result = (char *)palloc(result_size);
        SET_VARSIZE(result, result_size);
-       memcpy(VARDATA(result), wkb, VARSIZE(result) - VARHDRSZ);
+       memcpy(VARDATA(result), wkb, VARSIZE_ANY_EXHDR(result));
 
        /* Free raster objects used */
        rt_raster_destroy(raster);
@@ -153,7 +153,7 @@ Datum RASTER_fromWKB(PG_FUNCTION_ARGS)
 
        bytea_data = (bytea *) PG_GETARG_BYTEA_P(0);
        data = (uint8_t *) VARDATA(bytea_data);
-       data_len = VARSIZE(bytea_data) - VARHDRSZ;
+       data_len = VARSIZE_ANY_EXHDR(bytea_data);
 
        raster = rt_raster_from_wkb(data, data_len);
        PG_FREE_IF_COPY(bytea_data, 0);