Commit Graph

644 Commits

Author SHA1 Message Date
William S Fulton 355395200f More Python module loading simplification
Slightly faster checking to see if a module is in a package.
Issue #848
2018-12-18 07:50:48 +00:00
William S Fulton 2a00d0f784 Simpler Python module loading
Simplification possible given Python 2.7 is now the minimum supported.
Issue #848
2018-12-18 07:30:50 +00:00
William S Fulton 03323f5c8b The Python module import logic has changed to stop obfuscating real ImportError problems.
Only one import of the low-level C/C++ module from the pure Python module is
attempted now. Previously a second import of the low-level C/C++ module was attempted
after an ImportError occurred and was done to support 'split modules'. A 'split module' is
a configuration where the pure Python module is a module within a Python package and the
low-level C/C++ module is a global Python module. Now a 'split module' configuration is
no longer supported by default. This configuration can be supported with a simple
customization, such as:

  %module(package="mypackage", moduleimport="import $module") foo

or if using -builtin:

  %module(package="mypackage", moduleimport="from $module import *") foo

instead of

  %module(package="mypackage") foo

See the updated Python chapter titled "Location of modules" in the documentation.

Closes #848 #1343
2018-12-16 16:41:39 +00:00
William S Fulton 90221812c6 Revert removal of tp_print slot for Python -builtin
Some users might still want to customize this slot.
2018-12-11 08:00:44 +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 67f5ade7ad Remove -noolddefs command line option
This was a pointless option as it is off by default.
2018-12-10 07:07:49 +00:00
William S Fulton 9fe2b05faa Merge branch 'adr26-master'
* adr26-master:
  Cleanup accessing/decref of globals, to avoid code bloat in init function.
  Fix ISOC build errors.
  Fix unused variable warning.
  #1360: Leak of SWIG var link object

Conflicts:
	CHANGES.current
2018-12-04 20:12:42 +00:00
William S Fulton 9a7e2ed9ed Restore Python docstring location to immediately after the SWIG banner 2018-12-04 20:10:49 +00:00
William S Fulton 604ae7186b Fix for running 'python -m' when using swig -builtin
Same as e05b5ea for -builtin.

Also added runtime tests to check 'python -m'.
2018-12-04 19:12:13 +00:00
Andrew Rogers 402d55da52 Merge github.com:swig/swig
# Conflicts:
#	CHANGES.current
2018-11-29 07:02:49 +00:00
William S Fulton 75638e3371 Update comments and docs regarding recent addition to use __package__ for Python module imports 2018-11-28 23:48:58 +00:00
William S Fulton 6b5da094b2 Simpler Python -builtin import
When using -builtin, the two step C-extension module import is now
one step and the wrapped API is only available once and not in an underlying
module attribute like it is without -builtin. To understand this, consider a
module named 'example' (using: %module example). The C-extension is compiled into
a Python module called '_example' and a pure Python module provides the actual
API from the module called 'example'. It was previously possible to additionally
access the API from the module attribute 'example._example'. The latter was an
implementation detail and is no longer available. It shouldn't have been used, but
if necessary it can be resurrected using the moduleimport attribute described in the
Python chapter of the documentation. If both modules are provided in a Python
package, try:

  %module(moduleimport="from . import _example\nfrom ._example import *") example
or more generically:
  %module(moduleimport="from . import $module\nfrom .$module import *") example

and if both are provided as global modules, try:

  %module(moduleimport="import _example\nfrom _example import *") example
or more generically:
  %module(moduleimport="import $module\nfrom $module import *") example

The module import code shown will appear in the example.py file.
2018-11-28 23:36:13 +00:00
William S Fulton b380de031e Python -builtin %rename constructor refactor
The implementation for a renamed constructor for -builtin no longer
uses the same implementation for non-builtin mode which makes a call
into the compiled C module, eg _constructor_rename for a module called
constructor_rename. The output in the constructor_rename.py file is now:

  RenamedConstructor = new_RenamedConstructor

instead of

  def RenamedConstructor():
      val = _constructor_rename.new_RenamedConstructor()
      return val

when wrapping:

  struct Foo {
      %rename(RenamedConstructor) Foo();
      Foo() {}
  };

See the constructor_rename.i testcase.

This change has been made to make the wrapper more efficient and is a
step towards the next commit which will remove duplicating the symbols
in both the pure Python module and implementation C module
(constructor_rename and _constructor_rename respectively in this case).
2018-11-28 08:20:02 +00:00
Andrew Rogers a9e29d2bc7 Merge github.com:swig/swig 2018-11-27 23:31:27 +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
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
Andrew Rogers 6814f67cdb Merge branch 'master' of github.com:swig/swig
# Conflicts:
#	CHANGES.current
2018-11-24 20:06:02 +00: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
Andrew Rogers 65edf2258f #1360: Leak of SWIG var link object 2018-11-23 16:02:46 +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 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 fc79264a48f186f8bbd367e91fa9dbf9758aa092:
"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 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 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
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 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 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 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
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
Olly Betts 728b8955bd Drop support for Python classic classes
There were only needed to support Python < 2.2, and we now require at
least Python 2.6.

 Conflicts:
	.travis.yml
	Examples/test-suite/python/autodoc_runme.py
	Source/Modules/python.cxx

This is a cherry-pick and merge from patch in #1261
2018-10-12 07:10:47 +01:00
William S Fulton 18383340e9 Fix C default arguments with -builtin and -fastunpack and -modernargs.
Problem occurred when there is just one (defaulted) parameter in the parameter list.

Closes #1126
2018-10-04 08:06:01 +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
luz.paz ed28e7cbe2 Misc. typo and whitespace fixes
Found via `codespell -q 3 -L "uint,bae,objext,cmo,goin,struc,ois,upto"`
whitespaces were unintentionally fixed due to my editors settings.

Rebased patch #1327
2018-09-19 20:29:14 +01:00
William S Fulton c6547ac44e Fix functors (wrapped as __call__) when using -builtin -modern -fastunpack. 2018-09-19 20:10:11 +01:00
William S Fulton 040683d1b3 Fix Python -builtin and -fastdispatch regression.
Generated code did not compile
2018-09-06 21:07:59 +01:00
William S Fulton c2805e5a44 Change location of Python -fastproxy methods in proxy class
Output methods in the same place that they would be generated in the
proxy class when not using -fastproxy. When using autodoc, the two
definitions of the method are then right after each other.
2018-08-20 07:37:29 +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 91e9743014 Fix to make ISOC89 compliant: -Werror=declaration-after-statement 2018-08-10 12:44:23 +01:00
William S Fulton 36a7c49b1e Merge branch 'python-type-error'
* python-type-error:
  Python fastdispatch error message improvements
  Correct PyErr_Fetch/PyErr_Restore variable names
  Overloaded C++ function Python wrappers now raise a TypeError instead of NotImplementedError
2018-08-10 08:17:43 +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 fd651ff4e2 Overloaded C++ function Python wrappers now raise a TypeError instead of NotImplementedError
Occurs when the types passed are incorrect. This change means
there is now consistency with non-overloaded function wrappers which have always
raised TypeError when the incorrect types are passed.

See issue #1293
2018-08-10 08:14:12 +01:00
William S Fulton aaa67702ec Cosmetic corrections in python.cxx 2018-08-06 19:51:13 +01:00
William S Fulton 8f224694e7 Python help for py3 update 2018-07-23 07:56:47 +01:00
William S Fulton 89f00ca2f3 Fix pythonnondynamic feature for modern classes and Python 3
Corrects adding metaclass to the nondynamic class so that the
implementation works. Uses metaclass syntax that will work for both
python 2 and 3 or proper Python 3 syntax when using -py3.
2018-07-23 07:26:48 +01:00
William S Fulton fe082382c7 Fix pythonnondynamic feature for modern classes
Fixes nondynamic mode when an instance variable is set with the same
name as a class variable in a class derived from a SWIG proxy class.
The python_nondynamic testcase now works using -modern and testcase
enhanced slightly too.

Fixes #718
2018-07-23 07:25:11 +01:00
Rupert Nash e05b5ea67f
Make python shadow sub-modules runable
Python modules can be run as main from the command line with the -c flag
Currently this does not work as the python wrapper module does not correctly import the extension module. This commit makes the generated code consistent with PEP 366.
2018-07-03 11:03:43 +01:00
William S Fulton 50d7f36f45 Correct JavaDoc from doxygen comments indentation
Adds missing JavaDoc indentation for doxygen comments obtained from:
- enum values
- class methods
- constructors
- global functions/variables
2018-06-17 00:16:57 +01:00
Olly Betts 7f98830110 [Python] Fix new GCC8 warnings in generated code
Avoid casts between incompatible function types where possible (when
keyword args are in use, it is not possible to avoid such warnings as
they are inherent in the design of Python's C API in that particular
case).  Fixes #1259.
2018-06-11 15:51:53 +12:00
Olly Betts 1198155083 Drop Python 2.6 support too
See #701.
2018-06-08 11:08:31 +12:00
Philipp Kraft 0f88f9997c Stop exposing <CLASS>_swigregister to Python
It's not useful for user Python code to call this, and it just clutters the API unnecessarily.

Fixes #1225
2018-06-08 10:31:49 +12:00
Olly Betts 7c034ead32 Remove special handling for Python < 2.6
See #701.
2018-06-08 09:34:48 +12:00
William S Fulton 33921666a1 Merge branch 'vadz-doxygen'
This is the Doxygen work begun in Google Summer of Code projects 2008
and 2012 and subsequently improved by numerous contributors.

* vadz-doxygen: (314 commits)
  Add changes entry for Doxygen support
  Add some missing doctype tyemaps
  Doxygen warnings cleanup
  Move doxygen warning numbers
  Add Python doxygen example
  Doxygen example
  Add Doxygen to include paths
  Doxygen source rename
  More merge fixes from doxygen branches
  Correct python example headers
  Correct source code headers
  Another merge fix from doxygen branches
  Java enums output format fixes
  Add omitted doxygen_parsing_enums testcase
  PEP8 conformance for comment verifier module
  Clean up merge problem
  Doxygen html tweaks
  Update html chapter numbering for added Doxygen chapter
  Fixes to makechap.py to detect ill-formed headers
  html fixes for Doxygen
  Add missing CPlusPlus17.html file
  Format files to unix format
  Doxygen testcase tweak to match that in the html docs
  Doxygen html documentation updates and corrections
  Remove doxygen Examples subdirectory
  Beautify doxygen source code
  Code formatting fixes in doxygen code
  Remove unused doxygen code
  new_node refactor
  Various merge fixes in doxygen branches
  Unused variable warning fix
  Fix wrongly resetting indent after formulae in Doxygen comments
  Add support for doxygen:alias feature
  Get rid of meaningless return type of DoxygenParser methods
  Return enum, not untyped int, when classifying Doxygen commands
  Get rid of unnecessary "typedef enum" in C++ code
  Use slash, not backslash, in "C/C++" in the documentation
  Replace literal "<" with "&lt;" in HTML documentation
  Fix broken link to java.sun.com in Doxygen documentation
  Fix using com.sun.tools.javadoc package under macOS
  Fix error reporting for special characters in Doxygen parsing code
  Switch Python Doxygen unit tests to use inspect.getdoc()
  Use correct separator in Java class path under Windows.
  Remove executable permission from appveyor.yml.
  Use JAVA_HOME value in configure to detect Java.
  Display JAVA_HOME value in "make java_version".
  Fix harmless MSVC warning in DoxygenTranslator code.
  Reset "_last" for all but first enum elements.
  Don't duplicate Javadoc from global enum Doxygen comments twice.
  Move Doxygen comments concatenation from the parser to the lexer.
  Fix shift/reduce conflicts in Doxygen pre/post comment parsing.
  Rewrote part of the grammar dealing with Doxygen comments for enums.
  No changes, just remove spurious white space only differences.
  Move Doxygen comment mangling from the parser to the lexer.
  Merge "-builtin" autodoc bugs workarounds from master into test.
  Quote JAVA_HOME variable value in Java test suite makefile.
  Remove unused C_COMMENT_STRING terminal from the grammar.
  Fix missing returns in the Doxygen test suite code.
  Fix trimming whitespace from Doxygen comments.
  Remove code not doing anything from PyDocConverter.
  Remove unused <sstream> header.
  Remove unreferenced struct declaration.
  Remove unused Swig_warn() function.
  Remove any whitespace before ignored Doxygen commands.
  Remove trailing space from one of Doxygen tests.
  Fix autodoc strings generated in Python builtin case and the test.
  Fix Doxygen unit test in Python "-builtin" case.
  Use class docstrings in "-builtin" Python case.
  Don't indent Doxygen doc strings in generated Python code.
  Add a possibility to flexibly ignore custom Doxygen tags.
  Stop completely ignoring many Doxygen comments.
  Fix structural Doxygen comment recognition in the parser.
  No changes, just make checking for Doxygen structural tags more sane.
  Use "//", not "#", for comments in SWIG input.
  Allow upper case letters and digits in Doxygen words.
  Pass the node the Doxygen comment is attached to to DoxygenParser.
  Get rid of findCommand() which duplicaed commandBelongs().
  Recognize unknown Doxygen tags correctly.
  No real changes, just pass original command to commandBelongs().
  Describe Doxygen-specific %features in a single place.
  Give warnings for unknown Doxygen commands in Doxygen parser.
  Document the return type when translating Doxygen @return to Python.
  Fix translated Doxygen comments for overloaded functions in Python.
  Also merge Doxygen comments for overloaded constructors in Python.
  Allow using enum elements as default values for Python functions.
  Don't always use "*args" for all Python wrapper functions.
  No real changes, just make PYTHON::check_kwargs() const.
  Refactor: move makeParameterName() to common Language base class.
  Remove long line wrapping from Python parameter list generation code.
  Simplify and make more efficient building Python docstrings.
  Translate Doxygen code blocks to Sphinx code blocks.
  Add a simple test of multiple parameters to Doxygen test suite.
  Make Python parameters types hyperlinks in the doc strings.
  Make Language::classLookup() and enumLookup() static.
  Fix arguments of @param, @return etc translations to Python.
  Remove unused method from PyDocConverter.
  No real changes, just remove an unnecessary variable.
  Preserve relative indentation when parsing Doxygen comments.
  Use Sphinx-friendly formatting for overloaded functions documentation.
  Add poor man trailing white space detection to Doxygen Python tests.
  ...
2018-06-07 08:13:10 +01:00
William S Fulton ec2cb809cd Add Doxygen to include paths 2018-05-29 06:59:26 +01:00
Olly Betts d721b4d639 Fix comment typo "aruments" 2018-05-29 09:00:18 +12:00
William S Fulton ac85784a76 Doxygen source rename
Source/DoxygenTranslator/src directory is renamed Source/Doxygen
Renamed files in this directory to short names using lowercase as is the
convention for the rest of the SWIG source.
C++ extension is also .cxx like other SWIG source code.

I used doxy as the prefix for most file renames because without this
Doxygen/parser.* would be easily confused with CParse/parser.* so
Doxygen/doxyparser.* is renamed from DoxygenTranslator/src/DoxygenParser.*
2018-05-26 12:52:52 +01:00
William S Fulton 73c585b994 Code formatting fixes in doxygen code 2018-05-25 07:56:39 +01:00
William S Fulton 0cfd53cff7 Merge branch 'master' into vadz-doxygen
* master:
  Add Octave 4.4 to Travis allow_failures
  Fixes for appveyor image changes
  Javascript test-suite Makefile parallel jobs
  Add changes entry for csconstruct, dconstruct and javaconstruct fix
  Fix lookup of csconstruct, dconstructor and javaconstruct typemaps
  Javascript %nspace fix in generated C++ code
  Add C++17 documentation chapter
  Add changes notes for C++17 nested namespaces support
  Test for invalid C++17 nested namespace aliases
  Test c++17 nested namespaces and %nspace
  Add c++17 nested namespaces runtime test for C#
  Add c++17 nested namespaces runtime test for Python
  Add support for c++17 nested namespaces
  Update CHANGES.current
  .travis.yml: test against Octave 4.4
  Examples/test-suite/register_par.i: rename 'tree' to 'swig_tree'
  Examples/octave/module_load/runme.m: update 'exist()' statements for Octave >= 4.4
  Examples/octave/module_load/runme.m: do not use duplicate function names
  Examples/Makefile.in: unset OCTAVE_PATH when running Octave for tests
  Lib/octave: fix getting/setting global variables for Octave >= 4.4
  Lib/octave: use new class for function member dereference with Octave >= 4.4
  Lib/octave: fix operator installation for Octave >= 4.4
  Lib/Octave: in Octave >= 4.4, assign reference to base class in subclass
  Lib/octave: fix call to mlock() for Octave >= 4.4
  Lib/octave: fix call to octave::call_stack::current() for Octave >= 4.4
  Lib/octave: 'octave_exit' not longer exists in Octave >= 4.4
  Lib/octave: replace is_bool_type() with islogical() for Octave >= 4.4
  Lib/octave: replace is_numeric_type() with isnumeric() for Octave >= 4.4
  Lib/octave: replace is_cell() with iscell() for Octave >= 4.4
  Lib/octave: call octave::feval() instead of feval() for Octave >= 4.4
  Lib/octave: fix function name passed to unwind_protect::begin_frame()
  C#, D, Java methodmodifiers on destructors
  Javascript assert.h - move to header section
  Appveyor cl compiler warning fixes during configure
  Java vector wrappers cast correction
  test-suite fixes (Java directors) for compilers that don't support varargs
  Go - use director.swg like other languages
  test-suite fixes (2) for compilers that don't support varargs
  Consistent spacing in generated exception specifications
  test-suite fixes for compilers that don't support vararg macros
  Enhance Travis testing to use gcc 8 and test C++17 and C17
  Enhance SWIG_isfinite for older standards: C++03/C++98/C89
  test-suite support for gcc-8 targeting C++11 and C++14
  Scilab portability fixes - remove use of strdup
  Scilab array overbounds fix handling char type exceptions
  test-suite fix for c++17 and throw macro
  Remove use of 'register' in C source
  test-suite support for C++17: switch testing of the deprecated C++17 'register' keyword from C++ to C
  Examples update to support C++17: exception specification throw removal
  Cosmetic syntax tweak using throw in Octave directors
  test-suite support for C++17 (Java): exception specification throw removal
  test-suite support for C++17: exception specification throw removal
  __cplusplus macro usage tweak
  Improve detection of Python's 2to3 tool
  Correct C shared library creation when specifing CC to configure
  Remove superfluous parens in generated Python scripts.
  [ci] guile 2.2 build no longer expected to fail
  guile - resstructure some configure tests
  Disable guile configuration if guile-config and guile report a different version
  Fix guile executable detection on early 2.0.x guile versions
  guile - drop GDB_INTERFACE related stuff
  guile - replace obsolete scm_listify with scm_list_n
  guile - use more reliable method of finding guile executable based on guile-config
  Fix go version matching in configure for go1.10
  [Python] Suppress new pycodestyle warning
  Add if-no-present action for jsv8inc arg
  Fix typo in help --with-jscoreinc and --with-jscorelib
  Fix off-by-one error
  * Makefile.in (configfiles): Update URLs for latest configfiles.
  Add changes entry for Ruby %alias fix for global functions
  [Ruby] Pass Qnil instead of NULL to rb_funcall()
  Fix typo
  Fix ruby %alias directive for native c functions
  Stop testing Python on Appveyor msys/mingw
  Fix -Wimplicit-fallthrough gcc-7.3 warning
2018-05-17 19:57:02 +01:00
Ben Elliston 6fb6636ce2 Remove superfluous parens in generated Python scripts. 2018-04-28 12:28:11 +10:00
Vadim Zeitlin b7f78dd5a7 Merge branch 'master' into doxygen 2018-03-19 21:54:46 +01:00
William S Fulton 2d095b2fe3 Merge branch 'shared_ptr_directors'
* shared_ptr_directors:
  Add director typemaps for pointer const ref types
  Generation of director method declarations fixes
  Add director shared_ptr typemaps for D
  Add director shared_ptr typemaps for C#
  Typo correction in changes file
  Enhancements for directorin typemaps
  Add director shared_ptr typemaps for Java
  Director shared_ptr typemaps for scripting languages
  R memory handling standardisation
  Scilab, R and Octave shared_ptr typemaps null fix
  Octave and R shared_ptr typemaps update
  Remove duplicate director shared_ptr pointer reference typemaps
  For shared_ptr directorin, make copy of shared_ptr in all cases.
  Add directorin typemap for Python and Ruby shared_ptr.
2017-10-26 07:00:32 +01:00
William S Fulton ae044c1c2f Generation of director method declarations fixes
- Fixes generation of director method declarations containing C++11 ref-qualifiers.
- Fixes generation of director method declarations returning more complex types such
  as const ref pointers.
- Rewrite Swig_method_call to use more up to date code in the core.
2017-10-23 18:55:14 +01:00
William S Fulton 3f8b8fe734 Enhancements for directorin typemaps
The directorin typemaps will now generate a temporary variable
(specified after the type), such as:
%typemap(directorin) MyType (MyType *temp) { ... use temp ... }

The shared_ptr director typemaps have been fixed for use in functions
that take more than one parameter.
2017-10-16 19:28:27 +01:00
Olly Betts 91f9eab2d8 Fix comment typo 2017-10-13 18:35:51 +13:00
William S Fulton 4a7976a5d8 Fix platorm inconsistency in Python default argument handling.
32 bit and 64 bit compiled versions of SWIG generated different Python files
when default arguments were outside the range of 32 bit signed integers.
The default arguments specified in Python are now only those that are in the
range of a 32 bit signed integer, otherwise the default is obtained from C/C++ code.

Closes #1108
2017-10-06 21:57:04 +01:00
William S Fulton afd986c577 Python - set errno for default args handling
errno needs setting otherwise a failed strol may result in subsequent
unnecessary code generation to use *args instead of actual default
argument values. Related to issue #1108.
2017-10-04 06:50:47 +01:00
Vadim Zeitlin db65ae5aea Merge branch 'master' into doxygen
Fix the usual conflicts in autodoc unit test due to fixing the
divergences in autodoc generation between builtin and default cases in
this branch.
2017-09-19 14:02:53 +02:00
William S Fulton 2fee7c96cc Remove C casts in PyTypeObject for Python builtin type declarations
Choose compile time failures over runtime errors.
This change highlighted a problem in the constructor wrappers for tp_init
where the kwargs parameter was missing in the generated wrapper function.
Leave casts in for 0 initialization.
2017-09-12 18:10:57 +01:00
William S Fulton fbada9959c Fix types when calling PyTuple_New
Replace int with Py_ssize_t to fix warnings on Windows when using -O
and/or -builtin.
2017-08-27 14:18:00 +01:00
William S Fulton 7be6c10d4a Fix display of documented template types when using the autodoc feature for Python. 2017-07-07 19:35:44 +01:00
William S Fulton a2267a8152 Memory leak fixes in Python default argument handling 2017-06-23 14:19:12 +01:00
Olly Betts 2425c8d6d8 Don't handle cases like -1U as Python constants 2017-06-23 14:54:50 +12:00
Michael Thon 80ffb169c1 [Python] fix and improve default argument handling
1. Fix negative octals. Currently not handled correctly by `-py3`
   (unusual case, but incorrect).
2. Fix arguments of type "octal + something" (e.g. `0640 | 04`).
   Currently drops everything after the first octal. Nasty!
3. Fix bool arguments "0 + something" (e.g. `0 | 1`) are always
   "False" (unusual case, but incorrect).
4. Remove special handling of "TRUE" and "FALSE" from
   `convertValue` since there's no reason these have to match
   "true" and "false".
5. Remove the Python 2 vs. Python 3 distinction based on the
   `-py3` flag. Now the same python code is produced for default
   arguments for Python 2 and Python 3. For this, octal default
   arguments, e.g. 0644, are now wrapped as `int('644', 8)`. This
   is required, as Python 2 and Python 3 have incompatible syntax
   for octal literals.

Fixes #707
2017-06-23 13:38:49 +12:00
William S Fulton 687cf9c9c1 Add missing %python:maybecall to operator overloads.
This ensures NotImplemented is returned on error so that the Python
interpreter will handle the operators correctly instead of throwing an
exception. NotImplemented was not being returned for non-builtin wrappers
when the operator overload did not have a function overload.

See PEP 207 and https://docs.python.org/3/library/constants.html#NotImplemented

Mentioned in SF patch #303 and SF bug #1208.
2017-06-19 19:25:27 +01:00
William S Fulton 81ba06e59e Fix Python negative unsigned default values
Closes #993
2017-05-21 00:02:08 +01:00
Julien Schueller ed54cc904c Fix E731: do not assign a lambda expression
https://www.python.org/dev/peps/pep-0008/#programming-recommendations
2017-05-19 22:49:23 +02:00
William S Fulton ebd37155a8 Fix potential use of uninitialized variables in directors 2017-05-13 22:40:59 +01:00
Christophe Duvernois 4777a0ad3c #526 : propagate c++11 noexcept to director classes 2017-04-27 23:37:15 +02:00
Mark Dufour 13eeebd2fb [Coverity] fix issue reported for wrapper argument checking
Fix Coverity issue reported for wrapper argument checking:

"Null-checking args suggests that it may be null, but it has already
been dereferenced on all paths leading to the check."

So 'args' is null checked, but after dereferencing it with
PyTuple_Check(args).
2017-03-06 14:07:47 +01:00
Vadim Zeitlin e668c47b70 Merge branch 'master' into doxygen
The way Python docstrings are indented has changed on master, so use the
standard inspect module in Python autodoc unit test to ignore the differences
in their indentation level between -builtin and non-builtin cases to make the
test still pass with the branch version, which avoids the use of different
(but almost identical) values in the test itself.
2016-12-12 01:24:17 +01:00
William S Fulton 2d8ce2a5d7 Slight tweak to empty lines generated in python proxy file 2016-12-03 15:56:09 +00:00
William S Fulton bed5e5c105 Fix previous commit adding moduleimports option 2016-12-03 15:28:18 +00:00
William S Fulton 2a42031b08 Custom Python module importing code
Add optional moduleimport attribute to %module so that the
default module import code can be overridden. See the
"Searching for the wrapper module" documentation in Python.html.
Example:

  %module(moduleimport="import _foo") foo

$module also expands to the low-level C/C++ module name, so
the following is the same as above

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

Issue https://github.com/swig/swig/issues/769
2016-12-01 18:59:33 +00:00
William S Fulton 87bede9a99 Return to Python builtin tp_new initialization in init function. 2016-10-15 22:43:42 +01:00
William S Fulton d29fc38d1c Fix Python builtin binaryfunc slots when using -O
Code did not compile - recent regression due to 848628
2016-10-14 07:30:44 +01:00
William S Fulton 848628ae91 More flexible python builtin slots
The closure names used for builtin slots are mangled with their functype so
 that overloaded C++ method names can be used for multiple slots.
For example:
%feature("python:slot", "mp_subscript", functype="binaryfunc") SimpleArray::__getitem__;
%feature("python:slot", "sq_item", functype="ssizeargfunc") SimpleArray::__getitem__(Py_ssize_t n);
will generate closures:
  SWIGPY_SSIZEARGFUNC_CLOSURE(_wrap_SimpleArray___getitem__) /* defines _wrap_SimpleArray___getitem___ssizeargfunc_closure */
  SWIGPY_BINARYFUNC_CLOSURE(_wrap_SimpleArray___getitem__) /* defines _wrap_SimpleArray___getitem___binaryfunc_closure */
2016-09-25 14:15:38 +01:00
William S Fulton 0769e9b727 Fix iterators for containers of NULL pointers (or Python None) when using -builtin.
Previously iteration would stop at the first element that had a NULL pointer value.
2016-09-17 17:53:48 +01:00
Olly Betts 849f157efa [Python] Fix import in frozen app for Python 2.6 (#784)
Fix import handling for Python 2.6 to work in a frozen application.
Fixes #145, reported by Thomas Kluyver.
2016-09-12 08:11:47 +12:00
William S Fulton 5b7c08c214 Make Python builtin types hashable by default
Default hash is the underlying C/C++ pointer.
This matches up with testing for equivalence (Py_EQ in SwigPyObject_richcompare)
which compares the pointers.
2016-08-23 19:06:36 +01:00
William S Fulton ae32fb4f9a Python builtin minor tweaks
Remove internal Python struct names from generated code
Cosmetic code formatting
2016-08-22 19:28:52 +01:00
William S Fulton ad452edf3e Cosmetic code formatting corrections 2016-08-22 08:48:04 +01:00
William S Fulton bf4174d121 Further additional Python builtin slots as features for user customization
Added:
- tp_flags
- was_sq_slice
- was_sq_ass_slice
2016-08-22 08:39:24 +01:00