Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PyObject_AsReadBuffer移植问题_Python_C_Porting - Fatal编程技术网

Python PyObject_AsReadBuffer移植问题

Python PyObject_AsReadBuffer移植问题,python,c,porting,Python,C,Porting,正如我们所知,PyObject_AsReadBuffer在版本2.5中发生了更改 在v2.4上,我们可以这样使用它 int bufferLength = 0; const void* buffer = NULL; PyObject_AsReadBuffer(pyObj, &buffer, &buffer_len); 但我必须这样修改它才能在v2.7上运行 Py_ssize_t bufferLength = 0; const void* buffer = NULL; PyObj

正如我们所知,PyObject_AsReadBuffer在版本2.5中发生了更改

在v2.4上,我们可以这样使用它

int bufferLength = 0;
const void* buffer = NULL;
PyObject_AsReadBuffer(pyObj, &buffer, &buffer_len); 
但我必须这样修改它才能在v2.7上运行

Py_ssize_t bufferLength = 0;
const void* buffer = NULL;
PyObject_AsReadBuffer(pyObj, &buffer, &buffer_len);

如果我想在v2.4和v2.7上运行它,我应该怎么做?

在include/python2.7/patchlevel.h中

#define PY_MAJOR_VERSION        2
#define PY_MINOR_VERSION        7
因此,我们可以使用PY_MAJOR_版本PY_MINOR_版本来比较版本