Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b5b3229

Browse files
committed
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 14cca1b 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
1 parent 54e839f commit b5b3229

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/include/postgres.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ DatumGetFloat4(Datum X)
679679
float4 retval;
680680
} myunion;
681681

682-
myunion.value = GET_4_BYTES(X);
682+
myunion.value = DatumGetInt32(X);
683683
return myunion.retval;
684684
}
685685
#else
@@ -704,7 +704,7 @@ Float4GetDatum(float4 X)
704704
} myunion;
705705

706706
myunion.value = X;
707-
return SET_4_BYTES(myunion.retval);
707+
return Int32GetDatum(myunion.retval);
708708
}
709709
#else
710710
extern Datum Float4GetDatum(float4 X);
@@ -727,7 +727,7 @@ DatumGetFloat8(Datum X)
727727
float8 retval;
728728
} myunion;
729729

730-
myunion.value = GET_8_BYTES(X);
730+
myunion.value = DatumGetInt64(X);
731731
return myunion.retval;
732732
}
733733
#else
@@ -753,7 +753,7 @@ Float8GetDatum(float8 X)
753753
} myunion;
754754

755755
myunion.value = X;
756-
return SET_8_BYTES(myunion.retval);
756+
return Int64GetDatum(myunion.retval);
757757
}
758758
#else
759759
extern Datum Float8GetDatum(float8 X);

0 commit comments

Comments
 (0)