Commit Graph

721 Commits

Author SHA1 Message Date
Olly Betts e02efe25db Merge branch 'fbo/indus_doc_csharp' 2024-09-15 09:59:05 +12:00
Olly Betts 7a8c9fdfa8 Straighten out handling of char and string constants
Fixes #904
Fixes #1907
Fixes #2579
Fixes #2990
2024-08-17 16:12:45 +12:00
William S Fulton 74a8aafac0 Pydoc improvements for overloaded functions added to changes file
Also cosmetic code style improvements to the implementation.
2024-08-02 19:07:47 +01:00
William S Fulton 041e966b12 Merge commit '62b603768164e50af4c236fa2e8929cbb46b2ae9'
* commit '62b603768164e50af4c236fa2e8929cbb46b2ae9':
  Also fix docstrings when using Python with -builtin option
  Pass overloaded function itself to add_method() for clarity
  Fix Python docstring for overloads with some Doxygen comments
2024-08-02 19:06:43 +01:00
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 9ef15fd93f Add support for python-3.13 builtin wrappers
New slot, see 04492cbc9a

Start testing python-3.13 in GHA, but leave as 'can fail' as this version
isi still in beta for a few more days.
2024-07-21 10:30:51 +01:00
William S Fulton 71817abc5b Correct type for tp_watched slot 2024-07-21 09:10:01 +01:00
Alexander Shadchin c3e30c5734 Fix missing-field-initializers warning with Py3.13 (#2968)
Introduced https://github.com/python/cpython/pull/114900
2024-07-21 09:03:09 +01:00
Vadim Zeitlin 62b6037681 Also fix docstrings when using Python with -builtin option
Use the recently added find_overload_with_docstring() in builtin case
too.

Note that this relies on the parent commit as add_method() must be
called with the last function in the overload set, and not the last but
one, for find_overload_with_docstring() to work correctly.

Alternatively, we could change find_overload_with_docstring() to look at
all elements of the overload set, not just the preceding, but also the
following ones. However it seems better to keep things simpler and only
call it for the last one.
2024-07-18 17:03:07 +02:00
Vadim Zeitlin 9454c78fa7 Pass overloaded function itself to add_method() for clarity
It's unclear why did we pass the previous element of the overload set
when calling add_method() from dispatchFunction() but it seems that it
was done just to avoid passing anything at all if this function was not
overloaded, presumably because whatever add_method() does if the "node"
argument is not null was already done from elsewhere in this case.

Unfortunately, add_method() doesn't document when should this argument
be null and when it shouldn't be, so it's just guesswork, but at least
the test suite still passes after this change which makes the code a bit
more clear.

And now we use the properties of this node itself in add_method() when
the function is overloaded instead of, completely inexplicably, using
the properties of another overloaded function (which was probably mostly
fine in practice until now because most overloaded functions have the
same properties anyhow).
2024-07-18 16:59:06 +02:00
Vadim Zeitlin 60a695381e Fix Python docstring for overloads with some Doxygen comments
The existing code didn't work correctly if the last element of the
overload set didn't have a Doxygen comment: in this case, no docstring
was generated at all.

Fix this by trying to find any overload with a Doxygen comment, as
Python docstring is common for all of them: add a helper function to do
it and use it for both all kinds of ordinary functions (global, member
and static) and __init__ functions generated for C++ ctors, as docstring
was generated in the same wrong way for all of them in different places.

Note that currently the overloads without Doxygen comments are not
documented at all at Python level, as saying "there exist other
overloads but there is no documentation for them" doesn't seem very
useful and there doesn't seem anything else that we could do.

Add a new unit test for testing all the different combinations of
overloaded functions with and without Doxygen comments.
2024-07-18 15:35:04 +02:00
Erez Geva 2e9d570194
[python, ruby] Add Director guard file with C++ 11 std::mutex (#2870)
* Improve mutex for director use:
- Use C++ 11 mutex and lock classes.
  Most compilers support C++ 11 by default.
  Leave Win32 and POSIX support for older compiler.
- Use a single file for Python and Ruby.
- Use macro also for guard definition instead of using '#ifdef'.
- Rename old '__THREAD__' to 'SWIG_THREADS' to
  avoid collide with other libraries.
- Remove the use of '__PTHREAD__' as it may collide with other libraries.
- Remove mutex from OCaml, as it is not used in Director class.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>

* Fixes follow @wsfulton.

Improve description of director_guard.swg.
Remove duplicate line.
Change to SWIG_GUARD_DEFINITION and SWIG_GUARD_DECLARATION
 as full English words are much more easily understood
 than abbreviations.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>

---------

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2024-07-02 08:54:28 +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