1

Just starting to dig into SIP. I have a .h file that contains the following public method:

void Allocate(int width, int height, int pitch, bool withHost, float *devMem = NULL, float* hostMem = NULL); 

I have created a corresponding .sip file:

  1 //SIP wrapper for CUDA Image
  2
  3 class CudaImage
  4 {
  5 %TypeHeaderCode
  6 #include "cudaImage.h"
  7 %End
  8
  9   public:
 10     CudaImage();
 11
 12     void Allocate(int width, int height, int pitch, bool withHost, float *devMem=NULL, float *hostMem=NULL) /KeywordArgs="All"/;
 13     double Download();
 14
 15
 16     int width;
 17     int height;
 18     int pitch;
 19 };

Using CMake, I have the build working, can import the module into Python and can call the constructor (so limited success). I can also call the Allocate method. Unfortunately, on the Python side, I can not get the float *devMem=NULL or float *hostMem=Null arguments exposed. I have been over the SIP documentation and no Annotations are leaping out as missing.

The ultimate goal is to pass a numpy array (.data attribute I believe) to the hostMem argument.

How does one go about exposing pointers in SIP? What about pointers with a default, NULL, argument?

(Python 3.5, PyQt4, SIP 4.18.x)

Jzl5325
  • 3,898
  • 8
  • 42
  • 62

2 Answers2

0

I've gotten around this using ctypes.POINTER

https://docs.python.org/3/library/ctypes.html#ctypes.POINTER

You can pass in None for a NULL pointer.

dragonx
  • 14,963
  • 27
  • 44
0

You could try "/In/" annotation:

void Allocate(int width, int height, int pitch, bool withHost, float* devMem /In/ = NULL, SIP_PYOBJECT *hostMem /In/ = NULL) /KeywordArgs="All"/;

Please let me know if it works.

seifer_08ms
  • 375
  • 5
  • 17