Changeset: b3ec15ffd507 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=b3ec15ffd507
Modified Files:
        geom/monetdb5/geom.mx
Branch: default
Log Message:

geom: rewrite macros

make sure macros won't return the empty string (as error - quite
useless), at the same time, improve their error message.


diffs (270 lines):

diff --git a/geom/monetdb5/geom.mx b/geom/monetdb5/geom.mx
--- a/geom/monetdb5/geom.mx
+++ b/geom/monetdb5/geom.mx
@@ -977,25 +977,33 @@
 str
 wkbgetcoord@1(double *out, wkb **geom)
 {
-       str ret = "";
+       str ret = MAL_SUCCEED;
        GEOSGeom geosGeometry = wkb2geos(*geom);
-
-       if (geosGeometry) {  
 #if GEOS_CAPI_VERSION_MAJOR >= 1 && GEOS_CAPI_VERSION_MINOR >= 3
-               const GEOSCoordSequence *gcs = 
GEOSGeom_getCoordSeq(geosGeometry);
+       const GEOSCoordSequence *gcs;
 #else
-               const GEOSCoordSeq gcs = GEOSGeom_getCoordSeq(geosGeometry);
+       const GEOSCoordSeq gcs;
 #endif
 
-               /* we could also check if geom is a
-                       LineString, LinearRing or Point */ 
-               if (gcs && GEOSCoordSeq_get@1(gcs, 0, out) != 0) 
-                       ret = MAL_SUCCEED;
-               /* gcs shouldn't be freed, its internal to the GEOSGeom */
-               GEOSGeom_destroy(geosGeometry);
-       }
-       if (ret)
-               throw(MAL, "geom.@1", "Failed");
+       if (!geosGeometry)
+               throw(MAL, "geom.wkbgetcoord@1", "wkb2geos failed");
+
+       gcs = GEOSGeom_getCoordSeq(geosGeometry);
+
+       if (!gcs)
+               throw(MAL, "geom.wkbgetcoord@1", "GEOSGeom_getCoordSeq failed");
+
+       /* we could also check if geom is a
+               LineString, LinearRing or Point */ 
+       if (GEOSCoordSeq_get@1(gcs, 0, out) == 0)
+               ret = "GEOSCoordSeq_get@1 failed";
+
+       /* gcs shouldn't be freed, its internal to the GEOSGeom */
+       GEOSGeom_destroy(geosGeometry);
+
+       if (ret != MAL_SUCCEED)
+               throw(MAL, "geom.@1", ret);
+
        return ret;
 }
 @c
@@ -1141,21 +1149,29 @@
 str
 wkb@1( bit *out, wkb **a, wkb **b)
 {
-       str ret = "";
        GEOSGeom ga = wkb2geos(*a);
        GEOSGeom gb = wkb2geos(*b);
 
-       if (ga && gb) { 
-               *out= @2( ga, gb);
-               ret = MAL_SUCCEED;
+       if (!ga && gb) {
+               GEOSGeom_destroy(gb);
+               throw(MAL, "geom.@1", "wkb2geos(*a) failed");
        }
-       if (ga)
+       if (ga && !gb) {
                GEOSGeom_destroy(ga);
-       if (gb)
+               throw(MAL, "geom.@1", "wkb2geos(*b) failed");
+       }
+       if (!ga && !gb) {
+               GEOSGeom_destroy(ga);
                GEOSGeom_destroy(gb);
-       if (ret)
-               throw(MAL, "geom.@1", "Failed");
-       return ret;
+               throw(MAL, "geom.@1", "wkb2geos(*a) and wkb2geos(*b) both 
failed");
+       }
+
+       *out = @2(ga, gb);
+
+       GEOSGeom_destroy(ga);
+       GEOSGeom_destroy(gb);
+
+       return MAL_SUCCEED;
 }
 @= spatial2
 geom_export str
@@ -1164,21 +1180,29 @@
 str
 wkb@1( bit *out, wkb **a, wkb **b, @3 @4)
 {
-       str ret = "";
        GEOSGeom ga = wkb2geos(*a);
        GEOSGeom gb = wkb2geos(*b);
 
-       if (ga && gb) { 
-               *out= @2( ga, gb, @4);
-               ret = MAL_SUCCEED;
+       if (!ga && gb) {
+               GEOSGeom_destroy(gb);
+               throw(MAL, "geom.@1", "wkb2geos(*a) failed");
        }
-       if (ga)
+       if (ga && !gb) {
                GEOSGeom_destroy(ga);
-       if (gb)
+               throw(MAL, "geom.@1", "wkb2geos(*b) failed");
+       }
+       if (!ga && !gb) {
+               GEOSGeom_destroy(ga);
                GEOSGeom_destroy(gb);
-       if (ret)
-               throw(MAL, "geom.@1", "Failed");
-       return ret;
+               throw(MAL, "geom.@1", "wkb2geos(*a) and wkb2geos(*b) both 
failed");
+       }
+
+       *out = @2(ga, gb, @4);
+
+       GEOSGeom_destroy(ga);
+       GEOSGeom_destroy(gb);
+
+       return MAL_SUCCEED;
 }
 @c
 @:spatial(Equals,GEOSEquals)@
@@ -1198,16 +1222,19 @@
 str
 wkb@1( dbl *out, wkb **a)
 {
-       str ret = "";
+       str ret = MAL_SUCCEED;
        GEOSGeom ga = wkb2geos(*a);
 
-       if (ga) { 
-               if ( @2( ga, out) != 0)
-                       ret = MAL_SUCCEED;
-               GEOSGeom_destroy(ga);
-       }
-       if (ret)
-               throw(MAL, "geom.@1", "Failed");
+       if (!ga)
+               throw(MAL, "geom.@1", "wkb2geos failed");
+
+       if (@2(ga, out) == 0)
+               ret = "@2 failed";
+
+       GEOSGeom_destroy(ga);
+
+       if (ret != MAL_SUCCEED)
+               throw(MAL, "geom.@1", ret);
        return ret;
 }
 @= analysis2
@@ -1217,20 +1244,32 @@
 str
 wkb@1( dbl *out, wkb **a, wkb **b)
 {
-       str ret = "";
+       str ret = MAL_SUCCEED;
        GEOSGeom ga = wkb2geos(*a);
        GEOSGeom gb = wkb2geos(*b);
 
-       if (ga && gb) { 
-               if ( @2( ga, gb, out) != 0)
-                       ret = MAL_SUCCEED;
+       if (!ga && gb) {
+               GEOSGeom_destroy(gb);
+               throw(MAL, "geom.@1", "wkb2geos(*a) failed");
        }
-       if (ga)
+       if (ga && !gb) {
                GEOSGeom_destroy(ga);
-       if (gb)
+               throw(MAL, "geom.@1", "wkb2geos(*b) failed");
+       }
+       if (!ga && !gb) {
+               GEOSGeom_destroy(ga);
                GEOSGeom_destroy(gb);
-       if (ret)
-               throw(MAL, "geom.@1", "Failed");
+               throw(MAL, "geom.@1", "wkb2geos(*a) and wkb2geos(*b) both 
failed");
+       }
+
+       if (@2(ga, gb, out) == 0)
+               ret = "@2 failed";
+
+       GEOSGeom_destroy(ga);
+       GEOSGeom_destroy(gb);
+
+       if (ret != MAL_SUCCEED)
+               throw(MAL, "geom.@1", ret);
        return ret;
 }
 @= analysis3
@@ -1240,21 +1279,32 @@
 str
 wkb@1( @2 *out, wkb **a, wkb **b)
 {
-       str ret = "";
        GEOSGeom ga = wkb2geos(*a);
        GEOSGeom gb = wkb2geos(*b);
 
-       if (ga && gb) { 
-               if ( (*out=@4(@3( ga, gb))) != NULL)
-                       ret = MAL_SUCCEED;
+       if (!ga && gb) {
+               GEOSGeom_destroy(gb);
+               throw(MAL, "geom.@1", "wkb2geos(*a) failed");
        }
-       if (ga)
+       if (ga && !gb) {
                GEOSGeom_destroy(ga);
-       if (gb)
+               throw(MAL, "geom.@1", "wkb2geos(*b) failed");
+       }
+       if (!ga && !gb) {
+               GEOSGeom_destroy(ga);
                GEOSGeom_destroy(gb);
-       if (ret)
-               throw(MAL, "geom.@1", "Failed");
-       return ret;
+               throw(MAL, "geom.@1", "wkb2geos(*a) and wkb2geos(*b) both 
failed");
+       }
+
+       *out = @4(@3( ga, gb));
+
+       GEOSGeom_destroy(ga);
+       GEOSGeom_destroy(gb);
+
+       if (*out != NULL)
+               return MAL_SUCCEED;
+
+       throw(MAL, "geom.@1", "@3 failed");
 }
 @c
 @:analysis(Area,GEOSArea)@
@@ -1273,18 +1323,19 @@
 str
 wkbBuffer( wkb **out, wkb **geom, dbl *distance)
 {
-       str ret = "";
        GEOSGeom geosGeometry = wkb2geos(*geom);
 
-       if (geosGeometry) { 
-               if ((*out=geos2wkb(GEOSBuffer( geosGeometry, *distance, -1))) 
!= NULL) {
-                       ret = MAL_SUCCEED;
-               }
-               GEOSGeom_destroy(geosGeometry);
-       }
-       if (ret)
-               throw(MAL, "geom.Buffer", "Failed");
-       return ret;
+       if (!geosGeometry)
+               throw(MAL, "geom.Buffer", "wkb2geos failed");
+
+       *out = geos2wkb(GEOSBuffer(geosGeometry, *distance, -1));
+
+       GEOSGeom_destroy(geosGeometry);
+
+       if (*out != NULL)
+               return MAL_SUCCEED;
+
+       throw(MAL, "geom.Buffer", "GEOSBuffer failed");
 }
 
 @(
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to