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)
DBG("Start standardize_address");
- str = text2char(PG_GETARG_TEXT_P(0));
+ str = text_to_cstring(PG_GETARG_TEXT_P(0));
DBG("str='%s'", str);
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
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 ) {
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 ) {
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;
}
}
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;
}
}
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;
}
}
{
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' )
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;
}
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 */
}
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';
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;
}
}
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;
}
}
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';
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);
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();
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) ))
{
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);
variant = variant | WKB_NDR;
}
}
- wkb_size= VARSIZE(geom) - VARHDRSZ;
+ wkb_size= VARSIZE_ANY_EXHDR(geom);
/* Create WKB hex string */
lwgeom = lwgeom_from_gserialized(geom);
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);
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));
/* 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 */
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);
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);
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);
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);