• 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
Re: get superclass instance
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: get superclass instance


  • Subject: Re: get superclass instance
  • From: Thomas Lachand-Robert <email@hidden>
  • Date: Mon, 7 Mar 2005 21:40:15 +0100


Le 7 mars 05, à 19:57, Agent M a écrit :


You are confusing self and super here. "self" is a pointer to the receiver, so self->something or
id x = self;
make sense. "super" is a keyword, so super->something or id x = super doesn't make sense.


That's true but super is still some kind of struct which the compiler uses to create the function call. Try it:
super->class
"class" is the only structure member I could find by experimentation. super is not an objc_super struct- so I don't know what it is.

I have never tried that before, and I don't understand why the compiler accepts it. It should not, according to the documentation:


http://developer.apple.com/documentation/cocoa/Conceptual/ObjectiveC/ LanguageOverview/chapter_3_section_6.html#//apple_ref/doc/uid/20001424/ BAJHDGAC
and also
http://developer.apple.com/documentation/Cocoa/Reference/ ObjCRuntimeRef/index.html?http://developer.apple.com/documentation/ Cocoa/Reference/ObjCRuntimeRef/ObjCRuntimeRef/ chapter_1.1_section_1.html#//apple_ref/doc/uid/TP40001418- DontLinkChapterID_1


Also "void* x = super" is accepted, but it doesn't make sense. My guess is that there is a bug in the compiler here. Notice that "class" is not a correct instance variable for ordinary objects, so self->class is not accepted. Conversely "self->isa" is ok, but "super->isa" is not...

Such a call would break encapsulation, so it is not permitted by NSInvocation. More generally calls to super are reserved to the implementation of a given class.
It would make sense if each successive subclass had its own id, but I guess that's an implementation detail.


I don't understand what you mean, but it makes sense anyway. You are not supposed to access to an overriden method, that the exact sense of overriding.


-- as a last resort, you can fake the runtime by changing the "isa" pointer of the object:
// example:
void* oldisa = myobject->isa; // preserve the current isa
myobject->isa = [myobject superclass];
[NSInvocation setTarget:myobject];// the runtime will believe that it is a superclass instance
//call the invocation, etc...
myobject->isa = oldisa; // restore the pointer


This is dirty code though, and it is not guaranteed to work in all cases, or in any future.
That's a neat trick. Thanks.

Could you also explain why -invoke catches all exceptions? It makes tracking down bugs in invoked code very difficult.



But a breakpoint on -[NSException raise].

Thomas Lachand-Robert
********************** email@hidden
<< Et le chemin est long du projet à la chose. >> Molière, Tartuffe.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: get superclass instance
      • From: "Sean McBride" <email@hidden>
References: 
 >get superclass instance (From: Agent M <email@hidden>)
 >Re: get superclass instance (From: Thomas Lachand-Robert <email@hidden>)
 >Re: get superclass instance (From: Thomas Lachand-Robert <email@hidden>)

  • Prev by Date: Re: A question about binding and use
  • Next by Date: Re: [Newbie]: Proper window activation
  • Previous by thread: Re: get superclass instance
  • Next by thread: Re: get superclass instance
  • Index(es):
    • Date
    • Thread