Thread: [Pyobjc-dev] Functions in the Objective-C method table
Brought to you by:
ronaldoussoren
From: Ronald O. <ous...@ci...> - 2002-09-25 17:22:55
|
The major problem I see with the current version of PyObjC is the (large) list of functions that are used in the method dispatch tables in Objective-C classes (the file 'Modules/objc/register.m'). Using a static list makes the compile-time of PyObjC too long and makes it necessary to add C module when you want to override methods whose signature is not in the table. I'd like to find (and implement) a solution for this. But let me start with an in-depth description of the problem. Objective-C classes are basicly structs with a number of fields. One of those fields is a pointer to the super-class and another is a list of method descriptors, and each descriptor contains the method name, signature and a pointer to its implementation. If you subclass an Objective-C class from python and override and existing method (like 'init') it is necessary to add a method descriptor for the python method to the method list of the Objective-C end of your subclass. If we do not add such a descriptor the method resulotion code will find the descriptor in the superclass, which defeats our purpose. The method descriptor is not necessary for entirely new methods, because calls to those methods can be routed through 'forwardMethodInvocation'. In the current code the method implementation for the method descriptors are generated at compile-time, resulting in a large file: 1.6MByte, 56K lines. Only halve of that file contains the functions for the method descriptors, the other halve contains functions that are used to call the super-class implementation of a method from the new version of the method (e.g. these are used to implement 'super(MyClass, self).init()'). These functions are necessary because there is no 'NSInvocation' like interface for performing this task (neither as a neatly packaged class nor in the objective-C runtime). The only way to call a superclass implementation is through 'objc_msgSendSuper' in the objective-C runtime. I've been looking at libffi (homepage at http://sources.redhat.com, the most recent implementation is in the GCC CVS repository). From what I've seen it should be possible to use this library to: 1) Generate the functions for use in method descriptors at runtime 2) Write an 'NSInvocation' work-alike for calls to the superclass implementation As an added bonus, using libffi would make it possible to implement item 2 and 'execute_and_pythonify_method' in 1 function, thereby reducing the amount of code. And now on my questions... * Am I seeing ghosts or is register.m (and the python script generating it) as problemetic as I think it is? * Does any of you have experience with libffi, and if so could it do what I describe? * Are their alternatives to useing a library like libffi? * And last but not least, how are your opinions regarding the use of external libraries (e.g. libffi)? Ronald |
From: Jack J. <Jac...@cw...> - 2002-10-08 11:58:08
|
On Wednesday, Sep 25, 2002, at 19:23 Europe/Amsterdam, Ronald Oussoren wrote: > The major problem I see with the current version of PyObjC is the > (large) list of functions that are used in the method dispatch tables > in Objective-C classes (the file 'Modules/objc/register.m'). Using a > static list makes the compile-time of PyObjC too long and makes it > necessary to add C module when you want to override methods whose > signature is not in the table. Is it possible to find out how the ObjC-Java bridge handles this? It must have the same problems, if I'm not mistaken, and it'll also have the super method call problem. -- - Jack Jansen <Jac...@or...> http://www.cwi.nl/~jack - - If I can't dance I don't want to be part of your revolution -- Emma Goldman - |
From: Ronald O. <ous...@ci...> - 2002-10-08 13:06:53
|
On Tuesday, Oct 8, 2002, at 13:58 Europe/Amsterdam, Jack Jansen wrote: > On Wednesday, Sep 25, 2002, at 19:23 Europe/Amsterdam, Ronald Oussoren > wrote: > >> The major problem I see with the current version of PyObjC is the >> (large) list of functions that are used in the method dispatch tables >> in Objective-C classes (the file 'Modules/objc/register.m'). Using a >> static list makes the compile-time of PyObjC too long and makes it >> necessary to add C module when you want to override methods whose >> signature is not in the table. > > Is it possible to find out how the ObjC-Java bridge handles this? It > must have the same problems, if I'm not mistaken, and it'll also have > the super method call problem. I'll take a look at the code generated by bridget, but I wouldn't be surprised if they don't have the same problem because they generate static wrappers. Ronald |
From: Bill B. <bb...@co...> - 2002-10-08 15:20:19
|
In the context of going from Obj-C -> Java, there was both the formal bridget mechanism, but the ObjC->Java bridge also allowed for arbitrary messaging into Java for methods that had not been explicitly bridged in a jobs file. This was done dynamically and, as such, there must be a mechanism available that avoids the use of a mechanism like the whole "register.m" thing. In general, the presence of register.m is fairly inoffensive in everything but the compilation time -- it is a whole lot faster to do the dispatch via the stuff in register.m than it is to do something dynamic/on-the-fly. Why not add the compiled result of register.m to the CVS repository as register.o (or as a library) that everything can link against -- the only time it would be recompiled is when the register.m file is regenerated. In any case, the Java Bridge-- as of WebObjects 4.5-- works by creating an ObjC class for each bridged Java class. This includes creating both a class struct and a meta class struct to describe the Java class in terms of ObjC. The bridged classes do not bridge the instance variables, but do bridge each instance and class/static method. The method signatures were generated on the fly based on the Java class's method signatures. The bridged classes would also conditionally have a series of standard methods added to them; i.e. -copy, -retain, -description, etc... depending on the nature of the class being bridged (does it inherit from ObjC or Java, etc). An implementaton of -forward:: or -forwardInvocation: (because it had to work with both) was provided to do the forwarding of method invocations from ObjC into Java. This was done by effectively wrapping the instance of the Java object in a proxy class (NSJavaObject) that contained the appropriate forwarding mechanism. The forwarding mechanism basically ripped apart the stack by hand, converted the arguments to the corresponding Java types based on their ObjC signatures, invoked the Java method, then converted the return values, as needed. I could dig some more and see if I can find my notes that may provide more detail -- the above was done from memory. I have some deep scars from having to debug some truly painful interaction between ObjC and Java under WO 3.5 - 4.5. There were some nasty bugs that could potentially cause a deadlock in the bridge... b.bum On Tuesday, October 8, 2002, at 09:06 AM, Ronald Oussoren wrote: > > On Tuesday, Oct 8, 2002, at 13:58 Europe/Amsterdam, Jack Jansen wrote: >> On Wednesday, Sep 25, 2002, at 19:23 Europe/Amsterdam, Ronald >> Oussoren wrote: >> >>> The major problem I see with the current version of PyObjC is the >>> (large) list of functions that are used in the method dispatch >>> tables in Objective-C classes (the file 'Modules/objc/register.m'). >>> Using a static list makes the compile-time of PyObjC too long and >>> makes it necessary to add C module when you want to override methods >>> whose signature is not in the table. >> >> Is it possible to find out how the ObjC-Java bridge handles this? It >> must have the same problems, if I'm not mistaken, and it'll also have >> the super method call problem. > > I'll take a look at the code generated by bridget, but I wouldn't be > surprised if they don't have the same problem because they generate > static wrappers. > > Ronald > > > > ------------------------------------------------------- > This sf.net email is sponsored by:ThinkGeek > Welcome to geek heaven. > http://thinkgeek.com/sf > _______________________________________________ > Pyobjc-dev mailing list > Pyo...@li... > https://lists.sourceforge.net/lists/listinfo/pyobjc-dev > b.bum In cyberspace, no one can hear you laugh. |
From: Jack J. <Jac...@or...> - 2002-10-08 20:37:53
|
On dinsdag, oktober 8, 2002, at 03:06 , Ronald Oussoren wrote: >>> The major problem I see with the current version of PyObjC is >>> the (large) list of functions that are used in the method >>> dispatch tables in Objective-C classes (the file >>> 'Modules/objc/register.m'). Using a static list makes the >>> compile-time of PyObjC too long and makes it necessary to add >>> C module when you want to override methods whose signature is >>> not in the table. >> >> Is it possible to find out how the ObjC-Java bridge handles >> this? It must have the same problems, if I'm not mistaken, and >> it'll also have the super method call problem. > > I'll take a look at the code generated by bridget, but I > wouldn't be surprised if they don't have the same problem > because they generate static wrappers. Uhm... You've lost me here, why would static wrappers make a difference? Or are you suggesting that for every method [x] they generate both a [object x] and [super x] wrapper? -- - Jack Jansen <Jac...@or...> http://www.cwi.nl/~jack - - If I can't dance I don't want to be part of your revolution -- Emma Goldman - |