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.
* 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
Use a struct with specialization to dispatch the container
owner reference function instead of a function. Avoids
possible future problems if overloading were introduced.
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
Both the command line and %module options of the same name have been
removed. These were undocumented. The -outputtuple option returned a
Python tuple instead of a list, mostly typically in the OUTPUT
typemap implementations.
It unclear why a tuple instead of a list return type is needed and
hence this option has been removed as part of the simplification of
the SWIG Python command line options for SWIG 4.
Issue #1340.
Python fixed many APIs to use const char * instead of char * at around
Python 2.4. As we support 2.7 and later, we can now remove the non-const
string usage.
Types changed:
PyArg_ParseTuple
PyArg_ParseTupleAndKeywords
PyArg_UnpackTuple
PyDict_SetItemString
PyMethodDef
PyModuleDef
SWIG_Python_UnpackTuple
SWIG_Python_str_FromChar
SWIG_addvarlink
swig_const_info
This option, if used, has not had any effect on Python 3 code since commit a863d3 9 years ago.
I think we can assume that it is not needed for Python 3.
Running the examples and test-suite (Python 2) doesn't change the code
paths with and without -safecstrings because only SWIG_OLDOBJ and SWIG_NEWOBJ
are used in the typemaps and the following code is thus unaltered by -safecstrings
(which sets SWIG_PYTHON_SAFE_CSTRINGS):
%#if defined(SWIG_PYTHON_SAFE_CSTRINGS)
if (*alloc != SWIG_OLDOBJ)
%#else
if (*alloc == SWIG_NEWOBJ)
%#endif
{
*cptr = %new_copy_array(cstr, len + 1, char);
*alloc = SWIG_NEWOBJ;
printf("safe strings: %s\n", *cptr ? *cptr : "NULLSTRING");
} else {
*cptr = cstr;
*alloc = SWIG_OLDOBJ;
}
Note: nosafecstrings was also the default and -O didn't actually change this.
A custom implementation for Py_None was implemented in SWIG_Py_None().
This was used by default on Windows only. It isn't clear why this
was done just for Windows. Now Py_None is the real Py_None on all
operating systems.
What SWIG calls "modern" classes are supported by Python 2.3 and up
which means they're supported by all the Python versions we aim to
support in 4.0.0.
Conflicts:
Source/Modules/python.cxx
This is a cherry-pick and merge from the patch in #1261
Fix when using -builtin and wrapping std::map, std::set, std::unordered_map or
std::unordered_set to ensure __contains__ is called. This is a wrapper for the STL
container's find method. Without it, Python will do its own slower sequence search.
An error was not being set if an implicit conversion was attempted
calling an explicit constructor.
Fixes:
Fatal Python error: a function returned NULL without setting an error
SystemError: <built-in function new_A> returned NULL without setting an error
File "Examples/test-suite/python/implicittest.py", line 106 in __init_
- std::unordered_map compilation fix when just using std_unordered_map.i standalone
- std::unordered_multimap compilation fix when just using std_unordered_multimap.i standalone
- Add in the standalone unordered STL test cases
Closes#1319
The previous implementation failed with Python 3 and abstract base clases.
The new implementation replaces the Python 2 implementation using new.instancemethod with C API PyMethod_New to match the equivalent Python 3 implementation which uses PyInstanceMethod_New.
Closes#1310