[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: some unsigned/NSInteger to NSUInteger changes in -gui
From: |
Sebastian Reitenbach |
Subject: |
Re: some unsigned/NSInteger to NSUInteger changes in -gui |
Date: |
Tue, 10 Apr 2012 18:27:53 +0200 |
User-agent: |
SOGoMail 1.3.14 |
On Tuesday, April 10, 2012 17:39 CEST, Wolfgang Lux <address@hidden> wrote:
> Sebastian Reitenbach wrote:
>
> >
> > On Monday, April 9, 2012 22:37 CEST, Fred Kiefer <address@hidden> 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 0x000000020d409b65 in +[NSException raise:format:] (self=0x20d8816a0,
> > _cmd=Variable "_cmd" is not available.
> > ) at NSException.m:835
> > #2 0x000000020d4c88c2 in -[NSUnarchiver decodeValueOfObjCType:at:]
> > (self=0x206e20088, _cmd=0x20cf0dea0, type=0x20cd10b20 "I",
> > address=0x20dc2fd70) at NSUnarchiver.m:247
> > #3 0x000000020cb2972b in -[NSTabView initWithCoder:] (self=Variable "self"
> > is not available.
> > ) at NSTabView.m:634
> > #4 0x000000020d4c8200 in -[NSUnarchiver decodeValueOfObjCType:at:]
> > (self=0x206e20088, _cmd=0x20d8dda40, type=0x20d728790 "@",
> > address=0x20dc2df70) at NSUnarchiver.m:662
> > #5 0x000000020d4c627d in -[NSUnarchiver decodeArrayOfObjCType:count:at:]
> > (self=0x206e20088, _cmd=Variable "_cmd" is not available.
> > ) at NSUnarchiver.m:574
> > #6 0x000000020d3459de in -[GSMutableArray initWithCoder:]
> > (self=0x20721e648, _cmd=Variable "_cmd" is not available.
> > ) at GSArray.m:553
> > #7 0x000000020d4c8200 in -[NSUnarchiver decodeValueOfObjCType:at:]
> > (self=0x206e20088, _cmd=0x20cf42dd0, type=0x20cd157ca "@",
> > address=0x7f7fffff8798) at NSUnarchiver.m:662
> > #8 0x000000020cb79dc3 in -[NSView initWithCoder:] (self=Variable "self" is
> > not available.
> > ) at NSView.m:4740
> > #9 0x000000020d4c8200 in -[NSUnarchiver decodeValueOfObjCType:at:]
> > (self=0x206e20088, _cmd=0x20d8dda40, type=0x20d728790 "@",
> > address=0x20dc2dc00) at NSUnarchiver.m:662
> > #10 0x000000020d4c627d in -[NSUnarchiver decodeArrayOfObjCType:count:at:]
> > (self=0x206e20088, _cmd=Variable "_cmd" is not available.
> > ) at NSUnarchiver.m:574
> > ...
> > (gdb) frame 3
> > #3 0x000000020cb2972b 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
===================================================================
--- 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];
@@ -631,7 +631,10 @@
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_draws_background];
[aDecoder decodeValueOfObjCType: @encode(BOOL) at: &_truncated_label];
_delegate = [aDecoder decodeObject];
- [aDecoder decodeValueOfObjCType: "I" at: &_selected_item];
+ if (version < 3)
+ [aDecoder decodeValueOfObjCType: "i" at: &_selected_item];
+ else
+ [aDecoder decodeValueOfObjCType: "I" at: &_selected_item];
_selected = [_items objectAtIndex: _selected_item];
}
return self;
>
> Wolfgang
>
- some unsigned/NSInteger to NSUInteger changes in -gui, Sebastian Reitenbach, 2012/04/09
- Re: some unsigned/NSInteger to NSUInteger changes in -gui, Fred Kiefer, 2012/04/09
- Re: some unsigned/NSInteger to NSUInteger changes in -gui, Eric Wasylishen, 2012/04/09
- Re: some unsigned/NSInteger to NSUInteger changes in -gui, Fred Kiefer, 2012/04/09
- Re: some unsigned/NSInteger to NSUInteger changes in -gui, Sebastian Reitenbach, 2012/04/10
- Re: some unsigned/NSInteger to NSUInteger changes in -gui, Wolfgang Lux, 2012/04/10
- Re: some unsigned/NSInteger to NSUInteger changes in -gui,
Sebastian Reitenbach <=
- Re: some unsigned/NSInteger to NSUInteger changes in -gui, David Chisnall, 2012/04/10
- Re: some unsigned/NSInteger to NSUInteger changes in -gui, Sebastian Reitenbach, 2012/04/10
- Re: some unsigned/NSInteger to NSUInteger changes in -gui, David Chisnall, 2012/04/10
- Re: some unsigned/NSInteger to NSUInteger changes in -gui, Sebastian Reitenbach, 2012/04/10
- Re: some unsigned/NSInteger to NSUInteger changes in -gui, Fred Kiefer, 2012/04/10
- Re: some unsigned/NSInteger to NSUInteger changes in -gui, David Chisnall, 2012/04/10
- Re: some unsigned/NSInteger to NSUInteger changes in -gui, Sebastian Reitenbach, 2012/04/11