Commit graph

493 commits

Author SHA1 Message Date
Olly Betts
d721b4d639 Fix comment typo "aruments" 2018-05-29 09:00:18 +12:00
Ben Elliston
6fb6636ce2 Remove superfluous parens in generated Python scripts. 2018-04-28 12:28:11 +10: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
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
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
William S Fulton
e5a09c4141 Add additional Python builtin slots as features for user customization
Added:
- tp_is_gc
- tp_bases
- tp_mro
- tp_cache
- tp_subclasses
- tp_weaklist
- tp_del
- tp_allocs
- tp_frees
- tp_maxalloc
- tp_prev
- tp_next
2016-08-22 07:51:42 +01:00
William S Fulton
3b6f4af15c Set tp_new statically rather than during initialisation 2016-08-21 14:29:27 +01:00
William S Fulton
3744c45082 Customize slots tp_basicsize tp_methods tp_getset 2016-08-19 23:46:50 +01:00
William S Fulton
239785ce7d Additional Python builtin slot overrides and slightly better formatted Python generated code
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
2016-08-19 23:16:32 +01:00
William S Fulton
67ece1d2bf Python getSlot() refactor
getSlot() now takes a default that can override "0" default - simpler
code and for future commits to override some currently non-overridable
slots.
2016-08-19 08:43:40 +01:00
William S Fulton
a3fc743f32 Add Python builtin closure method in comment
For less mystifying code and easier code searching
2016-08-18 08:41:07 +01:00
William S Fulton
9b73cd036f Avoid polluting global python namespace with version_info symbol 2016-06-07 08:12:48 +01:00
William S Fulton
81adedd7dd Python: Do not import all of sys when using -relativeimport 2016-06-06 22:20:07 +01:00
Mike Romberg
d55151ac70 > to >= 2016-06-06 13:26:55 -06:00
Mike Romberg
9ce4b58df4 Make the check for python3 -relative does python runtime check. 2016-06-06 01:28:40 -06:00
Mike Romberg
1495313e53 fix for new split module test cases. 2016-06-02 23:56:15 -06:00
William S Fulton
bee6964b48 Compile warning fix 2016-05-28 15:13:23 +01:00
William S Fulton
d01efd82e1 Merge branch 'mromberg-implpkg'
* 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
2016-05-24 22:48:37 +01:00
Mike Romberg
10d71ca01a use relative import for -builtin and python2 2016-05-24 22:46:35 +01:00
William S Fulton
5e6ab1d61d Merge branch 'ejulien-python_operator_overload_test_suite'
* 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
2016-05-05 23:01:35 +01:00
Mike Romberg
ca63491d7a Python3 removes support for relative imports 2016-04-05 11:10:04 -06:00
Mike Romberg
23d2eb555f use importlib to load C extension modules for python 2.7 and newer 2016-04-05 10:58:50 -06:00
William S Fulton
a97441613e Merge branch 'ahnolds-py_gettar'
* ahnolds-py_gettar:
  update changes file for attribute fix
  Add python AttributeError test for non-existent attribute
  Fixing python attribute lookup

Conflicts:
	CHANGES.current
2016-04-02 18:06:03 +01:00