From: Mark Cave-Ayland Date: Thu, 15 Oct 2009 15:35:45 +0000 (+0000) Subject: Alter the FLAGS_SET_* macros so that they actually update the specified flag variable... X-Git-Tag: 1.5.0b1~369 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9ffba1ed154c6324f3801d239349b7b087ddeb20;p=postgis Alter the FLAGS_SET_* macros so that they actually update the specified flag variable, rather than just returning the new value of the flag variable. git-svn-id: http://svn.osgeo.org/postgis/trunk@4651 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/cu_geodetic.c b/liblwgeom/cunit/cu_geodetic.c index 95db1b848..77d7e8742 100644 --- a/liblwgeom/cunit/cu_geodetic.c +++ b/liblwgeom/cunit/cu_geodetic.c @@ -110,7 +110,7 @@ void test_gbox_from_spherical_coordinates(void) ll[3] = (double)rndlat; g = gserialized_from_lwgeom((LWGEOM*)lwline, 1, 0); - g->flags = FLAGS_SET_GEODETIC(g->flags, 1); + FLAGS_SET_GEODETIC(g->flags, 1); gbox_geocentric_slow = LW_FALSE; gbox = gserialized_calculate_gbox_geocentric(g); gbox_geocentric_slow = LW_TRUE; @@ -163,7 +163,7 @@ void test_gserialized_get_gbox_geocentric(void) #endif lwg = lwgeom_from_ewkt(gbox_data[i], PARSER_CHECK_NONE); g = gserialized_from_lwgeom(lwg, 1, 0); - g->flags = FLAGS_SET_GEODETIC(g->flags, 1); + FLAGS_SET_GEODETIC(g->flags, 1); lwgeom_free(lwg); gbox_geocentric_slow = LW_FALSE; gbox = gserialized_calculate_gbox_geocentric(g); @@ -562,4 +562,4 @@ void test_lwgeom_distance_sphere(void) lwgeom_free(lwg1); lwgeom_free(lwg2); -} \ No newline at end of file +} diff --git a/liblwgeom/cunit/cu_libgeom.c b/liblwgeom/cunit/cu_libgeom.c index 44c773b58..ebbb6b095 100644 --- a/liblwgeom/cunit/cu_libgeom.c +++ b/liblwgeom/cunit/cu_libgeom.c @@ -95,22 +95,22 @@ void test_flags_macros(void) uchar flags = 0; CU_ASSERT_EQUAL(0, FLAGS_GET_Z(flags)); - flags = FLAGS_SET_Z(flags, 1); + FLAGS_SET_Z(flags, 1); CU_ASSERT_EQUAL(1, FLAGS_GET_Z(flags)); - flags = FLAGS_SET_Z(flags, 0); + FLAGS_SET_Z(flags, 0); CU_ASSERT_EQUAL(0, FLAGS_GET_Z(flags)); CU_ASSERT_EQUAL(0, FLAGS_GET_BBOX(flags)); CU_ASSERT_EQUAL(0, FLAGS_GET_M(flags)); - flags = FLAGS_SET_M(flags, 1); + FLAGS_SET_M(flags, 1); CU_ASSERT_EQUAL(1, FLAGS_GET_M(flags)); CU_ASSERT_EQUAL(0, FLAGS_GET_BBOX(flags)); - flags = FLAGS_SET_BBOX(flags, 1); + FLAGS_SET_BBOX(flags, 1); CU_ASSERT_EQUAL(1, FLAGS_GET_BBOX(flags)); CU_ASSERT_EQUAL(0, FLAGS_GET_GEODETIC(flags)); - flags = FLAGS_SET_GEODETIC(flags, 1); + FLAGS_SET_GEODETIC(flags, 1); CU_ASSERT_EQUAL(1, FLAGS_GET_GEODETIC(flags)); flags = 0; @@ -188,13 +188,13 @@ void test_gbox_serialized_size(void) { uchar flags = gflags(0, 0, 0); CU_ASSERT_EQUAL(gbox_serialized_size(flags),0); - flags = FLAGS_SET_BBOX(flags, 1); + FLAGS_SET_BBOX(flags, 1); CU_ASSERT_EQUAL(gbox_serialized_size(flags),16); - flags = FLAGS_SET_Z(flags, 1); + FLAGS_SET_Z(flags, 1); CU_ASSERT_EQUAL(gbox_serialized_size(flags),24); - flags = FLAGS_SET_M(flags, 1); + FLAGS_SET_M(flags, 1); CU_ASSERT_EQUAL(gbox_serialized_size(flags),32); - flags = FLAGS_SET_GEODETIC(flags, 1); + FLAGS_SET_GEODETIC(flags, 1); CU_ASSERT_EQUAL(gbox_serialized_size(flags),24); } @@ -404,7 +404,7 @@ void test_on_gser_lwgeom_count_vertices(void) lwgeom = lwgeom_from_ewkt("MULTIPOINT(-1 -1,-1 2.5,2 2,2 -1,1 1,2 2,4 5)", PARSER_CHECK_NONE); CU_ASSERT_EQUAL(lwgeom_count_vertices(lwgeom),7); g_ser1 = gserialized_from_lwgeom(lwgeom, 1, &ret_size); - g_ser1->flags = FLAGS_SET_GEODETIC(g_ser1->flags, 1); + FLAGS_SET_GEODETIC(g_ser1->flags, 1); lwgeom_free(lwgeom); lwgeom = lwgeom_from_gserialized(g_ser1); @@ -456,4 +456,4 @@ void test_gbox_calculation(void) lwfree(box3d); } lwfree(gbox); -} \ No newline at end of file +} diff --git a/liblwgeom/g_coord.c b/liblwgeom/g_coord.c index b95ec7f19..c5b4c0176 100644 --- a/liblwgeom/g_coord.c +++ b/liblwgeom/g_coord.c @@ -72,7 +72,8 @@ GCOORDINATE* gcoord_new_with_flags_and_ordinates(uchar flags, double *ordinates) lwerror("Out of memory!"); return NULL; } - coord->flags = FLAGS_SET_READONLY(flags, 1); + coord->flags = flags; + FLAGS_SET_READONLY(coord->flags, 1); return coord; } @@ -85,7 +86,8 @@ GCOORDINATE* gcoord_copy(GCOORDINATE *coord) copy = (GCOORDINATE*)lwalloc(sizeof(GCOORDINATE)); if( ! copy ) return NULL; - copy->flags = FLAGS_SET_READONLY(coord->flags, 1); + copy->flags = coord->flags; + FLAGS_SET_READONLY(copy->flags, 1); copy->ordinates = (double*)lwalloc(sizeof(double) * FLAGS_NDIMS(copy->flags)); if( ! copy->ordinates ) return NULL; memcpy(copy->ordinates, coord->ordinates, FLAGS_NDIMS(copy->flags) * sizeof(double)); diff --git a/liblwgeom/g_serialized.c b/liblwgeom/g_serialized.c index cf4df026a..a8f436700 100644 --- a/liblwgeom/g_serialized.c +++ b/liblwgeom/g_serialized.c @@ -515,7 +515,7 @@ GSERIALIZED* gserialized_from_lwgeom(LWGEOM *geom, int is_geodetic, size_t *size result = lwgeom_calculate_gbox(geom, &gbox); if( result == G_SUCCESS ) { - gbox.flags = FLAGS_SET_BBOX(gbox.flags, 1); + FLAGS_SET_BBOX(gbox.flags, 1); expected_box_size = gbox_serialized_size(gbox.flags); } } diff --git a/liblwgeom/g_util.c b/liblwgeom/g_util.c index d8e4926be..f04af2df1 100644 --- a/liblwgeom/g_util.c +++ b/liblwgeom/g_util.c @@ -68,11 +68,11 @@ uchar gflags(int hasz, int hasm, int geodetic) { unsigned char flags = 0; if ( hasz ) - flags = FLAGS_SET_Z(flags, 1); + FLAGS_SET_Z(flags, 1); if ( hasm ) - flags = FLAGS_SET_M(flags, 1); + FLAGS_SET_M(flags, 1); if ( geodetic ) - flags = FLAGS_SET_GEODETIC(flags, 1); + FLAGS_SET_GEODETIC(flags, 1); return flags; } diff --git a/liblwgeom/libgeom.h b/liblwgeom/libgeom.h index 0d9e6d61e..72dec7595 100644 --- a/liblwgeom/libgeom.h +++ b/liblwgeom/libgeom.h @@ -46,11 +46,11 @@ #define FLAGS_GET_BBOX(flags) (((flags) & 0x4)>>2) #define FLAGS_GET_GEODETIC(flags) (((flags) & 0x08)>>3) #define FLAGS_GET_READONLY(flags) (((flags) & 0x10)>>4) -#define FLAGS_SET_Z(flags, value) ((value) ? ((flags) | 0x01) : ((flags) & 0xFE)) -#define FLAGS_SET_M(flags, value) ((value) ? ((flags) | 0x02) : ((flags) & 0xFD)) -#define FLAGS_SET_BBOX(flags, value) ((value) ? ((flags) | 0x04) : ((flags) & 0xFB)) -#define FLAGS_SET_GEODETIC(flags, value) ((value) ? ((flags) | 0x08) : ((flags) & 0xF7)) -#define FLAGS_SET_READONLY(flags, value) ((value) ? ((flags) | 0x10) : ((flags) & 0xEF)) +#define FLAGS_SET_Z(flags, value) ((flags) = (value) ? ((flags) | 0x01) : ((flags) & 0xFE)) +#define FLAGS_SET_M(flags, value) ((flags) = (value) ? ((flags) | 0x02) : ((flags) & 0xFD)) +#define FLAGS_SET_BBOX(flags, value) ((flags) = (value) ? ((flags) | 0x04) : ((flags) & 0xFB)) +#define FLAGS_SET_GEODETIC(flags, value) ((flags) = (value) ? ((flags) | 0x08) : ((flags) & 0xF7)) +#define FLAGS_SET_READONLY(flags, value) ((flags) = (value) ? ((flags) | 0x10) : ((flags) & 0xEF)) #define FLAGS_NDIMS(flags) (2 + FLAGS_GET_Z(flags) + FLAGS_GET_M(flags)) /** diff --git a/postgis/geography_estimate.c b/postgis/geography_estimate.c index 86a980e7d..531adfd82 100644 --- a/postgis/geography_estimate.c +++ b/postgis/geography_estimate.c @@ -507,7 +507,7 @@ Datum geography_gist_selectivity(PG_FUNCTION_ARGS) geometry = lwgeom_from_gserialized(serialized); /* Convert coordinates to 3D geodesic */ - search_box.flags = FLAGS_SET_GEODETIC(search_box.flags, 1); + FLAGS_SET_GEODETIC(search_box.flags, 1); if (!lwgeom_calculate_gbox_geodetic(geometry, &search_box)) { POSTGIS_DEBUG(3, " search box cannot be calculated"); @@ -830,7 +830,7 @@ compute_geography_stats(VacAttrStats *stats, AnalyzeAttrFetchFunc fetchfunc, sampleboxes = palloc(sizeof(GBOX *) * samplerows); /* Mark the GBOX as being geodetic */ - gbox.flags = FLAGS_SET_GEODETIC(gbox.flags, 1); + FLAGS_SET_GEODETIC(gbox.flags, 1); /* * First scan: diff --git a/postgis/geography_gist.c b/postgis/geography_gist.c index 16283e156..f88ba5522 100644 --- a/postgis/geography_gist.c +++ b/postgis/geography_gist.c @@ -404,7 +404,7 @@ GSERIALIZED* gidx_insert_into_gserialized(GSERIALIZED *g, GIDX *gidx) ptr = g_out->data; ptr += box_size; memcpy(ptr, g->data, VARSIZE(g) - 8); - g_out->flags = FLAGS_SET_BBOX(g_out->flags, 1); + FLAGS_SET_BBOX(g_out->flags, 1); SET_VARSIZE(g_out, varsize_new); } diff --git a/postgis/geography_inout.c b/postgis/geography_inout.c index 95bd39e59..fa60101f7 100644 --- a/postgis/geography_inout.c +++ b/postgis/geography_inout.c @@ -220,7 +220,7 @@ Datum geography_in(PG_FUNCTION_ARGS) ** functions do the right thing. */ g_ser = geography_serialize(lwgeom); - g_ser->flags = FLAGS_SET_GEODETIC(g_ser->flags, 1); + FLAGS_SET_GEODETIC(g_ser->flags, 1); /* ** Replace the unaligned lwgeom with a new aligned one based on GSERIALIZED. @@ -913,7 +913,7 @@ Datum geography_from_geometry(PG_FUNCTION_ARGS) ** functions do the right thing. */ g_ser = geography_serialize(lwgeom); - g_ser->flags = FLAGS_SET_GEODETIC(g_ser->flags, 1); + FLAGS_SET_GEODETIC(g_ser->flags, 1); /* ** Replace the unaligned lwgeom with a new aligned one based on GSERIALIZED.