ObjFW  Check-in [b156ec8284]

Overview
Comment:Rename -[replaceMethod:withMethodFromClass:] and friends.
The rename was needed as these replace instance methods.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b156ec828405af6b5c8fc479c05c36fea2112947060f5eac2525d8e59dbdc02a
User & Date: js on 2010-02-24 23:00:37
Other Links: manifest | tags
Context
2010-03-04
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
22:56
Merge to fix wrong parent of last commit. check-in: b190519866 user: js tags: trunk
Changes

Modified src/OFObject.h from [b67f49f2af] to [75b9a0dc79].

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
 * \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 method implementation with another implementation.
 *
 * \param newimp The new implementation for the method
 * \param selector The selector of the method to replace
 * \return The old implementation
 */
+ (IMP)setImplementation: (IMP)newimp
	       forMethod: (SEL)selector;

/**
 * Replaces a method with a method from another class.
 *
 * \param selector The selector of the method to replace
 * \param class_ The class from which the new method should be taken
 * \return The old implementation
 */
+  (IMP)replaceMethod: (SEL)selector
  withMethodFromClass: (Class)class_;

/**
 * Initializes an already allocated object.
 *
 * Derived classes may override this, but need to do self = [super init] before
 * they do any initialization themselves. init may never return nil, instead
 * an exception (for example OFInitializationFailed) should be thrown.







|

|
|



|


|

|
|


|
|







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
 * \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 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
 */
+ (IMP)setImplementation: (IMP)newimp
       forInstanceMethod: (SEL)selector;

/**
 * Replaces an instance method with an instance method from another class.
 *
 * \param selector The selector of the instance method to replace
 * \param class_ The class from which the new instance method should be taken
 * \return The old implementation
 */
+  (IMP)replaceInstanceMethod: (SEL)selector
  withInstanceMethodFromClass: (Class)class_;

/**
 * Initializes an already allocated object.
 *
 * Derived classes may override this, but need to do self = [super init] before
 * they do any initialization themselves. init may never return nil, instead
 * an exception (for example OFInitializationFailed) should be thrown.

Modified src/OFObject.m from [591acb6dd3] to [3fb2c436d1].

205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
	return class_getMethodImplementation(self, selector);
#else
	return method_get_imp(class_get_instance_method(self, selector));
#endif
}

+ (IMP)setImplementation: (IMP)newimp
	       forMethod: (SEL)selector
{
#ifdef OF_APPLE_RUNTIME
	Method method;

	if ((method = class_getInstanceMethod(self, selector)) == NULL)
		@throw [OFInvalidArgumentException newWithClass: self
						       selector: _cmd];







|







205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
	return class_getMethodImplementation(self, selector);
#else
	return method_get_imp(class_get_instance_method(self, selector));
#endif
}

+ (IMP)setImplementation: (IMP)newimp
       forInstanceMethod: (SEL)selector
{
#ifdef OF_APPLE_RUNTIME
	Method method;

	if ((method = class_getInstanceMethod(self, selector)) == NULL)
		@throw [OFInvalidArgumentException newWithClass: self
						       selector: _cmd];
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
		sarray_at_put_safe(((Class)self)->dtable,
		    (sidx)method->method_name->sel_id, method->method_imp);

	return oldimp;
#endif
}

+  (IMP)replaceMethod: (SEL)selector
  withMethodFromClass: (Class)class;
{
	IMP newimp;

#ifdef OF_APPLE_RUNTIME
	newimp = class_getMethodImplementation(class, selector);
#else
	newimp = method_get_imp(class_get_instance_method(class, selector));
#endif

	return [self setImplementation: newimp
			     forMethod: selector];
}

- init
{
	return self;
}








|
|










|







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
		sarray_at_put_safe(((Class)self)->dtable,
		    (sidx)method->method_name->sel_id, method->method_imp);

	return oldimp;
#endif
}

+  (IMP)replaceInstanceMethod: (SEL)selector
  withInstanceMethodFromClass: (Class)class;
{
	IMP newimp;

#ifdef OF_APPLE_RUNTIME
	newimp = class_getMethodImplementation(class, selector);
#else
	newimp = method_get_imp(class_get_instance_method(class, selector));
#endif

	return [self setImplementation: newimp
		     forInstanceMethod: selector];
}

- init
{
	return self;
}