Commit 591d0c69 authored by Raúl Marín's avatar Raúl Marín

Revert incorrect "Optimize varlena returning functions"

This reverts commit 0696fa46.

I'm not sure what I did there, it seems like I pushed smaller commits
instead of a squashed one, and then did a revert that undid everything.

References #4623
parent 59179cd8
Pipeline #140747573 passed with stage
in 28 minutes and 39 seconds
......@@ -10,14 +10,14 @@ Only tickets not included in 3.1.0alpha1
- #4656, Cast a geojson_text::geometry for implicit GeoJSON ingestion (Raúl Marín)
* Enhancements *
- #4651, ST_Simplify: Don't copy if nothing is removed (Raúl Marín)
- #4657, Avoid De-TOASTing where possible (Paul Ramsey)
- #4623, Optimize varlena returning functions (Raúl Marín)
- #4651: ST_Simplify: Don't copy if nothing is removed (Raúl Marín)
- #4657: Avoid De-TOASTing where possible (Paul Ramsey)
* Bug fixes *
- #4652, Fix several memory related bugs in ST_GeomFromGML (Raúl Marín)
- #4661, Fix access to spatial_ref_sys with a non default schema (Raúl Marín)
- #4670, ST_AddPoint: Fix bug when a positive position is requested (Raúl Marín)
- #4623, Optimize varlena returning functions (Raúl Marín)
PostGIS 3.1.0alpha1
2020/02/01
......
......@@ -101,15 +101,14 @@ bytebuffer_makeroom(bytebuffer_t *s, size_t size_to_add)
}
/** Returns a copy of the internal buffer */
uint8_t*
bytebuffer_get_buffer_copy(const bytebuffer_t *s, size_t *buffer_length)
lwvarlena_t *
bytebuffer_get_buffer_varlena(const bytebuffer_t *s)
{
size_t bufsz = bytebuffer_getlength(s);
uint8_t *buf = lwalloc(bufsz);
memcpy(buf, s->buf_start, bufsz);
if ( buffer_length )
*buffer_length = bufsz;
return buf;
lwvarlena_t *v = lwalloc(bufsz + LWVARHDRSZ);
memcpy(v->data, s->buf_start, bufsz);
LWSIZE_SET(v->size, bufsz + LWVARHDRSZ);
return v;
}
/** Returns a read-only reference to the internal buffer */
......@@ -182,6 +181,18 @@ bytebuffer_getlength(const bytebuffer_t *s)
/* Unused functions */
#if 0
/** Returns a copy of the internal buffer */
uint8_t*
bytebuffer_get_buffer_copy(const bytebuffer_t *s, size_t *buffer_length)
{
size_t bufsz = bytebuffer_getlength(s);
uint8_t *buf = lwalloc(bufsz);
memcpy(buf, s->buf_start, bufsz);
if ( buffer_length )
*buffer_length = bufsz;
return buf;
}
/**
* Allocate a new bytebuffer_t. Use bytebuffer_destroy to free.
*/
......
......@@ -31,7 +31,9 @@
#include <stdint.h>
#include "varint.h"
#include "liblwgeom_internal.h"
#include "lwgeom_log.h"
#define BYTEBUFFER_STARTSIZE 512
#define BYTEBUFFER_STATICSIZE 1024
......@@ -52,7 +54,7 @@ void bytebuffer_append_bytebuffer(bytebuffer_t *write_to, bytebuffer_t *write_fr
void bytebuffer_append_varint(bytebuffer_t *s, const int64_t val);
void bytebuffer_append_uvarint(bytebuffer_t *s, const uint64_t val);
size_t bytebuffer_getlength(const bytebuffer_t *s);
uint8_t* bytebuffer_get_buffer_copy(const bytebuffer_t *s, size_t *buffer_length);
lwvarlena_t *bytebuffer_get_buffer_varlena(const bytebuffer_t *s);
const uint8_t* bytebuffer_get_buffer(const bytebuffer_t *s, size_t *buffer_length);
/* Unused functions */
......@@ -61,6 +63,7 @@ void bytebuffer_destroy(bytebuffer_t *s);
bytebuffer_t *bytebuffer_create_with_size(size_t size);
bytebuffer_t *bytebuffer_create(void);
void bytebuffer_clear(bytebuffer_t *s);
uint8_t* bytebuffer_get_buffer_copy(const bytebuffer_t *s, size_t *buffer_length);
uint64_t bytebuffer_read_uvarint(bytebuffer_t *s);
int64_t bytebuffer_read_varint(bytebuffer_t *s);
bytebuffer_t* bytebuffer_merge(bytebuffer_t **buff_array, int nbuffers);
......
......@@ -951,21 +951,21 @@ static void test_geohash_precision(void)
static void test_geohash_point(void)
{
char *geohash;
lwvarlena_t *geohash;
geohash = geohash_point(0, 0, 16);
//printf("\ngeohash %s\n",geohash);
ASSERT_STRING_EQUAL(geohash, "s000000000000000");
ASSERT_VARLENA_EQUAL(geohash, "s000000000000000");
lwfree(geohash);
geohash = geohash_point(90, 0, 16);
//printf("\ngeohash %s\n",geohash);
ASSERT_STRING_EQUAL(geohash, "w000000000000000");
ASSERT_VARLENA_EQUAL(geohash, "w000000000000000");
lwfree(geohash);
geohash = geohash_point(20.012345, -20.012345, 15);
//printf("\ngeohash %s\n",geohash);
ASSERT_STRING_EQUAL(geohash, "kkqnpkue9ktbpe5");
ASSERT_VARLENA_EQUAL(geohash, "kkqnpkue9ktbpe5");
lwfree(geohash);
}
......@@ -975,40 +975,40 @@ static void test_geohash(void)
LWPOINT *lwpoint = NULL;
LWLINE *lwline = NULL;
LWMLINE *lwmline = NULL;
char *geohash = NULL;
lwvarlena_t *geohash = NULL;
lwpoint = (LWPOINT*)lwgeom_from_wkt("POINT(23.0 25.2)", LW_PARSER_CHECK_NONE);
geohash = lwgeom_geohash((LWGEOM*)lwpoint,0);
//printf("\ngeohash %s\n",geohash);
ASSERT_STRING_EQUAL(geohash, "ss2r77s0du7p2ewb8hmx");
ASSERT_VARLENA_EQUAL(geohash, "ss2r77s0du7p2ewb8hmx");
lwpoint_free(lwpoint);
lwfree(geohash);
lwpoint = (LWPOINT*)lwgeom_from_wkt("POINT(23.0 25.2 2.0)", LW_PARSER_CHECK_NONE);
geohash = lwgeom_geohash((LWGEOM*)lwpoint,0);
//printf("geohash %s\n",geohash);
ASSERT_STRING_EQUAL(geohash, "ss2r77s0du7p2ewb8hmx");
ASSERT_VARLENA_EQUAL(geohash, "ss2r77s0du7p2ewb8hmx");
lwpoint_free(lwpoint);
lwfree(geohash);
lwline = (LWLINE*)lwgeom_from_wkt("LINESTRING(23.0 23.0,23.1 23.1)", LW_PARSER_CHECK_NONE);
geohash = lwgeom_geohash((LWGEOM*)lwline,0);
//printf("geohash %s\n",geohash);
ASSERT_STRING_EQUAL(geohash, "ss0");
ASSERT_VARLENA_EQUAL(geohash, "ss0");
lwline_free(lwline);
lwfree(geohash);
lwline = (LWLINE*)lwgeom_from_wkt("LINESTRING(23.0 23.0,23.001 23.001)", LW_PARSER_CHECK_NONE);
geohash = lwgeom_geohash((LWGEOM*)lwline,0);
//printf("geohash %s\n",geohash);
ASSERT_STRING_EQUAL(geohash, "ss06g7h");
ASSERT_VARLENA_EQUAL(geohash, "ss06g7h");
lwline_free(lwline);
lwfree(geohash);
lwmline = (LWMLINE*)lwgeom_from_wkt("MULTILINESTRING((23.0 23.0,23.1 23.1),(23.0 23.0,23.1 23.1))", LW_PARSER_CHECK_NONE);
geohash = lwgeom_geohash((LWGEOM*)lwmline,0);
//printf("geohash %s\n",geohash);
ASSERT_STRING_EQUAL(geohash, "ss0");
ASSERT_VARLENA_EQUAL(geohash, "ss0");
lwmline_free(lwmline);
lwfree(geohash);
}
......
......@@ -251,11 +251,11 @@ static void test_lwgeom_from_gserialized2(void)
size1 = gserialized2_from_lwgeom_size(geom1);
g1 = gserialized2_from_lwgeom(geom1, &size2);
CU_ASSERT_EQUAL(size1, size2);
CU_ASSERT_EQUAL(SIZE_GET(g1->size), size2);
CU_ASSERT_EQUAL(LWSIZE_GET(g1->size), size2);
geom2 = lwgeom_from_gserialized2(g1);
CU_ASSERT_EQUAL(geom1->flags, geom2->flags);
g2 = gserialized2_from_lwgeom(geom2, &size2);
CU_ASSERT_EQUAL(SIZE_GET(g2->size), size2);
CU_ASSERT_EQUAL(LWSIZE_GET(g2->size), size2);
CU_ASSERT_EQUAL(g1->gflags, g2->gflags);
CU_ASSERT_EQUAL(FLAGS_GET_SOLID(geom2->flags), 1);
lwfree(g1);
......
......@@ -54,8 +54,6 @@ static void cu_twkb_in(char *wkt)
{
LWGEOM_PARSER_RESULT pr;
LWGEOM *g_a, *g_b;
uint8_t *twkb_a, *twkb_b;
size_t twkb_size_a, twkb_size_b;
/* int i; char *hex; */
/* Turn WKT into geom */
......@@ -71,23 +69,23 @@ static void cu_twkb_in(char *wkt)
g_a = pr.geom;
/* Turn geom into TWKB */
twkb_a = lwgeom_to_twkb(g_a, variant, precision, precision, precision, &twkb_size_a);
lwvarlena_t *twkb_a = lwgeom_to_twkb(g_a, variant, precision, precision, precision);
// printf("\n Size: %ld\n", twkb_size_a);
/* Turn TWKB back into geom */
g_b = lwgeom_from_twkb(twkb_a, twkb_size_a, LW_PARSER_CHECK_NONE);
g_b = lwgeom_from_twkb((uint8_t *)twkb_a->data, LWSIZE_GET(twkb_a->size) - LWVARHDRSZ, LW_PARSER_CHECK_NONE);
// printf("\n Org: %s\n 1st: %s\n 2nd: %s\n", wkt, lwgeom_to_ewkt(g_a), lwgeom_to_ewkt(g_b));
/* Turn geom to TWKB again */
twkb_b = lwgeom_to_twkb(g_b, variant, precision, precision, precision, &twkb_size_b);
lwvarlena_t *twkb_b = lwgeom_to_twkb(g_b, variant, precision, precision, precision);
/* Turn TWKB into hex for comparisons */
if ( hex_a ) lwfree(hex_a);
if ( hex_b ) lwfree(hex_b);
hex_a = hexbytes_from_bytes(twkb_a, twkb_size_a);
hex_b = hexbytes_from_bytes(twkb_b, twkb_size_b);
hex_a = hexbytes_from_bytes((uint8_t *)twkb_a->data, LWSIZE_GET(twkb_a->size) - LWVARHDRSZ);
hex_b = hexbytes_from_bytes((uint8_t *)twkb_b->data, LWSIZE_GET(twkb_b->size) - LWVARHDRSZ);
/* Clean up */
lwfree(twkb_a);
......
......@@ -63,8 +63,7 @@ static void cu_wkb_in(char *wkt)
{
LWGEOM_PARSER_RESULT pr;
LWGEOM *g_a, *g_b;
uint8_t *wkb_a, *wkb_b;
size_t wkb_size_a, wkb_size_b;
lwvarlena_t *wkb_a, *wkb_b;
/* int i; char *hex; */
if ( hex_a ) free(hex_a);
......@@ -83,17 +82,17 @@ static void cu_wkb_in(char *wkt)
g_a = pr.geom;
/* Turn geom into WKB */
wkb_a = lwgeom_to_wkb(g_a, WKB_NDR | WKB_EXTENDED, &wkb_size_a);
wkb_a = lwgeom_to_wkb_varlena(g_a, WKB_NDR | WKB_EXTENDED);
/* Turn WKB back into geom */
g_b = lwgeom_from_wkb(wkb_a, wkb_size_a, LW_PARSER_CHECK_NONE);
g_b = lwgeom_from_wkb((uint8_t *)wkb_a->data, LWSIZE_GET(wkb_a->size) - LWVARHDRSZ, LW_PARSER_CHECK_NONE);
/* Turn geom to WKB again */
wkb_b = lwgeom_to_wkb(g_b, WKB_NDR | WKB_EXTENDED, &wkb_size_b);
wkb_b = lwgeom_to_wkb_varlena(g_b, WKB_NDR | WKB_EXTENDED);
/* Turn geoms into WKB for comparisons */
hex_a = hexbytes_from_bytes(wkb_a, wkb_size_a);
hex_b = hexbytes_from_bytes(wkb_b, wkb_size_b);
hex_a = hexbytes_from_bytes((uint8_t *)wkb_a->data, LWSIZE_GET(wkb_a->size) - LWVARHDRSZ);
hex_b = hexbytes_from_bytes((uint8_t *)wkb_b->data, LWSIZE_GET(wkb_b->size) - LWVARHDRSZ);
/* Clean up */
lwfree(wkb_a);
......
......@@ -22,19 +22,13 @@
static void
do_encoded_polyline_test(char* in, int precision, char* out)
{
LWGEOM* g;
char* h;
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_to_encoded_polyline(g, precision);
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_to_encoded_polyline(g, precision);
if (strcmp(h, out))
fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
CU_ASSERT_STRING_EQUAL(h, out);
ASSERT_VARLENA_EQUAL(v, out);
lwgeom_free(g);
lwfree(h);
lwfree(v);
}
static void
......
......@@ -19,38 +19,25 @@
static void do_geojson_test(char * in, char * out, char * srs, int precision, int has_bbox)
{
LWGEOM *g;
char * h;
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_to_geojson(g, srs, precision, has_bbox);
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_to_geojson(g, srs, precision, has_bbox);
if (strcmp(h, out))
fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
CU_ASSERT_STRING_EQUAL(h, out);
ASSERT_VARLENA_EQUAL(v, out);
lwgeom_free(g);
lwfree(h);
lwfree(v);
}
static void do_geojson_unsupported(char * in, char * out)
{
LWGEOM *g;
char *h;
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_to_geojson(g, NULL, 0, 0);
if (strcmp(cu_error_msg, out))
fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n",
in, cu_error_msg, out);
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_to_geojson(g, NULL, 0, 0);
CU_ASSERT_STRING_EQUAL(out, cu_error_msg);
ASSERT_STRING_EQUAL(out, cu_error_msg);
cu_error_msg_reset();
lwfree(h);
lwfree(v);
lwgeom_free(g);
}
......
......@@ -20,171 +20,121 @@
static void do_gml2_test(char * in, char * out, char * srs, int precision)
{
LWGEOM *g;
char *h;
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_to_gml2(g, srs, precision, "gml:");
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_to_gml2(g, srs, precision, "gml:");
if (strcmp(h, out))
fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
CU_ASSERT_STRING_EQUAL(h, out);
ASSERT_VARLENA_EQUAL(v, out);
lwgeom_free(g);
lwfree(h);
lwfree(v);
}
static void do_gml2_test_prefix(char * in, char * out, char * srs, int precision, const char *prefix)
{
LWGEOM *g;
char *h;
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_to_gml2(g, srs, precision, prefix);
if (strcmp(h, out))
fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_to_gml2(g, srs, precision, prefix);
CU_ASSERT_STRING_EQUAL(h, out);
ASSERT_VARLENA_EQUAL(v, out);
lwgeom_free(g);
lwfree(h);
lwfree(v);
}
static void do_gml3_test_opts(char * in, char * out, char * srs, int precision, int opts)
{
LWGEOM *g;
char *h;
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_to_gml3(g, srs, precision, opts, "gml:", NULL);
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_to_gml3(g, srs, precision, opts, "gml:", NULL);
if (strcmp(h, out))
fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
CU_ASSERT_STRING_EQUAL(h, out);
ASSERT_VARLENA_EQUAL(v, out);
lwgeom_free(g);
lwfree(h);
lwfree(v);
}
static void do_gml3_test(char * in, char * out, char * srs, int precision, int is_geodetic)
{
LWGEOM *g;
char *h;
int opts = LW_GML_IS_DIMS;
if ( is_geodetic ) opts |= LW_GML_IS_DEGREE;
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_to_gml3(g, srs, precision, opts, "gml:", NULL);
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_to_gml3(g, srs, precision, opts, "gml:", NULL);
if (strcmp(h, out))
fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
CU_ASSERT_STRING_EQUAL(h, out);
ASSERT_VARLENA_EQUAL(v, out);
lwgeom_free(g);
lwfree(h);
lwfree(v);
}
static void do_gml3_test_prefix(char * in, char * out, char * srs, int precision, int is_geodetic, const char *prefix)
{
LWGEOM *g;
char *h;
int opts = LW_GML_IS_DIMS;
if ( is_geodetic ) opts |= LW_GML_IS_DEGREE;
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_to_gml3(g, srs, precision, opts, prefix, NULL);
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_to_gml3(g, srs, precision, opts, prefix, NULL);
if (strcmp(h, out))
fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
CU_ASSERT_STRING_EQUAL(h, out);
ASSERT_VARLENA_EQUAL(v, out);
lwgeom_free(g);
lwfree(h);
lwfree(v);
}
static void do_gml3_test_nodims(char * in, char * out, char * srs, int precision, int is_geodetic, int is_dims, const char *prefix)
{
LWGEOM *g;
char *h;
int opts = 0;
if ( is_geodetic ) opts |= LW_GML_IS_DEGREE;
if ( is_dims ) opts |= LW_GML_IS_DIMS;
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_to_gml3(g, srs, precision, opts, prefix, NULL);
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_to_gml3(g, srs, precision, opts, prefix, NULL);
if (strcmp(h, out))
fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
CU_ASSERT_STRING_EQUAL(h, out);
ASSERT_VARLENA_EQUAL(v, out);
lwgeom_free(g);
lwfree(h);
lwfree(v);
}
static void do_gml2_unsupported(char * in, char * out)
{
LWGEOM *g;
char *h;
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_to_gml2(g, NULL, 0, "");
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_to_gml2(g, NULL, 0, "");
if (strcmp(cu_error_msg, out))
fprintf(stderr, "\nGML 2 - In: %s\nOut: %s\nTheo: %s\n",
in, cu_error_msg, out);
CU_ASSERT_STRING_EQUAL(out, cu_error_msg);
ASSERT_STRING_EQUAL(out, cu_error_msg);
cu_error_msg_reset();
lwfree(h);
lwfree(v);
lwgeom_free(g);
}
static void do_gml2_extent_test(char * in, char * out, char * srs,
double precision, char * prefix)
{
LWGEOM *g;
char *h;
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_extent_to_gml2(g, srs, precision, prefix);
if (!v)
{
ASSERT_STRING_EQUAL(in, cu_error_msg);
}
else
{
ASSERT_VARLENA_EQUAL(v, out);
}
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_extent_to_gml2(g, srs, precision, prefix);
if ( ! h ) h = strdup(cu_error_msg);
if (strcmp(h, out))
fprintf(stderr, "\nEXT GML 2 - In: %s\nObt: %s\nExp: %s\n",
in, h, out);
CU_ASSERT_STRING_EQUAL(out, h);
cu_error_msg_reset();
lwfree(h);
lwfree(v);
lwgeom_free(g);
}
static void do_gml3_extent_test(char * in, char * out, char * srs,
double precision, int opts, char* prefix)
{
LWGEOM *g;
char *h;
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_extent_to_gml3(g, srs, precision, opts, prefix);
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_extent_to_gml3(g, srs, precision, opts, prefix);
if ( ! h ) h = strdup(cu_error_msg);
if (strcmp(h, out))
fprintf(stderr, "\nEXT GML 3 - In: %s\nObt: %s\nExp: %s\n",
in, h, out);
CU_ASSERT_STRING_EQUAL(out, h);
cu_error_msg_reset();
ASSERT_VARLENA_EQUAL(v, out);
lwfree(h);
lwgeom_free(g);
lwfree(v);
}
static void out_gml_test_precision(void)
......
......@@ -19,58 +19,38 @@
static void do_kml_test(char * in, char * out, int precision)
{
LWGEOM *g;
char * h;
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_to_kml2(g, precision, "");
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_to_kml2(g, precision, "");
if (strcmp(h, out))
fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
CU_ASSERT_STRING_EQUAL(h, out);
ASSERT_VARLENA_EQUAL(v, out);
lwgeom_free(g);
lwfree(h);
lwfree(v);
}
static void do_kml_unsupported(char * in, char * out)
{
LWGEOM *g;
char *h;
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_to_kml2(g, 0, "");
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_to_kml2(g, 0, "");
if (strcmp(cu_error_msg, out))
fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n",
in, cu_error_msg, out);
CU_ASSERT_STRING_EQUAL(out, cu_error_msg);
ASSERT_STRING_EQUAL(cu_error_msg, out);
cu_error_msg_reset();
lwfree(h);
lwfree(v);
lwgeom_free(g);
}
static void do_kml_test_prefix(char * in, char * out, int precision, const char *prefix)
{
LWGEOM *g;
char * h;
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_to_kml2(g, precision, prefix);
if (strcmp(h, out))
fprintf(stderr, "\nPrefix: %s\nIn: %s\nOut: %s\nTheo: %s\n",
prefix, in, h, out);
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_to_kml2(g, precision, prefix);
CU_ASSERT_STRING_EQUAL(h, out);
ASSERT_VARLENA_EQUAL(v, out);
lwgeom_free(g);
lwfree(h);
lwfree(v);
}
......
......@@ -19,39 +19,26 @@
static void do_svg_test(char * in, char * out, int precision, int relative)
{
LWGEOM *g;
char * h;
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_to_svg(g, precision, relative);
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_to_svg(g, precision, relative);
if (strcmp(h, out))
fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n", in, h, out);
CU_ASSERT_STRING_EQUAL(h, out);
ASSERT_VARLENA_EQUAL(v, out);
lwgeom_free(g);
lwfree(h);
lwfree(v);
}
static void do_svg_unsupported(char * in, char * out)
{
LWGEOM *g;
char *h;
g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
h = lwgeom_to_svg(g, 0, 0);
if (strcmp(cu_error_msg, out))
fprintf(stderr, "\nIn: %s\nOut: %s\nTheo: %s\n",
in, cu_error_msg, out);
LWGEOM *g = lwgeom_from_wkt(in, LW_PARSER_CHECK_NONE);
lwvarlena_t *v = lwgeom_to_svg(g, 0, 0);
CU_ASSERT_STRING_EQUAL(out, cu_error_msg);
ASSERT_STRING_EQUAL(cu_error_msg, out);
cu_error_msg_reset();
lwfree(h);
lwgeom_free(g);
lwfree(v);
}
......
......@@ -55,13 +55,11 @@ static int clean_twkb_out_suite(void)
static void cu_twkb(char *wkt, int8_t prec_xy, int8_t prec_z, int8_t prec_m, uint8_t variant)
{
LWGEOM *g = lwgeom_from_wkt(wkt, LW_PARSER_CHECK_NONE);
size_t twkb_size;
uint8_t *twkb;
if ( ! g ) lwnotice("input wkt is invalid: %s", wkt);
twkb = lwgeom_to_twkb(g, variant, prec_xy, prec_z, prec_m, &twkb_size);
lwvarlena_t *twkb = lwgeom_to_twkb(g, variant, prec_xy, prec_z, prec_m);
lwgeom_free(g);
if ( s ) free(s);
s = hexbytes_from_bytes(twkb, twkb_size);
s = hexbytes_from_bytes((uint8_t *)twkb->data, LWSIZE_GET(twkb->size) - LWVARHDRSZ);
free(twkb);
}
......@@ -73,15 +71,13 @@ static void cu_twkb_idlist(char *wkt, int64_t *idlist, int8_t prec_xy, int8_t pr
{
LWGEOM *g