Commit graph

20,828 commits

Author SHA1 Message Date
William S Fulton
6030f59741 Fix operator Python example for -builtin
Output was incorrect for -builtin as custom __str__ was not being
called.
2018-11-28 08:18:28 +00:00
William S Fulton
865dc1e71c Remove Python 2.6 and earlier import code 2018-11-25 22:18:43 +00:00
William S Fulton
e729a868b9 Minimum Python version check correction
Fixes Recent breakage when using -builtin and %import
2018-11-25 21:53:57 +00:00
Vadim Zeitlin
30bb977a64 Fix handling of abstract base classes nested inside templates
Code handling %template in the parser created a totally new top-level
module child of namespace type when handling templates inside a
namespace and copied the nodes from the previously parsed C++ template
declaration to it. However copies of this node kept their original
values of "abstracts" attribute, which contained pointers to the classes
in the original template declaration, i.e. outside of the subtree
created for the instantiated template. This, in turn, meant that during
the types resolution pass, the code in TypePass did not update the types
used in the methods of the classes appearing in the "abstracts" List,
even though it did update the types for the children of the instantiated
template subtree.

And this finally resulted in wrongly detecting overridden virtual
methods as abstract in Allocate::is_abstract_inherit() during the next
pass, as the signatures of the overridden method -- using resolved types
-- and of the method from the class pointed to by "abstract" -- using
the original types from C++ code -- didn't match.

Resolve this simply by not copying "abstracts" attributes when creating
the template subtree and doing another pass over this tree to recreate
them using the new nodes, just as it's already done for "defaultargs"
attribute, presumably for similar reasons. Note that doing another pass
over the tree is not as efficient as doing everything in a single pass,
but merging the new update_abstracts() with update_defaultargs() is not
completely obvious, so for now keep it simple and optimize it later if
necessary.

Also, add a test checking for the situation described above.

Closes #1353.
2018-11-24 19:21:47 +01:00
William S Fulton
0f61c5a847 Python minimum version checking fixes
When  using the moduleimport option, such as:

  %module(moduleimport="import $module") example

the minimum Python version check disappeared from the generated Python
file. The code has been refactored and _swig_python_version_info is
no longer deleted after initial use as it can be used in a few places,
in particular, when -builtin is used.
2018-11-23 18:08:33 +00:00
William S Fulton
55e1b5518b Update changes file with runnable Python modules fix 2018-11-22 18:12:37 +00:00
William S Fulton
c8bb566822 Merge branch 'rupertnash-master'
* rupertnash-master:
  Make python shadow sub-modules runable
2018-11-22 08:18:57 +00:00
William S Fulton
1194898206 Update changes file with recent commandline option changes 2018-11-22 08:15:36 +00:00
William S Fulton
902f3f0ac5 Appveyor mingw config changes to test Python
Set paths correctly for msys2 + mingw. With this correction, there is no
need to override the default gcc.

Provide a way to specify the name of the python interpreter using
a WITHLANG env variable. Needed where the native python3 executable is
called python.exe which is needed and not MinGW's pre-installed python3.exe.
2018-11-20 19:47:42 +00:00
William S Fulton
72fc013847 Revert "Stop testing Python on Appveyor msys/mingw"
This reverts commit 6fac581a2b.
2018-11-20 19:47:42 +00:00
William S Fulton
81b0abaf0b Fix MinGW 64bit native windows Python linking problems
Fixes linker error:
  undefined reference to `__imp_Py_InitModule4'
2018-11-20 19:47:42 +00:00
William S Fulton
1540ff451f 2to3 detection for Windows Python distributions
The 2to3 standalone tool does not exist on Windows. Use the 2to3.py
script instead.
2018-11-20 19:47:42 +00:00
William S Fulton
b3cc8fe8f9 configure fix for msys2 + mingw Python
For some unknown reason msys2 and mingw adds trailing whitespace when
running: python3-config --exec-prefix
2018-11-20 19:47:42 +00:00
William S Fulton
f3ad4e030c Don't attempt to detect Python 3.0 and 3.1 2018-11-20 19:47:42 +00:00
William S Fulton
e7638089f7 Don't attempt to detect versions of Python < 2.7 2018-11-20 19:47:42 +00: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
abb2a9259c Remove -noproxyimport command line option (Python)
This option turned off the insertion of Python import statements
derived from a %import directive. For example given:

  %module module_b
  %import "module_a.i"

then module_b.py will contain:

  import module_a

This option was originally added in 658add5, apparently to fix some sort
of circular import problem of which there are no details. It is
undocumented and is now removed as part of the simplification of the
SWIG Python command line options for SWIG 4.

Issue #1340.
2018-11-13 21:55:58 +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
027a38c71c Remove -cppcast and -nocppcast command line options
The -cppcast option is still turned on by default. The -nocppcast option
to turn off the use of c++ casts (const_cast, static_cast etc) has been
removed. However, defining SWIG_NO_CPLUSPLUS_CAST will still generate C casts
instead of C++ casts for C++ wrappers.

This a revert of commit fc79264a48:
"Revert "Remove -cppcast and -nocppcast command line options""

The Scilab and Javascript casting problems are now fixed, so -cppcast
is now switched on as default.
2018-11-13 07:36:09 +00:00
William S Fulton
c0481ce99d Add Python runtime test for const function pointer 2018-11-13 07:35:44 +00:00
William S Fulton
ebce018542 Fix constant function pointer typemaps
The function pointer typemaps were not being used when the function
pointer is const, like ADD_BY_VALUE_C in the funcptr_cpp.i testcase:

  %constant int (* const ADD_BY_VALUE_C)(const int &, int) = addByValue;

Problem affecting Javascript and observable when running test-suite with -cppcast.
2018-11-13 07:35:44 +00:00
William S Fulton
6f5417499a Fix incorrect casts for Scilab enums 2018-11-13 07:35:44 +00:00
William S Fulton
fc79264a48 Revert "Remove -cppcast and -nocppcast command line options"
This reverts commit c06f2b4497.

More work to be done as it breaks Scilab and Javascript tests.
2018-11-06 17:22:05 +00:00
William S Fulton
1251629f06 Add Python struct member limitation documentation
Closes #1336
2018-11-06 17:13:50 +00:00
William S Fulton
c06f2b4497 Remove -cppcast and -nocppcast command line options
The -cppcast option is still turned on by default. The -nocppcast option
to turn off the use of c++ casts (const_cast, static_cast etc) has been
removed. However, defining SWIG_NO_CPLUSPLUS_CAST will still generate C casts
instead of C++ casts for C++ wrappers.
2018-11-06 10:26:06 +00:00
Olly Betts
7a3af70419 Add changes entry for PHP7 reserved word change 2018-10-29 08:44:46 +13:00
Alexander Gabriel
ccbc16f810 PHP: Make reserved keywords to reserved function only (#1335)
[php] Make Keywords which are functions reserved functions
2018-10-29 08:41:16 +13:00
William S Fulton
23ce449ea5 Remove Python -new_vwm
Use the -newvwm alias name instead.
2018-10-24 20:04:31 +01:00
William S Fulton
39b48b8689 Remove Python -oldrepr option
This option controlled the __repr__ proxy class method.

Also removes:
  -old_repr
  -oldrepr
  -new_repr
  -newrepr

Note: -newrepr was and remains on by default. When -oldrepr/-old_repr
option resulted in code that did not run.
2018-10-24 20:04:31 +01:00
William S Fulton
1274c1abfc Remove Python -classptr option
This option was for backwards compatibility with very old versions of
SWIG that generated a shadow 'XPtr' class derived from proxy class X.

If anyone is still using these, they are best off using the actual proxy
class, or otherwise add them in manually using %pythoncode.

Issue #1340.
2018-10-24 20:04:31 +01:00
William S Fulton
0bd7134ffc Merge branch 'hakonhagland-doc_fix'
* hakonhagland-doc_fix:
  Documentation refers to wrong chapter.
2018-10-24 19:56:48 +01:00
William S Fulton
7375d4575a Typemap %apply docs clarification 2018-10-24 19:53:31 +01:00
William S Fulton
411c17f15d Remove Python 3 OSX Travis testing.
Pouring gcc-8.2.0.high_sierra.bottle.1.tar.gz
Error: The  step did not complete successfully

Above error needs fixing
2018-10-24 08:13:21 +01:00
William S Fulton
dc5885e22d Documentation correction about -fastproxy 2018-10-22 18:43:35 +01:00
William S Fulton
cd4732f3e3 Add changes entry about the reduced number of command line options 2018-10-22 18:43:32 +01:00
William S Fulton
cd8fc0a025 Remove Python -aliasobj0 option
This option was originally added to help users switch to using
-fastunpack so that typemaps using obj0 did not need changing by
providing an alias for swig_obj[0] to obj0. The correct solution was
always to replace obj0 with $self in the typemap. This is now mandatory.
However, the -nofastunpack option can still be used to circumvent using
the mandatory typemap change.
2018-10-22 08:19:50 +01:00
William S Fulton
04c5061698 Hardwire Python -fastunpack be on by default
The -nofastunpack option has been left in as there isn't much code
simplification in removing the nofastunpack code. This is because the
nofastunpack code is still sometimes needed (eg varags and overloaded
functions).
2018-10-22 08:19:50 +01: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
18f433d862 Tcl swig_const_info - use const char * 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
d84d26832f Hardwire Python -fastquery option to be always on
The Python dictionary cache used for SWIG types lookup is now always on.
2018-10-22 08:19:50 +01:00
William S Fulton
350396fcae Hardwire Python -fastinit option to be always on
This option runs the equivalent init code in Python C code instead of pure Python code.
The init code adds the C++ pointer into the 'this' variable.
If the variable already exists, it appends it. This
seems to only happen in directors and multiple inheritance, see
PyMulti in director_basic_runme.py.
2018-10-22 08:19:50 +01:00
William S Fulton
7d6bb6cd44 Add missing run of the functors testcase 2018-10-22 08:19:50 +01:00
Håkon Hægland
c97a455c34 Documentation refers to wrong chapter.
Chapter 10, first section, refers to Chapter 3 (Getting started on
Windows) but should presumably be Chapter 5 (SWIG Basics).
2018-10-17 13:00:04 +02:00
William S Fulton
fe155d7516 Disable Javascript Node 10 testing
Upgrade from v10.11.0 to v10.12.0 on Travis started breaking the builds
2018-10-12 18:33:19 +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
4a48e59dc6 Hard-wire -noproxydel on
We only still default to generate a no-op __del__ method for theoretical
compatibility with old code, and 4.0.0 is a good time to make a cut-off
should such code really still exist.

On the flip-side, the presence of a __del__ method seems to be able to
prevent garbage collection from kicking in (see #1215), so it's
definitely desirable to get rid of it when there's nothing for it to do.

 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
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