Re: Size difference between BOOL, WinBOOL, and BOOL results in incorrect archiving under Windows MSVC

Richard Frith-Macdonald <[email protected]> Tue, 2 Aug 2022 17:31:34 +0100
Newsgroups gmane.comp.lib.gnustep.devel
Message-ID <[email protected]>

> On 1 Aug 2022, at 11:10, Hugo Melder <[email protected]> wrote:
> 
> Hi Y’all,
> 
> I'm currently investigating various libs-base test failures on Windows 11 MSVC and I’m stuck on one particular failure involving the archiving and unarchiving of primitives into a binary bundle (Tests/base/coding/basictypes.m).
> 
> Apple describes NSArchiver as “[..] a concrete subclass of NSCoder [and] provides a way to encode objects into an architecture-independent format that can be stored in a file”. That’s why the test has precomputed .type files (e.g. BOOL-1.type) to validate the output of the archiver.
> 
> This validation fails: On Windows 11 MSVC a bool is 4-bytes long, thus the generated .type file is BOOL-4.type and the unarchive routine fails:
> 
> Failed test:     (2022-06-17 06:35:35.907 +0000) basictypes.m:157 ... can unarchive BOOL from D:/a/libs-base/libs base/source/Tests/base/coding/BOOL-1.type
> 
> 
> Now, there has been some issues related to the difference between BOOL, WinBOOL, and WINBOOL (https://github.com/gnustep/libs-base/pull/247#discussion_r835060626).
> 
> Here the difference:
> 	• I can’t find the definition of WinBOOL anywhere in the Windows Kit header files, nor online.
> 	• WINBOOL seems to be implicitly defined by the compiler switch -Ze and explicitly defined in GNUstep.
> 	• BOOL is defined as typedef int in Windows.h.
> 
> Maybe we can explicitly pack BOOL into one byte while archiving to maintain the architecture-independent format, or redefine BOOL in GNUstep to the correct size?

I don't think it's easily done.

Looking at the objc runtime headers, we have

#       ifdef STRICT_APPLE_COMPATIBILITY
typedef signed char BOOL;
#       else
#               if defined(__vxworks) || defined(_WIN32)
typedef  int BOOL;
#               else
typedef unsigned char BOOL;
#               endif
#       endif

So for portabilty our coding/archiving ought to tolerate either byte or word length data in the archive as being valid bool data.