Hi folks,
I'm trying to interface Python to Lisp using the official embedded API.
One aspect of this is that you can setup callback functions to pass data
from Python to Lisp.
Here's an example of a module (defined in C) containing such functions,
mapping a Python function name to the pointer:
static PyMethodDef ZZMethods[] = {
{"copy_webpage",emb_copy_webpage,METH_VARARGS, "copy_webpage"},
{NULL, NULL, 0, NULL}};
This structure is passed to Python with this command:
Py_InitModule("ltzz", ZZMethods);
It is an array of this structure:
struct PyMethodDef {
char *ml_name;
PyCFunction ml_meth;
int ml_flags;
char *ml_doc;
};
typedef struct PyMethodDef PyMethodDef;
Enclosed is the Lisp code that is my attempt at expressing this
structure, but when I try and run the function testlispy, it crashes out
with this message:
[6]> (testlispy)
If you can see this, Python is loaded and working
#<FOREIGN-ADDRESS #x0022B030>
#<FOREIGN-ADDRESS #x0022B030>
#<FOREIGN-ADDRESS #x0022B040>
#<FOREIGN-ADDRESS #x0022B050> C:\Python22\Lib\types.py:52: Warning:
'yield' will become a reserved keyword in the future
warning: Python C API version mismatch for module Methods: This Python
has API version 1011, module Methods has version 1003.
*** - handle_fault error2 ! address = 0x1 not in [0x19d70000,0x19ed27e8)
!
SIGSEGV cannot be cured. Fault address = 0x1.
Permanently allocated: 92032 bytes.
Currently in use: 2346812 bytes.
Free space: 426556 bytes.
Am I on the right lines, and if not, where have I gone wrong? I think
I've misunderstood the documentation regarding arrays of structures, but
because Clisp has no proper debugging environment, the only way to test
it out is to make a DLL and pass it a structure. Therefore, it's easier
to post to cffi-devel.
By the way, this project is for the Lisp community to use Python library
code in their Lisp programs, which would be useful to me at least, so
I'm not asking for help with a commercial project.
Thanks for any help,
Jeremy.
--
| Jeremy Smith BSc (Hons)
| Chief Scientist, Decompiler Technologies
| Member, British Computer Society
| England