[C++-sig] Wrapping classical C API for python access

Markus Schöpflin markus.schoepflin at comsoft.de
Mon Jun 27 16:30:20 CEST 2005


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?

TIA, Markus




More information about the Cplusplus-sig mailing list