Commit graph

4,341 commits

Author SHA1 Message Date
Olly Betts
f40658c2d0 [python] Avoid undefined behaviour
Cast a parameter type explicitly rather than implicitly by casting
the function pointer type, as the latter is undefined behaviour.

Caught by ubsan.
2022-10-20 10:37:47 +13:00
Olly Betts
a5bc48afea [Lua] Fix type resolution between SWIG-wrapped modules
See #2126
2022-10-20 10:14:59 +13:00
Olly Betts
747a6a264f [php] Fix handling of multi-module cases
Look up unknown base classes using SWIG_MangledTypeQueryModule().

Revert to using SWIG_TypeCheck() instead of SWIG_TypeCheckStruct()
as the latter doesn't seem to work for this case (at least for PHP
right now).

Add mod_runme.php as a regression test for this.

Adjust the PHP test harness not to set up reflection for the module
unless it's actually needed for a testcase.  Currently the approach
to find the module name doesn't work for multi-module testcases.

See #2126
2022-10-18 10:28:17 +13:00
William S Fulton
d8a0286012 R - Add support for std::vector<std::vector<std::string>>
Closes #2385
2022-10-17 20:14:45 +01:00
William S Fulton
4c86f45c54 Fix for Java 7 - std::set and std::unordered_set 2022-10-15 14:57:30 +01:00
William S Fulton
0e60d6b7a4 Correct new Raise functions to be static 2022-10-14 22:51:26 +01:00
William S Fulton
fd2420cdcc Remove STRING_VALUE to keep supporting older versions of R
STRING_VALUE does not work with R_NO_REMAP
in older versions (it broke 3.0.2)
2022-10-14 22:49:07 +01:00
William S Fulton
bba072d95d Merge branch 'fix-cast'
* fix-cast:
  add tests for new casting behavior
  skip tests when value is out of range
  refactor integers JS testcase to avoid repeating code
  Return uint64_t as double if is bigger than uint32_t
  Use SWIG_TypeCast in SWIG_V8_ConvertInstancePtr if types don't match (#3)
2022-10-14 19:19:13 +01:00
Michal Suchanek
c3f17b415d Define PY_SSIZE_T_CLEAN only when not defined yet
Users of swig 4.0.2 and python 3.10 will likely define the
PY_SSIZE_T_CLEAN macro by hand when relevant because their bindings
won't build otherwise.

Unconditionally defining PY_SSIZE_T_CLEAN in swig 4.10 will lead to
macro redefinition warning.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
2022-10-13 23:26:58 +02:00
William S Fulton
752b7e82cd Add missing SWIGTYPE *const& typemaps 2022-10-13 22:22:18 +01:00
William S Fulton
46f7501d94 Cleanup SWIG_VERSION definition
Add Swig_obligatory_macros which must be called by each
target language to define SWIG_VERSION correctly
in the generated code, as well as the language specific
macro SWIGXXX where XXX is the target language name.

Drop the #ifdef SWIGXXX that was previously generated -
I can't see the point of this and if users are defining
this macro somehow, then users will need to change this

Closes #1050
2022-10-13 19:47:43 +01:00
William S Fulton
c82aa3bb41 Quick fix SWIG_VERSION not being defined correctly in wrappers 2022-10-13 07:57:09 +01:00
William S Fulton
2268d6ee96 Fix compile error when using directors
Fix when using templates with more than one template parameter
and used as an input parameter in a virtual method in a
director class (problem affecting most of the scripting languages).

Fixes #2160
2022-10-10 19:51:08 +01:00
William S Fulton
cea25abca5 Completely remove CFFI
No meaningful progress to update CFFI to experimental status
has been made since CFFI was disabled in SWIG-4.0.0 as the first
stage to removal. This commit is the final stage to remove it.

See issue #1966 for an attempt at updating CFFI to experimental
status. Anyone wishing for SWIG to support CFFI again might
want to utilise this work.
2022-10-06 23:29:33 +01:00
Olly Betts
f54c504150 Remove dead conditional code
SWIG_POINTER_EXCEPTION has had the value zero since 2006 (it's only
still present for backward compatibility).
2022-10-06 18:09:08 +13:00
Olly Betts
631b41ae7b Use https for swig.org links 2022-10-06 13:16:39 +13:00
Olly Betts
6f3f4fbdf1 [Python] Remove deprecated and apparently useless defarg.swg
The only documentation is in the file itself and describes a Python
wrapper around the C function defined here, but digging though the git
history this Python wrapper doesn't seem to have ever actually been
generated by SWIG.

This file was also marked as deprecated in 2005.

Fixes #2390
Fixes #2391
2022-10-06 12:57:48 +13:00
William S Fulton
45f4b4d936 Merge branch 'python_subinterpreter_issues'
* python_subinterpreter_issues:
  added comment in CHANGES.current
  always get the type_pointer from capsule instead of using a static variable as the value may change after re-initilization/due to subinterpreters
  added interpreter_counter to deinitialize only once in case of subinterpreters

Conflicts:
	CHANGES.current
	Lib/python/pyrun.swg
2022-10-05 23:18:15 +01:00
Olly Betts
4ac3c87a29 Sort out predefined SWIG-specific macros
Ensure that SWIG_VERSION is defined both at SWIG-time and in the
generated C/C++ wrapper code (it was only defined in the wrapper
for some target languages previously).

SWIGGO and SWIGJAVASCRIPT are now defined in the generated wrappers
to match behaviour for all other target languages.

Stop defining SWIGVERSION in the wrapper.  This only happened as a
side-effect of how SWIG_VERSION was defined but was never documented and
is redundant.

The new testcase also checks that SWIG is defined at SWIG-time but not
in the generated wrapper, and that exactly one of a list of
target-language specific macros is defined.

Fixes #1050
2022-10-05 12:40:15 +13:00
William S Fulton
929cfde883 C# CreateWStringFromUTF32 optimisation
Avoid UTF-32 to UTF-8 conversion then get string from UTF-8
Missing change that should have gone into eaf468e9e8
2022-09-30 23:21:39 +01:00
William S Fulton
15b2ec53e3 Runtime tables deterministic ordering (4)
Output C/C++ type strings (| separated) in swig_type_info tables in
fixed order. The types are output in alphabetically sorted order,
with an exception. The final type is a fully resolved type, but
does not necessarily include default template parameters.
This type is the one used by SWIG_TypePrettyName which is commonly
used to display a type when the wrong type is passed in as a
parameter.

Previously the order was not very deterministic due to the use of
internal hash tables which do not have an ordering guarantee.
2022-09-29 19:40:47 +01:00
Olly Betts
9908f9f310 [php] Fix testcase segfaults with PHP 8.0
These testcases were segfaulting:

prefix
director_using_member_scopes
virtual_poly

The fix here is admittedly a hack - we perform the initialisation
of EG(class_table) from CG(class_table) which PHP will do, but
hasn't yet.

PHP doesn't seem to clearly document which API calls are actually
valid in minit or other initialisation contexts, but the code we're
generating works with all PHP 7.x and PHP 8.x versions aside from PHP
8.0 so it seems this is a bug in PHP 8.0 rather than that we're doing
something invalid, and we need to work with existing PHP 8.0 releases
so this hack seems a necessary evil.  It will at least have a limited
life as PHP 8.0 is only in active support until 2022-11-26, with
security support ending a year later.

Fixes #2383.
2022-09-29 13:13:52 +13:00
Olly Betts
246dd2d787 [php] Workaround PHP 8.2 header problem
We need to include php.h before stdio.h (and probably before most
other libc headers).
2022-09-28 19:01:01 +13:00
William S Fulton
eaf468e9e8 C# CreateWStringFromUTF32 optimisation
Avoid UTF-32 to UTF-8 conversion then get string from UTF-8
Issue #2369
2022-09-22 18:54:49 +01:00
William S Fulton
e407ccd4fe Move SWIG_Octave_Raise into a function
For efficiency and to fix some warnings
2022-09-19 14:48:33 +01:00
William S Fulton
ed333b6b97 std::string throws typemaps
Go, Guile, Racket, Scilab: Add throws typemaps for std::string so that
thrown string exception messages can be seen.

Test all language for std::string throws typemaps
2022-09-19 09:09:29 +01:00
William S Fulton
034e2358f9 Add Racket throws typemaps for char * 2022-09-19 09:09:29 +01:00
William S Fulton
d32943b2a9 Javascript v8 object to string exceptions improvement 2022-09-19 09:09:29 +01:00
William S Fulton
00190c484f Javascript, Octave, R - Improve exceptions for %catches
and exception specifications for native types.

Now the raised exception contains the string value as the exception
message instead of just the C/C++ type of the exception.

R exceptions were completely swallowed beforehand
2022-09-19 09:09:29 +01:00
William S Fulton
e97181ebc0 Add missing typecheck typemaps for std::auto_ptr and std::unique_ptr
To fix overloading when using these types.
2022-09-17 10:23:51 +01:00
William S Fulton
f0af17b324 Correct error handling in Guile pointer conversion 2022-09-16 19:13:02 +01:00
William S Fulton
c5610fd4b3 Guile - Add error checking to SWIGTYPE and SWIGTYPE & in typemaps
To prevent seg faults when passing #nil to these parameter types.
2022-09-16 18:52:52 +01:00
William S Fulton
dad7c93ca0 Provide SWIGTYPE MOVE typemaps in swigmove.i
For implementing full move semantics when passing parameters by value.
Based on SWIGTYPE && and std::unique_ptr typemaps which implement move
semantics.

Added for all languages, but untested for: Go, Ocaml, R, Scilab (and
unlikely to be fully functional for same reasons as for std::unique_ptr
support).

Issue #999
2022-09-16 08:36:25 +01:00
William S Fulton
c09020853d Update comments re _DEBUG redefinition before including Python.h 2022-09-09 22:53:29 +01:00
William S Fulton
0c2d0fea0f Move SwigValueWrapper to header section
Recent change to SwigValueWrapper required the <utility> header.
Included headers should be after the include of the language
specific header files (which go into the earlier runtime section).

Testcase required -Winit-list-lifetime warning suppression change
for Perl which somehow lost the warning suppression when put
into the %begin section.
2022-09-09 19:36:08 +01:00
William S Fulton
dcb2544a43 Visual C++ debug builds linking to Python release builds
Only use the corecrt.h workaround for #2090 when using
SWIG_PYTHON_INTERPRETER_NO_DEBUG as the problem seems to only
occur when undefining _DEBUG.

Also extend workaround for Visual Studio 2019 version 16.10 and 16.11
as per #2174 (_MSC_VER=1929).
2022-09-09 19:03:40 +01:00
William S Fulton
db432300a9
Merge pull request #2344 from clintonstimpson/py3-slice-object
Use PyObject instead of PySliceObject throughout with Python 3.2+
2022-09-08 20:14:12 +01:00
William S Fulton
c79f7f3d85 Merge branch 'rvalue-move'
* rvalue-move:
  rvalue reference outputs
  Remove broken %implicitconv for const SWIGTYPE &&
  Remove unnecessary const SWIGTYPE & typemap
  Temporarily remove rvalue reference python runtime test
  std::auto_ptr emulation fix in test case
  Ocaml typemap typo fix
  Fix Racket tests using schemerunme directory
  Docs on rvalue parameter changes
  Test/fixes to handle NULL pointer for unique_ptr/auto_ptr
  Octave - SWIG now marshalls a C/C++ NULL pointer into the null matrix, []
  Racket - NULL pointer handling
  SWIGTYPE && input typemaps now assume object has been moved - Go and OCaml
  SWIGTYPE && input typemaps now assume object has been moved
  SWIGTYPE && input typemaps now assume object has been moved - Java
  Cosmetic stray semi-colon removal after %typemap using quotes
  Cosmetic stray semi-colon removal after %typemap
2022-09-08 19:50:31 +01:00
Clinton Stimpson
e683168018 Use PyObject instead of PySliceObject throughout with Python 3.2+
This supports use of the Py_LIMITED_API.
2022-09-05 22:04:51 -06:00
William S Fulton
c5495fea79 Remove broken %implicitconv for const SWIGTYPE &&
Typemaps should be for SWIGTYPE &&, not just const SWIGTYPE &&.
Needs updating for new approach where the proxy object is moved
for a parameter containing an rvalue reference.
2022-09-05 09:20:59 +01:00
William S Fulton
859264ab94 Remove unnecessary const SWIGTYPE & typemap
This is a duplicate of SWIGTYPE & and the typemap rules result
in SWIGTYPE & being used if there is no const SWIGTYPE & tyemap.
2022-09-05 08:23:58 +01:00
William S Fulton
de13a0020b Ocaml typemap typo fix 2022-09-03 05:37:13 +01:00
Clinton Stimpson
2a0abbb7f6 Python: Use PyType_Modified() instead of modifying flags.
Closes #2345
Also supported with Py_LIMITED_API
2022-09-02 15:54:28 -06:00
William S Fulton
7934561874 Test/fixes to handle NULL pointer for unique_ptr/auto_ptr
Also add missing unique_ptr tests for Lua and Racket.
2022-08-31 19:42:55 +01:00
William S Fulton
ca9eebcb8d Octave - SWIG now marshalls a C/C++ NULL pointer into the null matrix, []
SWIG has always marshalled the null matrix into a NULL pointer; this remains
and now we have consistency in representing a NULL pointer.

This is a pre-requisite for a pending commit to fully support std::unique_ptr.
2022-08-31 19:40:13 +01:00
William S Fulton
2cfd77b1c0 Racket - NULL pointer handling
SWIG now converts a C/C++ NULL pointer into a null value by calling
scheme_make_null(), so that scheme's null? is true for a NULL C/C++
pointer value.

Consistency with Guile and needed for a pending commit for handling
NULL and std::unique_ptr.
2022-08-31 19:40:13 +01:00
William S Fulton
3f622ea65e SWIGTYPE && input typemaps now assume object has been moved - Go and OCaml
Not fully implemented and Untested.
Go's implementation needs fixing to fully support typemaps
before this can be done.
OCaml implementation does not have support for releasing ownership
which is required to add error checking preventing double deletes.
2022-08-31 19:40:13 +01:00
William S Fulton
e139a36511 SWIGTYPE && input typemaps now assume object has been moved
Replicated Java implementation.

Fully implemented for:
- C#
- D
- Guile
- Javascript (UTL)
- Lua
- MzScheme
- Octave (UTL)
- Perl (UTL)
- PHP
- Python (UTL)
- Ruby (UTL)
- Tcl (UTL)

PHP std::auto_ptr std::unique_ptr minor tweaks and testcase corrections
2022-08-31 19:40:14 +01:00
William S Fulton
0634883089 SWIGTYPE && input typemaps now assume object has been moved - Java
Implementation tweak - better RAII.
SWIGTYPE && null pointer check.
2022-08-31 19:40:13 +01:00
William S Fulton
c10a84c775 Cosmetic stray semi-colon removal after %typemap using quotes 2022-08-31 19:40:13 +01:00