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.
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
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.
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.
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 "<" 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.
...
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.*
* 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
* 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.
- 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.
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.
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
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.
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.
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
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.
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).
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.
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
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 */
Default hash is the underlying C/C++ pointer.
This matches up with testing for equivalence (Py_EQ in SwigPyObject_richcompare)
which compares the pointers.
The following slots can now be overidden by users if they know what they
are doing:
- tp_dictoffset
- tp_init
- tp_new
- tp_as_number
- tp_as_sequence
- tp_as_mapping
- tp_as_buffer
* mromberg-implpkg:
Minor edits to Python implicit namespace package docs
use %inline for test
use relative import for -builtin and python2
Python3 removes support for relative imports
Document implicit namespace packages for python
disable namespace package build
Attempt to calm the testing gods...
use whatever name winders uses for .so files.
Examples (and tests) for python namespace packages
disable namespace package build
spelling
Attempt to calm the testing gods...
use whatever name winders uses for .so files.
Don't run example for old pythons
Examples (and tests) for python namespace packages
use importlib to load C extension modules for python 2.7 and newer
* ejulien-python_operator_overload_test_suite:
Add __str__ to operator_overload testcase for python builtin
Python operator_overload runtime testcase cleanup
Work around a limitation of the Python binding generator related to the += family of operators.
Fix Python 3 division member operator when -builtin is not used.
Fix class member division operator.
Remove the PY3BUILTIN switch as its behavior can be achieved with the existing SWIG_FEATURES=-builtin switch.
Implement the operator overload test suite for Python.
Conflicts:
Examples/test-suite/operator_overload.i
Define the nb_divide/nb_inplace_divide slots in the interface and use it them as nb_divide/nb_inplace_divide for Python 2.x and as nb_true_divide/nb_inplace_trus_divide for Python 3.x.
The Python 3.x nb_floor_divide/nb_inplace_floor_divide slots (operator // in Python) are not populated by the interface.
Don't bother setting _object in modern mode since it isn't used
Catch __builtin__.Exception rather than AttributeError since the check for
object hasn't been through something that would raise an AttributeError since
3d8ddfc4 in 2008
Cleans up patch #232
Fixes misleading error messages from #588
If __getattr__ is called, this means that normal attribute lookup has failed.
If checking thisown and __swig_getmethods__ fails, then give up and raise
AttributeError instead of calling the non-existent object.__getattr__.
Note that in practice the result is essentially the same, since trying to
access object.__getattr__ fails and raises AttributeError, just with a
misleading message.
In addition, there's no point in having nondynamic attribute lookup.
It is possible that the module we're wrapping defines an Exception
class. This will confuse code that uses an unqualified "Exception"
class (e.g. "try: ... except Exception") since it now won't match
the Python builtin Exception. Fix this by explicitly using
the class from the __builtin__ module ("builtins" in Python 3).
* ahnolds-python34:
Python tp_allocs -> tp_next corrections
Cosmetic correction for Python tp_version -> tp_version_tag
Add -Wmissing-field-initializers to python Travis testing
Python 3.3 builtin missing field initializers added
Adding tp_finalize field to PyTypeObject for Python 3.4 and -builtin
Adding nb_matrix_multiply and nb_inplace_matrix_multiply fields to PyNumberMethods for Python version 3.5 and up
Adding tp_finalize field to PyTypeObject for Python version 3.4 and up
Reinstates autodoc for callback function testcase from #467, actually
tests the resulting docstring in the _runme.py and fixes SWIG/Python
so the expected result is obtained.
By using the 'except:', you can catch all kinds of exceptions, including
the KeyboardInterrupt and SystemExit exceptions. From the generated
code, it is quite obvious that it is not these cases that should be
caught, but more specific ones like AttributeError and TypeError. To be
on the safe side, I decided to keep using 'Exception' for now.
SWIG-3.0.5 and earlier sometimes truncated text provided in the docstring
feature.
SWIG-3.0.6 gave a 'Line indented less than expected' error instead of
truncating the docstring text.
Now the indentation for the 'docstring' feature is smarter and is
adjusted so that no truncation occurs.
Closes#475
Updated Doxygen error numbers yet again, as Python errors got added in the
meanwhile, pushing the Doxygen ones further off.
And re-merged PEP8/whitespace-related conflicts in autodoc_runme.py once again
(if anybody is looking for a motivating example about why significant
whitespace is bad, here is a great use case).
Previously SWIG looked at the indentation of the first line and removed
that many characters from each subsequent line, regardless of what those
characters were. This was made worse because SWIG's preprocessor removes
any whitespace before a '#'. Fixes github issue #379, reported by Joe
Orton.
Don't skip checking subsequent arguments just because one of them has "in"
typemap with numinputs=0 attribute.
Add a unit test showing the problem which is relatively rare as it doesn't
happen for the class methods and is hidden unless autodoc feature is used for
the global functions.
Closes#377.
Also fixes: "SystemError: error return without exception set" during error checking
when using just -builtin and the incorrect number of arguments is passed to a class
method expecting zero arguments.
Closes#256Closes#382
Use "compact" arguments form for the function if "default" typemap is defined
for any of its arguments to allow omitting this argument when calling it from
Python.
Closes#377.
Accept not only manifest pointer types (such as e.g. "void *") but also types
that are typedefs for pointer types when checking whether C++ value of 0 must
be represented as 0 or None in Python.
Closes#365, #376.
* amaeldoe-master:
Add python runtime test for dynamically added attributes
Attribute of SWIG wrapped classes instances were overwritten on __init__()
Fix SwigPyObject->dict memory leak
Make __dict__ accessible for Python builtin classes
Attribute set within instance of a SWIG Python wrapped class are
stored in SwigPyObject->dict, which tp_dictoffset slot is pointing to.
However, SWIG wrapped classes did not have a __dict__ attribute.
Inheriting subclasses did not get the attribute either because the
SWIG wrapped classes initialize the tp_dictoffset slot:
From http://bugs.python.org/issue16272:
"If a type defines a nonzero tp_dictoffset, that type is responsible for
defining a `__dict__` slot as part of the tp_getset structures. Failure to
do so will result in the dict being inaccessible from Python via
`obj.__dict__` from instances of the type or subtypes."
Provide a SwigPyObject_get___dict__() function to retrieve the dict
attribute or create it when it does not exist yet (it is normally
created when setting attribute set), and a PyGetSetDef entry pointing
to this function.
Change Doxygen error codes to start at 740 instead of at 720 as the latter was
taken by Scilab in the meanwhile.
Resolve conflicts in autodoc_runme.py once again.
Setting properties on classic classes was broken in swig-3.0.3 by attempting to use __setattr__. This regression is fixed now by using __dict__ again when using -classic.
Fixes patch #232.
* ptomulik-fix/py-object-const:
constant_directive_runme.py and classic classes
additional fixes to %constant directive
make %constant directive to work with structs/classes
Default values are no longer generated as Python code by default.
They must be explicitly turned on using the "python:defaultargs" feature.
Closes#294Closes#296
The problems in these two issues when "python:defaultargs" is turned
on still need to be fixed and should be addressed in separate patches.
The important thing is the default code generation is now fixed.
Use the proper AUTODOC_METHOD for autodoc strings generation when using
"-builtin", there is no reason to use AUTODOC_FUNC here when AUTODOC_METHOD is
used by default (i.e. without "-builtin").
This allows to (almost) stop differentiating between the two cases in the
autodoc unit test, allowing to simplify it significantly.
Also fix this test to pass after the recent changes removing docstring
indentation in the generated code.
This is unnecessary and inconsistent with "builtin" case in which the
docstrings are not indented in the generated C++ code, thus making it
impossible to write tests working in both cases.
Most of the changes in this commit simply remove the extra whitespace from the
expected values in the tests.
* vadz/py-args:
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.
Enum values are just (integer) constants in Python and so can be used as the
function default values just as well as literal numbers, account for this when
checking whether function parameters can be represented in Python.
Also rename is_primitive_defaultargs() to is_representable_as_pyargs() to
describe better what this function does.
Due to what seems like a bug introduced during Python 3 support merge, all the
generated Python functions used the general "*args" signature instead of using
the named parameters when possible.
This happened due to is_primitive_defaultargs() always returning false for the
functions without any default arguments as "value" passed to convertValue()
was NULL in this case and convertValue() always returns false for NULL.
Fix this by checking for value being non-NULL before calling convertValue().
Doing this exposed several problems with the handling of unnamed, duplicate
(happens for parameters called INOUT, for example) or clashing with keywords
parameter names, so the code dealing with them had to be fixed too. Basically
just use makeParameterName() consistently everywhere.