Commit b5b32291 authored by Tom Lane's avatar Tom Lane

Avoid -Wconversion warnings from direct use of GET_n_BYTES macros.

The GET/SET_n_BYTES macros are meant to be infrastructure for the
DatumGetFoo/FooGetDatum macros, which include a cast to the intended
target type.  Using them directly without a cast, as DatumGetFloat4
and friends previously did, can yield warnings when -Wconversion is on.
This is of little significance when building Postgres proper, because
there are such a huge number of such warnings in the server that nobody
would think -Wconversion is of any use.  But some extensions build with
-Wconversion due to outside constraints.  Commit 14cca1bf did a disservice
to those extensions by moving DatumGetFloat4 et al into postgres.h,
where they can now cause warnings in extension builds.

To fix, use DatumGetInt32 and friends in place of the low-level macros.
This is arguably a bit cleaner anyway.

Chapman Flack

Discussion: https://postgr.es/m/592E4D04.1070609@anastigmatix.net
parent 54e839fe
...@@ -679,7 +679,7 @@ DatumGetFloat4(Datum X) ...@@ -679,7 +679,7 @@ DatumGetFloat4(Datum X)
float4 retval; float4 retval;
} myunion; } myunion;
myunion.value = GET_4_BYTES(X); myunion.value = DatumGetInt32(X);
return myunion.retval; return myunion.retval;
} }
#else #else
...@@ -704,7 +704,7 @@ Float4GetDatum(float4 X) ...@@ -704,7 +704,7 @@ Float4GetDatum(float4 X)
} myunion; } myunion;
myunion.value = X; myunion.value = X;
return SET_4_BYTES(myunion.retval); return Int32GetDatum(myunion.retval);
} }
#else #else
extern Datum Float4GetDatum(float4 X); extern Datum Float4GetDatum(float4 X);
...@@ -727,7 +727,7 @@ DatumGetFloat8(Datum X) ...@@ -727,7 +727,7 @@ DatumGetFloat8(Datum X)
float8 retval; float8 retval;
} myunion; } myunion;
myunion.value = GET_8_BYTES(X); myunion.value = DatumGetInt64(X);
return myunion.retval; return myunion.retval;
} }
#else #else
...@@ -753,7 +753,7 @@ Float8GetDatum(float8 X) ...@@ -753,7 +753,7 @@ Float8GetDatum(float8 X)
} myunion; } myunion;
myunion.value = X; myunion.value = X;
return SET_8_BYTES(myunion.retval); return Int64GetDatum(myunion.retval);
} }
#else #else
extern Datum Float8GetDatum(float8 X); extern Datum Float8GetDatum(float8 X);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment