libftdi Archives

Subject: Re: [PATCH] Add missing argument to Python read_data docstring

From: Thomas Jarosch <thomas.jarosch@xxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx, Kevin Zheng <kevinz5000@xxxxxxxxx>
Cc: Michel Zou <xantares09@xxxxxxxxxxx>
Date: Tue, 6 Feb 2018 21:07:24 +0100
Hi Kevin,

On 01/25/2018 03:31 AM, Kevin Zheng wrote:
> I think the docstring for the Python read_data wrapper is missing an
> argument. Is this patch correct?
> 
> ---
>  python/ftdi1.i | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/python/ftdi1.i b/python/ftdi1.i
> index 93793f8..4f4c522 100644
> --- a/python/ftdi1.i
> +++ b/python/ftdi1.i
> @@ -86,7 +86,7 @@ inline char * str2charp_size(PyObject* pyObj, int * size)
>  %clear int mnf_len, int desc_len, int product_len, int serial_len;
>   %define ftdi_read_data_docstring
> -"read_data(context) -> (return_code, buf)"
> +"read_data(context, len) -> (return_code, buf)"
>  %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)); %}
> 

Thanks for the patch. I guess there is more funny stuff
going on with the python wrapper. The generated function for
read_data() and write_data() look like this with SWIG 3.2.0:

***build/python/ftdi1.py*********
def read_data(ftdi, buf):
    """read_data(context, len) -> (return_code, buf)"""
    return _ftdi1.read_data(ftdi, buf)

def write_data(ftdi, buf):
    """write_data(context, data) -> return_code"""
    return _ftdi1.write_data(ftdi, buf)
*********************************

I have no idea how the "len" argument is passed to the
_ftdi1.read_data() function. I tried to read the generated
SWIG code for 30 minutes but I didn't figure out how it works.

OTOH the python code for write_data_submit looks like this

*********************************
def write_data_submit(ftdi, buf, size):
    return _ftdi1.write_data_submit(ftdi, buf, size)
*********************************

-> it correctly passes on the "len" argument.


@Michel: Can you take a quick look at this, pretty please?


Also we probably should check the result of malloc()
in the custom SWIG typemap code, that's for sure.

Cheers,
Thomas

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

Current Thread