gnustep-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSControls failing to set status/label on BigEndian/64bit


From: Riccardo Mottola
Subject: Re: NSControls failing to set status/label on BigEndian/64bit
Date: Wed, 6 Jan 2021 18:34:34 +0100
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 SeaMonkey/2.53.5.1

Hi Wolfgang!

Wolfgang Lux wrote:
I don’t think you need any further testing. The _highlightsByMask member is 
declared as NSInteger in NSButtonCell.h (which means 64 bits on x86-64 and 
ppc64) but unarchived as unsigned int in NSButtonCell.m (which means 32 bits) 
and big endian architectures as less forgiving on such mismatches.

The same applies to (at least) _showAltState mask.
And encodeWithCoder: seems to get this wrong for both members, too.

good catch. We have two differences here 32bit vs 64bit, but also signed vs unsigned!

The first thing I tried was to use NSInteger/NSUInteger as approriate in encodeWithCode and initWithCoder, but Gorm files fail to load "Exception occurred while loading model: expected long long and got unsigned int"

I then tried just to use int to match NSInteger and reduce the signedness problem, then I get insted
"Exception occurred while loading model: expected int and got unsigned int"

I did a simple thing like this:



@@ -1715,9 +1715,9 @@
                  at: &_keyEquivalentModifierMask];
        }

-      [aCoder encodeValueOfObjCType: @encode(unsigned int)
+      [aCoder encodeValueOfObjCType: @encode(int)
               at: &_highlightsByMask];
-      [aCoder encodeValueOfObjCType: @encode(unsigned int)
+      [aCoder encodeValueOfObjCType: @encode(int)
               at: &_showAltStateMask];

       if([NSButtonCell version] >= 2)
@@ -1771,6 +1771,7 @@
           unsigned int bFlags = [aDecoder decodeIntForKey: @"NSButtonFlags"];
           GSButtonCellFlags buttonCellFlags;
           memcpy((void *)&buttonCellFlags,(void *)&bFlags,sizeof(struct _GSButtonCellFlags)); +         NSLog(@"for %@ - bFlags: %u %u", _contents, bFlags, (unsigned int)(void*)&buttonCellFlags);

           [self setTransparent: buttonCellFlags.isTransparent];
           [self setBordered: buttonCellFlags.isBordered];
@@ -1902,9 +1903,9 @@
         {
           _keyEquivalentModifierMask = _keyEquivalentModifierMask << 16;
         }
-      [aDecoder decodeValueOfObjCType: @encode(unsigned int)
+      [aDecoder decodeValueOfObjCType: @encode(int)
                                    at: &_highlightsByMask];
-      [aDecoder decodeValueOfObjCType: @encode(unsigned int)
+      [aDecoder decodeValueOfObjCType: @encode(int)
                                    at: &_showAltStateMask];


the "unsigned int" it getting (while expecting the type I get) is written somewhere else or is it inside the gorm file itself? that would be perhaps an issue, since it would mean changing the gorm format.

I attempted a super-ugly hack which I refrain from committing, relying on the compiler to do the cast and signed/unsigned conversion:

diff --git a/Source/NSButtonCell.m b/Source/NSButtonCell.m
index fe33626af..ae1d15bd4 100644
--- a/Source/NSButtonCell.m
+++ b/Source/NSButtonCell.m
@@ -1695,6 +1695,8 @@
     }
   else
     {
+      unsigned int tmp2;
+
       [aCoder encodeObject: _keyEquivalent];
       [aCoder encodeObject: _keyEquivalentFont];
       [aCoder encodeObject: _altContents];
@@ -1715,10 +1717,12 @@
                  at: &_keyEquivalentModifierMask];
        }

+      tmp2 = (unsigned int)_highlightsByMask;
       [aCoder encodeValueOfObjCType: @encode(unsigned int)
-              at: &_highlightsByMask];
+              at: &tmp2];
+      tmp2 = (unsigned int)_showAltStateMask;
       [aCoder encodeValueOfObjCType: @encode(unsigned int)
-              at: &_showAltStateMask];
+              at: &tmp2];

       if([NSButtonCell version] >= 2)
        {
@@ -1887,6 +1891,7 @@
       BOOL tmp;
       int version = [aDecoder versionForClassName: @"NSButtonCell"];
       NSString *key = nil;
+      unsigned int tmp2;

       [aDecoder decodeValueOfObjCType: @encode(id) at: &key];
       [self setKeyEquivalent: key]; // Set the key equivalent...
@@ -1903,9 +1908,11 @@
           _keyEquivalentModifierMask = _keyEquivalentModifierMask << 16;
         }
       [aDecoder decodeValueOfObjCType: @encode(unsigned int)
-                                   at: &_highlightsByMask];
+                                   at: &tmp2];
+      _highlightsByMask = (NSInteger)tmp2;
       [aDecoder decodeValueOfObjCType: @encode(unsigned int)
-                                   at: &_showAltStateMask];
+                                   at: &tmp2];
+      _showAltStateMask = (NSInteger)tmp2;

       if (version >= 2)
         {


what do you think? That way... things load and radio buttons and checkboxes work. I find it ugly. Also I want to be sure that Gorms are encoded correctly if created here

Then,. also, we have some Labels and especially MenuItems not loading in PopUpButtons. Maybe someting does not decode, e.g. Tags ?

Riccardo

Riccardo



reply via email to

[Prev in Thread] Current Thread [Next in Thread]