Changeset: 62013099714d for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=62013099714d
Modified Files:
        geom/ChangeLog.Aug2011
        geom/monetdb5/geom.mx
        geom/sql/Tests/geom-null-tests.stable.err
        geom/sql/Tests/geom-null-tests.stable.out
Branch: Aug2011
Log Message:

Implemented NULL checks in the geom module.
Now when given NULL as input, the module functions return NULL instead
of an exception.
This fixes bug 2814.


diffs (truncated from 628 to 300 lines):

diff --git a/geom/ChangeLog.Aug2011 b/geom/ChangeLog.Aug2011
--- a/geom/ChangeLog.Aug2011
+++ b/geom/ChangeLog.Aug2011
@@ -1,3 +1,8 @@
 # ChangeLog file for geom
 # This file is updated with Maddlog
 
+* Fri Jul 29 2011 Sjoerd Mullender <[email protected]>
+- Implemented NULL checks in the geom module.  Now when given NULL
+  as input, the module functions return NULL instead of an exception.
+  This fixes bug 2814.
+
diff --git a/geom/monetdb5/geom.mx b/geom/monetdb5/geom.mx
--- a/geom/monetdb5/geom.mx
+++ b/geom/monetdb5/geom.mx
@@ -940,8 +940,10 @@
        const GEOSCoordSeq gcs;
 #endif
 
-       if (!geosGeometry)
-               throw(MAL, "geom.wkbgetcoord@1", "wkb2geos failed");
+       if (!geosGeometry) {
+               *out = dbl_nil;
+               return MAL_SUCCEED;
+       }
 
        gcs = GEOSGeom_getCoordSeq(geosGeometry);
 
@@ -1081,8 +1083,10 @@
 {
        GEOSGeom geosGeometry = wkb2geos(*geom);
 
-       if (!geosGeometry)
-               throw(MAL, "geom.@1", "wkb2geos failed");
+       if (!geosGeometry) {
+               @7;
+               return MAL_SUCCEED;
+       }
 
        *out = @4(@3(geosGeometry));
 
@@ -1096,13 +1100,13 @@
 
 }
 @c
-@:basic(Dimension,int,GEOSGeom_getDimensions,,0,1)@
-@:basic(GeometryTypeId,int,GEOSGeomTypeId,,-1,1)@
-@:basic(SRID,int,GEOSGetSRID,,,0)@
-@:basic(Envelope,wkb*,GEOSEnvelope,geos2wkb,NULL,1)@
-@:basic(IsEmpty,bit,GEOSisEmpty,,2,1)@
-@:basic(IsSimple,bit,GEOSisSimple,,2,1)@
-@:basic(Boundary,wkb*,GEOSBoundary,geos2wkb,NULL,1)@
+@:basic(Dimension,int,GEOSGeom_getDimensions,,0,1,*out=int_nil)@
+@:basic(GeometryTypeId,int,GEOSGeomTypeId,,-1,1,*out=int_nil)@
+@:basic(SRID,int,GEOSGetSRID,,,0,*out=int_nil)@
+@:basic(Envelope,wkb*,GEOSEnvelope,geos2wkb,NULL,1,*out=geos2wkb(NULL))@
+@:basic(IsEmpty,bit,GEOSisEmpty,,2,1,*out=bit_nil)@
+@:basic(IsSimple,bit,GEOSisSimple,,2,1,*out=bit_nil)@
+@:basic(Boundary,wkb*,GEOSBoundary,geos2wkb,NULL,1,*out=geos2wkb(NULL))@
 
 @= spatial
 geom_export str wkb@1( bit *out, wkb **a, wkb **b);
@@ -1115,14 +1119,17 @@
 
        if (!ga && gb) {
                GEOSGeom_destroy(gb);
-               throw(MAL, "geom.@1", "wkb2geos(*a) failed");
+               *out = bit_nil;
+               return MAL_SUCCEED;
        }
        if (ga && !gb) {
                GEOSGeom_destroy(ga);
-               throw(MAL, "geom.@1", "wkb2geos(*b) failed");
+               *out = bit_nil;
+               return MAL_SUCCEED;
        }
        if (!ga && !gb) {
-               throw(MAL, "geom.@1", "wkb2geos(*a) and wkb2geos(*b) both 
failed");
+               *out = bit_nil;
+               return MAL_SUCCEED;
        }
 
        *out = @2(ga, gb);
@@ -1143,14 +1150,17 @@
 
        if (!ga && gb) {
                GEOSGeom_destroy(gb);
-               throw(MAL, "geom.@1", "wkb2geos(*a) failed");
+               *out = bit_nil;
+               return MAL_SUCCEED;
        }
        if (ga && !gb) {
                GEOSGeom_destroy(ga);
-               throw(MAL, "geom.@1", "wkb2geos(*b) failed");
+               *out = bit_nil;
+               return MAL_SUCCEED;
        }
        if (!ga && !gb) {
-               throw(MAL, "geom.@1", "wkb2geos(*a) and wkb2geos(*b) both 
failed");
+               *out = bit_nil;
+               return MAL_SUCCEED;
        }
 
        *out = @2(ga, gb, * @4);
@@ -1180,8 +1190,10 @@
        str ret = MAL_SUCCEED;
        GEOSGeom ga = wkb2geos(*a);
 
-       if (!ga)
-               throw(MAL, "geom.@1", "wkb2geos failed");
+       if (!ga) {
+               *out = dbl_nil;
+               return ret;
+       }
 
        if (@2(ga, out) == 0)
                ret = "@2 failed";
@@ -1204,14 +1216,17 @@
 
        if (!ga && gb) {
                GEOSGeom_destroy(gb);
-               throw(MAL, "geom.@1", "wkb2geos(*a) failed");
+               *out = dbl_nil;
+               return ret;
        }
        if (ga && !gb) {
                GEOSGeom_destroy(ga);
-               throw(MAL, "geom.@1", "wkb2geos(*b) failed");
+               *out = dbl_nil;
+               return ret;
        }
        if (!ga && !gb) {
-               throw(MAL, "geom.@1", "wkb2geos(*a) and wkb2geos(*b) both 
failed");
+               *out = dbl_nil;
+               return ret;
        }
 
        if (@2(ga, gb, out) == 0)
@@ -1225,27 +1240,30 @@
        return ret;
 }
 @= analysis3
-geom_export str wkb@1( @2 *out, wkb **a, wkb **b);
+geom_export str wkb@1( wkb **out, wkb **a, wkb **b);
 
 str
-wkb@1( @2 *out, wkb **a, wkb **b)
+wkb@1( wkb **out, wkb **a, wkb **b)
 {
        GEOSGeom ga = wkb2geos(*a);
        GEOSGeom gb = wkb2geos(*b);
 
        if (!ga && gb) {
                GEOSGeom_destroy(gb);
-               throw(MAL, "geom.@1", "wkb2geos(*a) failed");
+               *out = geos2wkb(NULL);
+               return MAL_SUCCEED;
        }
        if (ga && !gb) {
                GEOSGeom_destroy(ga);
-               throw(MAL, "geom.@1", "wkb2geos(*b) failed");
+               *out = geos2wkb(NULL);
+               return MAL_SUCCEED;
        }
        if (!ga && !gb) {
-               throw(MAL, "geom.@1", "wkb2geos(*a) and wkb2geos(*b) both 
failed");
+               *out = geos2wkb(NULL);
+               return MAL_SUCCEED;
        }
 
-       *out = @4(@3( ga, gb));
+       *out = @3(@2( ga, gb));
 
        GEOSGeom_destroy(ga);
        GEOSGeom_destroy(gb);
@@ -1253,17 +1271,17 @@
        if (*out != NULL)
                return MAL_SUCCEED;
 
-       throw(MAL, "geom.@1", "@3 failed");
+       throw(MAL, "geom.@1", "@2 failed");
 }
 @c
 @:analysis(Area,GEOSArea)@
 @:analysis(Length,GEOSLength)@
 @:analysis2(Distance,GEOSDistance)@
-@:basic(ConvexHull,wkb*,GEOSConvexHull,geos2wkb,NULL,1)@
-@:analysis3(Intersection,wkb*,GEOSIntersection,geos2wkb)@
-@:analysis3(Union,wkb*,GEOSUnion,geos2wkb)@
-@:analysis3(Difference,wkb*,GEOSDifference,geos2wkb)@
-@:analysis3(SymDifference,wkb*,GEOSSymDifference,geos2wkb)@
+@:basic(ConvexHull,wkb*,GEOSConvexHull,geos2wkb,NULL,1,*out=geos2wkb(NULL))@
+@:analysis3(Intersection,GEOSIntersection,geos2wkb)@
+@:analysis3(Union,GEOSUnion,geos2wkb)@
+@:analysis3(Difference,GEOSDifference,geos2wkb)@
+@:analysis3(SymDifference,GEOSSymDifference,geos2wkb)@
 
 @c
 geom_export str wkbBuffer(wkb **out, wkb **geom, dbl *distance);
@@ -1273,8 +1291,10 @@
 {
        GEOSGeom geosGeometry = wkb2geos(*geom);
 
-       if (!geosGeometry)
-               throw(MAL, "geom.Buffer", "wkb2geos failed");
+       if (!geosGeometry) {
+               *out = geos2wkb(NULL);
+               return MAL_SUCCEED;
+       }
 
        *out = geos2wkb(GEOSBuffer(geosGeometry, *distance, -1));
 
diff --git a/geom/sql/Tests/geom-null-tests.stable.err 
b/geom/sql/Tests/geom-null-tests.stable.err
--- a/geom/sql/Tests/geom-null-tests.stable.err
+++ b/geom/sql/Tests/geom-null-tests.stable.err
@@ -32,84 +32,6 @@
 # 15:05:38 >  mclient -lsql -ftest -i -e --host=ottar --port=32886 
 # 15:05:38 >  
 
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT id, Area(g) FROM geom WHERE id = 3; -- null argument, throws 
exception
-ERROR = !MALException:geom.Area:wkb2geos failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT id, Length(g) FROM geom WHERE id = 3; -- null argument, throws 
exception
-ERROR = !MALException:geom.Length:wkb2geos failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT Distance(g1.g, g2.g) FROM geom g1, geom g2 WHERE g1.id = 2 AND 
g2.id = 3; -- null argument, throws exception
-ERROR = !MALException:geom.Distance:wkb2geos(*b) failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT id, Buffer(g, 10) FROM geom WHERE id = 3; -- null argument, 
throws exception
-ERROR = !MALException:geom.Buffer:wkb2geos failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT id, ConvexHull(g) FROM geom WHERE id = 3; -- null argument, 
throws exception
-ERROR = !MALException:geom.ConvexHull:wkb2geos failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT Intersection(g1.g, g2.g) FROM geom g1, geom g2 WHERE g1.id = 2 
AND g2.id = 3; -- null argument, throws exception
-ERROR = !MALException:geom.Intersection:wkb2geos(*b) failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT "Union"(g1.g, g2.g) FROM geom g1, geom g2 WHERE g1.id = 2 AND 
g2.id = 3; -- null argument, throws exception
-ERROR = !MALException:geom.Union:wkb2geos(*b) failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT Difference(g1.g, g2.g) FROM geom g1, geom g2 WHERE g1.id = 2 
AND g2.id = 3; -- null argument, throws exception
-ERROR = !MALException:geom.Difference:wkb2geos(*b) failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT SymDifference(g1.g, g2.g) FROM geom g1, geom g2 WHERE g1.id = 2 
AND g2.id = 3; -- null argument, throws exception
-ERROR = !MALException:geom.SymDifference:wkb2geos(*b) failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT id, Dimension(g) FROM geom WHERE id = 3; -- null argument, 
throws exception
-ERROR = !MALException:geom.Dimension:wkb2geos failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT id, GeometryTypeId(g) FROM geom WHERE id = 3; -- null argument, 
throws exception
-ERROR = !MALException:geom.GeometryTypeId:wkb2geos failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT id, SRID(g) FROM geom WHERE id = 3; -- null argument, throws 
exception
-ERROR = !MALException:geom.SRID:wkb2geos failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT id, Envelope(g) FROM geom WHERE id = 3; -- null argument, 
throws exception
-ERROR = !MALException:geom.Envelope:wkb2geos failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT id, IsEmpty(g) FROM geom WHERE id = 3; -- null argument, throws 
exception
-ERROR = !MALException:geom.IsEmpty:wkb2geos failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT id, IsSimple(g) FROM geom WHERE id = 3; -- null argument, 
throws exception
-ERROR = !MALException:geom.IsSimple:wkb2geos failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT id, Boundary(g) FROM geom WHERE id = 3; -- null argument, 
throws exception
-ERROR = !MALException:geom.Boundary:wkb2geos failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT Equals(g1.g, g2.g) FROM geom g1, geom g2 WHERE g1.id = 2 AND 
g2.id = 3; -- null argument, throws exception
-ERROR = !MALException:geom.Equals:wkb2geos(*b) failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT Disjoint(g1.g, g2.g) FROM geom g1, geom g2 WHERE g1.id = 2 AND 
g2.id = 3; -- null argument, throws exception
-ERROR = !MALException:geom.Disjoint:wkb2geos(*b) failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT "Intersect"(g1.g, g2.g) FROM geom g1, geom g2 WHERE g1.id = 2 
AND g2.id = 3; -- null argument, throws exception
-ERROR = !MALException:geom.Intersect:wkb2geos(*b) failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT Touches(g1.g, g2.g) FROM geom g1, geom g2 WHERE g1.id = 2 AND 
g2.id = 3; -- null argument, throws exception
-ERROR = !MALException:geom.Touches:wkb2geos(*b) failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT Crosses(g1.g, g2.g) FROM geom g1, geom g2 WHERE g1.id = 2 AND 
g2.id = 3; -- null argument, throws exception
-ERROR = !MALException:geom.Crosses:wkb2geos(*b) failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT Within(g1.g, g2.g) FROM geom g1, geom g2 WHERE g1.id = 2 AND 
g2.id = 3; -- null argument, throws exception
-ERROR = !MALException:geom.Within:wkb2geos(*b) failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT Contains(g1.g, g2.g) FROM geom g1, geom g2 WHERE g1.id = 2 AND 
g2.id = 3; -- null argument, throws exception
-ERROR = !MALException:geom.Contains:wkb2geos(*b) failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT Overlaps(g1.g, g2.g) FROM geom g1, geom g2 WHERE g1.id = 2 AND 
g2.id = 3; -- null argument, throws exception
-ERROR = !MALException:geom.Overlaps:wkb2geos(*b) failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT id, X(g) FROM geom WHERE id = 3; -- null argument, throws 
exception
-ERROR = !MALException:geom.wkbgetcoordX:wkb2geos failed
-MAPI  = monetdb@ottar:32886
-QUERY = SELECT id, Y(g) FROM geom WHERE id = 3; -- null argument, throws 
exception
-ERROR = !MALException:geom.wkbgetcoordY:wkb2geos failed
 
 # 15:05:38 >  
 # 15:05:38 >  Done.
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to