Overview
Comment: | Add +[setImplemenation:forClassMethod:] and friends. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
a4b1a005b6582469310b54287421e22f |
User & Date: | js on 2010-03-04 12:28:15 |
Other Links: | manifest | tags |
Context
2010-03-04
| ||
21:37 | GCC always defines self as struct objc_class, even for class methods. check-in: 19890b42b2 user: js tags: trunk | |
12:28 | Add +[setImplemenation:forClassMethod:] and friends. check-in: a4b1a005b6 user: js tags: trunk | |
2010-02-24
| ||
23:00 |
Rename -[replaceMethod:withMethodFromClass:] and friends. The rename was needed as these replace instance methods. check-in: b156ec8284 user: js tags: trunk | |
Changes
Modified src/OFObject.h from [75b9a0dc79] to [eab33580e8].
︙ | |||
115 116 117 118 119 120 121 122 123 124 125 126 127 128 | 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | + + + + + + + + + + + + + + + + + + + + | /** * \param selector The selector for which the method should be returned * \return The implementation of the instance method for the specified selector * or nil if it isn't implemented */ + (IMP)instanceMethodForSelector: (SEL)selector; /** * Replaces a class method implementation with another implementation. * * \param newimp The new implementation for the class method * \param selector The selector of the class method to replace * \return The old implementation */ + (IMP)setImplementation: (IMP)newimp forClassMethod: (SEL)selector; /** * Replaces a class method with a class method from another class. * * \param selector The selector of the class method to replace * \param class_ The class from which the new class method should be taken * \return The old implementation */ + (IMP)replaceClassMethod: (SEL)selector withClassMethodFromClass: (Class)class_; /** * Replaces an instance method implementation with another implementation. * * \param newimp The new implementation for the instance method * \param selector The selector of the instance method to replace * \return The old implementation */ |
︙ |
Modified src/OFObject.m from [3fb2c436d1] to [69ac875773].
︙ | |||
203 204 205 206 207 208 209 210 211 212 213 214 215 216 | 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | { #ifdef OF_APPLE_RUNTIME return class_getMethodImplementation(self, selector); #else return method_get_imp(class_get_instance_method(self, selector)); #endif } + (IMP)setImplementation: (IMP)newimp forClassMethod: (SEL)selector { #ifdef OF_APPLE_RUNTIME Method method; if ((method = class_getClassMethod(self, selector)) == NULL) @throw [OFInvalidArgumentException newWithClass: self selector: _cmd]; return method_setImplementation(method, newimp); #else Method_t method; IMP oldimp; /* The class method is the instance method of the meta class */ if ((method = class_get_instance_method(self->class_pointer, selector)) == NULL) @throw [OFInvalidArgumentException newWithClass: self selector: _cmd]; if ((oldimp = method_get_imp(method)) == (IMP)0 || newimp == (IMP)0) @throw [OFInvalidArgumentException newWithClass: self selector: _cmd]; method->method_imp = newimp; /* Update the dtable if necessary */ if (sarray_get_safe(self->class_pointer->dtable, (sidx)method->method_name->sel_id)) sarray_at_put_safe(self->class_pointer->dtable, (sidx)method->method_name->sel_id, method->method_imp); return oldimp; #endif } + (IMP)replaceClassMethod: (SEL)selector withClassMethodFromClass: (Class)class; { IMP newimp; #ifdef OF_APPLE_RUNTIME newimp = method_getImplementation(class_getClassMethod(class, selector)); #else /* The class method is the instance method of the meta class */ newimp = method_get_imp(class_get_instance_method(class->class_pointer, selector)); #endif return [self setImplementation: newimp forClassMethod: selector]; } + (IMP)setImplementation: (IMP)newimp forInstanceMethod: (SEL)selector { #ifdef OF_APPLE_RUNTIME Method method; |
︙ | |||
230 231 232 233 234 235 236 | 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 | - - - + + | if ((oldimp = method_get_imp(method)) == (IMP)0 || newimp == (IMP)0) @throw [OFInvalidArgumentException newWithClass: self selector: _cmd]; method->method_imp = newimp; /* Update the dtable if necessary */ |
︙ |