wrapping a function with "unsigned short*" return type

Asked by René Fritze

Hi.
I'm trying to wrap this function using the gccxmlparser (using pybindgen 0.15):
unsigned short* GetMinimap(const char* fileName, int mipLevel);
but I get a TypeLookupError(['short unsigned int *'],) error.
I've tried various permutations of the return type in the header itself and tried to add type alias in the generator script, to no avail.
The full output:
INFO Parsing source file "unitsync_api.h" ...
INFO gccxml cmd: /usr/bin/gccxml -I"." -I"/share/projekte/spring/engine_git/rts" "unitsync_api.h" -fxml="/tmp/tmpuJN6YS.xml"
INFO GCCXML version - 0.9
/usr/lib/pymodules/python2.7/pygccxml/parser/scanner.py:337: UserWarning: unable to find out array size from expression ""
  warnings.warn( msg )
/share/projekte/spring/engine_git/tools/unitsync/unitsync_api.h:451: WrapperWarning: Return value 'short unsigned int *' error (used in extern short unsigned int * GetMinimap(char const * fileName, int mipLevel) [free function]): TypeLookupError(['short unsigned int *'],)
  EXPORT(unsigned short*) GetMinimap(const char* fileName, int mipLevel);

The header is at https://github.com/renemilk/spring/blob/usync_python/tools/unitsync/unitsync_api.h
and the generator script at https://github.com/renemilk/spring/blob/usync_python/tools/unitsync/binding_generator.py

Is there a way to resolve this?

Question information

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

This type is not wrapped. I can't even begin to know how to wrap it, it is too ambiguous type...
What are you supposed to do with the returned pointer? Can you give examples of the type of things you do with the pointer, what you do now in C and also what you'd expect to be like in Python?

Revision history for this message
René Fritze (renemilk) said :
#2

Example where m_get_minimap is the imported function pointer to the function in question:
https://github.com/renemilk/springlobby/blob/master/src/springunitsynclib.cpp#L736

Basically the library holds a static unsigned short imgbuf[1024*1024] and returns the associated pointer with each call to GetMinimap. I as the caller know from the int mipLevel input argument how much of the data is of interest for me. Each element is a 16bit RGB-565 color value.

From python I would want to be able to iterate over a given range and process the data 'behin' the poitner into something I can work with further, much like in c++ example usage.

Revision history for this message
Best Gustavo Carneiro (gjc) said :
#3

I feel your use case is a bit specific, so I just added an example with more or less what you want:

http://bazaar.launchpad.net/~gjc/pybindgen/trunk/revision/788

The only data type in python that supports this is the buffer object [1]. It lets you modify a memory buffer. But it works in bytes, not unsigned short, so you have to do some work. But I don't think there's any other builtin python type that supports this. If I converted to a Python list, you would be working on a copy of the buffer: changes on the list elements would not be reflected back in the original buffer.

[1] http://docs.python.org/c-api/buffer.html#PyBuffer_FromReadWriteMemory

Revision history for this message
René Fritze (renemilk) said :
#4

Thank you very much! I was able to incorporate that example into my generator.

Revision history for this message
René Fritze (renemilk) said :
#5

Thanks Gustavo Carneiro, that solved my question.