Re: Two questions

"Langer, Stephen A. \(Fed\) via Swig-user" <[email protected]> Tue, 31 May 2022 15:23:42 +0000
Newsgroups gmane.comp.programming.swig
Message-ID <[email protected]>
Hi William --

I'm using an iMac running macOS Big Sur 11.6.6.  All dependencies were installed with MacPorts.  I just figured out that the problem doesn't occur on Ubuntu 20.04.  I don't have access to other OS's.

I've attached a swig file and a cmake file, and the output from running cmake and make, with both swig 4.0.2 and 4.1.0 (from github).    The swig file just uses %inline to declare a simple function.  The same warning appears in both cases.

-- Steve

On 5/28/22, 4:39 AM, "William S Fulton" <[email protected]<mailto:[email protected]>> wrote:

For the pending 4.1.0 release we do have one change:

            [Python] Fix "too many initializers for 'PyHeapTypeObject'" errors
            using PyPy 3.8 and later.

but that is for PyPy not CPython. Try out master and if you still see the tp_print warnings, please put together a small testcase to demonstrate.

William

On Tue, 24 May 2022 at 23:23, Langer, Stephen A. (Fed) <[email protected]<mailto:[email protected]>> wrote:
Thanks for the response.   Using the tp_repr slot did just what I needed.

I still don't understand what's going on with the tp_print warnings, but I'm content to ignore them if that's what's recommended.  I am using swig 4.0.2, so shouldn't it be compatible with python 3.8?

-- Steve

On 5/20/22, 4:45 PM, "William S Fulton" <[email protected]<mailto:[email protected]>> wrote:

1. From the CHANGES file for swig-4.0.2:

2020-01-05: jschueller shadchin
            [Python] #1670 #1696 Add missing field initializers introduced in python 3.8:
            tp_vectorcall and tp_print.

2. Customise using slots with the "python:tp_repr" feature, see https://www.swig.org/Doc4.0/Python.html#Python_builtin_overloads<https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.swig.org%2FDoc4.0%2FPython.html%23Python_builtin_overloads&data=05%7C01%7Cstephen.langer%40nist.gov%7C20da5d4baa634781d41708da40859886%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C637893239791612972%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=EjXKcEltlUqhQfty2sojmo9wrTvfUIEv9cdDcj3BeEA%3D&reserved=0>.

William

On Fri, 29 Apr 2022 at 22:13, Langer, Stephen A. (Fed) via Swig-user <[email protected]<mailto:[email protected]>> wrote:
Hi --

I'm beginning to use Swig 4 on a project.  My previous experience was with Swig 1.1, so I have some catching up to do.  I'm generating python3 wrappers for C++.

The Swig web site says that Swig 4.0.1 added support for Python 3.8.  When I use Python 3.8, I get a lot of warnings that 'tp_print' is deprecated when compiling the _wrap.cxx files (using cmake on a Mac).  If I use Python 3.10, I don't get the warnings.  As far as I can tell, both versions work, but I'm confused.  Is 3.10 supported?  It looks like it's supported better than 3.8.  Or is the lack of warnings in 3.10 misleading?

My second question is how to override the default __repr__ for swigged classes.  With Swig 1.1 and Python 2.7, I could just monkey patch a new __repr__ in the python wrapper for the class.  With Swig 4, defining __repr__ in C++ or monkey patching it works only if I don't use -builtin.  If I do use -builtin, then monkey patching is forbidden and __repr__ defined in C++ is replaced by the generic SwigPyObject_repr.  Is it possible to redefine __repr__ for a swigged class when using -builtin?

Thanks.

 -- Steve




_______________________________________________
Swig-user mailing list
[email protected]<mailto:[email protected]>
https://lists.sourceforge.net/lists/listinfo/swig-user<https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.sourceforge.net%2Flists%2Flistinfo%2Fswig-user&data=05%7C01%7Cstephen.langer%40nist.gov%7C20da5d4baa634781d41708da40859886%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C637893239791612972%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=rGX%2Bxyk2zvewkCw9jyTFwIdrpM9g%2B6JwCjjdL77fDKQ%3D&reserved=0>

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user
CMakeLists.txt (text/plain, 560 B)
cmake_minimum_required(VERSION 3.16)
project(swigwarn VERSION 0.0.0)

include(FindSWIG)
include(UseSWIG)
find_package(SWIG 4.0 COMPONENTS python)
list(APPEND CMAKE_SWIG_FLAGS -py3)

find_package(Python3 3.8 EXACT COMPONENTS Interpreter Development)

set_property(
  SOURCE swigwarn.i
  PROPERTY CPLUSPLUS ON)
set_property(
  SOURCE swigwarn.i
  PROPERTY GENERATED_INCLUDE_DIRECTORIES
  ${Python3_INCLUDE_DIRS})
swig_add_library(
  swigwarn
  TYPE MODULE
  LANGUAGE PYTHON
  SOURCES swigwarn.i)
swig_link_libraries(
  swigwarn
  PUBLIC
  ${Python3_LIBRARIES})
swigwarn.i (application/octet-stream, 141 B) - not displayed
output40.txt (text/plain, 6.8 KB)
iolanthe 556>> mkdir build
iolanthe 557>> 
iolanthe 557>> cd build
iolanthe 558>> cmake ..
-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found SWIG: /opt/local/bin/swig (found version "4.0.2")  
-- Found SWIG: /opt/local/bin/swig (found suitable version "4.0.2", minimum required is "4.0") found components: python 
-- Found Python3: /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/bin/python3.8 (found suitable exact version "3.8.9") found components: Interpreter Development Development.Module Development.Embed 
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/langer/CMAKE/SWIGWARN/build
iolanthe 559>> make
Scanning dependencies of target swigwarn_swig_compilation
[ 33%] Swig compile swigwarn.i for python
[ 33%] Built target swigwarn_swig_compilation
[ 66%] Building CXX object CMakeFiles/swigwarn.dir/CMakeFiles/swigwarn.dir/swigwarnPYTHON_wrap.cxx.o
/Users/langer/CMAKE/SWIGWARN/build/CMakeFiles/swigwarn.dir/swigwarnPYTHON_wrap.cxx:1780:7: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
      0,                                    /* tp_print */
      ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
    Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
    ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                     ^
In file included from /Users/langer/CMAKE/SWIGWARN/build/CMakeFiles/swigwarn.dir/swigwarnPYTHON_wrap.cxx:178:
In file included from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/Python.h:85:
In file included from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/pytime.h:6:
In file included from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/object.h:746:
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/cpython/object.h:177:16: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
typedef struct _typeobject {
               ^
/Users/langer/CMAKE/SWIGWARN/build/CMakeFiles/swigwarn.dir/swigwarnPYTHON_wrap.cxx:1790:23: note: in implicit copy assignment operator for '_typeobject' first required here
    swigpyobject_type = tmp;
                      ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
    Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
    ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                     ^
In file included from /Users/langer/CMAKE/SWIGWARN/build/CMakeFiles/swigwarn.dir/swigwarnPYTHON_wrap.cxx:178:
In file included from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/Python.h:85:
In file included from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/pytime.h:6:
In file included from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/object.h:746:
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/cpython/object.h:177:16: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
typedef struct _typeobject {
               ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
    Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
    ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                     ^
/Users/langer/CMAKE/SWIGWARN/build/CMakeFiles/swigwarn.dir/swigwarnPYTHON_wrap.cxx:1947:7: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
      0,                                    /* tp_print */
      ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
    Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
    ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                     ^
/Users/langer/CMAKE/SWIGWARN/build/CMakeFiles/swigwarn.dir/swigwarnPYTHON_wrap.cxx:3251:9: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
        0,                                  /* tp_print */
        ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
    Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
    ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                     ^
5 warnings generated.
[100%] Linking CXX shared module _swigwarn.so
[100%] Built target swigwarn
iolanthe 560>>
output41.txt (text/plain, 6.8 KB)
iolanthe 573>> cmake ..
-- The C compiler identification is AppleClang 13.0.0.13000029
-- The CXX compiler identification is AppleClang 13.0.0.13000029
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found SWIG: /Users/langer/bin/swig (found version "4.1.0")  
-- Found SWIG: /Users/langer/bin/swig (found suitable version "4.1.0", minimum required is "4.0") found components: python 
-- Found Python3: /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/bin/python3.8 (found suitable exact version "3.8.9") found components: Interpreter Development Development.Module Development.Embed 
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/langer/CMAKE/SWIGWARN/build
iolanthe 574>> make
Scanning dependencies of target swigwarn_swig_compilation
[ 33%] Swig compile swigwarn.i for python
Deprecated command line option: -py3. Ignored, this option is no longer supported.
[ 33%] Built target swigwarn_swig_compilation
[ 66%] Building CXX object CMakeFiles/swigwarn.dir/CMakeFiles/swigwarn.dir/swigwarnPYTHON_wrap.cxx.o
/Users/langer/CMAKE/SWIGWARN/build/CMakeFiles/swigwarn.dir/swigwarnPYTHON_wrap.cxx:1482:7: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
      0,                                  /* tp_print */
      ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
    Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
    ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                     ^
In file included from /Users/langer/CMAKE/SWIGWARN/build/CMakeFiles/swigwarn.dir/swigwarnPYTHON_wrap.cxx:196:
In file included from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/Python.h:85:
In file included from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/pytime.h:6:
In file included from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/object.h:746:
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/cpython/object.h:177:16: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
typedef struct _typeobject {
               ^
/Users/langer/CMAKE/SWIGWARN/build/CMakeFiles/swigwarn.dir/swigwarnPYTHON_wrap.cxx:1492:18: note: in implicit copy assignment operator for '_typeobject' first required here
    varlink_type = tmp;
                 ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
    Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
    ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                     ^
In file included from /Users/langer/CMAKE/SWIGWARN/build/CMakeFiles/swigwarn.dir/swigwarnPYTHON_wrap.cxx:196:
In file included from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/Python.h:85:
In file included from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/pytime.h:6:
In file included from /Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/object.h:746:
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/cpython/object.h:177:16: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
typedef struct _typeobject {
               ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
    Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
    ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                     ^
/Users/langer/CMAKE/SWIGWARN/build/CMakeFiles/swigwarn.dir/swigwarnPYTHON_wrap.cxx:2075:7: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
      0,                                    /* tp_print */
      ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
    Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
    ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                     ^
/Users/langer/CMAKE/SWIGWARN/build/CMakeFiles/swigwarn.dir/swigwarnPYTHON_wrap.cxx:2255:7: warning: 'tp_print' is deprecated [-Wdeprecated-declarations]
      0,                                    /* tp_print */
      ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/cpython/object.h:260:5: note: 'tp_print' has been explicitly marked deprecated here
    Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
    ^
/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.8/include/python3.8/pyport.h:515:54: note: expanded from macro 'Py_DEPRECATED'
#define Py_DEPRECATED(VERSION_UNUSED) __attribute__((__deprecated__))
                                                     ^
5 warnings generated.
[100%] Linking CXX shared module _swigwarn.so
[100%] Built target swigwarn