void gbox_duplicate(const GBOX *original, GBOX *duplicate)
{
assert(duplicate);
+ assert(original);
memcpy(duplicate, original, sizeof(GBOX));
}
{
uint8_t *ptr;
assert(n < pa->npoints);
- ptr=getPoint_internal(pa, n);
+ ptr = getPoint_internal(pa, n);
switch ( FLAGS_GET_ZM(pa->flags) )
{
case 3:
elog(ERROR, "%s", lwg_unparser_result->message);
}
-
static void *
pg_alloc(size_t size)
{
{
/* install PostgreSQL handlers */
lwgeom_set_handlers(pg_alloc, pg_realloc, pg_free, pg_error, pg_notice);
+ /*
+ If you want to try with malloc:
+ lwgeom_set_handlers(NULL, NULL, NULL, pg_error, pg_notice);
+ */
lwgeom_set_debuglogger(pg_debug);
}
-/**
-* Utility method to call the serialization and then set the
-* PgSQL varsize header appropriately with the serialized size.
-*/
-
/**
* Utility method to call the serialization and then set the
* PgSQL varsize header appropriately with the serialized size.
/* create a text obj to return */
mytext = cstring_to_text(result);
- pfree(result);
+ lwfree(result);
PG_FREE_IF_COPY(geom,0);
PG_RETURN_TEXT_P(mytext);
/* Write to text and free the WKT */
result = cstring_to_text(wkt);
- pfree(wkt);
+ lwfree(wkt);
/* Return the text */
PG_FREE_IF_COPY(geom, 0);
result_array_data[i] = PointerGetDatum(GEOS2POSTGIS(geos_results[i], is3d));
GEOSGeom_destroy(geos_results[i]);
}
- pfree(geos_results);
+ lwfree(geos_results);
get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
result = construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
result_array_data[i] = PointerGetDatum(gserialized_from_lwgeom(lw_results[i], NULL));
lwgeom_free(lw_results[i]);
}
- pfree(lw_results);
+ lwfree(lw_results);
get_typlenbyvalalign(array->elemtype, &elmlen, &elmbyval, &elmalign);
result = construct_array(result_array_data, nclusters, array->elemtype, elmlen, elmbyval, elmalign);
Datum geom_from_gml(PG_FUNCTION_ARGS);
-static LWGEOM* lwgeom_from_gml(const char *wkt);
+static LWGEOM *lwgeom_from_gml(const char *wkt, int xml_size);
static LWGEOM* parse_gml(xmlNodePtr xnode, bool *hasz, int *root_srid);
typedef struct struct_gmlSrs
LWGEOM *lwgeom;
char *xml;
int root_srid=SRID_UNKNOWN;
-
+ int xml_size;
/* Get the GML stream */
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;
/* Zero for undefined */
root_srid = PG_GETARG_INT32(1);
- lwgeom = lwgeom_from_gml(xml);
+ lwgeom = lwgeom_from_gml(xml, xml_size);
if ( root_srid != SRID_UNKNOWN )
lwgeom->srid = root_srid;
/**
* Read GML
*/
-static LWGEOM* lwgeom_from_gml(const char* xml)
+static LWGEOM *
+lwgeom_from_gml(const char *xml, int xml_size)
{
xmlDocPtr xmldoc;
xmlNodePtr xmlroot=NULL;
- int xml_size = strlen(xml);
- LWGEOM *lwgeom;
+ LWGEOM *lwgeom = NULL;
bool hasz=true;
int root_srid=SRID_UNKNOWN;
/* Begin to Parse XML doc */
xmlInitParser();
- xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, XML_PARSE_SAX1);
- if (!xmldoc || (xmlroot = xmlDocGetRootElement(xmldoc)) == NULL)
+
+ xmldoc = xmlReadMemory(xml, xml_size, NULL, NULL, XML_PARSE_SAX1);
+ if (!xmldoc)
+ {
+ xmlCleanupParser();
+ gml_lwpgerror("invalid GML representation", 1);
+ return NULL;
+ }
+
+ xmlroot = xmlDocGetRootElement(xmldoc);
+ if (!xmlroot)
{
xmlFreeDoc(xmldoc);
xmlCleanupParser();
gml_lwpgerror("invalid GML representation", 1);
+ return NULL;
}
lwgeom = parse_gml(xmlroot, &hasz, &root_srid);
xmlCleanupParser();
/* shouldn't we be releasing xmldoc too here ? */
-
if ( root_srid != SRID_UNKNOWN )
lwgeom->srid = root_srid;
bool hasz=true;
xmlNodePtr xmlroot=NULL;
-
/* Get the KML stream */
if (PG_ARGISNULL(0)) PG_RETURN_NULL();
xml_input = PG_GETARG_TEXT_P(0);
if ( srid ) lwgeom_set_srid(lwgeom, srid);
/* Add a bbox if necessary */
if ( lwgeom_needs_bbox(lwgeom) ) lwgeom_add_bbox(lwgeom);
- pfree(wkb);
+ lwfree(wkb);
ret = geometry_serialize(lwgeom);
lwgeom_free(lwgeom);
}
SET_VARSIZE(result, text_size);
/* Clean up and return */
- pfree(hexwkb);
+ lwfree(hexwkb);
PG_FREE_IF_COPY(geom, 0);
PG_RETURN_TEXT_P(result);
}
/* Copy into text obect */
result = cstring_to_text(hexwkb);
- pfree(hexwkb);
+ lwfree(hexwkb);
/* Clean up and return */
PG_FREE_IF_COPY(geom, 0);
SET_VARSIZE(result, wkb_size+VARHDRSZ);
/* Clean up and return */
- pfree(wkb);
+ lwfree(wkb);
PG_FREE_IF_COPY(geom, 0);
PG_RETURN_BYTEA_P(result);
}
/* Write to text and free the WKT */
result = cstring_to_text(wkt);
- pfree(wkt);
+ lwfree(wkt);
/* Return the text */
PG_FREE_IF_COPY(geom, 0);
result = palloc(wkb_size + VARHDRSZ);
memcpy(VARDATA(result), wkb, wkb_size);
SET_VARSIZE(result, wkb_size + VARHDRSZ);
- pfree(wkb);
+ lwfree(wkb);
/* Return the text */
PG_FREE_IF_COPY(geom, 0);
/* Safe the result */
memcpy(context->result, r, sizeof(int) * N);
- pfree(r);
+ lwfree(r);
context->isdone = true;
}