On 11 Jul 2014, at 09:56, Cosmin Apreutesei <cosmin.apreute...@gmail.com> wrote:
> Hi,
> 
> I have a strange problem.
> 
> I am using C and the objc runtime on OSX 10.9.3 to get a value from a
> NSDictionary.
> 
> The objectForKey method returns an invalid pointer on x64 (not NULL,
> but the same address 0x937 for _any_ valid key), but works fine on
> i386.
> 
> I attached a small test case to show the problem.
> 
> Here's how to build and run the test case:
> 
> echo "on 32bit works..."
> gcc -arch i386 -O2 test5.c -o test5_32 -lobjc
> ./test5_32
> 
> echo "on 64bit crashes..."
> gcc -arch x86_64 -O2 test5.c -o test5 -lobjc
> ./test5
> 
> 
> Any help would be appreciated, even to tell me that you can or can't
> reproduce the problem or that you find problems with the code, or to
> redirect me to a different forum/mailing list.

Since Lion and on 64-bit programs, some NSNumber instances are not represented 
by full Objective-C objects. Instead, they are represented directly in the 
(tagged) pointer. I wrote about this when Lion came out:

http://objectivistc.tumblr.com/post/7872364181/tagged-pointers-and-fast-pathed-cfnumber-integers-in

and Mike Ash also wrote about it:

https://www.mikeash.com/pyblog/friday-qa-2012-07-27-lets-build-tagged-pointers.html

The layout has changed since then (IIRC type encoding is different now) but, in 
general, if you get an object pointer whose least significant bit is set (i.e., 
its integer representation is an odd number), then it’s a tagged pointer. Since 
the pointer does not point to a valid object, you cannot call an IMP on it 
directly. You should still be able to use it as the first argument to 
objc_msgSend(), though. Remember to cast objc_msgSend() to the corresponding 
function pointer type.

For Objective-C questions, you can write to objc-language@lists.


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to