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
Expanding test cases, which found a bug with static methods and global
functions (they needed their own special handling).
Fixing code to match swig style rules and some other code quality.
And documentation fixes.
We need a way to specify default arguments for functions. Sometimes
we can just take the arguments straight from c++ literals. Sometimes
you can't, and need to specify those by hand.
So to make this work we:
1. Shutoff handling all "defaultargs" variants of methods and constructors
which have cs:defaultargs defined for their node. This gets us a single
constructor or method and skips the variants.
2. As we emit arguments in the function declaration, check if there is a
definition for it it from cs:defaultargs, if so, use that. If not,
and the method has a cs:defaultargs declaration, then fall back to the
literal expression from c++.
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
[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.
Further corrections to pass SwigType * to methods expecting types
instead of passing readable type strings.
Required reworking code that adds a fake inheritance for smart pointers
using the smartptr feature. Swig_smartptr_upcast() added as a support
function for this.
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
* imfunc:
Add special variable imfuncname expansion for C# and D
Test and document imfuncname special variable expansion
Update docs.
Also expose in proxyClassFunctionHandler
Expose to javaout typemaps.
Conflicts:
CHANGES.current
* csharp-strenghten-overload-check:
Fix expanded director_basic test.
Improve correctness of SwigDerivedClassHasMethod() by making sure only methods that have `override` are used connected by director.
Segfault was actually avoided in previous commit ab23cb29.
This commit makes handling more robust in the event of
using %ignore just on the derived method, not tested as it is not
what one should do with directors, and possibly other cases.
Go still segfaults with the new testcase director_using_member_scopes.i.
Issue #1441.
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).
These were officially deprecated in 2001, and attempts to use them have
resulted in a warning (including a pointer to what to update them to)
for most if not all of that time.
Fixes#1984
Add ability to change the modifiers for the C# and Java
interface generated when using the %interface macros.
For C# use the 'csinterfacemodifiers' typemap.
For Java use the 'javainterfacemodifiers' typemap.
For example:
%typemap(csinterfacemodifiers) X "internal interface"
Closes#1874
* shared-ptr-template-upcast:
comments
Applying shared_ptr template upcast fix to CSharp, adding CSharp test, and cleanup
Adding test case demonstrating issue where SWIG does not generate a correctly typed, upcasted shared_ptr for a template instantiation deriving from a base class
WIP - Use the non-encoded type string for upcasting a shared_ptr of a derived type to a shared_ptr of the base type
comments
Applying shared_ptr template upcast fix to CSharp, adding CSharp test, and cleanup
Adding test case demonstrating issue where SWIG does not generate a correctly typed, upcasted shared_ptr for a template instantiation deriving from a base class
WIP - Use the non-encoded type string for upcasting a shared_ptr of a derived type to a shared_ptr of the base type
- Add support to DOH Replace for not replacing inside C comments
- Fix removing 'out' or 'ref' when these are present in C comments
in cstype typemaps.
Closes#1628
Previously just the Dispose() method was generated.
Now the Dispose() and Dispose(bool disposing) methods are generated.
Changes are required if custom "csfinalize", "csdestruct" or "csdestruct_derived"
typemaps are being used. Details in #421 on Github. SWIG will error out if one of
the "csfinalize, "csdestruct" or "csdestruct_derived" typemaps are found. Example
error message:
foo.h:60: Error: A deprecated csfinalize typemap was found for Foo, please remove
it and replace all csdestruct, csdestruct_derived and csfinalize typemaps by the
csdispose, csdispose_derived, csdisposing and csdisposing_derived typemaps.
Closes#421
Since we are mixing `new` and `override` a class instance may have multiple methods with the same name. in case of director_basic test one method comes from `MyClassMiddle` (one that participates in dynamic dispatch) and one comes from `MyClassEnd` (one with `new` keyword). Therefore all methods have to be checked.
C# does not treat `virtual` methods of child classes as overriding (ass opposed to c++). In order to override a method it must have `override` specified.
Previous version of this method treated `virtual void foo()` or `void foo()` in a subclass as methods that override virtual method of parent class. This resulted in `SwigDirectorConnect()` creating delegates and connecting them to a native class. Presence of such methods caused needless roundtrip through managed layer while in the end correct native function was called.
This is the old code flow:
```cpp
void SwigDirector_MyClass::nonOverride() {
if (!swig_callbacknonOverride) { // 0. swig_callbacknonOverride is set
MyClass::nonOverride();
return;
} else {
swig_callbacknonOverride(); // 1. this is called because wrapper mistakenly assumes overriding
}
}
SWIGEXPORT void SWIGSTDCALL CSharp_director_basicNamespace_MyClass_nonOverrideSwigExplicitMyClass(void * jarg1) {
MyClass *arg1 = (MyClass *) 0 ;
arg1 = (MyClass *)jarg1;
(arg1)->MyClass::nonOverride(); // 5. Correct method called in the end
}
```
```cs
private void SwigDirectornonOverride() {
nonOverride(); // 2.
}
public virtual void nonOverride() {
if (SwigDerivedClassHasMethod("nonOverride", swigMethodTypes4)) // 3. This returns `true`
director_basicPINVOKE.MyClass_nonOverrideSwigExplicitMyClass(swigCPtr); // 4. Native method of director class called explicitly
else
director_basicPINVOKE.MyClass_nonOverride(swigCPtr);
}
```
This is the new code flow:
```cpp
void SwigDirector_MyClass::nonOverride() {
if (!swig_callbacknonOverride) { // 0. swig_callbacknonOverride is not set
MyClass::nonOverride(); // 1. Calls correct method immediately
return;
} else {
swig_callbacknonOverride();
}
}
```
Add support so that the %csmethodmodifiers, %dmethodmodifiers,
%javamethodmodifiers can modify the method modifiers for the destructor wrappers
in the proxy class: dispose, Dispose, delete. With this feature, it is now possible
to make a C# proxy class sealed, eg when wrapping a class X, the virtual method modifiers
can be removed using:
%typemap(csclassmodifiers) X "public sealed class"
%csmethodmodifiers X::~X "public /*virtual*/";
- Fixes generation of director method declarations containing C++11 ref-qualifiers.
- Fixes generation of director method declarations returning more complex types such
as const ref pointers.
- Rewrite Swig_method_call to use more up to date code in the core.
The directorin typemaps will now generate a temporary variable
(specified after the type), such as:
%typemap(directorin) MyType (MyType *temp) { ... use temp ... }
The shared_ptr director typemaps have been fixed for use in functions
that take more than one parameter.