libftdi Archives

Subject: RE: ftdi.write_data doesn’t work with some python3 unicode strings

From: Michel Zou <xantares09@xxxxxxxxxxx>
To: "libftdi@xxxxxxxxxxxxxxxxxxxxxxx" <libftdi@xxxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 5 Nov 2015 15:13:52 +0000
Ok,

We'll have to cast to (Py_ssize_t*) then:

inline char * str2charp_size(PyObject* pyObj, int * size)
{
  char * v_ = 0;
#if PY_MAJOR_VERSION >= 3
  PyBytes_AsStringAndSize(pyObj, &v_, (Py_ssize_t*)size);
#else
  PyString_AsStringAndSize(pyObj, &v_, (Py_ssize_t*)size);
#endif
  return v_;
}


> From: thomas.jarosch@xxxxxxxxxxxxx
> To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
> CC: cbrackert@xxxx; xantares09@xxxxxxxxxxx
> Subject: Re: RE: ftdi.write_data doesn’t work with some python3 unicode strings
> Date: Thu, 5 Nov 2015 13:03:23 +0100
>
> On Wednesday, 4. November 2015 14:51:36 Chris Brackert wrote:
> > I have confirmed that the patch is also working with Python 2 for my code.
> > Thanks!
>
> thanks for testing, Chris!
>
> I do get a compiler warning though with the new code:
>
> libftdi/build/python/ftdi1PYTHON_wrap.c: In function ‘_wrap_write_data’:
> libftdi/build/python/ftdi1PYTHON_wrap.c:3618:47: warning: passing argument 2 of ‘str2charp_size’ from incompatible pointer type [-Wincompatible-pointer-types]
> arg2 = (unsigned char*)str2charp_size(obj1, &arg3);
> ^
> libftdi/build/python/ftdi1PYTHON_wrap.c:3010:15: note: expected ‘long int *’ but argument is of type ‘int *’
> inline char * str2charp_size(PyObject* pyObj, long * size)
>
> @xantares09: Should I just change the type to "int *size"?
>
> Thomas
>
>
> --
> libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
> To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx
>


libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx


Current Thread