summaryrefslogtreecommitdiff
path: root/src/backend/utils/fmgr
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2008-04-18 18:43:09 +0000
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2008-04-18 18:43:09 +0000
commit7861d72ea204ef4085861f79f9c1749597160f72 (patch)
treed778614447739d8388ed9726b48422e623868571 /src/backend/utils/fmgr
parentb8e5581d762acceda22dd7347ed43d2e013a6df1 (diff)
downloadpostgresql-7861d72ea204ef4085861f79f9c1749597160f72.tar.gz
Modify the float4 datatype to be pass-by-val. Along the way, remove the last
uses of the long-deprecated float32 in contrib/seg; the definitions themselves are still there, but no longer used. fmgr/README updated to match. I added a CREATE FUNCTION to account for existing seg_center() code in seg.c too, and some tests for it and the neighbor functions. At the same time, remove checks for NULL which are not needed (because the functions are declared STRICT). I had to do some adjustments to contrib's btree_gist too. The choices for representation there are not ideal for changing the underlying types :-( Original patch by Zoltan Boszormenyi, with some adjustments by me.
Diffstat (limited to 'src/backend/utils/fmgr')
-rw-r--r--src/backend/utils/fmgr/README27
-rw-r--r--src/backend/utils/fmgr/fmgr.c23
2 files changed, 32 insertions, 18 deletions
diff --git a/src/backend/utils/fmgr/README b/src/backend/utils/fmgr/README
index 3fd3a158ea..63990ca158 100644
--- a/src/backend/utils/fmgr/README
+++ b/src/backend/utils/fmgr/README
@@ -1,4 +1,4 @@
-$PostgreSQL: pgsql/src/backend/utils/fmgr/README,v 1.10 2008/03/20 17:55:15 momjian Exp $
+$PostgreSQL: pgsql/src/backend/utils/fmgr/README,v 1.11 2008/04/18 18:43:09 alvherre Exp $
Function Manager
================
@@ -211,14 +211,13 @@ also amenable to machine processing --- for example, we could probably
write a script that scans code like this and extracts argument and result
type info for comparison to the pg_proc table.
-For the standard data types float4, float8, and int8, these macros should
+For the standard data types float8 and int8, these macros should
hide the indirection and space allocation involved, so that the function's
code is not explicitly aware that these types are pass-by-reference. This
will offer a considerable gain in readability, and it also opens up the
opportunity to make these types be pass-by-value on machines where it's
feasible to do so. (For example, on an Alpha it's pretty silly to make int8
-be pass-by-ref, since Datum is going to be 64 bits anyway. float4 could
-become pass-by-value on all machines...)
+be pass-by-ref, since Datum is going to be 64 bits anyway.)
Here are the proposed macros and coding conventions:
@@ -248,20 +247,20 @@ which expands to
Argument values are ordinarily fetched using code like
int32 name = PG_GETARG_INT32(number);
-For float4, float8, and int8, the PG_GETARG macros will hide the pass-by-
-reference nature of the data types; for example PG_GETARG_FLOAT4 expands to
- (* (float4 *) DatumGetPointer(fcinfo->arg[number]))
+For float8 and int8, the PG_GETARG macros will hide the pass-by-reference
+nature of the data types; for example PG_GETARG_FLOAT8 expands to
+ (* (float8 *) DatumGetPointer(fcinfo->arg[number]))
and would typically be called like this:
- float4 arg = PG_GETARG_FLOAT4(0);
-Note that "float4" and "float8" are the recommended typedefs to use, not
-"float32data" and "float64data", and the macros are named accordingly.
-But 64-bit ints should be declared as "int64".
+ float8 arg = PG_GETARG_FLOAT8(0);
+Note that "float8" is the recommended typedef to use, not "float64data", and
+the macros are named accordingly. But 64-bit ints should be declared as
+"int64".
Non-null values are returned with a PG_RETURN_XXX macro of the appropriate
type. For example, PG_RETURN_INT32 expands to
return Int32GetDatum(x)
-PG_RETURN_FLOAT4, PG_RETURN_FLOAT8, and PG_RETURN_INT64 hide the pass-by-
-reference nature of their datatypes.
+PG_RETURN_FLOAT8 and PG_RETURN_INT64 hide the pass-by-reference nature of
+their datatypes.
fmgr.h will provide PG_GETARG and PG_RETURN macros for all the basic data
types. Modules or header files that define specialized SQL datatypes
@@ -334,7 +333,7 @@ Again, this style of coding does not allow for expressing NULL inputs
or receiving a NULL result.
As with the callee-side situation, I propose adding argument conversion
-macros that hide the pass-by-reference nature of int8, float4, and
+macros that hide the pass-by-reference nature of int8, and
float8, with an eye to making those types relatively painless to convert
to pass-by-value.
diff --git a/src/backend/utils/fmgr/fmgr.c b/src/backend/utils/fmgr/fmgr.c
index 44667e62be..853fb9eda9 100644
--- a/src/backend/utils/fmgr/fmgr.c
+++ b/src/backend/utils/fmgr/fmgr.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.115 2008/04/17 21:37:28 alvherre Exp $
+ * $PostgreSQL: pgsql/src/backend/utils/fmgr/fmgr.c,v 1.116 2008/04/18 18:43:09 alvherre Exp $
*
*-------------------------------------------------------------------------
*/
@@ -2060,10 +2060,25 @@ Int64GetDatum(int64 X)
Datum
Float4GetDatum(float4 X)
{
- float4 *retval = (float4 *) palloc(sizeof(float4));
+ union {
+ float4 value;
+ int32 retval;
+ } myunion;
- *retval = X;
- return PointerGetDatum(retval);
+ myunion.value = X;
+ return SET_4_BYTES(myunion.retval);
+}
+
+float4
+DatumGetFloat4(Datum X)
+{
+ union {
+ int32 value;
+ float4 retval;
+ } myunion;
+
+ myunion.value = GET_4_BYTES(X);
+ return myunion.retval;
}
Datum