Commit graph

897 commits

Author SHA1 Message Date
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
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
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
Andrew Rogers
3c090307a4 Fix ISOC build errors. 2018-11-25 04:23:18 +00:00
Andrew Rogers
493d96a732 Fix unused variable warning. 2018-11-24 20:07:44 +00:00
Andrew Rogers
65edf2258f #1360: Leak of SWIG var link object 2018-11-23 16:02:46 +00:00
Christian Landsiedel
3208ff2bf5 fix for creating new shadow class in python 3.6 2018-11-22 14:24:49 +01:00
William S Fulton
c7363fd95e Workaround for Python gcc MingGW WIN32 hypot declaration error
Fixes:
In file included from C:/msys64/mingw32/include/c++/7.3.0/math.h:36:0,
                 from C:/Python27/include/pyport.h:325,
                 from C:/Python27/include/Python.h:61,
                 from example_wrap.cxx:174:
C:/msys64/mingw32/include/c++/7.3.0/cmath:1136:11: error: '::hypot' has not been declared
   using ::hypot;
           ^~~~~

See https://stackoverflow.com/questions/28683358/error-hypot-has-not-been-declared-in-cmath-while-trying-to-embed-python/28683412 and https://bugs.python.org/issue11566
2018-11-20 19:47:42 +00:00
William S Fulton
0a9b36d3be Remove -outputtuple and -nooutputtuple command line options (Python)
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.
2018-11-13 19:46:31 +00:00
William S Fulton
3917225fdb Cosmetic Python error message improvement 2018-10-22 08:19:50 +01:00
William S Fulton
a1f40568d6 Remove non-const char * usage where the Python API now supports it
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
2018-10-22 08:19:50 +01:00
William S Fulton
de26ebbad1 Remove Python -safecstrings option.
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.
2018-10-22 08:19:50 +01:00
William S Fulton
b2aa01f492 Python options simplification: Remove -buildnone, -nobuildnone
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.
2018-10-22 08:19:50 +01:00
William S Fulton
edfbbab8e2 Merge branch 'python-options-rationalise'
* python-options-rationalise:
  Hard-wire -noproxydel on
  Hard-wire -modern and -modernargs on
  Drop support for Python classic classes
2018-10-12 07:13:12 +01:00
Olly Betts
e4fceee12f Hard-wire -modern and -modernargs on
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
2018-10-12 07:10:47 +01:00
Julien Schueller
c0c2d90497
[Python] Fix -Wstringop-overflow warning
fixes #1332
2018-10-01 09:31:42 +02:00
William S Fulton
142d4062df Fix invalid free in SWIG_Python_AddErrMesg
Closes #1331
2018-09-28 07:08:12 +01:00
William S Fulton
d30effd886 Python builtin closure minor tweaks 2018-09-23 19:20:22 +01:00
William S Fulton
631e26ae48 Python std::unordered_set tidy up and additional testing 2018-09-23 19:10:26 +01:00
William S Fulton
72ccea5080 Python std::unordered_map std::unordered_multimap improvements
- Fixes for -builtin
- Fix missing iterator support
2018-09-23 19:10:00 +01:00
William S Fulton
603285ecb6 Python std::unordered_map improvements
Pick up various bug fixes and improvements from the std::map
implementation.
2018-09-23 19:09:59 +01:00
William S Fulton
146998ce81 Python builtin - add indexing support to std::unordered_set 2018-09-23 19:09:59 +01:00
William S Fulton
05d6717de9 Python builtin - add indexing support to std::set 2018-09-23 19:09:54 +01:00
William S Fulton
4715a4e72c Python -builtin __contains__ fix for map and set like containers.
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.
2018-09-21 08:51:22 +01:00
William S Fulton
3af1b74e57 Python implicitconv assert fix using debug build of the Python interpreter
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_
2018-09-04 07:22:20 +01:00
Andreas Gaeer
0165180735 Fix assert in PyTuple_GET_SIZE
Occurs in debug interpreter builds of python-3.7 when calling tp_new in
a few testcases such as Examples/python/extend.

Closes #1321
2018-09-03 19:52:43 +01:00
William S Fulton
b3f736a9d1 Python typo fix 2018-08-31 20:30:35 +01:00
William S Fulton
2f31c3e94e Python C++11 hash tables compilation fixes
- 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
2018-08-31 20:26:46 +01:00
William S Fulton
c9cac931c7 Re-implement Python -fastproxy option.
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
2018-08-18 00:36:23 +01:00
William S Fulton
4313c2c168 Update pybuffer.i library to use new-style Python buffer C API.
Removed old API altogether as Python 2.7 is now the minimum version
supported and it supports the new-style buffer API.
2018-08-12 15:02:28 +01:00
William S Fulton
33f3dbb005 Merge branch 'gmazzamuto-pybuf_test'
* gmazzamuto-pybuf_test:
  pybuffer: don't use the old deprecated buffer protocol for Python 3
  Enable test case for python_pybuf
2018-08-12 14:19:40 +01:00
William S Fulton
91e9743014 Fix to make ISOC89 compliant: -Werror=declaration-after-statement 2018-08-10 12:44:23 +01:00
William S Fulton
4f7406624d Python fastdispatch error message improvements
When overloaded C++ methods are called, the fastdispatch mode sometimes
optimises out the generation of the typecheck typemap code, resulting in
the 'Possible C/C++ prototypes' information not being in the error message.
Now when a TypeError is thrown, the exception message is modified to contain the
'Possible C/C++ prototypes'.

See issue #1293
2018-08-10 08:14:19 +01:00
William S Fulton
e0b23969d0 Correct PyErr_Fetch/PyErr_Restore variable names 2018-08-10 08:14:19 +01:00
William S Fulton
5ce880ee41 Fix SWIG_Py_None regression from last commit 2018-07-18 11:44:27 +01:00
William S Fulton
344e9fefa8 Python singletons tidy up 2018-07-17 20:23:55 +01:00
William S Fulton
d56d7a7253 Initialize Python function-local statics (singletons)
Singletons are created during Python module initialization in order to avoid
deadlocks with subsequent multi-threaded usage.
Fixes #1275 #1279
2018-07-17 19:56:12 +01:00
William S Fulton
8e6799d783 Revert "Merge branch 'petrmitrichev-remove-function-local-statics'"
This reverts commit b8ed7759d5, reversing
changes made to 6f2399e86d.
2018-07-17 08:46:53 +01:00