aboutsummaryrefslogtreecommitdiff
path: root/test/test-imp-forwarding.m
diff options
context:
space:
mode:
authorcomex2015-01-16 06:32:58 -0500
committercomex2015-01-16 06:32:58 -0500
commit4ac639ebb0172560f6719f3eed45d1a3f054efe5 (patch)
tree6d9d2dd67d92928a0463d0585ff827d4c332a876 /test/test-imp-forwarding.m
parenthandle oom and silly machos and stuff (diff)
downloadsubstitute-4ac639ebb0172560f6719f3eed45d1a3f054efe5.tar.gz
and now for something completely different: assembly maybestret-IMPL
forwarding functions for atomicity
Diffstat (limited to '')
-rw-r--r--test/test-imp-forwarding.m26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/test-imp-forwarding.m b/test/test-imp-forwarding.m
new file mode 100644
index 0000000..da2ece2
--- /dev/null
+++ b/test/test-imp-forwarding.m
@@ -0,0 +1,26 @@
+#include "../lib/objc.c"
+#include <objc/runtime.h>
+#include <stdio.h>
+
+static void imp1(id self, SEL sel, int a, int b) {
+ printf("imp1: self=%p sel=%s a=%d b=%d\n", self, sel_getName(sel), a, b);
+}
+
+struct big {
+ int x[10];
+};
+
+static struct big imp2(id self, SEL sel, int a, int b) {
+ printf("imp2: self=%p sel=%s a=%d b=%d\n", self, sel_getName(sel), a, b);
+ return (struct big) {{0}};
+}
+
+int main() {
+ IMP old = (IMP) imp1;
+ SEL sel = @selector(some);
+ struct temp_block_literal temp_block = get_temp_block(&old, sel);
+ IMP new = imp_implementationWithBlock((id) &temp_block);
+ ((void (*)(id, SEL, int, int)) new)(@"foo", sel, 1, 2);
+ old = (IMP) imp2;
+ ((struct big (*)(id, SEL, int, int)) new)(@"bar", sel, 1, 2);
+}