Commit graph

303 commits

Author SHA1 Message Date
William S Fulton
15a0681b11 Add note about wchar_t marshalling fix required for Windows 2019-07-25 18:57:10 +01:00
smithx
03f7745364 fix undesirable wstring encoding at return value marshalling for C# 2019-07-22 19:11:21 +01:00
smithx
8f6d97ab8c fix undesirable wstring encoding at return value marshalling for C# 2019-07-22 19:11:21 +01:00
William S Fulton
53b425b638 Merge branch 'bugfix/616-csharp-bool-array'
* bugfix/616-csharp-bool-array:
  Add changes entry to fix C# bool[]
  Quieten failing bool[] testcase message
  Skip failing bool[] test cases when running under mono
  Change C# bool[] typemaps to marshall as 1-byte
2019-07-16 19:51:32 +01:00
Vadim Zeitlin
28c6140c56 Allow std::set<> C# typemaps to work for non-nullable types too
Notably make them work for primitive types, such as "int".

Doing this requires using "object" instead of the actual C# type of the
variable to store the current value in the iterator, as we don't
currently have a "csnullabletype" typemap that would expand to "T" for
nullable types and "T?" for the other ones. This is a bit ugly, but it
shouldn't matter much for the generated code and is already done in
std::vector<> typemaps.

Also add a simple unit test verifying the basic functionality for such
vectors.

Closes #1568.
2019-07-11 13:09:46 +02:00
Vadim Zeitlin
53d75dc133 Replace leftover string with the proper type in C# set typemap
This is just a mistake remaining from generalizing the old
string-specific typemap to any type.

Fix it now and update a unit test to test for sets of objects other than
strings.
2019-07-11 12:49:17 +02:00
Gareth Francis
58863bba59 Change C# bool[] typemaps to marshall as 1-byte
Default marshalling for bool[] now uses 1-byte entries in the array, to
ensure array contents is as expected in C++.

When running under mono csharp_lib_arrays_bool testcase will fail
due to an apparent bug in mono. Works correctly under Microsoft's
runtime. See https://github.com/mono/mono/issues/15592
2019-07-06 12:56:27 +01:00
William S Fulton
d67c133c4a Java/C# std::vector<bool> workarounds for clang
Workaround clang++ 9.1.0 error not knowing std::vector<bool>::const_reference
is actually typedef to bool:

  li_std_vector_wrap.cxx:1838:40: error: no matching constructor for initialization of 'std::vector<bool>::const_reference'

Workaround is use

  const value_type& getitem(int index) throw (std::out_of_range) { ...
  // bool specialization:
  bool getitem(int index) throw (std::out_of_range) { ...

instead of

  const_reference_type getitem(int index) throw (std::out_of_range) { ...

Although the following would be better, it would require a more
complicated implementation:

  const_reference_type getitem(int index) throw (std::out_of_range) { ...
  // bool specialization:
  bool getitem(int index) throw (std::out_of_range) { ...
2019-04-20 11:32:42 +01:00
William S Fulton
f87182ad98 Improve backwards compatibility in C#/Java std::array wrappers
For users who have typemaps for the parameters in the setitem or set methods.
2019-04-19 11:06:24 +01:00
William S Fulton
c79cf79085 Improve backwards compatibility in C# std::vector wrappers
For users who have typemaps for the parameters in the setitem method.
Correct definitions of const_reference to match the those in the
(C++11) standard.
2019-04-19 00:11:22 +01:00
William S Fulton
00528a1ef6 Fix C# wrappers FxCop warning CA2002 in SWIGPendingException
Fixes two warnings in each wrapper:

warning  : CA2002 : Microsoft.Reliability : 'examplePINVOKE.SWIGPendingException.Retrieve()' locks on a reference of type 'Type'. Replace this with a lock against an object with strong-identity.

warning  : CA2002 : Microsoft.Reliability : 'examplePINVOKE.SWIGPendingException.Set(Exception)' locks on a reference of type 'Type'. Replace this with a lock against an object with strong-identity.

Use lock statement advice not to use typeof for locks, see
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/lock-statement
2019-04-09 19:35:00 +01:00
William S Fulton
06462acdf9 Fix C# CA1063 warning by implementing the recommended Dispose methods.
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
2019-04-08 19:20:45 +01:00
William S Fulton
59030cb3d2 Replace void* with iterator* in C# std::list wrappers
Better to use the actual type rather than void* in the implementaton.
It also mean the %apply that was used in the implementation won't
inadvertently affect users other use of void* types.
2019-03-25 08:02:32 +00:00
William S Fulton
78051fdd33 C# std::list changes to support types that are not assignable
Assignable fixes are based on those used by C# std::vector where the
default wrappers work if there is no operator== available in the
template type. Enhanced wrappers are obtained via a macro:
 SWIG_STD_LIST_ENHANCED(SomeNamespace::Klass)
 %template(ListKlass) std::list<SomeNamespace::Klass>;

Remove bool specialization (left over from the original std::vector
wrappers).
Add in missing typedefs.
2019-03-25 07:19:49 +00:00
Adrien JUND
e7f9316e60 C# - add std::list 2019-03-25 07:19:49 +00:00
Vadim Zeitlin
04c9a97787 Fix header comment in C# std_set typemaps
Mention that these typemaps require .NET 4 or greater.
2019-03-11 23:08:19 +01:00
Vadim Zeitlin
aaa12450c0 Implement set-theoretic methods in std::set C# typemaps
These implementations are not optimized, i.e. are done in a naive way in
C#, rather than using C++ functions more efficiently, but are better
than nothing.
2019-03-11 23:05:38 +01:00
Vadim Zeitlin
f0067b6bbf Add std::set<> typemaps for C#
Create new Lib/csharp/std_set.i based on the existing std_map.i and run
li_std_set unit test for C# as well.

Notice that the set operations defined by the base ISet<> interface are
not implemented yet.
2019-03-11 22:49:03 +01:00
William S Fulton
52063a732b Consistent parameter names for std::pair 2019-02-14 22:44:27 +00:00
William S Fulton
6d27ead9c0 Add STL container copy constructors where missing
Also provide consistent copy constructor declarations.
2019-02-14 18:53:05 +00:00
William S Fulton
e26f6bb4e2 Add missing typedefs to std::vector + typedef corrections
Tests for std::vector of pointers added which check
 std::vector<T*>::const_reference and std::vector<T*>::reference
usage which gave compilation errors in Python and Perl which had
specialized these vectors incorrectly.
2019-02-13 22:46:28 +00:00
William S Fulton
a47c2553f5 Add missing typedefs to std::pair 2019-02-13 22:46:28 +00:00
William S Fulton
9dd33e6367 Add missing typedefs to std::map 2019-02-13 22:46:27 +00:00
William S Fulton
68e86614ff Create a consistent stl.i library file
Same file now for all languages except R which is still missing std_map.i.
Recent Java changes adding in std_set.i removed.
2019-02-12 18:46:05 +00:00
William S Fulton
368cd3b52c Add ToArray test for C# std::vector wrapper 2018-01-12 18:26:47 +00:00
William S Fulton
6227013da4 Merge branch 'master' of https://github.com/Liryna/swig into Liryna-master
* 'master' of https://github.com/Liryna/swig:
  [C#] Add ToArray to std_vector.i
2018-01-12 18:02:33 +00:00
William S Fulton
e86c881a70 Fix directorout typemaps which were causing undefined behaviour when returning pointers by reference.
Closes #1167
2017-12-14 07:00:42 +00:00
William S Fulton
dafe2d6949 Add director typemaps for pointer const ref types 2017-10-24 23:47:40 +01:00
Quentin
4326da9ab3 [C#] Add ToArray to std_vector.i 2017-10-19 09:45:57 +02:00
William S Fulton
46ea2ab0a6 Add director shared_ptr typemaps for C# 2017-10-17 21:55:31 +01:00
William S Fulton
e43dfc69e5 Precision loss warning fixes for C# std::complex<float> typemaps
For gcc -Wfloat-conversion and vc++ C4244 warnings
2017-10-10 19:26:54 +01:00
William S Fulton
a55981b883 Fix C# std::complex pass by value typemaps 2017-10-02 19:07:24 +01:00
William S Fulton
ed4b84f4d3 Fix overloading of shared_ptr method overloading
Add 'equivalent' attribute to typecheck typemap.
Closes #1098.
2017-09-23 15:19:34 +01:00
William S Fulton
32e7074d9b Whitespace fixes in STL wrappers 2017-06-03 18:36:59 +01:00
William S Fulton
fdca8e9829 Better variable naming consistency in STL containers 2017-05-26 22:37:29 +01:00
William S Fulton
2ec156fb7f Merge branch 'vadz-csharp-complex'
* vadz-csharp-complex:
  Add header to std_complex.i
  Fix linkage problems in C# std::complex wrappers
  C# std::complex wrappers marshalling by value
  C# std::complex wrappers SwigValueWrapper fix
  Use %naturalvar for C# std::complex wrappers
  Allow avoiding generation of unwanted std::complex<T> typemaps
  Also apply csvar{in,out} typemaps to std::complex references
  Add std_complex.i for C# too
  Extend C# complex support to member variables of this type
  Add support for std::complex<> to C#
  Use new unified Mono mcs compiler if available under Unix
2017-05-20 15:21:48 +01:00
William S Fulton
fb941315c1 Add header to std_complex.i 2017-05-19 20:25:15 +01:00
William S Fulton
57ec5ec056 Fix linkage problems in C# std::complex wrappers
Fix warnings and subsequent exception trying to use wrappers:
Warning C4190: 'CSharp_complextestNamespace_VectorStdCplx_getitemcopy'
has C-linkage specified, but returns UDT 'SwigSystemNumericsComplex'
which is incompatible with C

Rename swig_complex_typemaps macro to SWIG_COMPLEX_TYPEMAPS
2017-05-19 19:52:39 +01:00
William S Fulton
e11e1c4cb8 C# std::complex wrappers marshalling by value
Change the wrapping to marshall directly to the .net
System.Numerics.Complex type instead of using an intermediate
std::complex .net type.
2017-05-19 08:15:01 +01:00
William S Fulton
8c13ee2411 C# std::complex wrappers SwigValueWrapper fix
Fix std::complex constructor declaration to stop SwigValueWrapper from
being generated
2017-05-19 07:10:43 +01:00
William S Fulton
bb758d7810 Use %naturalvar for C# std::complex wrappers 2017-05-19 06:58:54 +01:00
William S Fulton
07ab80b49e Add raise methods for throwing c++ exceptions in C#, Java, D
The director c++ exceptions are thrown in a helper method instead of in
the director overloaded method. This circumvents compiler warnings about
throwing exceptions when the method has an exception specification or
noexcept. If the exception is thrown, abort will still be called!
In Java, the "director:noexcept" typemap can be used to do something
else. This typemap should be ported to the other languages too.
2017-05-13 17:01:15 +01:00
William S Fulton
ab1e9f5bd9 Consistent whitespace amongst all the shared_ptr and intrusive_ptr typemaps
[skip ci]
2017-04-20 19:21:47 +01:00
Vadim Zeitlin
03f229b314 Allow avoiding generation of unwanted std::complex<T> typemaps
In many cases, only one of std::complex<double> and std::complex<float> is
used, so while we continue to define typemaps for both by default, for
compatibility with the other modules, add a possibility to avoid generating
the code for the unwanted specialization by predefining the corresponding
SWIG_NO_STD_COMPLEX_$TYPE before including this file.
2017-04-15 20:28:30 +02:00
Vadim Zeitlin
95aa3d9389 Also apply csvar{in,out} typemaps to std::complex references
This is needed to handle the artificial complex-valued properties created
using %naturalvar correctly.
2017-04-15 20:18:24 +02:00
Vadim Zeitlin
485efd511f Add std_complex.i for C# too
For consistency with the other modules (Python, Ruby and JS), allow including
<std_complex.i> directly when using C# too instead of including <complex.i>
which only works in C++ mode (i.e. when using std::complex) anyhow with C# for
now.
2017-04-14 19:23:31 +02:00
Vadim Zeitlin
ec565f74cf Extend C# complex support to member variables of this type
Define csvar{in,out} typemaps needed to support properties of complex type and
apply the existing cstype and csin ones to them as well.

Add unit test verifying that this works as expected in C# and, also, in
Python, even though no changes were needed there.
2017-04-01 23:51:45 +02:00
Vadim Zeitlin
aa047c43f7 Add support for std::complex<> to C#
Create Lib/csharp/complex.i with simplest possible typemaps mapping
std::complex<> to System.Numerics.Complex.
2017-04-01 23:51:45 +02:00
William S Fulton
279744603f Merge branch 'vadz-use-cstype-vector-typemap'
* vadz-use-cstype-vector-typemap:
  Don't hardcode C# type corresponding to size_t in vector typemaps
2017-03-24 07:29:41 +00:00
William S Fulton
72ba741d1c Fix wrapping of references/pointers and qualifiers to member pointers
Also fix Go wrapping of member const function pointers.
2017-03-16 21:04:38 +00:00