typedef and pointer to pointer with pybindgen

Asked by Fabio C. Barrionuevo

I was trying to create a wrapper for these headers [1][2] that provides access to a functions of a proprietary library, however I did not find on pybindgen documentation how to handle with the typedef and pointer to pointer (**).

this is possible with the pybindgen or is outside the scope of this project?

[1] https://github.com/fabiocerqueira/nbio/tree/master/include
[2] https://github.com/luzfcb/nbio-python-wrapper-tests

--
PT-BR

Eu estava tentando criar um wrapper para estes headers[1][2] que fornecem acesso a uma série de funções de uma biblioteca proprietária, no entanto eu não encontrei na documentação pybindgen como lidar com o typedef e ponteiro para ponteiro (**).

isso é possivel com o pybindgen ou está fora do escopo deste projeto?

[1] https://github.com/fabiocerqueira/nbio/tree/master/include
[2] https://github.com/luzfcb/nbio-python-wrapper-tests

Question information

Language:
English Edit question
Status:
Answered
For:
PyBindGen Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Gustavo Carneiro (gjc) said :
#1

I'm afraid pointer-to-pointer is out of scope in PBG.

Something like

  void foo (bar_t **param)

probably means that param is OUT or IN/OUT parameter. You should just manually wrap the specific methods that require this type. For an example of manually wrapping see:

 - http://code.nsnam.org/ns-3.20/file/5f2f0408cdc0/src/core/bindings/modulegen_customizations.py#l83
 - http://code.nsnam.org/ns-3.20/file/5f2f0408cdc0/src/core/bindings/module_helpers.cc#l76

Basically, you write a normal Python wrapper, using the Python C API (for examples see the code that PBG generates for other methods). The wrapper is a standard Python wrapper except for one small modification that PBG requires in order to support overloading: the wrapper takes an additional "PyObject **return_exception" parameter. In case parsing of the parameters fails, you should set *return_exception parameter to be the exception raised during parameter parsing failure. In a normal Python wrapper you would normally do something like this:

   if (!PyArg_ParseTupleAndKeywords (args, kwargs, (char *) "s#", (char **) keywords, &name, &name_len)) {
       return NULL;
    }

In PBG, you modify it to fetch the exception and store it in the return_exception parameter:

   if (!PyArg_ParseTupleAndKeywords (args, kwargs, (char *) "s#", (char **) keywords, &name, &name_len)) {
       PyObject *exc_type, *traceback;
       PyErr_Fetch (&exc_type, return_exception, &traceback);
       Py_XDECREF (exc_type);
       Py_XDECREF (traceback);
       return NULL;
     }

Can you help with this problem?

Provide an answer of your own, or ask Fabio C. Barrionuevo for more information if necessary.

To post a message you must log in.