mirror of
https://git.osgeo.org/gitea/postgis/postgis
synced 2024-10-25 01:22:47 +00:00
Remove some calls to memcpy in favor of API functions.
git-svn-id: http://svn.osgeo.org/postgis/trunk@6384 b70326c6-7e19-0410-871a-916f4a2858ee
This commit is contained in:
parent
1a2af11f6d
commit
bc64e7a8ab
|
@ -166,7 +166,7 @@ lwgeom_make_geos_friendly(LWGEOM *geom)
|
|||
case MULTISURFACETYPE:
|
||||
case MULTICURVETYPE:
|
||||
default:
|
||||
lwerror("unsupported input geometry type: %d", geom->type);
|
||||
lwerror("unsupported input geometry type: %s (%d)", lwtype_name(geom->type), geom->type);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -89,11 +89,8 @@ Datum geom_from_gml(PG_FUNCTION_ARGS)
|
|||
/* Get the GML stream */
|
||||
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
|
||||
xml_input = PG_GETARG_TEXT_P(0);
|
||||
|
||||
xml_size = VARSIZE(xml_input) - VARHDRSZ; /* actual letters */
|
||||
xml = palloc(xml_size + 1); /* +1 for null */
|
||||
memcpy(xml, VARDATA(xml_input), xml_size);
|
||||
xml[xml_size] = 0; /* null term */
|
||||
xml = text2cstring(xml_input);
|
||||
xml_size = VARSIZE(xml_input) - VARHDRSZ;
|
||||
|
||||
/* Begin to Parse XML doc */
|
||||
xmlInitParser();
|
||||
|
|
|
@ -70,11 +70,8 @@ Datum geom_from_kml(PG_FUNCTION_ARGS)
|
|||
/* Get the KML stream */
|
||||
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
|
||||
xml_input = PG_GETARG_TEXT_P(0);
|
||||
|
||||
xml_size = VARSIZE(xml_input) - VARHDRSZ; /* actual letters */
|
||||
xml = palloc(xml_size + 1); /* +1 for null */
|
||||
memcpy(xml, VARDATA(xml_input), xml_size);
|
||||
xml[xml_size] = 0; /* null term */
|
||||
xml = text2cstring(xml_input);
|
||||
xml_size = VARSIZE(xml_input) - VARHDRSZ;
|
||||
|
||||
/* Begin to Parse XML doc */
|
||||
xmlInitParser();
|
||||
|
|
|
@ -169,9 +169,8 @@ PG_FUNCTION_INFO_V1(geometry_geometrytype);
|
|||
Datum geometry_geometrytype(PG_FUNCTION_ARGS)
|
||||
{
|
||||
PG_LWGEOM *lwgeom;
|
||||
char *type_text;
|
||||
text *type_text;
|
||||
char *type_str = palloc(32);
|
||||
size_t size;
|
||||
|
||||
lwgeom = (PG_LWGEOM*)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
|
||||
|
||||
|
@ -181,15 +180,13 @@ Datum geometry_geometrytype(PG_FUNCTION_ARGS)
|
|||
/* Build up the output string */
|
||||
strncat(type_str, "ST_", 32);
|
||||
strncat(type_str, lwtype_name(pglwgeom_get_type(lwgeom)), 32);
|
||||
size = strlen(type_str) + VARHDRSZ;
|
||||
|
||||
/* Build a text type to store things in */
|
||||
type_text = lwalloc(size);
|
||||
memcpy(VARDATA(type_text),type_str, size - VARHDRSZ);
|
||||
type_text = cstring2text(type_str);
|
||||
pfree(type_str);
|
||||
SET_VARSIZE(type_text, size);
|
||||
|
||||
PG_FREE_IF_COPY(lwgeom, 0);
|
||||
PG_RETURN_POINTER(type_text);
|
||||
PG_RETURN_TEXT_P(type_text);
|
||||
}
|
||||
|
||||
|
||||
|
@ -808,9 +805,7 @@ Datum LWGEOM_asText(PG_FUNCTION_ARGS)
|
|||
lwgeom_free(lwgeom);
|
||||
|
||||
/* Write to text and free the WKT */
|
||||
result = palloc(wkt_size - 1 + VARHDRSZ);
|
||||
memcpy(VARDATA(result), wkt, wkt_size - 1);
|
||||
SET_VARSIZE(result, wkt_size - 1 + VARHDRSZ);
|
||||
result = cstring2text(wkt);
|
||||
pfree(wkt);
|
||||
|
||||
/* Return the text */
|
||||
|
|
|
@ -910,18 +910,13 @@ Datum transform_geom(PG_FUNCTION_ARGS)
|
|||
if (!IsPROJ4LibPathSet)
|
||||
SetPROJ4LibPath();
|
||||
|
||||
/* Read the arguments */
|
||||
input_proj4_text = (PG_GETARG_TEXT_P(1));
|
||||
output_proj4_text = (PG_GETARG_TEXT_P(2));
|
||||
|
||||
input_proj4 = (char *)palloc(VARSIZE(input_proj4_text)+1-4);
|
||||
memcpy(input_proj4, VARDATA(input_proj4_text),
|
||||
VARSIZE(input_proj4_text)-VARHDRSZ);
|
||||
input_proj4[VARSIZE(input_proj4_text)-VARHDRSZ] = 0; /* null terminate */
|
||||
|
||||
output_proj4 = (char *) palloc(VARSIZE(output_proj4_text) +1-VARHDRSZ);
|
||||
memcpy(output_proj4, VARDATA(output_proj4_text),
|
||||
VARSIZE(output_proj4_text)-VARHDRSZ);
|
||||
output_proj4[VARSIZE(output_proj4_text)-VARHDRSZ] = 0; /* null terminate */
|
||||
/* Convert from text to cstring for libproj */
|
||||
input_proj4 = text2cstring(input_proj4_text);
|
||||
output_proj4 = text2cstring(output_proj4_text);
|
||||
|
||||
/* make input and output projection objects */
|
||||
input_pj = make_project(input_proj4);
|
||||
|
|
Loading…
Reference in a new issue