set-block-handlers are causing AV
Original Reporter info from Mantis: skalogryyz
-
Reporter name: Dmitry Boyarintsev
Original Reporter info from Mantis: skalogryyz
- Reporter name: Dmitry Boyarintsev
Description:
passing blocks as handler functions (callbacks) (not to be called immediately) are causing access violations.
Additional information:
program blocky;
{$mode delphi}
{$modeswitch objectivec1}
{$modeswitch cblocks}
{$linkframework Cocoa}
uses
CocoaAll;
type
readabilityHandler = reference to procedure (f: NSFileHandle); cdecl;
{ these methods were introduced in OSX 10.7
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSFileHandle_Class/#//apple_ref/occ/instp/NSFileHandle/availableData
}
NFFileHandleOSX107 = objccategory external (NSFileHandle)
procedure setReadabilityHandler(ahandler: readabilityHandler); message 'setReadabilityHandler:';
function readabilityHandler: readabilityHandler; message 'readabilityHandler';
end;
procedure MyHandler(f: NSFileHandle);
begin
writeln('ready to read!');
end;
var
hf: NSFileHandle;
path : NSString;
s: ansistring;
begin
if ParamCount=0 then begin
writeln('please give a path');
exit;
end;
s:=ParamStr(1);
path:=NSSTR(@s[1]);
hf:=NSFileHandle(NSFileHandle.fileHandleForReadingAtPath(path));
if not Assigned(hf) then begin
writeln('failed to open ', s,' for reading');
Exit;
end;
writeln('bytes available: ', hf.availableData.length);
writeln('setting handler');
// this line is causing AV (for x86_64)
hf.setReadabilityHandler(@MyHandler);
writeln('handler set!');
hf.closeFile;
hf.release;
writelN('done');
end.
Mantis conversion info:
- Mantis ID: 30022
- Version: 3.1.1
- Fixed in version: 3.1.1
- Fixed in revision: 33529 (#f50dec52)