Commit Graph

3576 Commits

Author SHA1 Message Date
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
Olly Betts ddb8791f92 Update comment referencing removed GH API 2023-12-01 11:40:20 +13: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
Christopher Chavez c7e1f591c2
[Tcl] Migrate `CONST` to `const`
`CONST`from tcl.h was for compatibility with systems lacking `const`.
It is to be deprecated in Tcl 8.7, and removed in Tcl 9.0.
2023-11-15 06:28:26 -06: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 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 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 b354e5b871 Merge branch 'part3'
* part3:
  Correct initialization order in Language
  Remove redundant initialization code
2023-10-19 20:11:35 +01:00
William S Fulton 9a691f44c7 Correct initialization order in Language 2023-10-19 08:47:45 +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 c4a4717a28 Remove redundant initialization code
Some of this code is redundant and taken care of by the initializer.
2023-10-16 16:48:04 -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 4a618cd646 Fix misindented line 2023-10-11 08:54:37 +13:00
William S Fulton 64c9720a7a Complete transition to rtypecheck typemaps from hard coded logic
See 973590ff91.

The rtypecheck typemaps implement typechecking in R for each function
parameter using functions such as is.numeric, is.character, is.logical,
is.null etc.

Closes #2605
2023-09-11 08:16:02 +01:00
William S Fulton a28b8cfed4 Redundant code removal in nested.cxx
c96c04c5ae
Replicate changes in this commit to add_symbols() for add_symbols_c().
Setting feature:immutable is now done in Allocate:cDeclaration.
Setting hasconsttype for static const variables (or constexpr) doesn't
look possible in this situation (C code for anonymous structs) - no
valid C syntax that I can figure out.

Anonymous nested structs are necessarily read-only (and set as
immutable in Swig_nested_name_unnamed_c_structs).

From https://sourceforge.net/p/swig/bugs/793/ ...

The union variable intRep below has a named type IntRepType.

typedef struct Object {
  int objtype;
  union IntRepType {
    double dvalue;
  } intRep;
} Object;

void tester() {
  /* approach (1) */
  obj.intRep.dvalue = 1.23;

  /* approach (2) */
  union IntRepType irt;
  irt.dvalue = 2.34;
  obj.intRep = irt;
}

Using C code there are two approaches to setting a value in intRep. Equivalents in perl are:

my $obj = example::Object->new();

 # approach (1)
$obj->{intRep}->{dvalue} = 3.45;

 # approach (2)
my $irt = example::IntRepType->new();
$irt->{dvalue} = 4.56;
$obj->{intRep} = $irt;

An Object_intRep_set wrapper is generated which takes type IntRepType as desired.

However, with an anonymous union:

typedef struct Object {
  int objtype;
  union IntRepType {
    double dvalue;
  } intRep;
} Object;

intRep does not have any named type name and is anonymous. It is thus not possible to create a type outside of Object to assign to intRep.
Only approach (1) is available in C and so SWIG can only provide approach (1) via wrappers too.
There is no Object_intRep_set wrapper, intRep is immutable.
2023-09-10 12:51:42 +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
William S Fulton 275764c7bb Non-assignable detection fixes when wrapping rvalue reference variables
Rvalue reference variables such as the following are non-assignable by
by default:

  X &&v;

Variable setters are not generated when wrapping these non-assignable
variables and classes containing such non-assignable variables.
2023-09-07 07:02:35 +01:00
William S Fulton 912c535add Non-assignable detection fixes when wrapping reference variables
Reference variables such as the following are non-assignable by
by default:

  int &v;

Variable setters are not generated when wrapping these non-assignable
variables and classes containing such non-assignable variables.
2023-09-07 07:02:35 +01:00
William S Fulton f3e12fbd47 Assignment operator detection fixes when wrapping static member variables
Also add tests for global variables are immutable via assignment.
2023-09-07 07:02:35 +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 e07957ad4c Implicit assignment operator detection fixes.
A class that does not have an explicit assignment operator does not
have an implicit assignment operator if a member variable is not
assignable. Similarly should one of the base classes also not be
assignable. Detection of these scenarios has been fixed so that when
wrapping a variable that is not assignable, a variable setter is not
generated in order to avoid a compiler error.

Template instantiation via %template is required in order for this to
work for templates that are not assignable.

Closes #1416
2023-09-07 04:41:52 +01:00
William S Fulton f11bffcb19 Variable setters for non-assignable types
Fix incorrect variable setters being generated when the type of the
variable is not assignable, due to variable type inheriting a private
assignment operator further up the inheritance chain (further up than
the immediate base).
2023-09-04 07:34:06 +01:00
William S Fulton abd299c6f4 Guile, Ocaml, Perl - add missing use of is_assignment() for variable wrappers
Don't attempt to generate a setter when wrapping
variables which have a private assignment operator as assignment is not
possible. This now matches the behaviour of all the other target languages.
2023-09-03 17:55:36 +01:00
William S Fulton bf330ba524 C++11 deleted destructors fixes
Fix problems wrapping deleted destructors. Derived classes are not
constructible, so don't attempt to generate default constructor or
copy constructor wrappers.

  struct StackOnly1 {
    // Only constructible on the stack
    ~StackOnly1() = delete;
  };
  struct StackOnlyDerived1 : StackOnly1 {
    // this class is not constructible due to deleted base destructor
  };
2023-09-02 22:55:58 +01:00
William S Fulton 1f8d4f8eb0 Tidy up internal "has_copy_constructor" attribute 2023-09-02 18:12:41 +01:00
William S Fulton 958e3891bb Tidy up internal "has_destructor" attributes 2023-09-02 18:00:46 +01:00
William S Fulton e69f77f2e1 Remove unused "has_constructor" internal attribute 2023-09-02 17:16:12 +01:00
William S Fulton 33d45f0428 Fix %copyctor feature and C++11 deleted copy constructors
A default constructor wrapper was sometimes incorrectly generated.
2023-09-02 16:55:01 +01:00
William S Fulton fb7e0ef069 C++11 single default deleted constructor fix
Fix for when a class has a default deleted constructor and does
not have any other constructors (except implicit or explicit copy
constructors).

Closes #1644
2023-09-02 14:07:47 +01:00
William S Fulton 605e5a1abb C++11 default deleted constructors fix
SwigValueWrapper was not being used when the default constructor is
deleted for a type passed around by value.

Fix is only for when other constructors declarations are present,
deleted, defaulted or not.

Issue #1644
2023-09-02 12:35:39 +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
Olly Betts 11e4b7c176 Remove lingering bit of except typemap support
Support was removed in 736c052d7d but
I missed this code.
2023-08-09 09:15:50 +12:00
Olly Betts 6ddcbf5959 [Ruby] Remove -feature command line option
This has been deprecated since SWIG 1.3.32 in 2007.  Use -init_name
instead.
2023-08-09 08:37:39 +12:00
Momtchil Momtchev 55207d5e52 handle `"tmap:in" == NULL`
Even if this can't really happen in practice
2023-08-09 08:24:48 +12:00
William S Fulton 2e1506c189 Add support for using declarations to introduce templated members
Add support for using declarations to introduce templated member
methods and for inheriting templated constructors, such as:

  struct Base {
    // templated constructor
    template <typename T> Base(const T &t, const char *s) {}
    // templated member method
    template <typename T> void template_method(const T &t, const char *s) {}
  };

  %template(Base) Base::Base<int>;
  %template(template_method) Base::template_method<double>;

  struct Derived : Base {
    using Base::Base;
    using Base::template_method;
  };

Previously the templated methods and constructors were ignored and
not introduced into the Derived class.
2023-08-07 07:37:28 +01:00
William S Fulton 93732bb195 Fix using declarations for deep inheritance hierarchies
Fixes 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. For example in the code below, Using1::usingmethod(int i)
was not wrapped for use in Using3:

  struct Using1 {
  protected:
    void usingmethod(int i) {}
  };
  struct Using2 : Using1 {
  protected:
    void usingmethod(int i, int j) {}
    using Using1::usingmethod;
  };
  struct Using3 : Using2 {
    void usingmethod(int i, int j, int k) {}
    using Using2::usingmethod;
  };

Similarly for C++11 using declarations for inheriting constructors.
2023-08-05 19:47:17 +01:00
William S Fulton e41080216c Missing scope restore in Allocate::classDeclaration
Restoring the scope was missing when handling base classes - the scope
was not set correctly after visiting base classes.

This bug doesn't seem to manifest itself in any way as either the code
uses fully resolved types or specifically sets the scope when needed,
so I can't see anything that is fixed by this.
2023-08-05 19:47:17 +01:00
William S Fulton 69d5373131 Fix missing constructor generation due to abstract class test failure
when a method is declared in the class along with a
using declaration and the using declaration is declared before
the method that implemented the pure virtual method, such as:

  struct ConcreteDerived : AbstractBase {
    ConcreteDerived() {} // was not wrapped
    using AbstractBase::f;
    virtual void f(int n) override {}
  };

SourceForge bug: https://sourceforge.net/p/swig/bugs/932/

check_implemented in allocate.cxx was correctly finding a
non-abstract method, however, Swig_symbol_clookup_local_check, was
using the using declaration node instead of using the node returned
by check_implemented. The checkfunc is now given more control by
returning the node to use rather than Swig_symbol_clookup_local_check
always using the head of the csym linked list.
2023-08-05 19:47:17 +01:00
William S Fulton 34e25241e7 Comment correction since recent code refactor 2023-08-05 19:46:16 +01:00
William S Fulton b9f1515514 Corrected type returned from calling nodeType 2023-08-05 19:46:15 +01:00
Olly Betts afd4c87b33 Merge branch 'napi-tm-in-duped'
Closes: #2653
2023-08-02 12:20:19 +12:00