Commit graph

950 commits

Author SHA1 Message Date
Andrew Rogers
4f453e0cde Tidy up handling of OOM exceptions - Py*_New will call PyErr_NoMemory() internally, so there is no need to call it again here, just correctly handle the NULL return value 2021-05-17 22:50:52 +01:00
Andrew Rogers
84ff84f4fb [Python] Fix memory leaks. 2021-05-12 23:42:32 +01:00
Olly Betts
f198ff0a43 Fix more "allows to" and other typos 2021-04-21 15:54:46 +12:00
Julien Schueller
9ed60ac7a0 Drop deprecated PyEval_CallObject method
see https://docs.python.org/3.9/whatsnew/3.9.html
2020-10-15 08:43:21 +02:00
William S Fulton
4b5baf0a60 0.0 float warning fix 2020-10-10 15:02:26 +01:00
William S Fulton
57957787b7 Convert C++ comment to C comment 2020-10-10 14:53:46 +01:00
William S Fulton
4f184500d7 Merge commit '8245277ad3' into c99-complex
* commit '8245277ad3':
  Remove test for unsupported complex or _Complex by itself
  More C99 complex fixes, plus Python tests
  Restore _Complex as standalone type
  Small corrections for handling C99 _Complex
  Properly handle C99 complex types even in C++ mode

Conflicts:
	Examples/test-suite/python/complextest_runme.py
2020-10-10 14:53:33 +01:00
William S Fulton
4d5f4bcd33 Merge branch 'PyBuffer_Release-pybuffer'
* PyBuffer_Release-pybuffer:
  Add tests.
  Fix the error handling for the PyObject_GetBuffer() calls in pybuffer.i
2020-10-07 22:37:17 +01:00
William S Fulton
9c50887daa Python 3.9 support
Remove PyEval_InitThreads() call for Python 3.7 and later as Python calls
it automatically now. This removes a deprecation warning when using Python 3.9.

https://docs.python.org/3/c-api/init.html#c.PyEval_InitThreads
2020-08-27 19:37:26 +01:00
Chris Burr
eafe1e2daa
Use Py_TYPE in SwigPyBuiltin_SetMetaType 2020-07-28 08:11:02 +02:00
Chris Burr
917110212e
PyTypeObject::ob_base isn't available in PyPy 2020-07-17 12:15:54 +02:00
Leo Singer
511df0e642 More C99 complex fixes, plus Python tests 2020-06-24 20:21:47 -04:00
Leo Singer
07b4b274e5 Restore _Complex as standalone type 2020-06-24 20:21:47 -04:00
Leo Singer
1adc7dac5d Small corrections for handling C99 _Complex 2020-06-24 20:21:47 -04:00
Leo Singer
13260f95b0 Properly handle C99 complex types even in C++ mode
Use the `_Complex` keyword rather than the `complex` macro.

Fixes #1487.
2020-06-24 20:21:47 -04:00
Zackery Spytz
772dfd5dcb Fix the error handling for the PyObject_GetBuffer() calls in pybuffer.i
Closes #1640.
2020-06-07 17:47:11 -06:00
William S Fulton
02e967d05d
Merge pull request #1716 from ZackerySpytz/Python-utf8-cache
Use PyUnicode_AsUTF8() for Python >= 3.3
2020-05-29 23:56:10 +01:00
William S Fulton
67a38589a8 Minor code refactor in Python traits_asptr::asptr 2020-02-13 19:32:13 +00:00
William S Fulton
339d427910 Merge branch 'master-fix-vector-shared_ptr'
* master-fix-vector-shared_ptr:
  fixing memleak of shared_ptr objects in python with creating a [wrapped] vector<shared_ptr<Foo>> from a list of shared_ptr<Bar> where Bar is derived from Foo.
2020-02-13 19:21:12 +00:00
William S Fulton
94b4c7dc21 Better error checking when setting 'this' in Python
If python_append.i is modified to use:
__slots__ = []
instead of
__slots__ = ["this"]
then this additional error checking prevents a crash and shows a stack trace and error:
  AttributeError: 'ForSlots' object has no attribute 'this'

Related to issue #1674
2020-02-06 07:27:08 +00:00
William S Fulton
a01e8474f6 Fixing setting this in Python when using __slots__
Don't attempt to use the class's __dict__ for setting 'this' when
a user has extended a class with:
    __slots__ = ['this'].
Was segfaulting. Now we fall back to a simple PyObject_SetAttr if the
usual approach to setting 'this' in __dict__ does not work.

Closes #1673 Closes #1674
2020-02-06 07:08:16 +00:00
Zackery Spytz
f6d97d2338 Use PyUnicode_AsUTF8() for Python >= 3.3 2020-01-31 23:48:32 -07:00
William S Fulton
10cbc9481f Merge branch 'Python-coverity'
* Python-coverity:
  Fix possible refleaks.
  Check Py{Bytes,String}_AsStringAndSize() for failure
2020-01-31 19:14:47 +00:00
Zackery Spytz
58e409dd2b Fix possible refleaks. 2020-01-29 10:00:22 -07:00
Julien Schueller
96c6bf4cc2 Fix unused-parameter warning in pycontainer.swg 2020-01-17 11:09:57 +01:00
William S Fulton
3759fcf999 Merge branch 'builtin-ctor-kwargs'
* builtin-ctor-kwargs:
  Python -builtin constructors silently ignored keyword arguments.
2020-01-13 19:29:47 +00:00
William S Fulton
67e8334ac8 Python -builtin constructors silently ignored keyword arguments.
Instead of silenty ignoring them, now a "TypeError: f() takes no keyword arguments"
exception is thrown if keyword arguments are used. Hence constructors and normal
methods/functions behave in the same way.

Closes issue #1595
2020-01-13 19:26:22 +00:00
Zackery Spytz
6adf19b52f Check Py{Bytes,String}_AsStringAndSize() for failure
PyBytes_AsStringAndSize() and PyString_AsStringAndSize() were not
being checked for failure.

Closes #1349.
2020-01-09 21:14:12 -07:00
Julien Schueller
b536702c01 Fix missing-field-initializers warning with Py3.8
Python 3.8 adds tp_vectorcall, tp_print is added for compat just for 3.8
https://github.com/python/cpython/pull/13185/files#diff-b5db2632fa7acaf3b44abb56f18b9615
2019-11-20 15:40:52 +01:00
William S Fulton
97a107ed25
Merge pull request #1619 from emminizer/fix-msvc2019-python
Fix error in generated code for Python in MSVC 2019.
2019-10-01 08:12:58 +01:00
William S Fulton
719eea090d Improve error handling calling PyObject_SetAttr
Less obscure error when setting 'this' on the SWIG proxy object
attempting to override __setattr__ in C++ (swig-user mailing list
query 19 Aug 2019).
2019-09-13 07:37:03 +01:00
Daniel Emminizer
9fc57f47bd Fix error in generated code for Python in MSVC 2019.
Visual Studio 2019 release builds:
error C4703: potentially uninitialized local pointer variable 'p' used
2019-08-29 09:10:41 -04:00
William S Fulton
86cb3a9532 Python STL container method overloading fix
Fix method overloading of methods that take STL containers of different types.
Due to some error handling that was not cleared during typehecking.
2019-08-06 19:36:14 +01:00
Christian Kellner
db9822788e Use PyObject_GC_UnTrack in lieu of the old variant
The _PyObject_GC_UNTRACK[1] macro got deprecated in 3.6 and finally
removed in 3.8. Therefore use PyObject_GC_UnTrack instead.

[1] https://docs.python.org/3/c-api/gcsupport.html#c._PyObject_GC_UNTRACK
2019-07-17 11:15:17 +02:00
William S Fulton
b655d3138b Remove the UnknownExceptionHandler director error handling class
Done in order to be C++17 compliant as it uses std::unexpected_handler
which was removed in C++17. This class was intended for director
exception handling but was never used by SWIG and was never documented.

Closes #1538
2019-06-27 07:40:49 +01:00
William S Fulton
5c1c69d140 Replace std::unexpected_handler with std::terminate_handler to be c++17 compliant
Closes #1538
2019-06-27 07:40:49 +01:00
Olly Betts
c864546b4a [Python] Fix implicit_conv tuple handling regression
Introduced in SWIG 4.0.0.  Fixes #1553, reported by Alexandre
Duret-Lutz.
2019-06-03 10:13:58 +12:00
Davy Durham
af97d8f29d fixing memleak of shared_ptr objects in python with creating a [wrapped] vector<shared_ptr<Foo>> from a list of shared_ptr<Bar> where Bar is derived from Foo. 2019-04-10 05:26:53 +00:00
William S Fulton
f3e2ab9195 Include all template parameters for std_unordered_multiset and std_unordered_set 2019-03-12 21:47:45 +00:00
William S Fulton
4a25ddbb97 Correct unordered_set/unordered_multiset template Key parameter name 2019-03-12 20:21:19 +00:00
William S Fulton
30f59ffe22 Include all template parameters for std_unordered_multimap and std_unordered_map 2019-03-12 20:03:14 +00:00
John Wason
cfdf65eb34 Include all template parameters for std_unordered_map macro 2019-03-01 19:13:35 -05:00
William S Fulton
2786bf37a1 Fix multiple definitions of swig::container_owner_attribute 2019-02-21 17:57:11 +00:00
William S Fulton
32b963ef1c Re-organise Python method creation and docstring functions declarations
Fix ‘PyMethodDef* SWIG_PythonGetProxyDoc(const char*)’ declared ‘static’ but
never defined [-Wunused-function]

Closes #1448 (again)
2019-02-19 22:54:08 +00:00
William S Fulton
a628bf9b6f Python std::vector back-reference changes
Give reference in container_owner a more unique name (back_reference).
Change back-reference 'ret' typemap to have a function name so that they
are less unwittingly be used elsewhere where not intended.

Note that they can be overridden by users if needed using:

%extend std::vector {
%typemap(ret)
  value_type const& __getitem__,
  value_type const& front,
  value_type const& back
  { ...  }
}

These override the SWIG supplied versions because the SWIG supplied
typemaps use non-const value_type&, but the methods use const, so the
above have a higher precedence in the typemap search algorithm.
2019-02-18 18:50:22 +00:00
William S Fulton
b634905b65 Merge branch 'jakecobb-python-container-memory'
* jakecobb-python-container-memory:
  Better name for container back-reference attribute
  Python - Struct spec. for container owner
  Python: Avoid container owner check for value types
  Python: Init container owner attribute in thread-safe way
  Python: Use PyObject_SetAttr instead of PyObject_GenericSetAttr for back-ref
  Python: Cleanup container back ref
  Python: Keep reference to owning container during element access
2019-02-18 07:11:19 +00:00
William S Fulton
62417708fd Better name for container back-reference attribute
Mangle name with swig so as not to clash with any attribute names a
user might use.
Remove Doxygen style comments - we don't use Doxygen in SWIG.
2019-02-15 22:01:38 +00:00
William S Fulton
6d0c495fd0 Add missing parameter names in STL container wrappers
Mostly in STL copy constructors.

Best to have parameter names as they make their way into the wrappers in
some target languages.
2019-02-13 22:45:47 +00:00
William S Fulton
68e86614ff Create a consistent stl.i library file
Same file now for all languages except R which is still missing std_map.i.
Recent Java changes adding in std_set.i removed.
2019-02-12 18:46:05 +00:00
William S Fulton
43438b66ab Re-organise some generate Python code for method creation and docstring support
Fix ‘PyMethodDef* SWIG_PythonGetProxyDoc(const char*)’ declared ‘static’ but
never defined [-Wunused-function]

Closes #1448
2019-02-10 22:55:16 +00:00