<div dir="ltr">On Fri, Apr 15, 2016 at 9:09 PM, Dmitry Boyarintsev <span dir="ltr"><<a href="mailto:skalogryz.lists@gmail.com" target="_blank">skalogryz.lists@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div><br></div><div>I'm going to update to the latest FPC revision now.<br></div><div></div></div></div></div></blockquote><div> </div><div>Using r33526, the app crashes with compiler native blocks at the same spot (on calling set block handler)</div><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><b>(lldb) bt</b></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">* 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)</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> * frame #0: 0x2469fa86 libobjc.A.dylib`objc_msgSend + 6</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> frame #1: 0x246a00cc libobjc.A.dylib`objc_setProperty_nonatomic_copy + 32</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> frame #2: 0x000d8da0 testbomber`___lldb_unnamed_function762$$testbomber + 1184</p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> frame #3: 0x000d8e9c testbomber`ZGL_JOYSTICK_$$_JOY_INIT$$BYTE + 32</p></div><div><br></div><div>Manually generated block worked (doesn't make feel any better, though).</div><div><br></div><div>-------</div><div><br></div><div>Two differences I can see between "manual" block and compiler block.<br></div><div><br></div><div>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 .</div><div><br></div><div>2) the compiler is using Simple description, where manual is using complex. I'm looking Blocks ABI (<a href="http://clang.llvm.org/docs/Block-ABI-Apple.html#imported-variables">http://clang.llvm.org/docs/Block-ABI-Apple.html#imported-variables</a>), </div><div><br></div><div>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")</div><div><br></div><div>Also, as far as I understand signature is used for functions returning structures (records)?</div><div><br></div><div>I'm looking at x86_64 code (which is a slightly modified version of the very first blocks example)</div><div>I can see that "signature" is populated, even though the procedure doesn't return anything.</div><div><br></div><div><div>{$mode objfpc}</div><div>{$modeswitch objectivec2}</div><div>{$modeswitch cblocks}</div><div><br></div><div>uses</div><div> ctypes,</div><div> CocoaAll;</div><div><br></div><div>type</div><div> tblock = FPC_Block_literal_base;</div><div> pblock = ^tblock;</div><div><br></div><div> NSArrayEnumeratorBlock = reference to procedure (obj: id; idx: NSUInteger; var stop: boolean); cdecl;</div><div><br></div><div> { normally part of the NSArray declaration, but not yet in</div><div> our units since the released compilers don't support blocks</div><div> yet }</div><div> enumcategory = objccategory external (NSArray)</div><div> procedure enumerateObjectsUsingBlock(block: NSArrayEnumeratorBlock); message 'enumerateObjectsUsingBlock:';</div><div> procedure enumerateObjectsUsingBlock2(block: pointer); message 'enumerateObjectsUsingBlock:';</div><div> end;</div><div><br></div><div><br></div><div>procedure myenumerate(obj: id; idx: NSUInteger; var stop: boolean); cdecl;</div><div>begin</div><div> NSLog(NSString.alloc.initWithUTF8String('Object at index %lu is %@'), idx, obj);</div><div>end;</div><div><br></div><div>procedure myenumerate_inblock( data: pblock; obj: id; idx: NSUInteger; var stop: boolean); cdecl;</div><div>begin</div><div> writeln('mb');</div><div> myenumerate(obj, idx, stop);</div><div>end;</div><div><br></div><div>var</div><div> arr: NSMutableArray;</div><div> str: NSString;</div><div> block : FPC_Block_literal_base;</div><div> descr : FPC_Block_descriptor_complex;</div><div><br></div><div>begin</div><div> fillchar(descr, sizeof(descr), 0);</div><div> descr.Block_size:=sizeof(block);</div><div><br></div><div> fillchar(block, sizeof(block), 0);</div><div> block.isa:=@_NSConcreteGlobalBlock; // could be left zero. didn't make any difference for x86_64<br></div><div> block.flags:=BLOCK_IS_GLOBAL; // could be left zero. didn't make any difference</div><div> block.descriptor:=@descr;<br></div><div> block.invoke:=@myenumerate_inblock;</div><div><br></div><div> arr := NSMutableArray.alloc.init;</div><div> str:=NSString.alloc.initWithUTF8String('abc');</div><div> arr.addObject(str);</div><div> str:=NSString.alloc.initWithUTF8String('123');</div><div> arr.addObject(str);</div><div> str:=NSString.alloc.initWithUTF8String('XYZ');</div><div> arr.addObject(str);</div><div> arr.enumerateObjectsUsingBlock2(@block);</div><div> arr.enumerateObjectsUsingBlock(@myenumerate);</div><div>end.</div></div><div><br></div><div>thanks,<br></div><div>Dmitry</div><div><br></div></div></div></div>