Commit graph

935 commits

Author SHA1 Message Date
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
Jake Cobb
30f16b9138 Python - Struct spec. for container owner
Use a struct with specialization to dispatch the container
owner reference function instead of a function.  Avoids
possible future problems if overloading were introduced.
2019-02-04 13:48:52 -05:00
William S Fulton
62c5ca89a6 Minor refactoring of generated Python code 2019-02-03 00:27:57 +00:00
Alec Woods
86e08c8e34 Fixes so that fastproxy and autodoc work correctly with both low-level C API and high-level Python Shadow API 2019-01-26 09:30:26 -05:00
Jake Cobb
40e327d742 Python: Avoid container owner check for value types 2019-01-23 16:10:26 -05:00
Jake Cobb
5185ce67b5 Python: Init container owner attribute in thread-safe way 2019-01-23 15:12:45 -05:00
William S Fulton
ef8a92578b Correct Python implicitconv code
Py_None is only possible with implicitconv so move this block of code
into the implicitconv if block.
2018-12-29 12:09:04 +00:00
William S Fulton
3efea1f4ab Fix typecheck typemaps for non-pointers and NULL
The typecheck typemaps succeed for non pointers (SWIGTYPE, SWIGTYPE&,
SWIGTYPE&&) when the equivalent to C NULL is passed from the target
language. This commit implements a fix for Python to not accept a Python
None for non-pointer types.

Issue #1202
2018-12-29 11:45:46 +00:00
William S Fulton
26b8523fc4
Merge pull request #1382 from lpchambers/master
[Python] Add missing keywords 'async' and 'await' to pythonkw.swg.
2018-12-20 08:25:16 +00:00
William S Fulton
d9ecff1fca Merge branch 'chlandsi-master'
* chlandsi-master:
  Testcase for testing __new__ override Python 3.6 fix
  fix for creating new shadow class in python 3.6
2018-12-20 08:12:41 +00:00
Lewis Chambers
83ab3567dc [Python] Add missing keywords 'async' and 'await' to pythonkw.swg. 2018-12-20 09:21:50 +10:00
William S Fulton
b8fc71b5f8 Remove functions associated with tp_print that are now redundant
Removes SwigPyPacked_print and swig_varlink_print
2018-12-11 08:08:14 +00:00
Andrew Rogers
f8bf286a6e #1368: AV in tp_print caused by mismatched Python/extension CRT usage 2018-12-11 07:54:57 +00:00
William S Fulton
0147fb2e64 Workaround for incorrect output formatting 2018-12-06 07:44:34 +00:00
William S Fulton
009415e43b Cosmetic changes in SWIG_globals
Make local variable name standards compliant
2018-12-04 22:15:52 +00:00
Andrew Rogers
0fecd1538f Cleanup accessing/decref of globals, to avoid code bloat in init function. 2018-11-27 23:30:51 +00:00