Re: some unsigned/NSInteger to NSUInteger changes in -gui

2012-04-10 Thread Sebastian Reitenbach
 
On Tuesday, April 10, 2012 23:48 CEST, David Chisnall  
wrote: 
 
> On 10.04.2012 19:57, Sebastian Reitenbach wrote:
> 
> > Thanks for your patience. Now I got it, the decoder already has the value, 
> > and just puts it in, where the pointer points it to. But I still think I 
> > need to assign
> > _selected = [_items objectAtIndex: tmp];
> 
> 
> No, _selected should be [_items objectAtIndex: _selected_item], because 
> -objectAtIndex: takes an NSUInteger.  Due to implicit casting these two are 
> equivalent, but there's no point in duplicating the code.
> 
> And you missed out the _selected_item = tmp assignment, so thi swould have 
> been left 0 instead of the correct value

Thank you Fred for taking care. I don't know what my brain did toI always mix 
up the _selected with _selected_item yesterday.
Looking at the svn changes this morning, its now crystal clear David meant 
yesterday.
Sorry, for my slow brain yesterday, I thought I had enough coffee, but maybe it 
was too much.

Even if I didn't figured what David wanted to tell me at the main point, I got 
a lot of interesting news out of the whole discussion
about the NSCoder and potential 64Bit big endian bugs. That makes me feel, like 
I should try tackling OpenBSD sparc64 again, after getting all the ports 
updated/working well with latest gnustep core releases (:

so in the end, thanks again for all your patience,
Sebastian

> 
> David
> 
> -- Sent from my IBM 1620
> 
> 
> ___
> Gnustep-dev mailing list
> Gnustep-dev@gnu.org
> https://lists.gnu.org/mailman/listinfo/gnustep-dev
 
 
 
 

___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: some unsigned/NSInteger to NSUInteger changes in -gui

2012-04-10 Thread David Chisnall
On 10.04.2012 19:57, Sebastian Reitenbach wrote:

> Thanks for your patience. Now I got it, the decoder already has the value, 
> and just puts it in, where the pointer points it to. But I still think I need 
> to assign
> _selected = [_items objectAtIndex: tmp];


No, _selected should be [_items objectAtIndex: _selected_item], because 
-objectAtIndex: takes an NSUInteger.  Due to implicit casting these two are 
equivalent, but there's no point in duplicating the code.

And you missed out the _selected_item = tmp assignment, so thi swould have been 
left 0 instead of the correct value

David

-- Sent from my IBM 1620


___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: some unsigned/NSInteger to NSUInteger changes in -gui

2012-04-10 Thread Fred Kiefer
Looks like you two will need another round to get David's explanations 
over. As this leaves the gui code broken for some time longer, I just 
committed David's fix.


Fred

On 10.04.2012 19:57, Sebastian Reitenbach wrote:


On Tuesday, April 10, 2012 19:24 CEST, David Chisnall  wrote:


On 10 Apr 2012, at 18:18, Sebastian Reitenbach wrote:


+   {
+ int tmp = (int)_selected_item;
+  [aDecoder decodeValueOfObjCType: @encode(int) at:&_selected_item];
+  _selected = [_items objectAtIndex: tmp];
+   }


No, this is still wrong, and I'm not really sure what it's trying to do...

Let's say you're on some big-endian LP64 system.  NSInteger will be a 64-bit 
integer while int will be a 32-bit integer.  You pass a pointer to the 
NSInteger to aDecoder, and tell it that it's a pointer to an int.  It will then 
cast this pointer and will write a 32-bit value into the first 32 bits of the 
ivar.  Unfortunately, because this is a big endian system, you've now set the 
value to something about four billion times as big as it should be...

As I said in my last email, the correct form is:

int tmp;
[aDecoder decodeValueOfObjCType: @encode(int) at:&tmp];
_selected_item = tmp;

This creates an int on the stack and passes a pointer to it to aDecoder, which 
then loads an int-sized value and stores it in the int.  You then assign this 
value to the ivar.  The implicit cast (you can make it explicit if you prefer) 
will extend this to the correct size.


Thanks for your patience. Now I got it, the decoder already has the value, and 
just puts it in, where the pointer points it to. But I still think I need to 
assign
_selected = [_items objectAtIndex: tmp];

so that it will be right.

Sebastian

Index: NSTabView.m
===
--- NSTabView.m (revision 35052)
+++ NSTabView.m (working copy)
@@ -52,7 +52,7 @@
  {
if (self == [NSTabView class])
  {
-  [self setVersion: 2];
+  [self setVersion: 3];

[self exposeBinding: NSSelectedIndexBinding];
[self exposeBinding: NSFontBinding];
@@ -550,7 +550,7 @@
[aCoder encodeValueOfObjCType: @encode(BOOL) at:&_draws_background];
[aCoder encodeValueOfObjCType: @encode(BOOL) at:&_truncated_label];
[aCoder encodeConditionalObject: _delegate];
-  [aCoder encodeValueOfObjCType: "I" at:&_selected_item];
+  [aCoder encodeValueOfObjCType: @encode(NSUInteger) at:&_selected_item];
  }
  }

@@ -631,8 +631,17 @@
[aDecoder decodeValueOfObjCType: @encode(BOOL) at:&_draws_background];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at:&_truncated_label];
_delegate = [aDecoder decodeObject];
-  [aDecoder decodeValueOfObjCType: "I" at:&_selected_item];
-  _selected = [_items objectAtIndex: _selected_item];
+  if (version<  3)
+   {
+ int tmp;
+  [aDecoder decodeValueOfObjCType: @encode(int) at:&tmp];
+  _selected = [_items objectAtIndex: tmp];
+   }
+  else
+   }
+  [aDecoder decodeValueOfObjCType: @encode(NSUInteger) 
at:&_selected_item];
+  _selected = [_items objectAtIndex: _selected_item];
+   }
  }
return self;
  }





David

-- Sent from my Cray X1



___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: some unsigned/NSInteger to NSUInteger changes in -gui

2012-04-10 Thread Sebastian Reitenbach
 
On Tuesday, April 10, 2012 19:24 CEST, David Chisnall  
wrote: 
 
> On 10 Apr 2012, at 18:18, Sebastian Reitenbach wrote:
> 
> > +   {
> > + int tmp = (int)_selected_item;
> > +  [aDecoder decodeValueOfObjCType: @encode(int) at: 
> > &_selected_item];
> > +  _selected = [_items objectAtIndex: tmp];
> > +   }
> 
> No, this is still wrong, and I'm not really sure what it's trying to do...
> 
> Let's say you're on some big-endian LP64 system.  NSInteger will be a 64-bit 
> integer while int will be a 32-bit integer.  You pass a pointer to the 
> NSInteger to aDecoder, and tell it that it's a pointer to an int.  It will 
> then cast this pointer and will write a 32-bit value into the first 32 bits 
> of the ivar.  Unfortunately, because this is a big endian system, you've now 
> set the value to something about four billion times as big as it should be...
> 
> As I said in my last email, the correct form is:
> 
>   int tmp;
>   [aDecoder decodeValueOfObjCType: @encode(int) at: &tmp];
>   _selected_item = tmp;
> 
> This creates an int on the stack and passes a pointer to it to aDecoder, 
> which then loads an int-sized value and stores it in the int.  You then 
> assign this value to the ivar.  The implicit cast (you can make it explicit 
> if you prefer) will extend this to the correct size.

Thanks for your patience. Now I got it, the decoder already has the value, and 
just puts it in, where the pointer points it to. But I still think I need to 
assign
_selected = [_items objectAtIndex: tmp];

so that it will be right.

Sebastian

Index: NSTabView.m
===
--- NSTabView.m (revision 35052)
+++ NSTabView.m (working copy)
@@ -52,7 +52,7 @@
 {
   if (self == [NSTabView class])
 {
-  [self setVersion: 2];
+  [self setVersion: 3];
 
   [self exposeBinding: NSSelectedIndexBinding];
   [self exposeBinding: NSFontBinding];
@@ -550,7 +550,7 @@
   [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_draws_background];
   [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_truncated_label];
   [aCoder encodeConditionalObject: _delegate];
-  [aCoder encodeValueOfObjCType: "I" at: &_selected_item];
+  [aCoder encodeValueOfObjCType: @encode(NSUInteger) at: &_selected_item];
 }
 }
 
@@ -631,8 +631,17 @@
   [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_draws_background];
   [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_truncated_label];
   _delegate = [aDecoder decodeObject];
-  [aDecoder decodeValueOfObjCType: "I" at: &_selected_item];
-  _selected = [_items objectAtIndex: _selected_item];
+  if (version < 3)
+   {
+ int tmp;
+  [aDecoder decodeValueOfObjCType: @encode(int) at: &tmp];
+  _selected = [_items objectAtIndex: tmp];
+   }
+  else
+   }
+  [aDecoder decodeValueOfObjCType: @encode(NSUInteger) at: 
&_selected_item];
+  _selected = [_items objectAtIndex: _selected_item];
+   }
 }
   return self;
 }



> 
> David
> 
> -- Sent from my Cray X1 
 
 
 

___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: some unsigned/NSInteger to NSUInteger changes in -gui

2012-04-10 Thread David Chisnall
On 10 Apr 2012, at 18:18, Sebastian Reitenbach wrote:

> + {
> +   int tmp = (int)_selected_item;
> +  [aDecoder decodeValueOfObjCType: @encode(int) at: &_selected_item];
> +  _selected = [_items objectAtIndex: tmp];
> + }

No, this is still wrong, and I'm not really sure what it's trying to do...

Let's say you're on some big-endian LP64 system.  NSInteger will be a 64-bit 
integer while int will be a 32-bit integer.  You pass a pointer to the 
NSInteger to aDecoder, and tell it that it's a pointer to an int.  It will then 
cast this pointer and will write a 32-bit value into the first 32 bits of the 
ivar.  Unfortunately, because this is a big endian system, you've now set the 
value to something about four billion times as big as it should be...

As I said in my last email, the correct form is:

int tmp;
[aDecoder decodeValueOfObjCType: @encode(int) at: &tmp];
_selected_item = tmp;

This creates an int on the stack and passes a pointer to it to aDecoder, which 
then loads an int-sized value and stores it in the int.  You then assign this 
value to the ivar.  The implicit cast (you can make it explicit if you prefer) 
will extend this to the correct size.

David

-- Sent from my Cray X1
___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: some unsigned/NSInteger to NSUInteger changes in -gui

2012-04-10 Thread Sebastian Reitenbach
 
On Tuesday, April 10, 2012 18:36 CEST, David Chisnall  
wrote: 
 
> Hi Sebastian,
> 
> On 10 Apr 2012, at 17:27, Sebastian Reitenbach wrote:
> 
> > I thought one of the goals is to be more compatible with Coocoa, and there 
> > its an NSUInteger. therefore I decided to follow your first suggestion, 
> > bumping the NSTabView class version, and add a check to the decoder method. 
> > There is already another check for version < 2.
> > The patch below now again makes the broken Apps work for me.
> > 
> > Is that OK, or is there more that would need to be fixed?
> 
> As someone else said, please consider using @encode(int) instead of "i" and 
> @encode(NSUInteger) instead of "l".  The former is a style thing, the later 
> is just wrong - NSUInteger is a typedef and may not always be l (long).  For 
> the current version, I had a macro version somewhere that was defined as:

Ah, there was this additional explanation missing, now I understand the point, 
thanks.


> 
> #define DECODE(x) [aDecoder decodeValueOfObjCType: @encode(__typeof__(x)) at: 
> &(x)]
> 
> You then just write:
> 
> DECODE(_draws_background);
> DECODE(_truncated_label);
> DECODE(_selected_item);
> 
> and so on.
> 
> Your legacy compatibility code is also subtly wrong.  If int is 32 bits and 
> NSInteger is 64 bits then this is broken on big-endian platforms.  You should 
> instead write:

But then, the version that was there before my change, also had this subtle bug 
already, so even if I made it worse, it helped to spot another bug with your 
help ;)

> 
> if (version < 3)
> {
>   int tmp;
>   [aDecoder decodeValueOfObjCType: @encode(int) at: &tmp];
>   _selected_item = tmp;
> }
> else
> ...


did you meant something like this then, without your nice macro:

Index: NSTabView.m
===
--- NSTabView.m (revision 35052)
+++ NSTabView.m (working copy)
@@ -52,7 +52,7 @@
 {
   if (self == [NSTabView class])
 {
-  [self setVersion: 2];
+  [self setVersion: 3];
 
   [self exposeBinding: NSSelectedIndexBinding];
   [self exposeBinding: NSFontBinding];
@@ -550,7 +550,7 @@
   [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_draws_background];
   [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_truncated_label];
   [aCoder encodeConditionalObject: _delegate];
-  [aCoder encodeValueOfObjCType: "I" at: &_selected_item];
+  [aCoder encodeValueOfObjCType: @encode(NSUInteger) at: &_selected_item];
 }
 }
 
@@ -631,8 +631,17 @@
   [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_draws_background];
   [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_truncated_label];
   _delegate = [aDecoder decodeObject];
-  [aDecoder decodeValueOfObjCType: "I" at: &_selected_item];
-  _selected = [_items objectAtIndex: _selected_item];
+  if (version < 3)
+   {
+ int tmp = (int)_selected_item;
+  [aDecoder decodeValueOfObjCType: @encode(int) at: &_selected_item];
+  _selected = [_items objectAtIndex: tmp];
+   }
+  else
+   }
+  [aDecoder decodeValueOfObjCType: @encode(NSUInteger) at: 
&_selected_item];
+  _selected = [_items objectAtIndex: _selected_item];
+   }
 }
   return self;
 }


otherwise I don't get why I should encode tmp, without giving it a useful value.

with regard to the subtle compatibility bug, the  encoder had this before my 
initial change:

[aCoder encodeValueOfObjCType: "i" at: &_selected_item];

Which then also probably was wrong before the same way like the decoder? So 
when it encoded things wrongly, it should also decode things wrongly to get it 
right again?

But maybe I still did not got the whole picture :(

Sebastian


> 
> David
> 
> -- Send from my Jacquard Loom 
 
 
 

___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: some unsigned/NSInteger to NSUInteger changes in -gui

2012-04-10 Thread David Chisnall
Hi Sebastian,

On 10 Apr 2012, at 17:27, Sebastian Reitenbach wrote:

> I thought one of the goals is to be more compatible with Coocoa, and there 
> its an NSUInteger. therefore I decided to follow your first suggestion, 
> bumping the NSTabView class version, and add a check to the decoder method. 
> There is already another check for version < 2.
> The patch below now again makes the broken Apps work for me.
> 
> Is that OK, or is there more that would need to be fixed?

As someone else said, please consider using @encode(int) instead of "i" and 
@encode(NSUInteger) instead of "l".  The former is a style thing, the later is 
just wrong - NSUInteger is a typedef and may not always be l (long).  For the 
current version, I had a macro version somewhere that was defined as:

#define DECODE(x) [aDecoder decodeValueOfObjCType: @encode(__typeof__(x)) at: 
&(x)]

You then just write:

DECODE(_draws_background);
DECODE(_truncated_label);
DECODE(_selected_item);

and so on.

Your legacy compatibility code is also subtly wrong.  If int is 32 bits and 
NSInteger is 64 bits then this is broken on big-endian platforms.  You should 
instead write:

if (version < 3)
{
int tmp;
[aDecoder decodeValueOfObjCType: @encode(int) at: &tmp];
_selected_item = tmp;
}
else
...

David

-- Send from my Jacquard Loom
___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: some unsigned/NSInteger to NSUInteger changes in -gui

2012-04-10 Thread Sebastian Reitenbach
 
On Tuesday, April 10, 2012 17:39 CEST, Wolfgang Lux  
wrote: 
 
> Sebastian Reitenbach wrote:
> 
> > 
> > On Monday, April 9, 2012 22:37 CEST, Fred Kiefer  wrote: 
> > 
> >> I just checked the code in base and Eric seems to be right here. The >> 
> >> type check code in NSUnarchiver (we aren't talking about keyed coding >> 
> >> here) has a lot of HACK warnings, but it seems to do what we need here, 
> >> allow for different integer types to be used interchangeable.
> >> 
> >> Please go ahead and apply this change.
> > 
> > Argh, now I recognized, I seem to broke at least Fisicalab and Addresses on 
> > startup:
> > 
> > 2012-04-10 17:05:54.485 FisicaLab[10884] Exception occured while loading 
> > model: expected unsigned int and got int
> > 2012-04-10 17:05:54.508 FisicaLab[10884] Failed to load Gorm
> > 2012-04-10 17:05:54.528 FisicaLab[10884] Cannot load the main model file 
> > 'Fisica.gorm'
> > 
> > putting a breakpoint at NSException, I end up here:
> > 
> > Breakpoint 2, -[NSException raise] (self=0x205b8f608, _cmd=0x20d881a50) at 
> > NSException.m:956
> > 956   if (_reserved == 0)
> > Current language:  auto; currently minimal
> > (gdb) bt
> > #0  -[NSException raise] (self=0x205b8f608, _cmd=0x20d881a50) at 
> > NSException.m:956
> > #1  0x00020d409b65 in +[NSException raise:format:] (self=0x20d8816a0, 
> > _cmd=Variable "_cmd" is not available.
> > ) at NSException.m:835
> > #2  0x00020d4c88c2 in -[NSUnarchiver decodeValueOfObjCType:at:] 
> > (self=0x206e20088, _cmd=0x20cf0dea0, type=0x20cd10b20 "I", 
> > address=0x20dc2fd70) at NSUnarchiver.m:247
> > #3  0x00020cb2972b in -[NSTabView initWithCoder:] (self=Variable "self" 
> > is not available.
> > ) at NSTabView.m:634
> > #4  0x00020d4c8200 in -[NSUnarchiver decodeValueOfObjCType:at:] 
> > (self=0x206e20088, _cmd=0x20d8dda40, type=0x20d728790 "@", 
> > address=0x20dc2df70) at NSUnarchiver.m:662
> > #5  0x00020d4c627d in -[NSUnarchiver decodeArrayOfObjCType:count:at:] 
> > (self=0x206e20088, _cmd=Variable "_cmd" is not available.
> > ) at NSUnarchiver.m:574
> > #6  0x00020d3459de in -[GSMutableArray initWithCoder:] 
> > (self=0x20721e648, _cmd=Variable "_cmd" is not available.
> > ) at GSArray.m:553
> > #7  0x00020d4c8200 in -[NSUnarchiver decodeValueOfObjCType:at:] 
> > (self=0x206e20088, _cmd=0x20cf42dd0, type=0x20cd157ca "@", 
> > address=0x7f7f8798) at NSUnarchiver.m:662
> > #8  0x00020cb79dc3 in -[NSView initWithCoder:] (self=Variable "self" is 
> > not available.
> > ) at NSView.m:4740
> > #9  0x00020d4c8200 in -[NSUnarchiver decodeValueOfObjCType:at:] 
> > (self=0x206e20088, _cmd=0x20d8dda40, type=0x20d728790 "@", 
> > address=0x20dc2dc00) at NSUnarchiver.m:662
> > #10 0x00020d4c627d in -[NSUnarchiver decodeArrayOfObjCType:count:at:] 
> > (self=0x206e20088, _cmd=Variable "_cmd" is not available.
> > ) at NSUnarchiver.m:574
> > ...
> > (gdb) frame 3
> > #3  0x00020cb2972b in -[NSTabView initWithCoder:] (self=Variable "self" 
> > is not available.
> > ) at NSTabView.m:634
> > 634   [aDecoder decodeValueOfObjCType: "I" at: &_selected_item];
> > (gdb) list
> > 629 }
> > 630 }
> > 631   [aDecoder decodeValueOfObjCType: @encode(BOOL) at: 
> > &_draws_background];
> > 632   [aDecoder decodeValueOfObjCType: @encode(BOOL) at: 
> > &_truncated_label];
> > 633   _delegate = [aDecoder decodeObject];
> > 634   [aDecoder decodeValueOfObjCType: "I" at: &_selected_item];
> > 635   _selected = [_items objectAtIndex: _selected_item];
> > 636 }
> > 637   return self;
> > 638 }
> > 
> > but in AppKit/NSTabView.h:  
> > I have: NSUInteger _selected_item;
> > 
> > so I don't really understand, why the decoder thinks its getting an int?
> > 
> > Someone can help me understand how I broke that?
> 
> The problem is that existing archives are coded using int values rather than 
> unsigned int values.
> The only safe way to change the encoding from signed to unsigned values and 
> vice versa is to increment the version number for objects. Furthermore you 
> will need to check the version number while decoding and either decode a 
> signed int (if you find an old object version) or an unsigned (if you find a 
> new object version).
> However, I don't think this is worth the hassles, so its better to revert 
> your change (and if you are paranoid you could raise exceptions while 
> encoding and decoding if the _selected_item attribute is out of range).

Thanks Wolfgang for your quick answer.

I thought one of the goals is to be more compatible with Coocoa, and there its 
an NSUInteger. therefore I decided to follow your first suggestion, bumping the 
NSTabView class version, and add a check to the decoder method. There is 
already another check for version < 2.
The patch below now again makes the broken Apps work for me.

Is that OK, or is there more that would need to be fixed?

thanks,
Sebastian


Index: NSTabView.m
==

Re: some unsigned/NSInteger to NSUInteger changes in -gui

2012-04-10 Thread Wolfgang Lux
Sebastian Reitenbach wrote:

> 
> On Monday, April 9, 2012 22:37 CEST, Fred Kiefer  wrote: 
> 
>> I just checked the code in base and Eric seems to be right here. The 
>> type check code in NSUnarchiver (we aren't talking about keyed coding 
>> here) has a lot of HACK warnings, but it seems to do what we need here, 
>> allow for different integer types to be used interchangeable.
>> 
>> Please go ahead and apply this change.
> 
> Argh, now I recognized, I seem to broke at least Fisicalab and Addresses on 
> startup:
> 
> 2012-04-10 17:05:54.485 FisicaLab[10884] Exception occured while loading 
> model: expected unsigned int and got int
> 2012-04-10 17:05:54.508 FisicaLab[10884] Failed to load Gorm
> 2012-04-10 17:05:54.528 FisicaLab[10884] Cannot load the main model file 
> 'Fisica.gorm'
> 
> putting a breakpoint at NSException, I end up here:
> 
> Breakpoint 2, -[NSException raise] (self=0x205b8f608, _cmd=0x20d881a50) at 
> NSException.m:956
> 956   if (_reserved == 0)
> Current language:  auto; currently minimal
> (gdb) bt
> #0  -[NSException raise] (self=0x205b8f608, _cmd=0x20d881a50) at 
> NSException.m:956
> #1  0x00020d409b65 in +[NSException raise:format:] (self=0x20d8816a0, 
> _cmd=Variable "_cmd" is not available.
> ) at NSException.m:835
> #2  0x00020d4c88c2 in -[NSUnarchiver decodeValueOfObjCType:at:] 
> (self=0x206e20088, _cmd=0x20cf0dea0, type=0x20cd10b20 "I", 
> address=0x20dc2fd70) at NSUnarchiver.m:247
> #3  0x00020cb2972b in -[NSTabView initWithCoder:] (self=Variable "self" 
> is not available.
> ) at NSTabView.m:634
> #4  0x00020d4c8200 in -[NSUnarchiver decodeValueOfObjCType:at:] 
> (self=0x206e20088, _cmd=0x20d8dda40, type=0x20d728790 "@", 
> address=0x20dc2df70) at NSUnarchiver.m:662
> #5  0x00020d4c627d in -[NSUnarchiver decodeArrayOfObjCType:count:at:] 
> (self=0x206e20088, _cmd=Variable "_cmd" is not available.
> ) at NSUnarchiver.m:574
> #6  0x00020d3459de in -[GSMutableArray initWithCoder:] (self=0x20721e648, 
> _cmd=Variable "_cmd" is not available.
> ) at GSArray.m:553
> #7  0x00020d4c8200 in -[NSUnarchiver decodeValueOfObjCType:at:] 
> (self=0x206e20088, _cmd=0x20cf42dd0, type=0x20cd157ca "@", 
> address=0x7f7f8798) at NSUnarchiver.m:662
> #8  0x00020cb79dc3 in -[NSView initWithCoder:] (self=Variable "self" is 
> not available.
> ) at NSView.m:4740
> #9  0x00020d4c8200 in -[NSUnarchiver decodeValueOfObjCType:at:] 
> (self=0x206e20088, _cmd=0x20d8dda40, type=0x20d728790 "@", 
> address=0x20dc2dc00) at NSUnarchiver.m:662
> #10 0x00020d4c627d in -[NSUnarchiver decodeArrayOfObjCType:count:at:] 
> (self=0x206e20088, _cmd=Variable "_cmd" is not available.
> ) at NSUnarchiver.m:574
> ...
> (gdb) frame 3
> #3  0x00020cb2972b in -[NSTabView initWithCoder:] (self=Variable "self" 
> is not available.
> ) at NSTabView.m:634
> 634   [aDecoder decodeValueOfObjCType: "I" at: &_selected_item];
> (gdb) list
> 629 }
> 630 }
> 631   [aDecoder decodeValueOfObjCType: @encode(BOOL) at: 
> &_draws_background];
> 632   [aDecoder decodeValueOfObjCType: @encode(BOOL) at: 
> &_truncated_label];
> 633   _delegate = [aDecoder decodeObject];
> 634   [aDecoder decodeValueOfObjCType: "I" at: &_selected_item];
> 635   _selected = [_items objectAtIndex: _selected_item];
> 636 }
> 637   return self;
> 638 }
> 
> but in AppKit/NSTabView.h:  
> I have: NSUInteger _selected_item;
> 
> so I don't really understand, why the decoder thinks its getting an int?
> 
> Someone can help me understand how I broke that?

The problem is that existing archives are coded using int values rather than 
unsigned int values.
The only safe way to change the encoding from signed to unsigned values and 
vice versa is to increment the version number for objects. Furthermore you will 
need to check the version number while decoding and either decode a signed int 
(if you find an old object version) or an unsigned (if you find a new object 
version).
However, I don't think this is worth the hassles, so its better to revert your 
change (and if you are paranoid you could raise exceptions while encoding and 
decoding if the _selected_item attribute is out of range).

Wolfgang


___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: some unsigned/NSInteger to NSUInteger changes in -gui

2012-04-10 Thread Sebastian Reitenbach
 
On Monday, April 9, 2012 22:37 CEST, Fred Kiefer  wrote: 
 
> I just checked the code in base and Eric seems to be right here. The 
> type check code in NSUnarchiver (we aren't talking about keyed coding 
> here) has a lot of HACK warnings, but it seems to do what we need here, 
> allow for different integer types to be used interchangeable.
> 
> Please go ahead and apply this change.

Argh, now I recognized, I seem to broke at least Fisicalab and Addresses on 
startup:

2012-04-10 17:05:54.485 FisicaLab[10884] Exception occured while loading model: 
expected unsigned int and got int
2012-04-10 17:05:54.508 FisicaLab[10884] Failed to load Gorm
2012-04-10 17:05:54.528 FisicaLab[10884] Cannot load the main model file 
'Fisica.gorm'

putting a breakpoint at NSException, I end up here:

Breakpoint 2, -[NSException raise] (self=0x205b8f608, _cmd=0x20d881a50) at 
NSException.m:956
956   if (_reserved == 0)
Current language:  auto; currently minimal
(gdb) bt
#0  -[NSException raise] (self=0x205b8f608, _cmd=0x20d881a50) at 
NSException.m:956
#1  0x00020d409b65 in +[NSException raise:format:] (self=0x20d8816a0, 
_cmd=Variable "_cmd" is not available.
) at NSException.m:835
#2  0x00020d4c88c2 in -[NSUnarchiver decodeValueOfObjCType:at:] 
(self=0x206e20088, _cmd=0x20cf0dea0, type=0x20cd10b20 "I", address=0x20dc2fd70) 
at NSUnarchiver.m:247
#3  0x00020cb2972b in -[NSTabView initWithCoder:] (self=Variable "self" is 
not available.
) at NSTabView.m:634
#4  0x00020d4c8200 in -[NSUnarchiver decodeValueOfObjCType:at:] 
(self=0x206e20088, _cmd=0x20d8dda40, type=0x20d728790 "@", address=0x20dc2df70) 
at NSUnarchiver.m:662
#5  0x00020d4c627d in -[NSUnarchiver decodeArrayOfObjCType:count:at:] 
(self=0x206e20088, _cmd=Variable "_cmd" is not available.
) at NSUnarchiver.m:574
#6  0x00020d3459de in -[GSMutableArray initWithCoder:] (self=0x20721e648, 
_cmd=Variable "_cmd" is not available.
) at GSArray.m:553
#7  0x00020d4c8200 in -[NSUnarchiver decodeValueOfObjCType:at:] 
(self=0x206e20088, _cmd=0x20cf42dd0, type=0x20cd157ca "@", 
address=0x7f7f8798) at NSUnarchiver.m:662
#8  0x00020cb79dc3 in -[NSView initWithCoder:] (self=Variable "self" is not 
available.
) at NSView.m:4740
#9  0x00020d4c8200 in -[NSUnarchiver decodeValueOfObjCType:at:] 
(self=0x206e20088, _cmd=0x20d8dda40, type=0x20d728790 "@", address=0x20dc2dc00) 
at NSUnarchiver.m:662
#10 0x00020d4c627d in -[NSUnarchiver decodeArrayOfObjCType:count:at:] 
(self=0x206e20088, _cmd=Variable "_cmd" is not available.
) at NSUnarchiver.m:574
...
(gdb) frame 3
#3  0x00020cb2972b in -[NSTabView initWithCoder:] (self=Variable "self" is 
not available.
) at NSTabView.m:634
634   [aDecoder decodeValueOfObjCType: "I" at: &_selected_item];
(gdb) list
629 }
630 }
631   [aDecoder decodeValueOfObjCType: @encode(BOOL) at: 
&_draws_background];
632   [aDecoder decodeValueOfObjCType: @encode(BOOL) at: 
&_truncated_label];
633   _delegate = [aDecoder decodeObject];
634   [aDecoder decodeValueOfObjCType: "I" at: &_selected_item];
635   _selected = [_items objectAtIndex: _selected_item];
636 }
637   return self;
638 }

but in AppKit/NSTabView.h:  
I have: NSUInteger _selected_item;

so I don't really understand, why the decoder thinks its getting an int?

Someone can help me understand how I broke that?

Sebastian



> 
> Fred
> 
> On 09.04.2012 21:14, Eric Wasylishen wrote:
> > Hi,
> > What's safe is encoding with any supported integer type and decoding with 
> > another integer type, so you can write a keyed archive with @encode(long) 
> > and decode it as @encode(int), even if long is 64-bits and int is 32-bits.
> >
> > In other words it's safe to use @encode(NS[U]Integer). However, if the ivar 
> > is changed to NSUInteger, I think these:
> >
> >>> -  [aCoder encodeValueOfObjCType: "i" at:&_selected_item];
> >>> +  [aCoder encodeValueOfObjCType: "I" at:&_selected_item];
> >
> >>> -  [aDecoder decodeValueOfObjCType: "i" at:&_selected_item];
> >>> +  [aDecoder decodeValueOfObjCType: "I" at:&_selected_item];
> >
> > should actually use @encode(NSUInteger), not "l". Otherwise the patch looks 
> > good :-).
> >
> > Eric
> >
> > On 2012-04-09, at 11:08 AM, Fred Kiefer wrote:
> >
> >> Most of the patch is ok, but we have too ake a careful look at the coding 
> >> change. This may break backwards and forewards compatibility. Maybe 
> >> Richard is able to explain if this change is save or not.
> >>
> >> Fred
> >>
> >> On the road
> >>
> >> Am 09.04.2012 um 18:02 schrieb "Sebastian 
> >> Reitenbach":
> >>
> >>> Hi,
> >>>
> >>> while looking at compilation warnings from the latest releases, I found 
> >>> in -gui (svn) some parts in NSTableView that would need to be changed. 
> >>> First is easy, declare i as NSUInteger (was unsigned before). Further I 
> >>> think _selected_item declared in the header as NSInteger also should be a 
> >>> NSUI

Re: some unsigned/NSInteger to NSUInteger changes in -gui

2012-04-09 Thread Fred Kiefer
I just checked the code in base and Eric seems to be right here. The 
type check code in NSUnarchiver (we aren't talking about keyed coding 
here) has a lot of HACK warnings, but it seems to do what we need here, 
allow for different integer types to be used interchangeable.


Please go ahead and apply this change.

Fred

On 09.04.2012 21:14, Eric Wasylishen wrote:

Hi,
What's safe is encoding with any supported integer type and decoding with 
another integer type, so you can write a keyed archive with @encode(long) and 
decode it as @encode(int), even if long is 64-bits and int is 32-bits.

In other words it's safe to use @encode(NS[U]Integer). However, if the ivar is 
changed to NSUInteger, I think these:


-  [aCoder encodeValueOfObjCType: "i" at:&_selected_item];
+  [aCoder encodeValueOfObjCType: "I" at:&_selected_item];



-  [aDecoder decodeValueOfObjCType: "i" at:&_selected_item];
+  [aDecoder decodeValueOfObjCType: "I" at:&_selected_item];


should actually use @encode(NSUInteger), not "l". Otherwise the patch looks 
good :-).

Eric

On 2012-04-09, at 11:08 AM, Fred Kiefer wrote:


Most of the patch is ok, but we have too ake a careful look at the coding 
change. This may break backwards and forewards compatibility. Maybe Richard is 
able to explain if this change is save or not.

Fred

On the road

Am 09.04.2012 um 18:02 schrieb "Sebastian 
Reitenbach":


Hi,

while looking at compilation warnings from the latest releases, I found in -gui 
(svn) some parts in NSTableView that would need to be changed. First is easy, 
declare i as NSUInteger (was unsigned before). Further I think _selected_item 
declared in the header as NSInteger also should be a NSUInteger.

is it OK when I commit the patch?

Sebastian

Index: Source/NSTabView.m
===
--- Source/NSTabView.m(revision 35049)
+++ Source/NSTabView.m(working copy)
@@ -123,7 +123,7 @@

- (void) removeTabViewItem: (NSTabViewItem*)tabViewItem
{
-  unsigned i = [_items indexOfObject: tabViewItem];
+  NSUInteger i = [_items indexOfObject: tabViewItem];

  if (i == NSNotFound)
return;
@@ -202,7 +202,7 @@

- (void) selectNextTabViewItem: (id)sender
{
-  if ((_selected_item != NSNotFound)&&  ((unsigned)(_selected_item + 1)<  
[_items count]))
+  if ((_selected_item != NSNotFound)&&  ((_selected_item + 1)<  [_items 
count]))
{
  [self selectTabViewItemAtIndex: _selected_item + 1];
}
@@ -550,7 +550,7 @@
  [aCoder encodeValueOfObjCType: @encode(BOOL) at:&_draws_background];
  [aCoder encodeValueOfObjCType: @encode(BOOL) at:&_truncated_label];
  [aCoder encodeConditionalObject: _delegate];
-  [aCoder encodeValueOfObjCType: "i" at:&_selected_item];
+  [aCoder encodeValueOfObjCType: "I" at:&_selected_item];
}
}

@@ -631,7 +631,7 @@
  [aDecoder decodeValueOfObjCType: @encode(BOOL) at:&_draws_background];
  [aDecoder decodeValueOfObjCType: @encode(BOOL) at:&_truncated_label];
  _delegate = [aDecoder decodeObject];
-  [aDecoder decodeValueOfObjCType: "i" at:&_selected_item];
+  [aDecoder decodeValueOfObjCType: "I" at:&_selected_item];
  _selected = [_items objectAtIndex: _selected_item];
}
  return self;
Index: Headers/AppKit/NSTabView.h
===
--- Headers/AppKit/NSTabView.h(revision 35049)
+++ Headers/AppKit/NSTabView.h(working copy)
@@ -54,7 +54,7 @@
  BOOL _draws_background;
  BOOL _truncated_label;
  id _delegate;
-  NSInteger _selected_item;
+  NSUInteger _selected_item;
}
- (void)addTabViewItem:(NSTabViewItem *)tabViewItem;
- (void)insertTabViewItem:(NSTabViewItem *)tabViewItem



___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: some unsigned/NSInteger to NSUInteger changes in -gui

2012-04-09 Thread Eric Wasylishen
Hi,
What's safe is encoding with any supported integer type and decoding with 
another integer type, so you can write a keyed archive with @encode(long) and 
decode it as @encode(int), even if long is 64-bits and int is 32-bits.

In other words it's safe to use @encode(NS[U]Integer). However, if the ivar is 
changed to NSUInteger, I think these:

>> -  [aCoder encodeValueOfObjCType: "i" at: &_selected_item];
>> +  [aCoder encodeValueOfObjCType: "I" at: &_selected_item];

>> -  [aDecoder decodeValueOfObjCType: "i" at: &_selected_item];
>> +  [aDecoder decodeValueOfObjCType: "I" at: &_selected_item];

should actually use @encode(NSUInteger), not "l". Otherwise the patch looks 
good :-).

Eric

On 2012-04-09, at 11:08 AM, Fred Kiefer wrote:

> Most of the patch is ok, but we have too ake a careful look at the coding 
> change. This may break backwards and forewards compatibility. Maybe Richard 
> is able to explain if this change is save or not.
> 
> Fred
> 
> On the road
> 
> Am 09.04.2012 um 18:02 schrieb "Sebastian Reitenbach" 
> :
> 
>> Hi,
>> 
>> while looking at compilation warnings from the latest releases, I found in 
>> -gui (svn) some parts in NSTableView that would need to be changed. First is 
>> easy, declare i as NSUInteger (was unsigned before). Further I think 
>> _selected_item declared in the header as NSInteger also should be a 
>> NSUInteger.
>> 
>> is it OK when I commit the patch?
>> 
>> Sebastian
>> 
>> Index: Source/NSTabView.m
>> ===
>> --- Source/NSTabView.m(revision 35049)
>> +++ Source/NSTabView.m(working copy)
>> @@ -123,7 +123,7 @@
>> 
>> - (void) removeTabViewItem: (NSTabViewItem*)tabViewItem
>> {
>> -  unsigned i = [_items indexOfObject: tabViewItem];
>> +  NSUInteger i = [_items indexOfObject: tabViewItem];
>> 
>>  if (i == NSNotFound)
>>return;
>> @@ -202,7 +202,7 @@
>> 
>> - (void) selectNextTabViewItem: (id)sender
>> {
>> -  if ((_selected_item != NSNotFound) && ((unsigned)(_selected_item + 1) < 
>> [_items count]))
>> +  if ((_selected_item != NSNotFound) && ((_selected_item + 1) < [_items 
>> count]))
>>{
>>  [self selectTabViewItemAtIndex: _selected_item + 1];
>>}
>> @@ -550,7 +550,7 @@
>>  [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_draws_background];
>>  [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_truncated_label];
>>  [aCoder encodeConditionalObject: _delegate];
>> -  [aCoder encodeValueOfObjCType: "i" at: &_selected_item];
>> +  [aCoder encodeValueOfObjCType: "I" at: &_selected_item];
>>}
>> }
>> 
>> @@ -631,7 +631,7 @@
>>  [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_draws_background];
>>  [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_truncated_label];
>>  _delegate = [aDecoder decodeObject];
>> -  [aDecoder decodeValueOfObjCType: "i" at: &_selected_item];
>> +  [aDecoder decodeValueOfObjCType: "I" at: &_selected_item];
>>  _selected = [_items objectAtIndex: _selected_item];
>>}
>>  return self;
>> Index: Headers/AppKit/NSTabView.h
>> ===
>> --- Headers/AppKit/NSTabView.h(revision 35049)
>> +++ Headers/AppKit/NSTabView.h(working copy)
>> @@ -54,7 +54,7 @@
>>  BOOL _draws_background;
>>  BOOL _truncated_label;
>>  id _delegate;
>> -  NSInteger _selected_item;
>> +  NSUInteger _selected_item;
>> }
>> - (void)addTabViewItem:(NSTabViewItem *)tabViewItem;
>> - (void)insertTabViewItem:(NSTabViewItem *)tabViewItem
>> 
>> ___
>> Gnustep-dev mailing list
>> Gnustep-dev@gnu.org
>> https://lists.gnu.org/mailman/listinfo/gnustep-dev
> 
> ___
> Gnustep-dev mailing list
> Gnustep-dev@gnu.org
> https://lists.gnu.org/mailman/listinfo/gnustep-dev


___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/gnustep-dev


Re: some unsigned/NSInteger to NSUInteger changes in -gui

2012-04-09 Thread Fred Kiefer
Most of the patch is ok, but we have too ake a careful look at the coding 
change. This may break backwards and forewards compatibility. Maybe Richard is 
able to explain if this change is save or not.

Fred

On the road

Am 09.04.2012 um 18:02 schrieb "Sebastian Reitenbach" 
:

> Hi,
> 
> while looking at compilation warnings from the latest releases, I found in 
> -gui (svn) some parts in NSTableView that would need to be changed. First is 
> easy, declare i as NSUInteger (was unsigned before). Further I think 
> _selected_item declared in the header as NSInteger also should be a 
> NSUInteger.
> 
> is it OK when I commit the patch?
> 
> Sebastian
> 
> Index: Source/NSTabView.m
> ===
> --- Source/NSTabView.m(revision 35049)
> +++ Source/NSTabView.m(working copy)
> @@ -123,7 +123,7 @@
> 
> - (void) removeTabViewItem: (NSTabViewItem*)tabViewItem
> {
> -  unsigned i = [_items indexOfObject: tabViewItem];
> +  NSUInteger i = [_items indexOfObject: tabViewItem];
> 
>   if (i == NSNotFound)
> return;
> @@ -202,7 +202,7 @@
> 
> - (void) selectNextTabViewItem: (id)sender
> {
> -  if ((_selected_item != NSNotFound) && ((unsigned)(_selected_item + 1) < 
> [_items count]))
> +  if ((_selected_item != NSNotFound) && ((_selected_item + 1) < [_items 
> count]))
> {
>   [self selectTabViewItemAtIndex: _selected_item + 1];
> }
> @@ -550,7 +550,7 @@
>   [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_draws_background];
>   [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_truncated_label];
>   [aCoder encodeConditionalObject: _delegate];
> -  [aCoder encodeValueOfObjCType: "i" at: &_selected_item];
> +  [aCoder encodeValueOfObjCType: "I" at: &_selected_item];
> }
> }
> 
> @@ -631,7 +631,7 @@
>   [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_draws_background];
>   [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_truncated_label];
>   _delegate = [aDecoder decodeObject];
> -  [aDecoder decodeValueOfObjCType: "i" at: &_selected_item];
> +  [aDecoder decodeValueOfObjCType: "I" at: &_selected_item];
>   _selected = [_items objectAtIndex: _selected_item];
> }
>   return self;
> Index: Headers/AppKit/NSTabView.h
> ===
> --- Headers/AppKit/NSTabView.h(revision 35049)
> +++ Headers/AppKit/NSTabView.h(working copy)
> @@ -54,7 +54,7 @@
>   BOOL _draws_background;
>   BOOL _truncated_label;
>   id _delegate;
> -  NSInteger _selected_item;
> +  NSUInteger _selected_item;
> }
> - (void)addTabViewItem:(NSTabViewItem *)tabViewItem;
> - (void)insertTabViewItem:(NSTabViewItem *)tabViewItem
> 
> ___
> Gnustep-dev mailing list
> Gnustep-dev@gnu.org
> https://lists.gnu.org/mailman/listinfo/gnustep-dev

___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/gnustep-dev


some unsigned/NSInteger to NSUInteger changes in -gui

2012-04-09 Thread Sebastian Reitenbach
Hi,

while looking at compilation warnings from the latest releases, I found in -gui 
(svn) some parts in NSTableView that would need to be changed. First is easy, 
declare i as NSUInteger (was unsigned before). Further I think _selected_item 
declared in the header as NSInteger also should be a NSUInteger.

is it OK when I commit the patch?

Sebastian

Index: Source/NSTabView.m
===
--- Source/NSTabView.m  (revision 35049)
+++ Source/NSTabView.m  (working copy)
@@ -123,7 +123,7 @@
 
 - (void) removeTabViewItem: (NSTabViewItem*)tabViewItem
 {
-  unsigned i = [_items indexOfObject: tabViewItem];
+  NSUInteger i = [_items indexOfObject: tabViewItem];
   
   if (i == NSNotFound)
 return;
@@ -202,7 +202,7 @@
 
 - (void) selectNextTabViewItem: (id)sender
 {
-  if ((_selected_item != NSNotFound) && ((unsigned)(_selected_item + 1) < 
[_items count]))
+  if ((_selected_item != NSNotFound) && ((_selected_item + 1) < [_items 
count]))
 {
   [self selectTabViewItemAtIndex: _selected_item + 1];
 }
@@ -550,7 +550,7 @@
   [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_draws_background];
   [aCoder encodeValueOfObjCType: @encode(BOOL) at: &_truncated_label];
   [aCoder encodeConditionalObject: _delegate];
-  [aCoder encodeValueOfObjCType: "i" at: &_selected_item];
+  [aCoder encodeValueOfObjCType: "I" at: &_selected_item];
 }
 }
 
@@ -631,7 +631,7 @@
   [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_draws_background];
   [aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_truncated_label];
   _delegate = [aDecoder decodeObject];
-  [aDecoder decodeValueOfObjCType: "i" at: &_selected_item];
+  [aDecoder decodeValueOfObjCType: "I" at: &_selected_item];
   _selected = [_items objectAtIndex: _selected_item];
 }
   return self;
Index: Headers/AppKit/NSTabView.h
===
--- Headers/AppKit/NSTabView.h  (revision 35049)
+++ Headers/AppKit/NSTabView.h  (working copy)
@@ -54,7 +54,7 @@
   BOOL _draws_background;
   BOOL _truncated_label;
   id _delegate;
-  NSInteger _selected_item;
+  NSUInteger _selected_item;
 }
 - (void)addTabViewItem:(NSTabViewItem *)tabViewItem;
 - (void)insertTabViewItem:(NSTabViewItem *)tabViewItem

___
Gnustep-dev mailing list
Gnustep-dev@gnu.org
https://lists.gnu.org/mailman/listinfo/gnustep-dev