ObjFW  Check-in [d3a2e59414]

Overview
Comment:Initial -[forwarindTargetForSelector:].

This only works with the ObjFW runtime so far. The Apple runtime will
require an assembly implementation for every architecture.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: d3a2e59414615eda751863f50c2d1b31ea65b6b318c05029bb3e97efeda9f689
User & Date: js on 2012-11-14 15:39:10
Other Links: manifest | tags
Context
2012-11-16
21:16
Implement forwarding target for the Apple runtime. check-in: 2b20e164d7 user: js tags: trunk
2012-11-14
15:39
Initial -[forwarindTargetForSelector:]. check-in: d3a2e59414 user: js tags: trunk
08:00
Fix objc_get_type_encoding(). check-in: 28f58d5a6e user: js tags: trunk
Changes

Modified src/OFObject.h from [856cc09e65] to [710d8a991e].

806
807
808
809
810
811
812












813
814
815
816
817
818
819
 * @param delay The delay after which the selector will be performed
 */
- (void)performSelector: (SEL)selector
	       onThread: (OFThread*)thread
	     withObject: (id)object1
	     withObject: (id)object2
	     afterDelay: (double)delay;












@end

/*!
 * @brief A protocol for the creation of copies.
 */
@protocol OFCopying
/*!







>
>
>
>
>
>
>
>
>
>
>
>







806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
 * @param delay The delay after which the selector will be performed
 */
- (void)performSelector: (SEL)selector
	       onThread: (OFThread*)thread
	     withObject: (id)object1
	     withObject: (id)object2
	     afterDelay: (double)delay;

/*!
 * @brief This method is called when @ref resolveClassMethod: or
 *	  @ref resolveInstanceMethod: returned NO. It should return a target
 *	  to which the message should be forwarded.
 *
 * @note When the message should not be forwarded, you should not return nil,
 *	 but instead return the result of the superclass!
 *
 * @return The target to forward the message to
 */
- (id)forwardingTargetForSelector: (SEL)selector;
@end

/*!
 * @brief A protocol for the creation of copies.
 */
@protocol OFCopying
/*!

Modified src/OFObject.m from [130a752ea7] to [4b4eff1419].

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
149
150
151
152
153
154
155
156
157
158



159
160
161




162


163
164
165
166
167
168
169
	    class_getName(object_getClass(obj)));
	abort();
}

static IMP
forward_handler(id obj, SEL sel)
{



	if (class_isMetaClass(object_getClass(obj))) {
		if (![obj respondsToSelector: @selector(resolveClassMethod:)])
			return method_not_found_handler;

		if (![obj resolveClassMethod: sel])
			return method_not_found_handler;

		if (![obj respondsToSelector: sel]) {
			fprintf(stderr, "Runtime error: [%s "
			    "resolveClassMethod: %s] returned YES without "
			    "adding the method!\n", class_getName(obj),
			    sel_getName(sel));
			abort();
		}



	} else {
		Class c = object_getClass(obj);

		if (![c respondsToSelector: @selector(resolveInstanceMethod:)])
			return method_not_found_handler;

		if (![c resolveInstanceMethod: sel])
			return method_not_found_handler;

		if (![obj respondsToSelector: sel]) {
			fprintf(stderr, "Runtime error: [%s "
			    "resolveInstanceMethod: %s] returned YES without "
			    "adding the method!\n",
			    class_getName(object_getClass(obj)),
			    sel_getName(sel));
			abort();



		}
	}





	return objc_msg_lookup(obj, sel);


}
#endif

#ifndef HAVE_OBJC_ENUMERATIONMUTATION
void
objc_enumerationMutation(id object)
{







>
>
>

|
<
<
|
<
<
|
|
|
|
|
|
|
>
>
>



|
<
<
|
<
<
|
|
|
|
|
|
|
>
>
>



>
>
>
>
|
>
>







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


149


150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
	    class_getName(object_getClass(obj)));
	abort();
}

static IMP
forward_handler(id obj, SEL sel)
{
	id target;

	/* Try resolveClassMethod:/resolveInstanceMethod: */
	if (class_isMetaClass(object_getClass(obj))) {
		if ([obj respondsToSelector: @selector(resolveClassMethod:)] &&


		    [obj resolveClassMethod: sel]) {


			if (![obj respondsToSelector: sel]) {
				fprintf(stderr, "Runtime error: [%s "
				    "resolveClassMethod: %s] returned YES "
				    "without adding the method!\n",
				    class_getName(obj), sel_getName(sel));
				abort();
			}

			return objc_msg_lookup(obj, sel);
		}
	} else {
		Class c = object_getClass(obj);

		if ([c respondsToSelector: @selector(resolveInstanceMethod:)] &&


		    [c resolveInstanceMethod: sel]) {


			if (![obj respondsToSelector: sel]) {
				fprintf(stderr, "Runtime error: [%s "
				    "resolveInstanceMethod: %s] returned YES "
				    "without adding the method!\n",
				    class_getName(object_getClass(obj)),
				    sel_getName(sel));
				abort();
			}

			return objc_msg_lookup(obj, sel);
		}
	}

	/* Try forwardingTargetForSelector: */
	target = [obj forwardingTargetForSelector: sel];

	if (target != obj && target != nil)
		return objc_msg_lookup(target, sel);

	return method_not_found_handler;
}
#endif

#ifndef HAVE_OBJC_ENUMERATIONMUTATION
void
objc_enumerationMutation(id object)
{
949
950
951
952
953
954
955





956
957
958
959
960
961
962
		PRE_IVAR->lastMem = PRE_MEM(pointer)->prev;

	/* To detect double-free */
	PRE_MEM(pointer)->owner = nil;

	free(PRE_MEM(pointer));
}






- retain
{
#if defined(OF_ATOMIC_OPS)
	of_atomic_inc_32(&PRE_IVAR->retainCount);
#elif defined(OF_THREADS)
	OF_ENSURE(of_spinlock_lock(&PRE_IVAR->retainCountSpinlock));







>
>
>
>
>







956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
		PRE_IVAR->lastMem = PRE_MEM(pointer)->prev;

	/* To detect double-free */
	PRE_MEM(pointer)->owner = nil;

	free(PRE_MEM(pointer));
}

- (id)forwardingTargetForSelector: (SEL)selector
{
	return nil;
}

- retain
{
#if defined(OF_ATOMIC_OPS)
	of_atomic_inc_32(&PRE_IVAR->retainCount);
#elif defined(OF_THREADS)
	OF_ENSURE(of_spinlock_lock(&PRE_IVAR->retainCountSpinlock));