libftdi Archives

Subject: Re: SWIG: Python: compiler warnings

From: Yegor Yefremov <yegorslists@xxxxxxxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Tue, 6 Aug 2019 11:43:16 +0200
On Tue, Aug 6, 2019 at 10:43 AM Thomas Jarosch
<thomas.jarosch@xxxxxxxxxxxxx> wrote:
>
> Hi Yegor,
>
> You wrote on Mon, Aug 05, 2019 at 03:46:16PM +0200:
> > I get following compiler warnings when compiling libftdi Python
> > bindings with gcc version 8.3.0 (Ubuntu 8.3.0-6ubuntu1):
> >
> > Scanning dependencies of target _ftdi1
> > [ 22%] Building C object
> > python/CMakeFiles/_ftdi1.dir/CMakeFiles/_ftdi1.dir/ftdi1PYTHON_wrap.c.o
> > /home/user/Documents/versioned/libftdi/build/python/CMakeFiles/_ftdi1.dir/ftdi1PYTHON_wrap.c:
> > In function ‘_wrap_read_data’:
> > /home/user/Documents/versioned/libftdi/build/python/CMakeFiles/_ftdi1.dir/ftdi1PYTHON_wrap.c:3842:3:
> > warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
> >    if(result<0) arg3=0; resultobj =
> > SWIG_Python_AppendOutput(resultobj, charp2str((char*)arg2, arg3));
> > free(arg2);
> >    ^~
> > /home/user/Documents/versioned/libftdi/build/python/CMakeFiles/_ftdi1.dir/ftdi1PYTHON_wrap.c:3842:24:
> > note: ...this statement, but the latter is misleadingly indented as if
> > it were guarded by the ‘if’
> >    if(result<0) arg3=0; resultobj =
> > SWIG_Python_AppendOutput(resultobj, charp2str((char*)arg2, arg3));
> > free(arg2);
> >                         ^~~~~~~~~
> > /home/user/Documents/versioned/libftdi/build/python/CMakeFiles/_ftdi1.dir/ftdi1PYTHON_wrap.c:
> > In function ‘_wrap_get_eeprom_buf’:
> > /home/user/Documents/versioned/libftdi/build/python/CMakeFiles/_ftdi1.dir/ftdi1PYTHON_wrap.c:4084:3:
> > warning: this ‘if’ clause does not guard... [-Wmisleading-indentation]
> >    if(result<0) arg3=0; resultobj =
> > SWIG_Python_AppendOutput(resultobj, charp2str((char*)arg2, arg3));
> > free(arg2);
> >    ^~
> > /home/user/Documents/versioned/libftdi/build/python/CMakeFiles/_ftdi1.dir/ftdi1PYTHON_wrap.c:4084:24:
> > note: ...this statement, but the latter is misleadingly indented as if
> > it were guarded by the ‘if’
> >    if(result<0) arg3=0; resultobj =
> > SWIG_Python_AppendOutput(resultobj, charp2str((char*)arg2, arg3));
> > free(arg2);
> >                         ^~~~~~~~~
> >
> > The code looking wired indeed i.e. either without parenthesis or 
> > indentation.
>
> indeed, this auto-generated code looks very hard to read. May be there is an
> option in SWIG to output "beautified" code, it will be the same on the machine
> level anyway.
>
> I also quickly grepped for "charp2":
>     ftdi1.i:inline PyObject* charp2str(const char *v_, long len)
>
> so it should be in the generated code.

The code in question is not auto-generated. It is part of the python.ftdi1.i.

%typemap(argout) (unsigned char *buf, int size) %{ if(result<0) $2=0;
$result = SWIG_Python_AppendOutput($result, charp2str((char*)$1, $2));
free($1); %}

> On a different note, I'm back in libftdi business after guiding a mass scale
> kernel upgrade from 3.14 to 4.19 on way too many different machines.
> Let's try to put out a libftdi release in August finally.

This would be great!

Btw I have an issue, I mentioned in this e-mail [1]. Are you using buildroot?

So far I could find a qemu target in buildroot where I can easily
change the compiler and test whether I can import ftdi1. So far I have
following combinations:

GCC 7.x external toolchain: failure
GCC 8x built via buildroot: failure
GCC 5.x built via buildroot: OK

Buildroot uses SWIG 3.0.12.

A defconfig for the failed import:

BR2_arm=y
BR2_cortex_a9=y
BR2_ARM_ENABLE_NEON=y
BR2_ARM_ENABLE_VFP=y
BR2_TOOLCHAIN_EXTERNAL=y
BR2_TOOLCHAIN_EXTERNAL_LINARO_ARM=y
BR2_TARGET_GENERIC_GETTY_PORT="ttyAMA0"
BR2_SYSTEM_DHCP="eth0"
BR2_LINUX_KERNEL=y
BR2_LINUX_KERNEL_CUSTOM_VERSION=y
BR2_LINUX_KERNEL_CUSTOM_VERSION_VALUE="4.19.16"
BR2_LINUX_KERNEL_DEFCONFIG="vexpress"
BR2_LINUX_KERNEL_DTS_SUPPORT=y
BR2_LINUX_KERNEL_INTREE_DTS_NAME="vexpress-v2p-ca9"
BR2_PACKAGE_PYTHON=y
BR2_PACKAGE_LIBFTDI1=y
BR2_PACKAGE_LIBFTDI1_PYTHON_BINDINGS=y
BR2_TARGET_ROOTFS_EXT2=y
# BR2_TARGET_ROOTFS_TAR is not set
BR2_PACKAGE_HOST_QEMU=y
BR2_PACKAGE_HOST_QEMU_SYSTEM_MODE=y

[1] http://developer.intra2net.com/mailarchive/html/libftdi/2019/msg00038.html

Cheers,
Yegor

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

Current Thread