[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 19:57:38 +0200 |
User-agent: |
SOGoMail 1.3.14 |
On Tuesday, April 10, 2012 19:24 CEST, David Chisnall <address@hidden> 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
- 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, 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, David Chisnall, 2012/04/10
- Re: some unsigned/NSInteger to NSUInteger changes in -gui,
Sebastian Reitenbach <=
- 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