X-Git-Url: http://developer.intra2net.com/git/?p=libftdi;a=blobdiff_plain;f=python%2Fftdi1.i;h=8b179f98fa104bf026eef56057616cc62c0218f9;hp=93793f802df8825f8967d2b54988933f17a3a9c9;hb=e6478214f57dc20aeee7fbaa6b44af86f9bfb3fa;hpb=b829fe92a5a283744daee3f689e58729ae930967 diff --git a/python/ftdi1.i b/python/ftdi1.i index 93793f8..8b179f9 100644 --- a/python/ftdi1.i +++ b/python/ftdi1.i @@ -19,14 +19,16 @@ inline PyObject* charp2str(const char *v_, long len) #endif } -inline char * str2charp_size(PyObject* pyObj, int * size) +char * str2charp_size(PyObject* pyObj, int * size) { char * v_ = 0; + Py_ssize_t len = 0; #if PY_MAJOR_VERSION >= 3 - PyBytes_AsStringAndSize(pyObj, &v_, (Py_ssize_t*)size); + PyBytes_AsStringAndSize(pyObj, &v_, &len); #else - PyString_AsStringAndSize(pyObj, &v_, (Py_ssize_t*)size); + PyString_AsStringAndSize(pyObj, &v_, &len); #endif + *size = len; return v_; } %} @@ -90,7 +92,12 @@ inline char * str2charp_size(PyObject* pyObj, int * size) %enddef %feature("autodoc", ftdi_read_data_docstring) ftdi_read_data; %typemap(in,numinputs=1) (unsigned char *buf, int size) %{ $2 = PyInt_AsLong($input);$1 = (unsigned char*)malloc($2*sizeof(char)); %} -%typemap(argout) (unsigned char *buf, int size) %{ if(result<0) $2=0; $result = SWIG_Python_AppendOutput($result, charp2str((char*)$1, $2)); free($1); %} +%typemap(argout) (unsigned char *buf, int size) %{ + if(result<0) + $2=0; + $result = SWIG_Python_AppendOutput($result, charp2str((char*)$1, $2)); + free($1); +%} int ftdi_read_data(struct ftdi_context *ftdi, unsigned char *buf, int size); %clear (unsigned char *buf, int size); @@ -130,7 +137,12 @@ inline char * str2charp_size(PyObject* pyObj, int * size) %clear int* value; %typemap(in,numinputs=1) (unsigned char *buf, int size) %{ $2 = PyInt_AsLong($input);$1 = (unsigned char*)malloc($2*sizeof(char)); %} -%typemap(argout) (unsigned char *buf, int size) %{ if(result<0) $2=0; $result = SWIG_Python_AppendOutput($result, charp2str((char*)$1, $2)); free($1); %} +%typemap(argout) (unsigned char *buf, int size) %{ + if(result<0) + $2=0; + $result = SWIG_Python_AppendOutput($result, charp2str((char*)$1, $2)); + free($1); +%} int ftdi_get_eeprom_buf(struct ftdi_context *ftdi, unsigned char * buf, int size); %clear (unsigned char *buf, int size);