I am currently writing a Python module using python4delphi. I would like to use the standard C API Function PyArg_ParseTupleAndKeywords.
As you can see from the documentation the signature is so:
int PyArg_ParseTupleAndKeywords(PyObject *args, PyObject *kw, const char *format,
char *keywords[], ...)
Now this function is not wrapped in python4delphi so I've added it by myself:
PyArg_ParseTupleAndKeywords: function (args, kw: PPyObject; format: PAnsiChar;
keywords: array of PAnsiChar {;...}): Integer; cdecl varargs;
....
PyArg_ParseTupleAndKeywords := Import('PyArg_ParseTupleAndKeywords');
The problem I have is that I am getting an access violation error when I try to use it in way similar to this snippet:
function PyScript_MyFunction(pself, args, keywds : PPyObject) : PPyObject; cdecl;
var
AAA, BBB : PChar;
kwlist : array[0..2] of PAnsiChar;
begin
kwlist[0] := 'AAA';
kwlist[1] := 'BBB';
kwlist[2] := nil;
BBB := 'BBB';
with GetPythonEngine do
begin
if (PyErr_Occurred() = nil) and (PyArg_ParseTupleAndKeywords(args, keywds,
's|s:Script_MyFunction', kwlist, @AAA, @BBB) <> 0) then
begin
Result := VariantAsPyObject(MyFunction(AAA, BBB));
end
else
Result := nil;
end;
end;
//Module is my Python module I am working with
Module.AddMethodWithKeywords('Wrapped', @PyScript_MyFunction, 'no doc');
How can I fix this? Is there a way to debug such kind of errors?