Commit d9b0ee7a authored by Paul Ramsey's avatar Paul Ramsey

Replace VARSIZE(foo)-VARHDRSZ pattern with VARSIZE_ANY_EXHDR(foo)

macro from standard Pg.


git-svn-id: http://svn.osgeo.org/postgis/trunk@17271 b70326c6-7e19-0410-871a-916f4a2858ee
parent 814d1e03
Pipeline #48784603 failed with stage
in 5 minutes and 40 seconds
......@@ -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 @@ 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);
......
......@@ -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 ) {
......
......@@ -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;
}
}
......
......@@ -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' )
......
......@@ -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;
......
......@@ -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;
}
}
......
......@@ -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';
......
......@@ -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);
......
......@@ -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();
......
......@@ -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);
......
......@@ -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);
......
......@@ -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));
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment