Commit Graph

710 Commits

Author SHA1 Message Date
William S Fulton e0b83d61b9 Single line C# documentation indentation formatting fix
Indent single line comments to same level as function definition below
the comment.

Also correct String * -> char * type in Python and C# apis
2024-07-30 00:12:01 +01:00
William S Fulton 2c70a912a6 Add $isvoid special variable
The $isvoid special variable expands to 1 if the
wrapped function has a void return, otherwise expands to 0.

In the implementation, use a consistent variable name, returntype,
for a node's "type" attribute.

Issue #2907
2024-06-15 23:13:12 +01:00
William S Fulton c9f5e1d48e Quick fix demonstration for fixing argout output parameters
Add in $isvoid special variable which expands to 1 if the
wrapped function has a void return, 0 otherwise.
2024-06-15 23:11:46 +01:00
William S Fulton d79ab5ac6b Additional casts for Python DecRef change 2024-03-24 18:12:21 +00:00
William S Fulton 67bc1cbb0f Py_XDECREF -> Py_DecRef for stable ABI compliance 2024-03-24 18:12:21 +00:00
William S Fulton 53ee3fe97b Py_DECREF -> Py_DecRef for stable ABI compliance 2024-03-24 18:12:21 +00:00
William S Fulton 5298707057 Py_IncRef casts 2024-03-24 18:12:21 +00:00
William S Fulton b4cbb91101 Py_XINCREF -> Py_IncRef for stable ABI compliance 2024-03-24 18:12:21 +00:00
William S Fulton e3f25aab51 Py_INCREF -> Py_IncRef for stable ABI compliance 2024-03-24 18:12:21 +00:00
William S Fulton 3be670e8db Fix assertion handling upcasting when using %shared_ptr on some templates.
A different approach is taken for supporting casting smart pointers up the
inheritance hierarchy. We no longer try to replace the underlying pointer type,
provided in the 'feature:smartptr', with the base class type. Such as morphing
'std::shared_ptr<(Derived)>' into 'std::shared_ptr<(Base)>'. Instead, we simply
use 'feature:smartptr' from the base class. This is more reliable than trying to
pattern match the pointer type in the feature. The base class must of course
also have the 'feature:smartptr' set, and this is still checked for as before.
The feature is now parsed in one place and stored in the parse tree in the
new 'smart' attribute for handling by the target languages.

Fix also improves the handling of the type parsed in 'feature:smartptr' in that
the type is now normalized and resolved in the scope of the class it is attached
to.

Closes #2768
2024-01-30 22:24:42 +00:00
William S Fulton 344ca5fbc6 Friend operator overloading fix for Python builtin
Don't generate calls to
  SWIGPY_BINARYFUNC_CLOSURE(_wrap___lshift__)
for the 'global' function wrappers for the friend functions.

Only occurred when a friend class is within a namespace due to the
renames in pyopers.swg, such as:
  %rename(__lshift__) *::operator<<;
The rename was intended for member functions but was also being attached
to friends that are within a namespace.
2024-01-27 14:56:55 +00:00
Olly Betts ab1f9f076c Remove removed -stable-abi option from --help output
See #2727.
2023-12-23 07:57:55 +13: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 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 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 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 c0b36721a3 Replace Language::is_assignable with Language::is_immutable
Avoids confusion with newly created Allocate::is_assignable.
Language::is_immutable is just a wrapper around the
"feature:immutable" flag since previous commit.

is_mutable rename wip
2023-09-07 07:01:37 +01:00
William S Fulton f64ce2cdb7 Add in missing feature:python:tp_watched for python-3.12 2023-08-17 01:11:33 +01:00
William S Fulton 3c5119c614 Test python-3.12 on GHA, fix missing field initialization for builtin 2023-08-17 00:27:17 +01:00
Alexander Shadchin 8aab1590f2 Fix missing-field-initializers warning with Py3.12 2023-08-16 20:10:34 +03:00
William S Fulton 84542f6b59 Replace Language::directorsEnabled() with Swig_directors_enabled()
For use outside of the target languages for forthcoming commits
which move adding default constructors/destructors from Language
to Allocate.
2023-07-12 18:44:42 +01:00
Olly Betts 736c052d7d Remove long deprecated features
These features were all deprecated in 1.3.26 (October 9, 2005)
or before (many long before), so all more than 17 years and 3 new major
versions ago which seems more than enough time for users to have stopped
using them, especially as most emit a deprecation warning if used.
2023-06-15 15:05:15 +12:00
Julien Schueller 2cc4f51f9a Avoid unused parameter self warning 2023-01-27 11:17:30 +13:00
William S Fulton 29bc7492a2 SwigType * handling corrections - Python builtin mangling
Further corrections to pass SwigType * to methods expecting types
instead of passing readable type strings.

Swig_string_mangle() takes a generic String *, but it was calling
functions that require SwigType *. Swig_string_mangle_type() is
now provided for SwigType *.

The previous commit is a pre-requisite in order to prevent duplicate
symbols from being generated in the C++ wrappers.
2022-11-18 19:44:00 +00: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 2f55379687 Improve director unwrap detection for the return type
Resolve the return type to correctly determine if the type is a pointer or
reference to a director class.

SwigType_refptr_count_return() recently added as a simpler fix is no
longer needed.

The conventional approach of using the "type" rather than "decl" to
analyse the return type is used instead too.

Issue #1823
2022-10-10 08:45:26 +01:00
William S Fulton 4a397869a2 Merge branch 'director-unwrap-result'
* director-unwrap-result:
  Unwrap director classes only when returning a pointer or reference to an object
2022-10-07 18:41:14 +01:00
Olly Betts 631b41ae7b Use https for swig.org links 2022-10-06 13:16:39 +13:00
William S Fulton e147f2af69 Generate richcompare switch statements in sorted order 2022-09-30 23:04:06 +01:00
William S Fulton 1d56bc6b85 Add initialisers for additional members in PyHeapTypeObject
(builtin mode) for Python-3.11 - _ht_tpname, _spec_cache.
2022-08-01 08:24:52 +01:00
William S Fulton 6939d91e4c Header file tidyup
Fix Visual C++ warning in scilab.cxx:
  warning C4996: 'strtok': This function or variable may be unsafe.
2022-05-07 11:56:06 +01:00
Kris Thielemans f5934b099b [Python] Replace tp_print with tp_vectorcall_offset slot for Python 3.8
The tp_print slot is no longer supported and replaced with tp_vectorcall_offset.
The (printfunc) cast that we used caused problems on PyPy.

Fixes #2262
2022-04-21 12:28:54 +01:00
Olly Betts 1aeaa2a644 Recognise and ignore Doxygen group commands @{ and @}
Fixes #1750
2022-04-07 12:05:54 +12:00
William S Fulton fe0af80933 Remove some unnecessary empty lines from generated .py file 2022-04-07 00:17:18 +01:00
William S Fulton a12fc916e4 Remove unused functions in Python builtin mode 2022-04-07 00:17:15 +01:00
William S Fulton 9c67a2c007 Remove legacy USE_THISOWN conditional compilation
Seems to be a left over from 'thisown' partial removal
in 985adc13fb
2022-04-06 22:58:17 +01:00
William S Fulton a5be4a10b5 Slight performance improvement for %pythonnondynamic
Setting this is much more likely than thisown
2022-04-06 22:48:33 +01:00
William S Fulton b35ebc81a9 Doxygen comments take precedence over the autodoc feature.
If a "docstring" feature is present it will still override a Doxygen comment.
If the "autodoc" feature is also present, the combined "autodoc" and "docstring"
will override the Doxygen comment. If no "docstring" is present then the
"autodoc" feature will not be generated when there is a Doxygen comment.

This way the "autodoc" feature can be specified and used to provide documentation
for 'missing' Doxygen comments.

Closes #1635
2022-04-06 08:08:14 +01:00
William S Fulton d1b93f2c0e Merge branch 'feature/python-builtin-separate-runtime-data'
* feature/python-builtin-separate-runtime-data:
  Rework swig_and_compile_multi_cpp makefile helper
  Different capsule names for builtin changes entry
  Use different capsule names with and without -builtin

Conflicts:
	CHANGES.current
2022-03-26 15:18:55 +00:00
William S Fulton b737a64ec5 Remove minimum Python version check
The version checking was historically done to deal with
different versions and importing the low-level Python
module. Then it was used to try and help when using -py3.
A minimum version check implies that the wrappers work
with any version >= 2.7, which is not really correct.
The correct thing to do is to check that the exact
version used matches the one that the C layer was compiled
against, which can only be left for the user to do, perhaps
using %pythonbegin.

Issue #1779
2022-03-25 19:09:17 +00:00
William S Fulton a343b7e254 Remove -py3 command line option
Closes #1779
2022-03-23 18:13:07 +00:00
William S Fulton df86fbc54e Remove option to use Python 3 only syntax for %pythonnondynamic feature
A metaclass is added using a decorator @_swig_add_metaclass which
is designed to provide a metaclass that works for both Python 2 and Python 3.
The option to use the Python 3 only syntax: metaclass=_SwigNonDynamicMeta
via the -py3 command line option has been removed as part of a
simplification to remove the -py3 option.

Issue #1779
2022-03-23 07:58:39 +00:00
William S Fulton f068f2c2d6 Add Python < 3.3 support for pyabc.i
pyabc.i for abstract base classes now supports versions of Python
prior to 3.3 by using the collection module for these older versions.
Python-3.3 and later continue to use the collections.abc module.
The -py3 option no longer has any effect on the %pythonabc feature.
2022-03-23 07:58:01 +00:00
William S Fulton 21c2e47661 Python -flatstaticmethod corrections
Correct logic for suppressing static methods.
Previous logic was missing director disown methods.
Add changes file entry for -flatstaticmethod.

Closes #2137
2022-03-21 19:22:49 +00:00
Eugene Toder f733efd3c0 Use different capsule names with and without -builtin
Types generated with and without -builtin are not compatible. Mixing
them in a common type list leads to crashes. Avoid this by using
different capsule names: "type_pointer_capsule" without -builtin and
"type_pointer_capsule_builtin" with.

See #1684
2022-03-18 13:44:54 -04:00
Jim Easterbrook b8f10a55f9 Enable flat static constructor methods
These are needed to provide renamed overloaded constructors and the
like.
2022-03-18 11:10:14 +01:00
Jim Easterbrook 63ef91939b Use flat static method if it's a "friend"
This allows the friends test case to pass, with or without -builtin.
2022-03-18 11:10:14 +01:00
Julien Schueller 484e5316f2 Python: Option to generate flat class methods 2022-03-18 11:10:14 +01:00
Olly Betts 55377bdc08 Add DOH Exit() and SetExitHandler()
Exit() is a wrapper for exit() by default, but SetExitHandler() allows
specifying a function to call instead.

This means that failures within DOH (e.g. Malloc() failing due to lack
of memory) will now perform cleanup such as removing output files.

This commit also cleans up exit statuses so SWIG should now reliably
exit with status 0 if the run was successful and status 1 if there was
an error (or a warning and -Werror was in effect).

Previously in some situations SWIG would try to exit with the status set
to the number of errors encountered, but that's problematic - for
example if there were 256 errors this would result in exit status 0 on
most platforms.  Also some error statuses have special meanings e.g.
those defined by <sysexits.h>.

Also SWIG/Javascript tried to exit with status -1 in a few places (which
typically results in exit status 255).
2022-03-06 12:33:54 +13:00