From: Sandro Santilli Date: Thu, 20 Nov 2003 15:34:02 +0000 (+0000) Subject: expected in-transaction memory release for btree operators X-Git-Tag: pgis_0_8_0~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c3f31dc5e59ad043cfec227330eedf3ad852201f;p=postgis expected in-transaction memory release for btree operators git-svn-id: http://svn.osgeo.org/postgis/trunk@376 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis_ops.c b/postgis_ops.c index e1e9fcfa7..ec08e46c2 100644 --- a/postgis_ops.c +++ b/postgis_ops.c @@ -11,6 +11,9 @@ * ********************************************************************** * $Log$ + * Revision 1.12 2003/11/20 15:34:02 strk + * expected in-transaction memory release for btree operators + * * Revision 1.11 2003/11/19 15:26:57 strk * Added geometry_le, geometry_ge, geometry_cmp functions, * modified geometry_lt, geometry_gt, geometry_eq to be consistent. @@ -303,6 +306,8 @@ Datum geometry_lt(PG_FUNCTION_ARGS) GEOMETRY *geom1 = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); GEOMETRY *geom2 = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); + //elog(NOTICE, "geometry_lt called"); + if (geom1->SRID != geom2->SRID) { elog(ERROR, @@ -349,8 +354,12 @@ Datum geometry_le(PG_FUNCTION_ARGS) GEOMETRY *geom1 = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); GEOMETRY *geom2 = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); + //elog(NOTICE, "geometry_le called"); + if (geom1->SRID != geom2->SRID) { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); elog(ERROR, "Operation on two GEOMETRIES with different SRIDs\n"); PG_RETURN_NULL(); @@ -358,40 +367,79 @@ Datum geometry_le(PG_FUNCTION_ARGS) if ( ! FPeq(geom1->bvol.LLB.x , geom2->bvol.LLB.x) ) { if (geom1->bvol.LLB.x < geom2->bvol.LLB.x) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(FALSE); } if ( ! FPeq(geom1->bvol.LLB.y , geom2->bvol.LLB.y) ) { if (geom1->bvol.LLB.y < geom2->bvol.LLB.y) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(FALSE); } if ( ! FPeq(geom1->bvol.LLB.z , geom2->bvol.LLB.z) ) { if (geom1->bvol.LLB.z < geom2->bvol.LLB.z) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(FALSE); } if ( ! FPeq(geom1->bvol.URT.x , geom2->bvol.URT.x) ) { if (geom1->bvol.URT.x < geom2->bvol.URT.x) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(FALSE); } if ( ! FPeq(geom1->bvol.URT.y , geom2->bvol.URT.y) ) { if (geom1->bvol.URT.y < geom2->bvol.URT.y) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(FALSE); } if ( ! FPeq(geom1->bvol.URT.z , geom2->bvol.URT.z) ) { if (geom1->bvol.URT.z < geom2->bvol.URT.z) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(FALSE); } + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); + PG_RETURN_BOOL(TRUE); } @@ -401,30 +449,61 @@ Datum geometry_eq(PG_FUNCTION_ARGS) GEOMETRY *geom1 = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); GEOMETRY *geom2 = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); + //elog(NOTICE, "geometry_eq called"); + if (geom1->SRID != geom2->SRID) { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); elog(ERROR, "Operation on two GEOMETRIES with different SRIDs\n"); PG_RETURN_NULL(); } if ( ! FPeq(geom1->bvol.LLB.x , geom2->bvol.LLB.x) ) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(FALSE); + } if ( ! FPeq(geom1->bvol.LLB.y , geom2->bvol.LLB.y) ) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(FALSE); + } if ( ! FPeq(geom1->bvol.LLB.z , geom2->bvol.LLB.z) ) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(FALSE); + } if ( ! FPeq(geom1->bvol.URT.x , geom2->bvol.URT.x) ) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(FALSE); + } if ( ! FPeq(geom1->bvol.URT.y , geom2->bvol.URT.y) ) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(FALSE); + } if ( ! FPeq(geom1->bvol.URT.z , geom2->bvol.URT.z) ) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(FALSE); + } + + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); } @@ -435,8 +514,12 @@ Datum geometry_ge(PG_FUNCTION_ARGS) GEOMETRY *geom1 = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); GEOMETRY *geom2 = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); + //elog(NOTICE, "geometry_ge called"); + if (geom1->SRID != geom2->SRID) { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); elog(ERROR, "Operation on two GEOMETRIES with different SRIDs\n"); PG_RETURN_NULL(); @@ -444,40 +527,67 @@ Datum geometry_ge(PG_FUNCTION_ARGS) if ( ! FPeq(geom1->bvol.LLB.x , geom2->bvol.LLB.x) ) { if (geom1->bvol.LLB.x > geom2->bvol.LLB.x) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } PG_RETURN_BOOL(FALSE); } if ( ! FPeq(geom1->bvol.LLB.y , geom2->bvol.LLB.y) ) { if (geom1->bvol.LLB.y > geom2->bvol.LLB.y) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } PG_RETURN_BOOL(FALSE); } if ( ! FPeq(geom1->bvol.LLB.z , geom2->bvol.LLB.z) ) { if (geom1->bvol.LLB.z > geom2->bvol.LLB.z) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } PG_RETURN_BOOL(FALSE); } if ( ! FPeq(geom1->bvol.URT.x , geom2->bvol.URT.x) ) { if (geom1->bvol.URT.x > geom2->bvol.URT.x) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } PG_RETURN_BOOL(FALSE); } if ( ! FPeq(geom1->bvol.URT.y , geom2->bvol.URT.y) ) { if (geom1->bvol.URT.y > geom2->bvol.URT.y) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } PG_RETURN_BOOL(FALSE); } if ( ! FPeq(geom1->bvol.URT.z , geom2->bvol.URT.z) ) { if (geom1->bvol.URT.z > geom2->bvol.URT.z) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } PG_RETURN_BOOL(FALSE); } + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); + PG_RETURN_BOOL(TRUE); } @@ -487,8 +597,14 @@ Datum geometry_gt(PG_FUNCTION_ARGS) GEOMETRY *geom1 = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); GEOMETRY *geom2 = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); + //elog(NOTICE, "geometry_gt called"); + if (geom1->SRID != geom2->SRID) { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) + pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) + pfree(geom2); elog(ERROR, "Operation on two GEOMETRIES with different SRIDs\n"); PG_RETURN_NULL(); @@ -496,34 +612,61 @@ Datum geometry_gt(PG_FUNCTION_ARGS) if ( ! FPeq(geom1->bvol.LLB.x , geom2->bvol.LLB.x) ) { if (geom1->bvol.LLB.x > geom2->bvol.LLB.x) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } } if ( ! FPeq(geom1->bvol.LLB.y , geom2->bvol.LLB.y) ) { if (geom1->bvol.LLB.y > geom2->bvol.LLB.y) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } } if ( ! FPeq(geom1->bvol.LLB.z , geom2->bvol.LLB.z) ) { if (geom1->bvol.LLB.z > geom2->bvol.LLB.z) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } } if ( ! FPeq(geom1->bvol.URT.x , geom2->bvol.URT.x) ) { if (geom1->bvol.URT.x > geom2->bvol.URT.x) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } } if ( ! FPeq(geom1->bvol.URT.y , geom2->bvol.URT.y) ) { if (geom1->bvol.URT.y > geom2->bvol.URT.y) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } } if ( ! FPeq(geom1->bvol.URT.z , geom2->bvol.URT.z) ) { if (geom1->bvol.URT.z > geom2->bvol.URT.z) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_BOOL(TRUE); + } } + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); + PG_RETURN_BOOL(FALSE); } @@ -533,8 +676,14 @@ Datum geometry_cmp(PG_FUNCTION_ARGS) GEOMETRY *geom1 = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0)); GEOMETRY *geom2 = (GEOMETRY *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1)); + //elog(NOTICE, "geometry_cmp called"); + if (geom1->SRID != geom2->SRID) { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) + pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) + pfree(geom2); elog(ERROR, "Operation on two GEOMETRIES with different SRIDs\n"); PG_RETURN_NULL(); @@ -542,48 +691,83 @@ Datum geometry_cmp(PG_FUNCTION_ARGS) if ( ! FPeq(geom1->bvol.LLB.x , geom2->bvol.LLB.x) ) { if (geom1->bvol.LLB.x < geom2->bvol.LLB.x) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_INT32(-1); + } + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_INT32(1); } if ( ! FPeq(geom1->bvol.LLB.y , geom2->bvol.LLB.y) ) { if (geom1->bvol.LLB.y < geom2->bvol.LLB.y) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_INT32(-1); + } + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_INT32(1); } if ( ! FPeq(geom1->bvol.LLB.z , geom2->bvol.LLB.z) ) { if (geom1->bvol.LLB.z < geom2->bvol.LLB.z) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_INT32(-1); + } + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_INT32(1); } if ( ! FPeq(geom1->bvol.URT.x , geom2->bvol.URT.x) ) { if (geom1->bvol.URT.x < geom2->bvol.URT.x) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_INT32(-1); + } + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_INT32(1); } if ( ! FPeq(geom1->bvol.URT.y , geom2->bvol.URT.y) ) { if (geom1->bvol.URT.y < geom2->bvol.URT.y) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_INT32(-1); + } + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_INT32(1); } if ( ! FPeq(geom1->bvol.URT.z , geom2->bvol.URT.z) ) { if (geom1->bvol.URT.z < geom2->bvol.URT.z) + { + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_INT32(-1); + } + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); PG_RETURN_INT32(1); } + if ( (Pointer *)PG_GETARG_DATUM(0) != (Pointer *)geom1 ) pfree(geom1); + if ( (Pointer *)PG_GETARG_DATUM(1) != (Pointer *)geom2 ) pfree(geom2); + PG_RETURN_INT32(0); } - - - - //order of points in a ring IS important //order of rings is also important bool is_same_polygon(POLYGON3D *poly1, POLYGON3D *poly2)