[C++-sig] Wrapping classical C API for python access
Mike Rovner
mrovner at propel.com
Mon Jun 27 21:52:25 CEST 2005
I'd consider pyrex.
Petrucio wrote:
> From my experience on trying to export a similar API, SWIG has been a more
> feasible solution to do this job.
>
> It has pre made typemaps that help you do just that:
> http://www.swig.org/Doc1.3/Arguments.html
>
> At 12:19 27/6/2005, you wrote:
>
>>Markus Schöpflin <markus.schoepflin at comsoft.de> writes:
>>
>>
>>>I'm currently in the process of evaluating how feasible it would be to use
>>>boost.python to expose a classical C API to python.
>>>
>>>By classical C API I mean that most arguments are passed around as
>>
>>pointers
>>
>>>(both in and out), and nearly every function has an int return value for
>>>the error code.
>>>
>>>How do I deal with functions using pointers as out parameters? Given, for
>>>example, the function "int test(char const *s, int *p)" where p is an out
>>>parameter, I can easily wrap it with BP using test("foo", foo).
>>>
>>>But when trying to call this function from python, I keep getting the
>>>following error:
>>>
>>> >>> a = int(0)
>>> >>> print test("foo", a)
>>>Traceback (most recent call last):
>>> File "<stdin>", line 1, in ?
>>>Boost.Python.ArgumentError: Python argument types in
>>> pyubss.test(str, int)
>>>did not match C++ signature:
>>> test(char*, int*)
>>>
>>>So how do I specify that p is an out parameter? How do I have to call the
>>>function in Python? Is it possible?
>>
>>Decide what interface you'd like to see in Python; that's your first
>>step.
>>
>> http://article.gmane.org/gmane.comp.python.c++/964
>>
>>might give you an idea.
>>
>>--
>>Dave Abrahams
>>Boost Consulting
>>www.boost-consulting.com
>>
>>_______________________________________________
>>C++-sig mailing list
>>C++-sig at python.org
>>http://mail.python.org/mailman/listinfo/c++-si
>
> g
More information about the Cplusplus-sig
mailing list