(Meant to post in General board,!not freepascal —> General, sorry)
I struggle often with the correct placement of code, and I have a suspicion my latest problem relates to this.
I am using a more updated library that I recently managed to compile as a new DLL and code that I wrote to use the library from about 5 years ago (when FPC was probably v2 or early v3).
The function I am having a problem with is called the same in the DLL as it was 5 years ago, except there is now an additional error buffer in the function call. So I have updated the call structure in my code, accordingly. But, with the new DLL call, I get a seemingly undebuggable SIGSEGV error now, which, in my experience, usually means you are trying to access something that either does not exist (perhaps not created) or cannot be reached. The asembler window just show ??? everywhere
Would one of you mind looking at this stripped down version of the code from my library call, and see if you can see why or where the error is forming? I haven't included all the code because it is enormous and I suspect I have something in the wrong place. But I've tried to make sure the bits that matter are included. Note, however, that this code structure is largely unchanged from when I used it with the DLL compiled from the same (older) library of 5 years ago, and the only thing that is new that I can see is the use of @err in fLibEWFCheckSig which was added because the new library states that the C syntax is no longer just the filename, but also an error buffer (2 parameters, not 1):
.Ft int
.Fn libewf_check_file_signature "const char *filename" "libewf_error_t **error"
https://github.com/libyal/libewf/blob/57dfc1f510f08f34eb34452f6679c38185be9472/manuals/libewf.3#L26myunit
{$MODE Delphi}
interface
uses
...
type
TLibEWFCheckSig = function(filename : pansiChar; error:pointer) : integer; cdecl;
...
TLibEWF = class(TObject)
private
fLibHandle : TLibHandle;
fLibEWFCheckSig : TLibEWFCheckSig;
public
constructor create();
function libewf_check_file_signature(const filename : ansistring ) : integer;
...
const
...
implementation
...
begin
constructor TLibEWF.create();
...
if fLibHandle<>nilhandle then
begin
// _libewf_check_file_signature is from here : https://github.com/libyal/libewf/blob/57dfc1f510f08f34eb34452f6679c38185be9472/manuals/libewf.3#L26
@fLibEWFCheckSig :=GetProcAddress(fLibHandle,'_libewf_check_file_signature'); // Debugger shows OK and loaded
// lots more loaded
end;
end;
function TLibEWF.libewf_open(const filename : ansistring;flag:byte=$1) : integer;
begin
...
// Filename gets assigned to curFilename with some other code
while FileExists(curFilename) do
begin
if libewf_check_file_signature(curFilename)=1 then // Calls the check_file_signature function below
begin
filenames.Add(curFilename)
end
else break;
curFilename:=filenameRoot+'.E'+Format('%.2d',[filenames.Count+1]);
end;
...
end;
function TLibEWF.libewf_check_file_signature(const filename : ansistring) : integer; // Filename is showing correctly in debugger
var
err:pointer;
begin
Result:=0;
err := nil;
if fLibHandle<>0 then // Handle is showing as valid in debugger
begin
Result:=fLibEWFCheckSig(pansiChar(filename), @err); //SIGSEGV raised here. Can't walk into it.
end;
end;
I do wonder if the **error and my equivlanet FPC syntax of @err is correct? ** in C means "pointer to pointer" I think? So err : pointer declares "the pointer", and so "@err" means "pointer to the err pointer", which is equivalent of "**err" in C?