From 710b2368cca8039523cdfef217626b3345f17e65 Mon Sep 17 00:00:00 2001 From: Rupert Daniel Date: Thu, 3 Oct 2019 09:07:33 +0100 Subject: [PATCH] Fixed crash when using self in imp_implementationWithBlock on armv7a --- Test/BlockImpTest.m | 2 ++ block_trampolines.S | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Test/BlockImpTest.m b/Test/BlockImpTest.m index ce9931a..4ccd05b 100644 --- a/Test/BlockImpTest.m +++ b/Test/BlockImpTest.m @@ -26,6 +26,7 @@ int main(void) { __block int b = 0; void* blk = ^(id self, int a) { + assert([self class] == [Foo class]); b += a; return b; }; blk = Block_copy(blk); @@ -45,6 +46,7 @@ int main(void) assert(imp_getBlock(imp) != (blk)); blk = ^(id self) { + assert([self class] == [Foo class]); struct big b = {1, 2, 3, 4, 5}; return b; }; diff --git a/block_trampolines.S b/block_trampolines.S index 70e321d..6107e7a 100644 --- a/block_trampolines.S +++ b/block_trampolines.S @@ -126,7 +126,7 @@ .thumb .macro trampoline arg0, arg1 sub r12, pc, #4095 - mov \arg0, \arg1 // Move self over _cmd + mov \arg1, \arg0 // Move self over _cmd ldr \arg0, [r12, #-5] // Load the block pointer over self ldr r12, [r12, #-1] // Jump to the block function bx r12 @@ -134,7 +134,7 @@ # else .macro trampoline arg0, arg1 sub r12, pc, #4096 - mov \arg0, \arg1 // Move self over _cmd + mov \arg1, \arg0 // Move self over _cmd ldr \arg0, [r12, #-8] // Load the block pointer over self ldr pc, [r12, #-4] // Jump to the block function .endm