Commit Graph

6177 Commits

Author SHA1 Message Date
William S Fulton f8c2dd67cd docstring example for stable abi
Remove -O (-fastproxy) from the docstrings example as -fastproxy
does not currently work with the stable abi
2023-12-19 21:17:41 +00:00
William S Fulton ef0bbcd6ed Document Python stable ABI support
Remove -stable-abi option: going forwards enabling the stable ABI
simply requires setting Py_LIMITED_ABI when compiling the wrappers.
2023-12-18 23:30:36 +00:00
William S Fulton f89dd59d4b Replace SWIG_Python_str_AsChar with SWIG_PyUnicode_AsUTF8AndSize
SWIG_Python_str_AsChar has undefined behaviour when Py_LIMITED_API is defined
as it returns a pointer to a string in a PyBytes object that no longer exists.

SWIG_PyUnicode_AsUTF8AndSize is an efficient replacement, but requires a
different API and the caller to decrement the refcount on the intermediate
PyObject in the Py_LIMITED_API < 0x030A0000 implementation. The alternative
would have required copying the returned char * string as was done in a
previous implementation requiring a call to the defunct SWIG_Python_str_DelForPy3
function.

Any users calling the removed API will have to make changes.
2023-12-13 19:55:34 +00:00
Olly Betts da018ed6f7 Support type deduction of enums
Fixes #2715
2023-12-01 08:57:41 +13:00
William S Fulton d11d729fbd Add missing cpp20_constexpr_destructor testcase 2023-11-25 08:50:25 +00:00
William S Fulton 8d17973f08 Add support for C++20 constexpr destructors
In the parser, cpp_end and cpp_vend are very similar. cpp_end is removed
and instead replaced by cpp_vend and additional checks that ensure a
non-virtual destructor does not have a pure specifier.
2023-11-24 20:12:02 +00:00
Olly Betts 0ea0c8ccc8 Only suppress -Wbool-compare for GCC >= 5 2023-11-19 22:25:39 +13:00
Olly Betts 7852bf7b1d Avoid warning in cpp11_decltype
GCC was emitting:

../../cpp11_decltype_wrap.cxx:1374:15: warning: ‘~’ on an expression of type ‘bool’ [-Wbool-operation]
 1374 |     decltype(~false) should_be_int3;
      |               ^~~~~
../../cpp11_decltype_wrap.cxx:1374:15: note: did you mean to use logical not (‘!’)?

Adjust to test operator `~` on a character constant instead.
2023-11-19 22:23:17 +13:00
Olly Betts b5ca500b40 Deduce type of TYPE(EXPRESSION)
This is actually an easy case - e.g. the type of `double(4)` is
`double`.
2023-11-19 22:08:25 +13:00
Olly Betts 5f8b9135cc Fix director_classes testcase failures on x86
Adjust the floating point constants to be 1.125 and 2.25 (which
can be exactly represented in base-2 floating point) instead of
1.1 and 2.2 (which can't).  This avoids problems on platforms where
floating point calculations suffer from excess precision, the most
commonly used of which is x86 when using 387 FP instructions.
2023-11-19 21:45:30 +13:00
Olly Betts f50cea31e0 Suppress -Wbool-comapre warnings in constant_expr_c testcase
We're deliberately testing constant expressions contains comparisons
here.
2023-11-19 21:45:30 +13:00
Olly Betts d506235a6d Fix testcase addition in previous commit 2023-11-19 21:15:46 +13:00
Olly Betts 967dd4e5c1 Fix dropping of parentheses around < and > expressions
We were dropping parentheses in these cases, which can change the value
of the expression.
2023-11-19 16:28:13 +13:00
Olly Betts 25654e4ad9 Fix deduced result type of bitwise not
This wasn't getting integer promotion applied to it.
2023-11-19 16:27:17 +13:00
William S Fulton faf1e17b45 Merge branch 'std_filesystem_python'
* std_filesystem_python:
  Add <type_traits> fragment for traits usage in std::filesystem
  Correct const std::filesystem & typemaps
  Fix memory leak wrapping const std::filesystem&
  std::filesystem pointer handling correction
  Python std::filesystem cleanup
  Cosmetic whitespace corrections
  Try to use wstring/wchar_t on windows
  Reformat
  Rename the helpers within the fragment to be more uniquely named
  Make CI rerun (and output all failed cases for the specialPath)
  Address review comments
  Need to see which assert is failing on mingw
  Verbose assert to try and see the failure on mingw
  path::string() returns a copy not a const ref.
  Remove cpp17_std_filesystem from common.mk, only defined for Python for now
  Extend roundtrip test
  Address review comment by @degasus on #1999 originally
  Had trouble getting the test to be properly ignored. If I wrap the inline line 35 in #if __cplusplus the wrapper code isn't generated
  Tweak tests setup
  Cherry pick from yasamoka/master

Conflicts:
	CHANGES.current
2023-11-18 10:50:29 +00:00
William S Fulton 9bbd176038 Correct const std::filesystem & typemaps
Marshal to pathlib.Path
2023-11-18 10:03:52 +00:00
Olly Betts 997616e652 Improve type deduction
Create a new T_UNKNOWN type code and use this for the cases where
we previously abused T_INT.  This means we can now reliably deduce
`int` when we see T_INT.

Fix the deduced result types of unary plus and unary minus which weren't
getting integer promotion applied to them.

Fix the deduced result type of the C++ logical not operator which was
`int` but should be `bool`.
2023-11-18 18:27:29 +13:00
William S Fulton ac5cd598f8 std::filesystem pointer handling correction
Only passing std:filesystem by value and const ref is marshalled to a pathlib.Path.
This is consistent with all other marhalling in SWIG.
2023-11-17 23:01:28 +00:00
William S Fulton f6d8c6b089 Python std::filesystem cleanup 2023-11-17 22:29:59 +00:00
Olly Betts 3ce0174a0c Fix random doubled spaces in code 2023-11-17 09:49:36 +13:00
William S Fulton 22303787eb
Enhance the C# std::unordered_set testcase 2023-11-11 21:23:20 +00:00
William S Fulton d8c21410e2 Replace empty() method with IsEmpty C# property in STL containers
For consistency across all containers, although only some .NET container
interfaces define IsEmpty.
2023-11-10 07:45:01 +00:00
William S Fulton dfef236a4a Add C# std_unordered_set.i for wrapping std::std_unordered_set 2023-11-10 07:45:01 +00:00
Olly Betts 13eca97013 Support -std= command line option
SWIG now supports command line options -std=cXX and -std=c++XX to
specify the C/C++ standards version.  The only effect of these options
is to set appropriate values for __STDC_VERSION__ and __cplusplus
respectively, which is useful if you're wrapping headers which have
preprocessor checks based on their values.

Closes #2591
2023-11-09 12:27:44 +13:00
William S Fulton 432daea78c Merge branch 'bda_add_unordered_map'
* bda_add_unordered_map:
  Add runtime tests for C# std::unordered_map
  csharp: Added std_unordered_map.i

Conflicts:
	CHANGES.current
2023-11-08 18:13:28 +00:00
William S Fulton cb9d53b8be Add runtime tests for C# std::unordered_map 2023-11-08 18:11:40 +00:00
William S Fulton 3cfaae48ef Add csbegin, dbegin, javabegin for %module
[C#] Support nullable reference types. A generic C# option to the
%module directive allows one to add in any code at the beginning of every
C# file. This can add the #nullable enable preprocessor directive at the beginning
of every C# file in order to enable nullable reference types as follows:

  %module(csbegin="#nullable enable\n") mymodule

Closes #2681

[D, Java] Add the dbegin option to the %module directive for generating code at
the beginning of every D file. Similarly javabegin for Java. This enables one
to add a common comment at the start of each D/Java file.
2023-11-06 19:12:35 +00:00
William S Fulton ec6640d6d2 Modify testcase to be c++98 compliant 2023-11-03 19:23:56 +00:00
William S Fulton 68b0fd809f $typemap() fix for handling variable overrides
Fix when variable override contains a pointer dereference ->.
This enables use of $1.x as a variable override value as SWIG
replaces $1.x with a pointer dereference expression, such as
(&arg1)->x.

Added a testcase showing how Python typemaps could alternatively
be written using $typemap() instead of using C++ templates as used in
the UTL. I'm not convinced this is fully reliable or even a good idea,
so the variable replacements in $typemap() remain undocumented.
2023-11-03 09:07:51 +00:00
William S Fulton e8d3c74590 Improvements to $typemap() special variable replacement overrides
In $typemap(), the $n special variables are replaced by the appropriate
value for the type associated with the typemap calling $typemap().
The (undocumented) special variable overrides now also support
controlling what the $n special variables are replaced with from the
calling typemap, for example:

  %typemap(in) std::pair<std::string, int> {
    int& input_value_second = $1.second;
    $typemap(in, int, 1=input_value_second);
    ...
  }

replaces $1 in the int typemap with input_value_second instead of
whatever is the default for the target language (a variable that holds
the int value after marshalling from the target language).

This additional functionality might make it possible to replace the C++
templates used in the UTL with a much simpler system of typemaps utilising
$typemap(). See follow on commit to typemaps.c.
2023-11-03 09:07:51 +00:00
William S Fulton d701f0b4b2 Correct the implementation of Python PEP 207.
Don't convert all exceptions into a NotImplemented return
when wrapping operators which are marked with %pythonmaybecall.

Closes #1783
2023-10-21 09:25:10 +01:00
William S Fulton 5e5549929c Merge branch 'part2'
* part2:
  Use single characters instead of strings where possible
2023-10-19 20:11:31 +01:00
William S Fulton 5eb3810dac C++11 enum base type is now used for D enum base type 2023-10-18 19:57:20 +01:00
William S Fulton af72fbb08b C++11 enum base type is now used for C# underlying enum type 2023-10-18 19:56:08 +01:00
Rose 5932fff4e2 Use single characters instead of strings where possible
This makes the code clearer and faster
2023-10-16 17:51:48 -04:00
William S Fulton 791d0a5e17 Further using declarations fix for inheritance hierarchies
more than two deep and the using declarations are overloaded.
Using declarations from a base class' base were not available for use
in the target language when the using declaration was before a method
declaration.

Closes #2687
2023-10-16 20:05:34 +01:00
Olly Betts 4a85d04793 [PHP] Fix testcase director_finalizer with PHP 8.3
Fixes #2685
2023-10-11 09:16:06 +13:00
Olly Betts bb2b97b228 Fix comment typos 2023-10-11 08:54:37 +13:00
William S Fulton fb91d1fa25 Improved C long handling for C#
Defining SWIGWORDSIZE64 now applies the (unsigned)
long long typemaps to (unsigned) long for a better match on systems
where long is 64-bits. A new "Type mapping" section has been added into
the CSharp.html documentation covering this and marshalling of primitive
types. C (unsigned) long handling remains as is by default, that is,
marshall as 32-bit.

The INPUT[], OUTPUT[], INOUT[], FIXED[] typemaps for long and unsigned long
in arrays_csharp.i can now be used and compiled on 64-bit platforms where
sizeof(long) != sizeof(int). Requires SWIGWORDSIZE64 to be defined.

Move SWIGWORDSIZE64 check into fragments

Changes also made so that the C# test-suite passes using:
  env SWIG_FEATURES=-DSWIGWORDSIZE64 make check-csharp-test-suite

See issue #2379
2023-10-05 21:30:52 +01:00
William S Fulton 7bba06b03e Java - SWIGWORDSIZE64 for long type
Defining SWIGWORDSIZE64 now applies the (unsigned) long long
typemaps to (unsigned) long for a better match on systems
where long is 64-bits.

Although size_t typemaps are now applied from the int typemaps instead
of the long typemaps, identical code is generated and the mapping is
still to the Java signed long type.

Closes #646
Closes #649

Running the test-suite as follows on a 64-bit long system:

  env SWIG_FEATURES=-DSWIGWORDSIZE64 make check-java-test-suite

passes, except for a few tests which fail where they expect the
default Java type to be int or long instead of long or BigInteger
respectively.

Also arrays_java.i results in:
  invalid conversion from ‘long int*’ to ‘long long int*’ [-fpermissive]
  invalid conversion from ‘long int**’ to ‘long long int**’ [-fpermissive]
2023-10-05 21:30:30 +01:00
William S Fulton 4b6b711fa3 Merge branch 'issue/2625'
* issue/2625:
  Enhanced std::map for non-default constructible types changes entry
  Add missing exception.i for std::map wrappers for MzScheme and Guile
  std::map wrappers and non-default constructible
  Fixed make file ordering
  Fixed line endings
  Added unit test
  Using #ifdef instead of #if to prevent warnings
  Fix for #2625 Using c++17 insert_or_assign for std::map when available.

Conflicts:
	CHANGES.current
2023-09-18 19:29:56 +01:00
William S Fulton 7f63ea6b2f Enhanced std::map for non-default constructible types changes entry
Improve testcase too.
2023-09-18 19:29:04 +01:00
William S Fulton 8d3f5e75d0 Add missing exception.i for std::map wrappers for MzScheme and Guile 2023-09-15 19:17:34 +01:00
William S Fulton 76fdf2c355 std::map wrappers and non-default constructible
Fix and test Guile, MzScheme, Java, Javascript
Octave is also failing.
2023-09-15 19:17:34 +01:00
William S Fulton 68ec78b37a Add test for C++ boolean types in preprocessor
preproc_cpptest was missing in common.mk

Issue #2394
2023-09-11 20:41:11 +01:00
AndLLA 04355afeb3
Rtest3 (#2448)
Improve li_std_vector_vector runtime test for R

- Fix unittest_sequence to fail if elements don't match.
- li_std_vector_vector testcase fixes.

Replace list with c because vectors in R are not exactly lists,
therefore comparing vectors (returned by C++) with R lists
complicates things a lot. Added as.integer because by default
numbers are numeric and I guess we want to check the exact type
returned by C++ which is integer the first check fails because
make_vector_int returns a vector of strings (containing numbers),
not integers (in the previous version this test would pass
because R does an implicit 

Closes #2448
2023-09-11 18:35:57 +01:00
William S Fulton 650aad82ed Fix incorrect variable setters being generated when wrapping arrays
A setter is no longer generated if the type of the array members
are non-assignable.
2023-09-09 19:15:15 +01:00
William S Fulton d4abe14f7e Non-assignable detection fixes when wrapping const 2D arrays
Const member variables such as the following are non-assignable by
by default:

  const int x[2][2];

Variable setters are not generated when wrapping these non-assignable
variables and classes containing such non-assignable variables.
2023-09-09 12:31:33 +01:00
William S Fulton c96c04c5ae Non-assignable detection fixes when wrapping const member variables
Const member variables such as the following are non-assignable by
by default:

  char * const x;
  const int x;
  const int x[1];

but not:

  const char * x;

Variable setters are not generated when wrapping these non-assignable
variables and classes containing such non-assignable variables.
2023-09-09 06:24:14 +01:00
William S Fulton ec53b06b8a Restore missing variable setters for types containing non-assignable static members
A struct/class that contains a non-assignable member variable is
actually assignable itself. Only non-static members, not static members,
contribute to the containing class being non-assignable.

Recent regression fix from a few commits back.
2023-09-08 07:49:01 +01:00