libftdi Archives

Subject: Re: [PATCH] Use a separate Py_ssize_t var instead of casting an int pointer as a Py_ssize_t pointer.

From: Jordan Rupprecht <rupprecht@xxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Tue, 2 Oct 2018 14:04:06 -0700
Ping -- does anyone have time to take a look at this patch/merge it in
to master if it looks good?

On Thu, Sep 20, 2018 at 11:06 AM Jordan Rupprecht <rupprecht@xxxxxxxxxx> wrote:
>
> Casting is fine if Py_ssize_t == int, but not when Py_ssize_t == long.
>
> Signed-off-by: Jordan Rupprecht <rupprecht@xxxxxxxxxx>
> ---
>  python/ftdi1.i | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/python/ftdi1.i b/python/ftdi1.i
> index 93793f8..d53ebb0 100644
> --- a/python/ftdi1.i
> +++ b/python/ftdi1.i
> @@ -22,11 +22,13 @@ inline PyObject* charp2str(const char *v_, long len)
>  inline 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_;
>  }
>  %}
> --
> 2.19.0.444.g18242da7ef-goog
>

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

Current Thread