From fcda9c6a208d3a7fe651ef661b2eb6e462a89c17 Mon Sep 17 00:00:00 2001 From: Eneas U de Queiroz Date: Tue, 31 Jul 2018 17:44:57 -0300 Subject: [PATCH] CMake: use find_package (SWIG) for cmake >= 3.0.0 There's a workaround for a bug (fixed in cmake 3.0.0) that does not work in CMake 3.12. Only use the workaround with cmake < 3.0.0. Signed-off-by: Eneas U de Queiroz --- python/CMakeLists.txt | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 4843396..7bdd9f9 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -3,7 +3,7 @@ if ( PYTHON_BINDINGS ) # workaround for cmake bug #0013449 - if ( NOT DEFINED CMAKE_FIND_ROOT_PATH ) + if ( NOT DEFINED CMAKE_FIND_ROOT_PATH OR CMAKE_VERSION VERSION_GREATER_EQUAL 3.0.0 ) find_package ( SWIG ) else () find_program ( SWIG_EXECUTABLE NAMES swig2.0 swig ) -- 1.7.1 From bfbd47b7de65aa41c433945283d7bc0ebfa5576a Mon Sep 17 00:00:00 2001 From: Jordan Rupprecht Date: Thu, 20 Sep 2018 11:05:56 -0700 Subject: [PATCH] Use a separate Py_ssize_t var instead of casting an int pointer as a Py_ssize_t pointer. Casting is fine if Py_ssize_t == int, but not when Py_ssize_t == long. Signed-off-by: Jordan Rupprecht --- python/ftdi1.i | 6 ++++-- 1 files 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_; } %} -- 1.7.1 From 3eca5150db07262c1c6eb737e12149201f631d47 Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Tue, 6 Aug 2019 13:42:06 +0200 Subject: [PATCH] swig: python: fix unresolved symbol issue GCC later than 5.x produce _fdti1.so file with an undefined symbol str2charp_size due to C99 inline semantics change. So remove this keyword. Signed-off-by: Yegor Yefremov --- python/ftdi1.i | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/python/ftdi1.i b/python/ftdi1.i index d53ebb0..f397f84 100644 --- a/python/ftdi1.i +++ b/python/ftdi1.i @@ -19,7 +19,7 @@ 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; -- 1.7.1 From e6478214f57dc20aeee7fbaa6b44af86f9bfb3fa Mon Sep 17 00:00:00 2001 From: Yegor Yefremov Date: Thu, 22 Aug 2019 15:47:06 +0200 Subject: [PATCH] swig: improve indentation Fixes -Wmisleading-indentation warnings. --- python/ftdi1.i | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-) diff --git a/python/ftdi1.i b/python/ftdi1.i index f397f84..8b179f9 100644 --- a/python/ftdi1.i +++ b/python/ftdi1.i @@ -92,7 +92,12 @@ 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); @@ -132,7 +137,12 @@ 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); -- 1.7.1 From 41871ae234838d2540fc4297295fbec71f57067d Mon Sep 17 00:00:00 2001 From: Richard Shaw Date: Mon, 18 Feb 2019 19:42:30 +0100 Subject: [PATCH] CMake/Swig updates for python wrapper libftdi was FTBFS[1] in Fedora Rawhide after a GCC 9.0.X mass rebuild but the problem turned out to be behavior changes[2] in CMake with regards to SWIG[3]. The UseSWIG module in cmake 3.13+ will now use standard target names and not generate the SWIG_MODULE__REAL_NAME variable. Replace the deprecated swig_add_module with swig_add_library. [Refinements from Intra2net: - Use swig_add_library for cmake 3.8+ only - Add cmake version guard for the new CMP0078 policy - Use "NOT CMAKE_VERSION VERSION_LESS" construct to support cmake versions below 3.7.0] [1] https://bugzilla.redhat.com/show_bug.cgi?id=1675275 [2] https://cmake.org/cmake/help/latest/policy/CMP0078.html?highlight=cmp0078 [3] https://cmake.org/cmake/help/latest/module/UseSWIG.html --- python/CMakeLists.txt | 12 +++++++++++- 1 files changed, 11 insertions(+), 1 deletions(-) diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 376dae6..494f6ff 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -2,6 +2,12 @@ option ( LINK_PYTHON_LIBRARY "Link against python libraries" ON ) if ( PYTHON_BINDINGS ) + # swig_add_library behavior changed in cmake 3.13 and SWIG_MODULE__REAL_NAME + # is no longer set by default so set policy to the old behavior. + if(NOT CMAKE_VERSION VERSION_LESS 3.13.0) + cmake_policy(SET CMP0078 OLD) + endif () + # workaround for cmake bug #0013449 if ( NOT DEFINED CMAKE_FIND_ROOT_PATH OR CMAKE_VERSION VERSION_GREATER_EQUAL 3.0.0 ) find_package ( SWIG ) @@ -25,7 +31,11 @@ link_directories ( ${CMAKE_CURRENT_BINARY_DIR}/../src ) if ( DOCUMENTATION AND DOXYGEN_FOUND ) set(CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND}) endif() - swig_add_module ( ftdi1 python ftdi1.i ) + if(NOT CMAKE_VERSION VERSION_LESS 3.8.0) + swig_add_library ( ftdi1 LANGUAGE python SOURCES ftdi1.i ) + else () + swig_add_module ( ftdi1 python ftdi1.i ) + endif() swig_link_libraries ( ftdi1 ftdi1 ) if ( LINK_PYTHON_LIBRARY ) -- 1.7.1