[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 |