Here is a patch that changes FB_MESSAGE alignment to match Firebird
definitions.

I have purposely didn't tested for C++11 to use alignas. I think it's
better to have an error when problematic types are used and this keyword
is not available.

There is a question about others 32-bit non-Windows/non-Linux.

That code assumes only Linux is problematic now, but maybe all
non-Windows are?


Adriano


On 08/03/2019 14:48, Adriano dos Santos Fernandes wrote:
> On 07/03/2019 13:19, Adriano dos Santos Fernandes wrote:
>> Decimal64 seems to be some 64-bit integers in sequence, so won't the
>> alignment instead be sizeof(SINT64)?
> 
> It's single SINT64, so it's not a problem. At least in 64 bits...
> 
> 
>> If we think on FB_MESSAGE (i.e., a struct) things will not match.
>>
>> Also seems problematic SINT64 which is 32-bit aligned in 32-bit arch
>> AFAIK but is defined as sizeof(SINT64) in type_alignments.
>>
> ISC_INT64 (as well dec floats) does not work in Linux 32 bits with
> FB_MESSAGE. The alignments are really defined incorrectly in
> type_alignments.
> 
> It's interesting that alignof and std::alignment_of also gives wrong
> result. Some details here. Kernel people also did it wrong:
> https://patchwork.kernel.org/patch/9251121/
> 
> 
> Adriano
> 

diff --git a/src/include/firebird/Message.h b/src/include/firebird/Message.h
index d89e7051e2..9e314e2697 100644
--- a/src/include/firebird/Message.h
+++ b/src/include/firebird/Message.h
@@ -29,6 +29,12 @@
 #include <assert.h>
 #include <string.h>
 
+#if defined(__linux__) && defined(__i386__)
+#define FB__INT64_ALIGNAS alignas(8)
+#else
+#define FB__INT64_ALIGNAS
+#endif
+
 #define FB_MESSAGE(name, statusType, fields)	\
 	FB__MESSAGE_I(name, statusType, 2, FB_BOOST_PP_CAT(FB__MESSAGE_X fields, 0), )
 
@@ -195,14 +201,14 @@
 
 #define FB__TYPE_FB_SCALED_SMALLINT(x)			ISC_SHORT
 #define FB__TYPE_FB_SCALED_INTEGER(x)			ISC_LONG
-#define FB__TYPE_FB_SCALED_BIGINT(x)			ISC_INT64
+#define FB__TYPE_FB_SCALED_BIGINT(x)			FB__INT64_ALIGNAS ISC_INT64
 #define FB__TYPE_FB_SMALLINT					ISC_SHORT
 #define FB__TYPE_FB_INTEGER						ISC_LONG
-#define FB__TYPE_FB_BIGINT						ISC_INT64
+#define FB__TYPE_FB_BIGINT						FB__INT64_ALIGNAS ISC_INT64
 #define FB__TYPE_FB_FLOAT						float
 #define FB__TYPE_FB_DOUBLE						double
-#define FB__TYPE_FB_DECFLOAT16					FB_DEC16
-#define FB__TYPE_FB_DECFLOAT34					FB_DEC34
+#define FB__TYPE_FB_DECFLOAT16					FB__INT64_ALIGNAS FB_DEC16
+#define FB__TYPE_FB_DECFLOAT34					FB__INT64_ALIGNAS FB_DEC34
 #define FB__TYPE_FB_BLOB						ISC_QUAD
 #define FB__TYPE_FB_BOOLEAN						ISC_UCHAR
 #define FB__TYPE_FB_DATE						::Firebird::FbDate
Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to