git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8472bf7)
Make earthdistance use version-0 calling convention if not USE_FLOAT8_BYVAL,
2008年4月21日 01:11:43 +0000 (01:11 +0000)
2008年4月21日 01:11:43 +0000 (01:11 +0000)
and version-1 if USE_FLOAT8_BYVAL. This might seem a bit pointless, but the
idea is to have at least one regression test that will fail if we ever
accidentally break version-0 functions that return float8. However, they're
already broken, or at least hopelessly unportable, in the USE_FLOAT8_BYVAL
case.

Per a recent suggestion from Greg Stark.


diff --git a/contrib/earthdistance/earthdistance.c b/contrib/earthdistance/earthdistance.c
index 72be0f1ad6955b6b62d1d0bacc305adc37bc46bc..6c191a5c38e09257c88ec258e65a81a59a885a8d 100644 (file)
--- a/contrib/earthdistance/earthdistance.c
+++ b/contrib/earthdistance/earthdistance.c
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/contrib/earthdistance/earthdistance.c,v 1.14 2008年04月20日 01:05:52 tgl Exp $ */
+/* $PostgreSQL: pgsql/contrib/earthdistance/earthdistance.c,v 1.15 2008年04月21日 01:11:43 tgl Exp $ */
#include "postgres.h"
@@ -17,10 +17,6 @@ PG_MODULE_MAGIC;
static const double EARTH_RADIUS = 3958.747716;
static const double TWO_PI = 2.0 * M_PI;
-PG_FUNCTION_INFO_V1(geo_distance);
-
-Datum geo_distance(PG_FUNCTION_ARGS);
-
/******************************************************
*
@@ -37,26 +33,22 @@ degtorad(double degrees)
return (degrees / 360.0) * TWO_PI;
}
-
/******************************************************
*
- * geo_distance - distance between points
+ * geo_distance_internal - distance between points
*
* args:
* a pair of points - for each point,
* x-coordinate is longitude in degrees west of Greenwich
* y-coordinate is latitude in degrees above equator
*
- * returns: float8
+ * returns: double
* distance between the points in miles on earth's surface
******************************************************/
-Datum
-geo_distance(PG_FUNCTION_ARGS)
+static double
+geo_distance_internal(Point *pt1, Point *pt2)
{
- Point *pt1 = PG_GETARG_POINT_P(0);
- Point *pt2 = PG_GETARG_POINT_P(1);
- float8 result;
double long1,
lat1,
long2,
@@ -81,7 +73,57 @@ geo_distance(PG_FUNCTION_ARGS)
cos(lat1) * cos(lat2) * sin(longdiff / 2.) * sin(longdiff / 2.));
if (sino > 1.)
sino = 1.;
- result = 2. * EARTH_RADIUS * asin(sino);
+ return 2. * EARTH_RADIUS * asin(sino);
+}
+
+
+/******************************************************
+ *
+ * geo_distance - distance between points
+ *
+ * args:
+ * a pair of points - for each point,
+ * x-coordinate is longitude in degrees west of Greenwich
+ * y-coordinate is latitude in degrees above equator
+ *
+ * returns: float8
+ * distance between the points in miles on earth's surface
+ *
+ * If float8 is passed-by-value, the oldstyle version-0 calling convention
+ * is unportable, so we use version-1. However, if it's passed-by-reference,
+ * continue to use oldstyle. This is just because we'd like earthdistance
+ * to serve as a canary for any unintentional breakage of version-0 functions
+ * with float8 results.
+ ******************************************************/
+
+#ifdef USE_FLOAT8_BYVAL
+
+Datum geo_distance(PG_FUNCTION_ARGS);
+PG_FUNCTION_INFO_V1(geo_distance);
+
+Datum
+geo_distance(PG_FUNCTION_ARGS)
+{
+ Point *pt1 = PG_GETARG_POINT_P(0);
+ Point *pt2 = PG_GETARG_POINT_P(1);
+ float8 result;
+
+ result = geo_distance_internal(pt1, pt2);
PG_RETURN_FLOAT8(result);
}
+
+#else /* !USE_FLOAT8_BYVAL */
+
+double *geo_distance(Point *pt1, Point *pt2);
+
+double *
+geo_distance(Point *pt1, Point *pt2)
+{
+ double *resultp = palloc(sizeof(double));
+
+ *resultp = geo_distance_internal(pt1, pt2);
+ return resultp;
+}
+
+#endif /* USE_FLOAT8_BYVAL */
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /