[postgis-tickets] r17271 - Replace VARSIZE(foo)-VARHDRSZ pattern with VARSIZE_ANY_EXHDR(foo)
Raúl Marín Rodríguez
rmrodriguez at carto.com
Fri Feb 22 09:01:54 PST 2019
Nice!
On Fri, Feb 22, 2019 at 5:51 PM Paul Ramsey <pramsey at cleverelephant.ca> wrote:
>
> Author: pramsey
> Date: 2019-02-22 08:51:34 -0800 (Fri, 22 Feb 2019)
> New Revision: 17271
>
> Modified:
> trunk/extensions/address_standardizer/address_parser.c
> trunk/extensions/address_standardizer/address_standardizer.c
> trunk/postgis/geography_inout.c
> trunk/postgis/gserialized_estimate.c
> trunk/postgis/gserialized_gist_nd.c
> trunk/postgis/lwgeom_export.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/mvt.c
> trunk/raster/rt_pg/rtpg_gdal.c
> trunk/raster/rt_pg/rtpg_inout.c
> trunk/raster/rt_pg/rtpg_wkb.c
> Log:
> Replace VARSIZE(foo)-VARHDRSZ pattern with VARSIZE_ANY_EXHDR(foo)
> macro from standard Pg.
>
>
> Modified: trunk/extensions/address_standardizer/address_parser.c
> ===================================================================
> --- trunk/extensions/address_standardizer/address_parser.c 2019-02-21 20:44:29 UTC (rev 17270)
> +++ trunk/extensions/address_standardizer/address_parser.c 2019-02-22 16:51:34 UTC (rev 17271)
> @@ -22,14 +22,6 @@
>
> 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 @@
>
> DBG("Start standardize_address");
>
> - str = text2char(PG_GETARG_TEXT_P(0));
> + str = text_to_cstring(PG_GETARG_TEXT_P(0));
>
> DBG("str='%s'", str);
>
>
> Modified: trunk/extensions/address_standardizer/address_standardizer.c
> ===================================================================
> --- trunk/extensions/address_standardizer/address_standardizer.c 2019-02-21 20:44:29 UTC (rev 17270)
> +++ trunk/extensions/address_standardizer/address_standardizer.c 2019-02-22 16:51:34 UTC (rev 17271)
> @@ -19,14 +19,6 @@
> 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 @@
>
> 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 @@
>
> 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 ) {
>
> Modified: trunk/postgis/geography_inout.c
> ===================================================================
> --- trunk/postgis/geography_inout.c 2019-02-21 20:44:29 UTC (rev 17270)
> +++ trunk/postgis/geography_inout.c 2019-02-22 16:51:34 UTC (rev 17271)
> @@ -260,7 +260,7 @@
> 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 = "";
> }
> @@ -267,12 +267,12 @@
> 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 @@
> 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,7 +389,7 @@
> 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 = "";
> }
> @@ -396,12 +396,12 @@
> 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;
> }
> }
>
> Modified: trunk/postgis/gserialized_estimate.c
> ===================================================================
> --- trunk/postgis/gserialized_estimate.c 2019-02-21 20:44:29 UTC (rev 17270)
> +++ trunk/postgis/gserialized_estimate.c 2019-02-22 16:51:34 UTC (rev 17271)
> @@ -304,7 +304,7 @@
> {
> 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' )
>
> Modified: trunk/postgis/gserialized_gist_nd.c
> ===================================================================
> --- trunk/postgis/gserialized_gist_nd.c 2019-02-21 20:44:29 UTC (rev 17270)
> +++ trunk/postgis/gserialized_gist_nd.c 2019-02-22 16:51:34 UTC (rev 17271)
> @@ -141,7 +141,7 @@
> 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;
>
> Modified: trunk/postgis/lwgeom_export.c
> ===================================================================
> --- trunk/postgis/lwgeom_export.c 2019-02-21 20:44:29 UTC (rev 17270)
> +++ trunk/postgis/lwgeom_export.c 2019-02-22 16:51:34 UTC (rev 17271)
> @@ -233,7 +233,7 @@
> }
> 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 @@
> }
> 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,7 +355,7 @@
> 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 = "";
> }
> @@ -362,12 +362,12 @@
> 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,7 +581,7 @@
> 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 = "";
> }
> @@ -588,12 +588,12 @@
> 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;
> }
> }
>
> Modified: trunk/postgis/lwgeom_in_geojson.c
> ===================================================================
> --- trunk/postgis/lwgeom_in_geojson.c 2019-02-21 20:44:29 UTC (rev 17270)
> +++ trunk/postgis/lwgeom_in_geojson.c 2019-02-22 16:51:34 UTC (rev 17271)
> @@ -51,7 +51,7 @@
> 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';
>
> Modified: trunk/postgis/lwgeom_in_gml.c
> ===================================================================
> --- trunk/postgis/lwgeom_in_gml.c 2019-02-21 20:44:29 UTC (rev 17270)
> +++ trunk/postgis/lwgeom_in_gml.c 2019-02-22 16:51:34 UTC (rev 17271)
> @@ -108,7 +108,7 @@
> 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);
>
> Modified: trunk/postgis/lwgeom_in_kml.c
> ===================================================================
> --- trunk/postgis/lwgeom_in_kml.c 2019-02-21 20:44:29 UTC (rev 17270)
> +++ trunk/postgis/lwgeom_in_kml.c 2019-02-22 16:51:34 UTC (rev 17271)
> @@ -86,7 +86,7 @@
> 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();
>
> Modified: trunk/postgis/lwgeom_inout.c
> ===================================================================
> --- trunk/postgis/lwgeom_inout.c 2019-02-21 20:44:29 UTC (rev 17270)
> +++ trunk/postgis/lwgeom_inout.c 2019-02-22 16:51:34 UTC (rev 17271)
> @@ -374,7 +374,7 @@
> 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 @@
> 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 @@
> variant = variant | WKB_NDR;
> }
> }
> - wkb_size= VARSIZE(geom) - VARHDRSZ;
> + wkb_size= VARSIZE_ANY_EXHDR(geom);
> /* Create WKB hex string */
> lwgeom = lwgeom_from_gserialized(geom);
>
>
> Modified: trunk/postgis/lwgeom_ogc.c
> ===================================================================
> --- trunk/postgis/lwgeom_ogc.c 2019-02-21 20:44:29 UTC (rev 17270)
> +++ trunk/postgis/lwgeom_ogc.c 2019-02-22 16:51:34 UTC (rev 17271)
> @@ -830,7 +830,7 @@
> 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);
>
> Modified: trunk/postgis/mvt.c
> ===================================================================
> --- trunk/postgis/mvt.c 2019-02-21 20:44:29 UTC (rev 17270)
> +++ trunk/postgis/mvt.c 2019-02-22 16:51:34 UTC (rev 17271)
> @@ -1183,7 +1183,7 @@
> 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));
>
> Modified: trunk/raster/rt_pg/rtpg_gdal.c
> ===================================================================
> --- trunk/raster/rt_pg/rtpg_gdal.c 2019-02-21 20:44:29 UTC (rev 17270)
> +++ trunk/raster/rt_pg/rtpg_gdal.c 2019-02-22 16:51:34 UTC (rev 17271)
> @@ -77,7 +77,7 @@
> /* 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 @@
> 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);
>
> Modified: trunk/raster/rt_pg/rtpg_inout.c
> ===================================================================
> --- trunk/raster/rt_pg/rtpg_inout.c 2019-02-21 20:44:29 UTC (rev 17270)
> +++ trunk/raster/rt_pg/rtpg_inout.c 2019-02-22 16:51:34 UTC (rev 17271)
> @@ -142,7 +142,7 @@
> 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);
>
> Modified: trunk/raster/rt_pg/rtpg_wkb.c
> ===================================================================
> --- trunk/raster/rt_pg/rtpg_wkb.c 2019-02-21 20:44:29 UTC (rev 17270)
> +++ trunk/raster/rt_pg/rtpg_wkb.c 2019-02-22 16:51:34 UTC (rev 17271)
> @@ -81,7 +81,7 @@
> 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 @@
>
> 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);
>
> _______________________________________________
> postgis-tickets mailing list
> postgis-tickets at lists.osgeo.org
> https://lists.osgeo.org/mailman/listinfo/postgis-tickets
--
Raúl Marín Rodríguez
carto.com
More information about the postgis-tickets
mailing list