[fpc-devel] c-blocks (darwin aarch64)
Dmitry Boyarintsev
skalogryz.lists at gmail.com
Sat Apr 16 06:18:35 CEST 2016
On Fri, Apr 15, 2016 at 9:09 PM, Dmitry Boyarintsev <
skalogryz.lists at gmail.com> wrote:
>
> I'm going to update to the latest FPC revision now.
>
Using r33526, the app crashes with compiler native blocks at the same spot
(on calling set block handler)
*(lldb) bt*
* thread #1: tid = 0x16034c, 0x2469fa86 libobjc.A.dylib`objc_msgSend + 6,
queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1,
address=0xe92d40bc)
* frame #0: 0x2469fa86 libobjc.A.dylib`objc_msgSend + 6
frame #1: 0x246a00cc libobjc.A.dylib`objc_setProperty_nonatomic_copy +
32
frame #2: 0x000d8da0 testbomber`___lldb_unnamed_function762$$testbomber
+ 1184
frame #3: 0x000d8e9c testbomber`ZGL_JOYSTICK_$$_JOY_INIT$$BYTE + 32
Manually generated block worked (doesn't make feel any better, though).
-------
Two differences I can see between "manual" block and compiler block.
1) set of flags. Manual block doesn't set any of them (in the original
example, and GLOBAL flag is set in the example below), where the compiler
always sets up BLOCK_HAS_SIGNATURE .
2) the compiler is using Simple description, where manual is using complex.
I'm looking Blocks ABI (
http://clang.llvm.org/docs/Block-ABI-Apple.html#imported-variables),
I don't see any reference if "copy" and "dispose" fields could omit and
it's allowed to "signature" follow "size" field right away. (I'd think they
would use "union" in this case to declare "description")
Also, as far as I understand signature is used for functions returning
structures (records)?
I'm looking at x86_64 code (which is a slightly modified version of the
very first blocks example)
I can see that "signature" is populated, even though the procedure doesn't
return anything.
{$mode objfpc}
{$modeswitch objectivec2}
{$modeswitch cblocks}
uses
ctypes,
CocoaAll;
type
tblock = FPC_Block_literal_base;
pblock = ^tblock;
NSArrayEnumeratorBlock = reference to procedure (obj: id; idx:
NSUInteger; var stop: boolean); cdecl;
{ normally part of the NSArray declaration, but not yet in
our units since the released compilers don't support blocks
yet }
enumcategory = objccategory external (NSArray)
procedure enumerateObjectsUsingBlock(block: NSArrayEnumeratorBlock);
message 'enumerateObjectsUsingBlock:';
procedure enumerateObjectsUsingBlock2(block: pointer); message
'enumerateObjectsUsingBlock:';
end;
procedure myenumerate(obj: id; idx: NSUInteger; var stop: boolean); cdecl;
begin
NSLog(NSString.alloc.initWithUTF8String('Object at index %lu is %@'),
idx, obj);
end;
procedure myenumerate_inblock( data: pblock; obj: id; idx: NSUInteger; var
stop: boolean); cdecl;
begin
writeln('mb');
myenumerate(obj, idx, stop);
end;
var
arr: NSMutableArray;
str: NSString;
block : FPC_Block_literal_base;
descr : FPC_Block_descriptor_complex;
begin
fillchar(descr, sizeof(descr), 0);
descr.Block_size:=sizeof(block);
fillchar(block, sizeof(block), 0);
block.isa:=@_NSConcreteGlobalBlock; // could be left zero. didn't make
any difference for x86_64
block.flags:=BLOCK_IS_GLOBAL; // could be left zero. didn't make any
difference
block.descriptor:=@descr;
block.invoke:=@myenumerate_inblock;
arr := NSMutableArray.alloc.init;
str:=NSString.alloc.initWithUTF8String('abc');
arr.addObject(str);
str:=NSString.alloc.initWithUTF8String('123');
arr.addObject(str);
str:=NSString.alloc.initWithUTF8String('XYZ');
arr.addObject(str);
arr.enumerateObjectsUsingBlock2(@block);
arr.enumerateObjectsUsingBlock(@myenumerate);
end.
thanks,
Dmitry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160416/fe70050d/attachment.html>
More information about the fpc-devel
mailing list