Commit graph

1,000 commits

Author SHA1 Message Date
William S Fulton
45f4b4d936 Merge branch 'python_subinterpreter_issues'
* python_subinterpreter_issues:
  added comment in CHANGES.current
  always get the type_pointer from capsule instead of using a static variable as the value may change after re-initilization/due to subinterpreters
  added interpreter_counter to deinitialize only once in case of subinterpreters

Conflicts:
	CHANGES.current
	Lib/python/pyrun.swg
2022-10-05 23:18:15 +01:00
William S Fulton
e97181ebc0 Add missing typecheck typemaps for std::auto_ptr and std::unique_ptr
To fix overloading when using these types.
2022-09-17 10:23:51 +01:00
William S Fulton
dad7c93ca0 Provide SWIGTYPE MOVE typemaps in swigmove.i
For implementing full move semantics when passing parameters by value.
Based on SWIGTYPE && and std::unique_ptr typemaps which implement move
semantics.

Added for all languages, but untested for: Go, Ocaml, R, Scilab (and
unlikely to be fully functional for same reasons as for std::unique_ptr
support).

Issue #999
2022-09-16 08:36:25 +01:00
William S Fulton
c09020853d Update comments re _DEBUG redefinition before including Python.h 2022-09-09 22:53:29 +01:00
William S Fulton
dcb2544a43 Visual C++ debug builds linking to Python release builds
Only use the corecrt.h workaround for #2090 when using
SWIG_PYTHON_INTERPRETER_NO_DEBUG as the problem seems to only
occur when undefining _DEBUG.

Also extend workaround for Visual Studio 2019 version 16.10 and 16.11
as per #2174 (_MSC_VER=1929).
2022-09-09 19:03:40 +01:00
William S Fulton
db432300a9
Merge pull request #2344 from clintonstimpson/py3-slice-object
Use PyObject instead of PySliceObject throughout with Python 3.2+
2022-09-08 20:14:12 +01:00
William S Fulton
c79f7f3d85 Merge branch 'rvalue-move'
* rvalue-move:
  rvalue reference outputs
  Remove broken %implicitconv for const SWIGTYPE &&
  Remove unnecessary const SWIGTYPE & typemap
  Temporarily remove rvalue reference python runtime test
  std::auto_ptr emulation fix in test case
  Ocaml typemap typo fix
  Fix Racket tests using schemerunme directory
  Docs on rvalue parameter changes
  Test/fixes to handle NULL pointer for unique_ptr/auto_ptr
  Octave - SWIG now marshalls a C/C++ NULL pointer into the null matrix, []
  Racket - NULL pointer handling
  SWIGTYPE && input typemaps now assume object has been moved - Go and OCaml
  SWIGTYPE && input typemaps now assume object has been moved
  SWIGTYPE && input typemaps now assume object has been moved - Java
  Cosmetic stray semi-colon removal after %typemap using quotes
  Cosmetic stray semi-colon removal after %typemap
2022-09-08 19:50:31 +01:00
Clinton Stimpson
e683168018 Use PyObject instead of PySliceObject throughout with Python 3.2+
This supports use of the Py_LIMITED_API.
2022-09-05 22:04:51 -06:00
Clinton Stimpson
2a0abbb7f6 Python: Use PyType_Modified() instead of modifying flags.
Closes #2345
Also supported with Py_LIMITED_API
2022-09-02 15:54:28 -06:00
William S Fulton
c10a84c775 Cosmetic stray semi-colon removal after %typemap using quotes 2022-08-31 19:40:13 +01:00
William S Fulton
1d56bc6b85 Add initialisers for additional members in PyHeapTypeObject
(builtin mode) for Python-3.11 - _ht_tpname, _spec_cache.
2022-08-01 08:24:52 +01:00
Olly Betts
e23d912b49 [python] Fix inheriting from multiple director classes
Fix mishandling of a Python class inheriting from multiple SWIG-wrapped
director classes.

Fixes #422
Fixes https://sourceforge.net/p/swig/bugs/1379/
2022-07-20 14:18:49 +12:00
William S Fulton
8b654afdef Merge branch 'unique_ptr-inputs'
* unique_ptr-inputs:
  std::unique_ptr std::auto_ptr tidyup
  Add support for std::auto_ptr inputs
  Cosmetic formatting and doc updates in std_unique_ptr.i files
  Add Perl support for std::unique_ptr inputs
  Add Ruby support for std::unique_ptr inputs
  Add Python support for std::unique_ptr inputs
  Add C# support std::unique_ptr inputs
  Java unique_ptr test ownership enhancement to test
  Java unique_ptr enhance test for double release
  SWIGTYPE && input typemaps now assume object has been moved
  Add Java support for std::unique<T> for input parameters.

Closes #692

Conflicts:
	CHANGES.current
2022-07-19 20:26:18 +01:00
Olly Betts
0b9d4eff09 Update everything for dropping Python 3.2 support 2022-07-19 13:20:07 +12:00
Julien Schueller
a55d40dbb5 Drop support for Python 3.2
Closes #2314
2022-07-19 11:23:48 +12:00
William S Fulton
db5e37a1d7 Add support for std::auto_ptr inputs
Ported from std::unique, behaviour is identical with regard to memory ownership/handling
2022-07-18 08:32:26 +01:00
William S Fulton
5dd5e80a84 Cosmetic formatting and doc updates in std_unique_ptr.i files 2022-07-17 20:44:20 +01:00
William S Fulton
c3c061cac8 Add Python support for std::unique_ptr inputs
Equivalent to Java/C# implementation.
2022-07-17 15:20:20 +01:00
William S Fulton
319442a8c4 More move semantics improvements
More removal of casts in the out typemaps when copying objects to enable
C++ compilers to possibly make use of move semantics.
2022-07-04 11:19:50 +01:00
William S Fulton
71cd6a38fe Performance optimisation for directors for classes passed by value
The directorin typemaps in the director methods now use std::move on the
input parameter when copying the object from the stack to the heap prior
to the callback into the target language, thereby taking advantage of
move semantics if available.
2022-07-04 11:19:29 +01:00
William S Fulton
980e21a3bf Cosmetic changes to auto_ptr library files 2022-07-02 16:17:23 +01:00
William S Fulton
299880e6a6 Add std::unique support
Simple copy of current auto_ptr support (just suppport for
functions returning std::unique_ptr).

Closes #1722
2022-07-02 16:17:18 +01:00
William S Fulton
8e3f0fd793 Suppress -Wregister gcc warnings in Python.h
Such as:
/usr/include/python2.7/unicodeobject.h:534:24: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]

Closes #2227
2022-05-27 20:01:57 +01:00
William S Fulton
7f009eddf0 Merge branch 'python'
* python:
  Define PY_SSIZE_T_CLEAN macro
  Python: define PY_SSIZE_T_CLEAN

Conflicts:
	CHANGES.current
2022-05-27 19:00:05 +01:00
William S Fulton
abc8e0bb27 Define PY_SSIZE_T_CLEAN macro
before #include "Python.h" as recommended in Python 3.7 and later.

Issue #2277
2022-05-27 18:58:04 +01:00
William S Fulton
d60724b636 Merge branch 'more_argcargv'
* more_argcargv:
  Document argc argv library
  argcargv.i cosmetic updates
  Typemaps for (int ARGC, char **ARGV) fixup
  Fix argcargv.i in Perl5, Tcl, PHP Add missing type map for type check. Add testing of argcargv.i for Perl5, Tcl, PHP and Ruby.
  Add Lua test for argcargv.i
  Add argcargv.i to more languages: Perl 5, Tcl, PHP
  Add argcargv.i to Lua
2022-05-15 19:42:25 +01:00
William S Fulton
e4cdf9d98f argcargv.i cosmetic updates 2022-05-15 18:32:53 +01:00
Heinrich Schuchardt
ca6a73277b Python: define PY_SSIZE_T_CLEAN
It is recommended to always define PY_SSIZE_T_CLEAN before including
Python.h. Cf. https://docs.python.org/3/c-api/intro.html

This avoids errors like:

    SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
2022-05-10 19:37:07 +02:00
William S Fulton
72bb68d556 Visual C++ warning fix in Python < 3.2 builtin wrappers
Fixes:
warning C4311: 'type cast': pointer truncation from 'void *' to 'long'
warning C4302: 'type cast': truncation from 'void *' to 'long'
2022-05-07 06:22:25 +01:00
Kris Thielemans
8dc4e3a8cb fix white-space 2022-04-28 08:00:42 +01:00
Kris Thielemans
f5934b099b [Python] Replace tp_print with tp_vectorcall_offset slot for Python 3.8
The tp_print slot is no longer supported and replaced with tp_vectorcall_offset.
The (printfunc) cast that we used caused problems on PyPy.

Fixes #2262
2022-04-21 12:28:54 +01:00
William S Fulton
d1b93f2c0e Merge branch 'feature/python-builtin-separate-runtime-data'
* feature/python-builtin-separate-runtime-data:
  Rework swig_and_compile_multi_cpp makefile helper
  Different capsule names for builtin changes entry
  Use different capsule names with and without -builtin

Conflicts:
	CHANGES.current
2022-03-26 15:18:55 +00:00
William S Fulton
f068f2c2d6 Add Python < 3.3 support for pyabc.i
pyabc.i for abstract base classes now supports versions of Python
prior to 3.3 by using the collection module for these older versions.
Python-3.3 and later continue to use the collections.abc module.
The -py3 option no longer has any effect on the %pythonabc feature.
2022-03-23 07:58:01 +00:00
Eugene Toder
f733efd3c0 Use different capsule names with and without -builtin
Types generated with and without -builtin are not compatible. Mixing
them in a common type list leads to crashes. Avoid this by using
different capsule names: "type_pointer_capsule" without -builtin and
"type_pointer_capsule_builtin" with.

See #1684
2022-03-18 13:44:54 -04:00
William S Fulton
dea0c3f0b2 Add some code comments about Python objects and capsule reference counting
Issue #2208
2022-03-15 08:46:20 +00:00
Olly Betts
b4a92ae34f Fix SWIG_Py*Method_New conditional
This should be a SWIG-time conditional, but was inside %{ %} so was
instead a compile-time conditional.

Fix for bug in the changes in #2191
2022-03-14 12:49:41 +13:00
Olly Betts
e5996be10c [Python] Fix memory leak.
SWIG python objects were being freed after the corresponding SWIG
module information was destroyed in Python 3, causing leaks when as
a result the object destructor could not be invoked. To prevent this
misordering, SWIG python objects now obtain a reference to the
Python capsule wrapping the module information, so that the module
information is correctly destroyed after all SWIG python objects
have been freed (and corresponding destructors invoked).

Fixes #2154
Fixes #2208
2022-03-07 14:29:17 +13:00
Olly Betts
b127e11f1e Fix typos in docs and comments 2022-02-27 18:15:46 +13:00
benjamin-sch
a2992fe42e always get the type_pointer from capsule instead of using a static variable
as the value may change after re-initilization/due to subinterpreters
2022-02-08 09:09:17 +01:00
benjamin-sch
a9f76c89ec added interpreter_counter to deinitialize only once in case of subinterpreters 2022-02-08 09:09:00 +01:00
Seth R Johnson
de78b80de9 Renames performed by %namewarn with rename= are printed in warning message
This is necessary for regex-like renames (where you can't use the #define trick
as is done in many of the %keywordwarn directives). It's now unnecessary to print
the "renaming to '`x`'" code explicitly by the kw.swg files.
2022-02-06 13:51:37 -05:00
Olly Betts
951f946341 [Python] Improve handling of SWIG_Py*Method_New
The SWIG_PyInstanceMethod_New method is no longer added to wrapped
classes except when it's actually needed, which is when
(!builtin && fastproxy) is true (which it isn't by default).

The SWIG_PyStaticMethod_New method is no longer is now similarly
gated - previously only (fastproxy) was checked.

Finally the C/C++ functions that implement these were always compiled
into the module, but now they're only included if
(!builtin && fastproxy) is true.

Issue noted by vadz in #2190.
2022-02-04 12:58:56 +13:00
Olly Betts
bede0b407b [python] Workaround MSVC2022-related bug
Fixes #2090
2022-02-03 17:54:50 +13:00
Olly Betts
7963807308 [python] Remove unused bogus fallback macro
This fallback version of PyString_AS_STRING() for Python 3 makes use of
PyUnicode_AS_STRING, but I can find no evidence that ever existed in
Python - all references I've found are to SWIG or SWIG-generated code.

The only uses of PyString_AS_STRING() in SWIG generated code are for
Python 2 #if-branches, so this fallback is never used by SWIG.

Because it doesn't work it can't be usefully used in user interface
files either, so let's remove it to avoid potential user confusion
(such as #987).
2022-01-27 09:32:25 +13:00
William S Fulton
3aa302c08f %callback and Python class access for C++ static member functions fixes
Fix access to C++ static member functions using Python class
staticmethod syntax, such as Klass.memberfunction instead of
Klass_memberfunction, when using -fastproxy and -builtin in
combination with %callback.

The docstring containing the callback pointers were not being patched
during module initialisation.
2022-01-14 23:00:59 +00:00
Victor Stinner
e902ab5160 Add Python 3.11 support: use Py_SET_TYPE()
On Python 3.9 and newer, SwigPyBuiltin_SetMetaType() now calls
Py_SET_TYPE(). Py_TYPE() can no longer be usd as an l-value on
Python 3.11:

* https://docs.python.org/dev/c-api/structures.html#c.Py_SET_TYPE
* https://docs.python.org/dev/whatsnew/3.11.html#c-api-changes
2021-12-06 23:17:33 +01:00
John Senneker
160b8c5da3 Added extern "C" block that was removed in previous commit. 2021-12-01 15:15:24 -05:00
John Senneker
ebe14e6e2a Fixed crashes when using embedded Python interpreters.
Fixes #2101. There are 3 related changes made here:
1. Move the SWIG_globals() singleton into pyrun from pyint so it
   is visible to SWIG_Python_DestroyModule(). The static globals
   varlink has been extracted out of the function so that it can
   be set to NULL in SWIG_Python_DestroyModule(), which fixes the
   issue described in #2101. (Now when the second interpreter
   starts up, the Swig_Globals_global pointer will be NULL, so it
   knows it has to create a new one.)
2. Remove a Py_DECREF on the globals varlink. The decrement is now
   performed by DestroyModule(), so there's no need to do it in
   SWIG_init().
3. Fixed similar issue with SWIG_Python_TypeCache().
2021-11-30 16:13:17 -05:00
Andrew Rogers
448e8d57bd Further leak fixes 2021-05-18 13:07:48 +01:00
Andrew Rogers
16123466f4 Update tests for failing Python API calls to all use '!= 0' 2021-05-18 13:05:51 +01:00