Commit graph

2,944 commits

Author SHA1 Message Date
Vadim Zeitlin
cd526caed4 Harmonize parameters in autodoc in Ruby and Octave with Python
Backport changes to Python version of make_autodocParmList() to Ruby and
Octave modules, which use similar code.

In particular, this improves handling of parameters clashing with the
language keywords/reserved words for these languages as well.
2019-01-21 01:08:45 +01:00
Olly Betts
3b03f920e7 Suppress warnings about PyCFunction casts
These remaining warnings are due to the design of Python's C API,
so suppress them by casting via void(*)(void) (which GCC documents
as the way to suppress this warning).

Closes #1259.
2019-01-20 12:27:36 +13:00
William S Fulton
65cab79071 Merge branch 'ZackerySpytz-OCaml-dead-code-overloaded-funcs'
* ZackerySpytz-OCaml-dead-code-overloaded-funcs:
  [OCaml] Fix dead code generation in overloaded function wrappers
2019-01-19 23:03:07 +00:00
William S Fulton
6634016962 Merge branch 'ZackerySpytz-OCaml-error-msg-incorrect-overloaded-call'
* ZackerySpytz-OCaml-error-msg-incorrect-overloaded-call:
  [OCaml] Improve the error message for incorrect overloaded function calls
2019-01-19 22:59:12 +00:00
William S Fulton
2e9b270cbb Merge branch 'vadz-better-param-names'
* vadz-better-param-names:
  Enable keyword arguments for keyword_rename unit test
  Update error messages test suite
  Add more tests for Python parameter renaming
  Improve handling parameters clashing with language keywords
2019-01-17 18:19:36 +00:00
Zackery Spytz
b3f903722b [OCaml] Improve the error message for incorrect overloaded function calls
List the possible prototypes in the error message. The code was taken
from python.cxx's dispatchFunction().
2019-01-16 23:08:12 -07:00
Zackery Spytz
fa1a0a378c [OCaml] Fix dead code generation in overloaded function wrappers
The OCaml module was generating dead code in the wrappers for
overloaded functions. Only the generated dispatch function needs to
allocate an array for the passed arguments.

In addition, add overload_extend, overload_rename and overload_subtype
runtime tests.
2019-01-16 20:00:40 -07:00
William S Fulton
32a8cd8f2f Merge branch 'ZackerySpytz-OCaml-constant-char-wrapping'
* ZackerySpytz-OCaml-constant-char-wrapping:
  [OCaml] Fix the wrapping of static const member chars
2019-01-16 21:46:57 +00:00
William S Fulton
e210982b7c Merge branch 'ZackerySpytz-OCaml-caml_-prefix'
* ZackerySpytz-OCaml-caml_-prefix:
  [OCaml] Add the caml_ prefix to some OCaml functions
2019-01-16 21:44:20 +00:00
William S Fulton
cf1624ebc4 Python static method wrapper changes
- Static method wrappers were using the 'fastproxy' approach by default.
  This is inconsistent with instance method wrappers. The fastproxy approach
  is now turned off by default to be consistent with instance methods.
  Static method wrappers can now also be controlled using the -fastproxy and
  -olddefs options.

  Example:

    struct Klass {
      static int statmethod(int a = 2);
    };

  generates:

  class Klass(object):
      ...
      @staticmethod
      def statmethod(a=2):
          return _example.Klass_statmethod(a)

  instead of:

    class Klass(object):
      ...
      statmethod = staticmethod(_example.Klass_statmethod)

- Modernise wrappers for static methods to use decorator syntax - @staticmethod.

- Add missing runtime test for static class methods and using the actual
  class method.
2019-01-16 08:21:00 +00:00
Vadim Zeitlin
3f5c17824c Improve handling parameters clashing with language keywords
Previously, only Python tried to preserve the original parameter name
(by prepending or appending an underscore to it, but otherwise keeping
the original name) if it conflicted with one of the language keywords,
while all the other languages replaced the parameter name with a
meaningless "argN" in this case.

Now do this for all languages as this results in more readable generated
code and there doesn't seem to be any reason to restrict this to Python
only.
2019-01-16 04:16:59 +01:00
Zackery Spytz
c61c221057 [OCaml] Fix the wrapping of static const member chars
OCaml's constantWrapper() was adding unneeded quotes when wrapping
static const member chars.

Add runtime tests for char_constant, chartest, and
static_const_member.
2019-01-15 16:37:26 -07:00
Zackery Spytz
05589508a6 [OCaml] Add the caml_ prefix to some OCaml functions
In OCaml 3.08.0, many functions in the OCaml C API were renamed to
include a caml_ prefix. Their previous names were retained as macros
in caml/compatibility.h and were (apparently) deprecated.

Rename occurrences of alloc_string, alloc_tuple, callback, callback2,
callback3, copy_double, copy_int64, copy_string, failwith, and modify
in the OCaml module.

The OCaml module requires OCaml >= 3.08.3, so this change is safe
for all supported OCaml versions.
2019-01-14 20:45:13 -07:00
William S Fulton
b64d685d5f Merge branch 'ZackerySpytz-OCaml-fix-member-var-access'
* ZackerySpytz-OCaml-fix-member-var-access:
  OCaml's classHandler() requires name, not sym:name.
  [OCaml] Fix member var getters and setters
2019-01-11 18:42:19 +00:00
Zackery Spytz
4ca6fdc551 OCaml's classHandler() requires name, not sym:name.
In classHandler(), assign sym:name to the classname global so that it
can be used in membervariableHandler().

Add a small runme test for li_std_vector.
Use swigp4 when compiling the runme tests.
2019-01-08 20:10:07 -07:00
William S Fulton
c4481362b1
Merge pull request #1396 from ZackerySpytz/OCaml-unused-_v-var
[OCaml] Don't generate unused _v variables
2019-01-07 08:24:33 +00:00
Zackery Spytz
4a912668fc [OCaml] Fix member var getters and setters
Add `membervariableHandler()` to the `OCAML` class in ocaml.cxx (it is
partly based on the code in python.cxx and octave.cxx).

In Lib/ocaml/class.swg, wrapped classes/structs were not being added
to `class_master_list`. This is fixed by adding a call to
`register_class_byname`.

Add a unit test in the form of struct_value_runme.ml.
2019-01-06 09:40:25 -07:00
William S Fulton
96d33287b4 Fix Ruby docstring feature.
The docstring was not encapsulated within /* */ comments.

The implementation had code for autodoc strings being either single or
multi-line and then adding extra newlines. However, in practice only multi-line
autodoc string are ever generated, so this bit of code handling was removed.
The docstring feature does not attempt to add newlines depending on the
existence of newlines in the docstring.

Closes #538
2019-01-05 19:21:04 +00:00
Zackery Spytz
fe85dd22d8 [OCaml] Don't generate unused _v variables 2019-01-05 11:17:06 -07:00
William S Fulton
6a80ec314a Merge branch 'typecheck-null-nonpointers'
* typecheck-null-nonpointers:
  Fix overloading for non-pointers and NULL - MzScheme
  Overloading for non-pointers and NULL - Chicken
  Fix overloading for non-pointers and NULL - Scilab
  Fix overloading for non-pointers and NULL - R
  Fix overloading for non-pointers and NULL - Php
  Fix overloading for non-pointers and NULL - Octave
  Fix overloading for non-pointers and NULL - Lua
  Overloading for non-pointers and NULL - Javascript
  Fix overloading for non-pointers and NULL - Guile
  Fix overloading for non-pointers and NULL - Tcl
  Fix overloading for non-pointers and NULL - Perl
  Fix overloading for non-pointers and NULL - Ruby
  Add test for overloading and NULL
  Correct Python implicitconv code
  Fix typecheck typemaps for non-pointers and NULL
2019-01-03 08:13:19 +00:00
William S Fulton
07884f10ee Python - remove duplicate proxy method definitions for global function wrappers.
Global functions previously generated two definitions, eg:

  def foo():
      return _example.foo()
  foo = _example.foo

The first definition is replaced by the second definition and so the second definition
is the one used when the method is actually called. Now just the first definition is
generated by default and if the -fastproxy command line option is used, just the second
definition is generated. The second definition is faster as it avoids the proxy Python
method as it calls the low-level C wrapper directly. Using both -fastproxy and -olddefs
command line options will restore the previously generated code as it will generate both
method definitions.

With this change, the wrappers for global C/C++ functions and C++ class methods now work
in the same way wrt to generating just a proxy method by default and control via
-fastproxy/-olddefs options.

Closes #639.
2019-01-01 12:12:56 +00:00
William S Fulton
f181d20dd1 Fix overloading for non-pointers and NULL - R 2018-12-30 13:46:51 +00:00
William S Fulton
d314b53820 Python -newvwm command line option remains undocumented
Remove option from -help output text
It is hard to explain exactly what it does and is unclear as to how useful it is!
2018-12-18 19:51:38 +00:00
William S Fulton
5d6786598c Python command line options tidyup 2018-12-18 19:51:38 +00:00
William S Fulton
398ac5f01c Remove redundant Python options: -nocastmode -nodirvtable -noextranative -nofastproxy
Also remove redundant %module options: nocastmode, noextranative
Issue #1340
2018-12-18 19:51:32 +00:00
William S Fulton
152b66deaf Tidy up Python command line options help text
Also remove non-existent -noexcept option
2018-12-18 18:32:55 +00:00
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 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