2 // NSMethodSignature+WOTest.m
5 // Created by Wincent Colaiuta on 30 January 2006.
7 // Copyright 2006-2007 Wincent Colaiuta.
8 // This program is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
13 // This program is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
18 // You should have received a copy of the GNU General Public License
19 // along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #import "NSMethodSignature+WOTest.h"
23 #import <objc/objc-class.h>
27 The real 10.4 NSMethodSignature API (obtained using class-dump; TODO: run class-dump to get 10.5 API):
29 @interface NSMethodSignature : NSObject
33 unsigned int _sizeofParams;
34 unsigned int _returnValueLength;
40 + (id)signatureWithObjCTypes:(const char *)fp8;
41 - (BOOL)_isReturnStructInRegisters;
44 - (unsigned int)retainCount;
45 - (const char *)methodReturnType; // PUBLIC
46 - (unsigned int)methodReturnLength; // PUBLIC
47 - (BOOL)isOneway; // PUBLIC
48 - (const char *)getArgumentTypeAtIndex:(unsigned int)fp8; // PUBLIC
49 - (struct _arginfo)_argumentInfoAtIndex:(unsigned int)fp8;
50 - (unsigned int)frameLength; // PUBLIC
51 - (unsigned int)numberOfArguments; // PUBLIC
53 - (id)debugDescription;
59 @interface NSMethodSignature : NSObject {
63 unsigned _sizeofParams;
64 unsigned _returnValueLength;
70 - (unsigned)numberOfArguments;
71 - (const char *)getArgumentTypeAtIndex:(unsigned)index;
72 - (unsigned)frameLength;
74 - (const char *)methodReturnType;
75 - (unsigned)methodReturnLength;
79 Many public implementations of that use NSProxy subclasses to implement trampolines make use of the signatureWithObjCTypes: private API.
82 http://www.cocoadev.com/index.pl?LSTrampoline
83 http://www.cocoadev.com/index.pl?BSTrampoline
85 See also http://www.stuffonfire.com/2005/12/signaturewithobjctypes_is_stil.html
89 @interface NSMethodSignature (WOApplePrivate)
91 /*! Private Apple API. */
92 + (id)signatureWithObjCTypes:(const char *)fp8;
96 @interface NSMethodSignature ()
98 - (id)initWithObjCTypes:(const char *)types;
102 @implementation NSMethodSignature (WOTest)
104 + (id)WOTest_signatureBasedOnObjCTypes:(const char *)types
106 NSParameterAssert(types != NULL);
108 #ifdef WO_USE_OWN_METHOD_SIGNATURE_IMPLEMENTATION
110 return [[self alloc] initWithObjCTypes:types];
112 #else /* use private Apple API */
114 NSAssert([self respondsToSelector:@selector(signatureWithObjCTypes:)], @"signatureWithObjCTypes: selector not recognized");
115 return [self signatureWithObjCTypes:types];
121 - (id)initWithObjCTypes:(const char *)types
123 NSParameterAssert(types != NULL);
124 if ((self = [super init]))
126 // TODO: finish implementation
128 /* unsigned method_getNumberOfArguments(Method);
129 unsigned method_getSizeOfArguments(Method); */
131 // I hate using private Apple APIs, even ones that appear stable, but
132 // not sure that meddling with these instance variables is a good idea