Commit Graph

23902 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 a2f852b6f4 Corrections for using EXTRA_CXXFLAGS in GHA 2023-12-19 09:03:35 +00:00
William S Fulton d2a071e8b0 Fix for python-3.11+ and stable abi
For printf
2023-12-19 08:54:41 +00:00
William S Fulton dff1afce33 Fix seg fault using stable abi for Python < 3.10 for invalid unicode
Restore Python error instead of seg faulting

Fixes unicode_strings testcase for Py_LIMITED_API < 3.10
2023-12-19 00:02:25 +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 2e956c1607 SWIG_AsCharPtrAndSize simplification and performance improvement
Only make a copy of the returned string if the passed in Python object
does not own the returned char* string. Callers of SWIG_AsCharPtrAndSize
should now ensure that the returned string is only used while the passed
in PyObject * string is valid. Performance improvement is for Python 3
input string handling.

The new SWIG_PyUnicode_AsUTF8AndSize function allows for this simplification.
2023-12-15 22:31:50 +00:00
William S Fulton 17ca54844c Revert mistaken directorout std::string_view typemap change 2023-12-14 07:24:12 +00:00
William S Fulton 84f6031aa5 Fix std::string_view typemaps for Py_LIMITED_API
Except for directorout typemaps which are fundamentally broken as a string_view is returned when viewing a deleted char *
2023-12-13 22:12:17 +00:00
William S Fulton 2c4c404e44 -Werror=declaration-after-statement fix for Python 2 2023-12-13 21:21:39 +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
William S Fulton 2808e1d834 Simpler SWIG_AsCharPtrAndSize implementation - remove usage of SWIG_Python_str_AsChar 2023-12-13 08:30:22 +00:00
William S Fulton a75b87d318 Rename -py3-stable-abi option to -stable-abi
Since this was first added, the -py3 option has been dropped
and the Stable ABI is known as exactly that, not the Python3 Stable ABI.

Document the new option and turn on c++20 testing for it to cover
std::filesystem and std::string_view testing which are affected
2023-12-06 08:01:22 +00:00
William S Fulton 360b19102c Python stable abi memory leak fix
Add missing Py_XDECREF after calling PyObject_GetAttrString.

Cleanup:
SWIG_Python_str_AsChar() no longer needs a call to SWIG_Python_str_DelForPy3
to free allocated memory, see 0b9d4eff09
2023-12-04 20:14:32 +00:00
William S Fulton 29626ad18d Python stable abi for std::filesystem 2023-12-04 19:18:36 +00:00
William S Fulton 265065b677 Merge conflict fixes and consistent error reporting in stable abi checks 2023-12-04 19:18:19 +00:00
William S Fulton 1451607eda Merge branch 'py3-stable-abi'
* py3-stable-abi:
  Add CI build using -py3-stable-abi option
  Make Python buffer typemaps compatible with limited API
  Don't use PyUnicode_AsUTF8() when python limited API is used
  Make directors implementation for Python work with limited API
  Support using stable Python ABI

Conflicts:
	.github/workflows/ci.yml
	Lib/python/pyhead.swg
	Lib/python/pyrun.swg
	Source/Modules/python.cxx
2023-12-01 18:38:07 +00:00
William S Fulton 88c2715154 Add changes entry for python potential multi-thread crash 2023-12-01 10:18:07 +00:00
William S Fulton 4fa04e621f Merge branch 'fix-python-threads-crash'
* fix-python-threads-crash:
  [python] Prevent a potential multithreading crash
2023-12-01 10:11:24 +00:00
Olly Betts ddb8791f92 Update comment referencing removed GH API 2023-12-01 11:40:20 +13:00
Olly Betts b9e02505e4 [guile] Remove unnecessary (char*) casts
All these guile API functions take const char* - it looks like these
casts were needed with older versions of the GH API and were just
carried over when SWIG migrated from generating code targeting GH to
targeting SCM.
2023-12-01 11:40:20 +13:00
Olly Betts a1e5b1b633 Eliminate lingering use of removed GH API
Looks like the patch to remove uses of the GH API crossed with the
patch which added this code.
2023-12-01 11:40:07 +13:00
Olly Betts e7128e8539 Fix out-dated developer docs 2023-12-01 10:46:48 +13:00
Olly Betts ab6397a891 Removed unused T_ENUM code
As best I can make out T_ENUM has never been used since it was added by
an apparently unrelated commit in 2000:
bcc6cbfb16
2023-12-01 08:59:30 +13:00
Olly Betts da018ed6f7 Support type deduction of enums
Fixes #2715
2023-12-01 08:57:41 +13:00
Olly Betts bf99d0f28a Address decltype(foo(0)) segfault better
The underlying problem here is that NewSwigType() returns an empty
string for T_USER and some other codes, so instead check for that
in deduce_type() and map to NULL instead.

This should fix any other such cases which currently segfault.
2023-12-01 08:24:40 +13:00
Olly Betts d2c0105d72 Fix segfault on decltype(foo(0))
We don't yet handle inferring the type of a function call, but we
shouldn't segfault.

No regression test as I couldn't see how to write one (if I use
%ignore the segfault isn't triggered) but hopefully we can teach
SWIG to actually deduce the type in this case.
2023-11-30 18:03:28 +13:00
Olly Betts 35c21c2db2 Update type inference documentation
We can now handle many more cases.
2023-11-30 17:56:00 +13:00
Olly Betts a8091575c1 Fix typos in comments and docs 2023-11-30 17:07:16 +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 bd093173af Add <type_traits> fragment for traits usage in std::filesystem 2023-11-18 10:32:31 +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 d2221f1547 Fix memory leak wrapping const std::filesystem& 2023-11-17 23:11:30 +00: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
William S Fulton 50312e21f5 Cosmetic whitespace corrections 2023-11-17 22:06:16 +00:00
William S Fulton 940b41f40a GHA allow fail for ruby-3.3
ruby-3.3 is in dev at the moment and has just started asserting.
Started with ruby 3.3.0dev (2023-11-12 master 60e19a0b5f)
2023-11-17 18:36:01 +00:00
William S Fulton 7b4e562dc1 Fix for closing off C# property declaration
Consistently handle variables as constants or as variable wrappers
to match code in Language::staticmembervariableHandler(). This fixes
the following:

  #define constexpr
  %immutable Foo::Constant;
  struct Foo {
      static size_t constexpr ConstantA = 22;
      static constexpr size_t ConstantB = 64;
  };

which is actually invalid C++, but being done to workaround a SWIG
parser limitation for parsing ConstantA (ConstantB is okay) if constexpr
is left in.

Closes #2573
2023-11-17 07:47:43 +00:00
Olly Betts 3ce0174a0c Fix random doubled spaces in code 2023-11-17 09:49:36 +13:00
Olly Betts 714cd79f11 Add CHANGES entries for previous two commits 2023-11-17 09:47:19 +13:00