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.
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.
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
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
* 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
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.
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.
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.
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.
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.
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.
* 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
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`.
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