1

刚刚开始深入研究 SIP。我有一个 .h 文件,其中包含以下公共方法:

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

我创建了一个相应的 .sip 文件:

  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 };

使用 CMake,我可以构建工作,可以将模块导入 Python 并可以调用构造函数(成功有限)。我也可以调用 Allocate 方法。不幸的是,在 Python 方面,我无法暴露float *devMem=NULLorfloat *hostMem=Null参数。我已经浏览过 SIP 文档,并且没有任何注释因为缺失而跳出来。

最终目标是将一个numpy数组(我相信.data属性)传递给hostMem参数。

如何在 SIP 中公开指针?带有默认 NULL 参数的指针呢?

(Python 3.5、PyQt4、SIP 4.18.x)

4

2 回答 2

0

您可以尝试“/In/”注释:

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

请让我知道它是否有效。

于 2017-12-14T05:43:51.927 回答
0

我已经使用 ctypes.POINTER 解决了这个问题

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

您可以为 NULL 指针传入 None 。

于 2016-09-30T21:30:39.650 回答