[anaphora-devel] Python embedded API and passing arrays with CFFI

Jeremy Smith jeremy at decompiler.org
Mon Jan 30 19:50:24 UTC 2006


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CFFIPythonDLL.lisp
Type: application/x-unknown-content-type-acl.file
Size: 2829 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/cffi-devel/attachments/20060130/d537823d/attachment.bin>


More information about the cffi-devel mailing list