• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Some in-depth Obj-C runtime questions.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Some in-depth Obj-C runtime questions.


  • Subject: Some in-depth Obj-C runtime questions.
  • From: "John C. Randolph" <email@hidden>
  • Date: Mon, 2 Jul 2001 00:42:36 -0700

Poking around in GDB, I obtained the following description for the method signature of [NSView drawRect:].

(gdb) po [sender methodSignatureForSelector:(SEL)NSSelectorFromString(@"drawRect:")]
NSMethodSignature <0x18c45a0> types(v@:{?={?=ff}{?=ff}}) nargs(3) frameSize(160) retType(v) retSize(0)
{0 : type(@:{?={?=ff}{?=ff}}) size(4) offset(128)}
{1 : type(:{?={?=ff}{?=ff}}) size(4) offset(132)}
{2 : type({?={?=ff}{?=ff}}) size(16) offset(136)}
{0 : type({?=ff}{?=ff}}) size(8) offset(136)}
{0 : type(ff}{?=ff}}) size(4) offset(136)}
{1 : type(f}{?=ff}}) size(4) offset(140)}
{1 : type({?=ff}}) size(8) offset(144)}
{0 : type(ff}}) size(4) offset(144)}
{1 : type(f}}) size(4) offset(148)}

Now, this method should have three arguments: self, _cmd, and rect. "rect" of course, is a struct containing two other structs, an NSPoint and an NSSize, each of which is a struct of two floats.

{0 : type(@:{?={?=ff}{?=ff}}) size(4) offset(128)}

So, according to the Objective-C docs, "@" is the type encoding for an object (self, in this case). I'm with it so far.

{1 : type(:{?={?=ff}{?=ff}}) size(4) offset(132)}

..and ":" is the type encoding for a SEL, so far so good..

{2 : type({?={?=ff}{?=ff}}) size(16) offset(136)}

.."{" means a struct.. "{?" means a struct for which no name is known...

{0 : type({?=ff}{?=ff}}) size(8) offset(136)}
{0 : type(ff}{?=ff}}) size(4) offset(136)}
{1 : type(f}{?=ff}}) size(4) offset(140)}

Here's what I don't get. This looks to me like a bug in the -description method, because I would expect this to be:

{0 : type({?=ff}{?=ff}}) size(8) offset(136)}
{0 : type(f) size(4) offset(136)}
{1 : type(f) size(4) offset(140)}

since the components of the NSPoint are just floats, I don't see why they're followed by what looks like a struct encoding.

If I forget about using -description and just go right to

(gdb) p (char *) [$5 getArgumentTypeAtIndex:2]

I get:

"{?={?=ff}{?=ff}}\000"

Can I safely assume that the size of any argument can be obtained by just tallying up the sizes of all the f's, i's, :'s, etc?

How is [NSMethodSignature description] obtaining the offsets of each of these elements? Is it pulling them out of the runtime, or relying on the type encoding?

One other question, is why is self's offset 128 bytes from the beginning of the stack frame? What all is in the stack frame besides the return address?

-jcr

begin
(If this message looks like it has an attachment, your mail reader is brain-dead.)


  • Follow-Ups:
    • Re: Some in-depth Obj-C runtime questions.
      • From: Chris Kane <email@hidden>
    • Re: Some in-depth Obj-C runtime questions.
      • From: Christopher Lloyd <email@hidden>
  • Prev by Date: RE: [HELP] How to change Desktop background pic in OSX from Cocoa-Java?
  • Next by Date: This may be a bit of a twisted idea...
  • Previous by thread: Re: [HELP] How to change Desktop background pic in OSX from Cocoa-Java?
  • Next by thread: Re: Some in-depth Obj-C runtime questions.
  • Index(es):
    • Date
    • Thread