Commit Graph

352 Commits

Author SHA1 Message Date
Olly Betts 8a73e25fe2 argcargv.i: NULL terminate argv with empty input
Fixes needed for: C# R
2023-05-23 10:12:49 +12:00
Olly Betts 858c637353 [c#] argcargv.i: Allow empty array or empty string 2023-05-22 13:42:02 +12:00
Olly Betts 43f8153f53 Clean up naming of csharp array helpers 2023-05-22 09:57:44 +12:00
Olly Betts a94976f1fd Put csharp string array helpers in a fragment 2023-05-22 09:56:04 +12:00
Olly Betts 52a12fefa6 Tweak comment formatting 2023-05-22 09:39:40 +12:00
Erez Geva 1bff377fc3 [C#] Update argv argc typemap to generic format. 2023-05-21 22:36:33 +02:00
Olly Betts 44d5979b6e Drop extra tokens after #endif
Fixes this warning from SWIG:

Warning 206: Unexpected tokens after #endif directive.

See #2602
2023-05-22 08:19:40 +12:00
Olly Betts 8d5f9dd405 Fix comment typo 2023-05-20 16:17:00 +12:00
Erez Geva bdc2190cde Add argc and argv multi-argument typemap to Java, Guile, JavaScript, Scilab and C#
Fixes #2552

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2023-05-20 16:17:00 +12:00
Olly Betts 6085a9661e Initial support for std::string_view
So far C#, Java, Lua and PHP are supported.

Closes: #2540
See #1567
2023-05-08 15:56:37 +12:00
Olly Betts 1f5ff2e6a5 Allow using snprintf() instead of sprintf() in wrappers
We aim to produce code that works with C90 or C++98 so we can't
assume snprintf() is available, but it almost always is (even
on systems from before it was standardised) so having a way to
use it is helpful.

Enable this automatically if the compiler claims conformance
with at least C90 or C++98 and check SWIG_HAVE_SNPRINTF to allow
turning on manually, but disable if SWIG_NO_SNPRINTF if defined.

The fallback is to call sprintf() without a buffer size check -
checking after the call is really shutting the stable door after
the horse has bolted, and most of our uses either have a fixed maximum
possible size or dynamically allocate a buffer that's large enough.

Fixes: #2502 (sprintf deprecation warnings on macos)
Fixes: #2548
2023-04-27 10:08:57 +12:00
Olly Betts 01b6268b30 Make typemaps consistently use string::data() vs c_str()
Use c_str() only when we need a terminating zero byte and data() when
we don't (as we already did in most cases).  The two methods in fact
do the same thing as of C++11 (and in practice did for all C++98
implementations I'm aware of) but it's useful to make clear when we need
a terminating zero byte and when we don't, for example for adding
string_view support (string_view supports data(), but can't support
c_str() (since it could be a slice from the middle of a std::string).
2023-04-24 11:49:23 +12:00
William S Fulton 8cb29ef20a Merge branch 'bda_resolve_warnings'
* bda_resolve_warnings:
  Use $self instead of self
  Lib/csharp: Resolve a few warnings about unused parameters
2023-03-24 19:47:37 +00:00
William S Fulton 327ba13f4c Use $self instead of self 2023-03-24 19:47:18 +00:00
William S Fulton 20f7309220 std_array.i std_vector.i tweaks
Efficiency fixes and tidy up from previous commit.
Add test case for constructing from differently sized containers.

Issue #2478
2023-03-22 21:05:13 +00:00
Mario Emmenlauer e15cf1ac2d Lib/csharp: Resolve a few warnings about unused parameters 2023-01-10 17:16:26 +01:00
Mario Emmenlauer 5533ca1061 Lib/csharp: Better standardized std_vector.i and std_array.i 2023-01-10 17:14:26 +01: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
Olly Betts 4ac3c87a29 Sort out predefined SWIG-specific macros
Ensure that SWIG_VERSION is defined both at SWIG-time and in the
generated C/C++ wrapper code (it was only defined in the wrapper
for some target languages previously).

SWIGGO and SWIGJAVASCRIPT are now defined in the generated wrappers
to match behaviour for all other target languages.

Stop defining SWIGVERSION in the wrapper.  This only happened as a
side-effect of how SWIG_VERSION was defined but was never documented and
is redundant.

The new testcase also checks that SWIG is defined at SWIG-time but not
in the generated wrapper, and that exactly one of a list of
target-language specific macros is defined.

Fixes #1050
2022-10-05 12:40:15 +13:00
William S Fulton 929cfde883 C# CreateWStringFromUTF32 optimisation
Avoid UTF-32 to UTF-8 conversion then get string from UTF-8
Missing change that should have gone into eaf468e9e8
2022-09-30 23:21:39 +01:00
William S Fulton eaf468e9e8 C# CreateWStringFromUTF32 optimisation
Avoid UTF-32 to UTF-8 conversion then get string from UTF-8
Issue #2369
2022-09-22 18:54:49 +01:00
William S Fulton e97181ebc0 Add missing typecheck typemaps for std::auto_ptr and std::unique_ptr
To fix overloading when using these types.
2022-09-17 10:23:51 +01:00
William S Fulton dad7c93ca0 Provide SWIGTYPE MOVE typemaps in swigmove.i
For implementing full move semantics when passing parameters by value.
Based on SWIGTYPE && and std::unique_ptr typemaps which implement move
semantics.

Added for all languages, but untested for: Go, Ocaml, R, Scilab (and
unlikely to be fully functional for same reasons as for std::unique_ptr
support).

Issue #999
2022-09-16 08:36:25 +01:00
William S Fulton e139a36511 SWIGTYPE && input typemaps now assume object has been moved
Replicated Java implementation.

Fully implemented for:
- C#
- D
- Guile
- Javascript (UTL)
- Lua
- MzScheme
- Octave (UTL)
- Perl (UTL)
- PHP
- Python (UTL)
- Ruby (UTL)
- Tcl (UTL)

PHP std::auto_ptr std::unique_ptr minor tweaks and testcase corrections
2022-08-31 19:40:14 +01:00
William S Fulton c10a84c775 Cosmetic stray semi-colon removal after %typemap using quotes 2022-08-31 19:40:13 +01:00
William S Fulton db5e37a1d7 Add support for std::auto_ptr inputs
Ported from std::unique, behaviour is identical with regard to memory ownership/handling
2022-07-18 08:32:26 +01:00
William S Fulton 5dd5e80a84 Cosmetic formatting and doc updates in std_unique_ptr.i files 2022-07-17 20:44:20 +01:00
William S Fulton c737bd5713 Add C# support std::unique_ptr inputs
Based on Java implementation.
2022-07-17 15:20:13 +01:00
William S Fulton 319442a8c4 More move semantics improvements
More removal of casts in the out typemaps when copying objects to enable
C++ compilers to possibly make use of move semantics.
2022-07-04 11:19:50 +01:00
William S Fulton 71cd6a38fe Performance optimisation for directors for classes passed by value
The directorin typemaps in the director methods now use std::move on the
input parameter when copying the object from the stack to the heap prior
to the callback into the target language, thereby taking advantage of
move semantics if available.
2022-07-04 11:19:29 +01:00
William S Fulton 980e21a3bf Cosmetic changes to auto_ptr library files 2022-07-02 16:17:23 +01:00
William S Fulton 299880e6a6 Add std::unique support
Simple copy of current auto_ptr support (just suppport for
functions returning std::unique_ptr).

Closes #1722
2022-07-02 16:17:18 +01:00
William S Fulton bf36bf7d8a Movable and move-only types supported in "out" typemaps.
Enhance SWIGTYPE "out" typemaps to use std::move when copying
objects, thereby making use of move semantics when wrapping a function returning
by value if the returned type supports move semantics.

Wrapping functions that return move only types 'by value' now work out the box
without having to provide custom typemaps.

The implementation removed all casts in the "out" typemaps to allow the compiler to
appropriately choose calling a move constructor, where possible, otherwise a copy
constructor. The implementation alsoand required modifying SwigValueWrapper to
change a cast operator from:

  SwigValueWrapper::operator T&() const;

to

  #if __cplusplus >=201103L
    SwigValueWrapper::operator T&&() const;
  #else
    SwigValueWrapper::operator T&() const;
  #endif

This is not backwards compatible for C++11 and later when using the valuewrapper feature
if a cast is explicitly being made in user supplied "out" typemaps. Suggested change
in custom "out" typemaps for C++11 and later code:

1. Try remove the cast altogether to let the compiler use an appropriate implicit cast.
2. Change the cast, for example, from static_cast<X &> to static_cast<X &&>, using the
   __cplusplus macro if all versions of C++ need to be supported.

Issue #999
Closes #1044

More about the commit:
Added some missing "varout" typemaps for Ocaml which was falling back to
use "out" typemaps as they were missing.

Ruby std::set fix for SwigValueWrapper C++11 changes.
2022-06-30 17:26:48 +01:00
William S Fulton bb39235c9c Add C# wchar_t * director typemaps
More Python std::wstring directors Python testing
2022-05-04 21:37:47 +01:00
William S Fulton 751d443046 C# std::wstring director support
Updates for #1706
2022-05-04 21:37:47 +01:00
tartanpaint 3377b63dad Fix line endings 2022-05-04 21:37:47 +01:00
tartanpaint 5b7447b20e Fix marshalling of std::wstring parameters in directors
std::wstring parameters on SWIG directors were being truncated to a single character due to marshalling inconsistencies.
This patch applies the same MarshalAs(UnmanagedType.LPWStr) attribute to director delegate methods and allows std::wstrings to be successfully received in the C# code via director calls.
2022-05-04 21:37:47 +01:00
William S Fulton 79a9389355 Add support for throwing wstring exceptions
Throw an ApplicationException for std::wstring and wchar_t * strings
2022-05-02 21:08:19 +01:00
William S Fulton 0fbd6cc364 wchar_t C# marshalling tweak
Use more appropriate unsigned short (2 byte type) pointer
for C# ctype instead of wchar_t pointer
2022-05-02 21:08:19 +01:00
William S Fulton ed42422d1c Add support for wchar_t * and std::wstring Unicode strings on Linux
Initial contributions for Linux provided in issue #1233, modified to work
on both Windows and Linux. Dual support is possible by detecting
the sizeof wchar_t which is different on each of these systems.
2022-05-02 21:08:19 +01:00
gteubl 8a6290b12f Fix CS0034 in Capacity method of std::vector 2022-03-18 08:01:37 +01:00
William S Fulton 8e4868af75 More director const std::string& testing and C# leak fix
Issue #998
2022-02-13 23:00:04 +00:00
Olly Betts 31af3ce9bf Avoid -Wempty-body warnings from SWIG_contract_assert 2022-02-11 18:39:08 +13:00
Seth R Johnson de78b80de9 Renames performed by `%namewarn` with `rename=` are printed in warning message
This is necessary for regex-like renames (where you can't use the #define trick
as is done in many of the %keywordwarn directives). It's now unnecessary to print
the "renaming to '`x`'" code explicitly by the kw.swg files.
2022-02-06 13:51:37 -05:00
Olly Betts 7a21da90fd [C#] Fix memory leak in directorin typemap for std::string.
Fixes #998
2022-02-03 22:50:28 +13:00
Olly Betts f198ff0a43 Fix more "allows to" and other typos 2021-04-21 15:54:46 +12:00
William S Fulton c1b004f4fa Add access modifier support for interface feature
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
2020-09-25 18:54:25 +01:00
Gareth Francis beb1d8498d Fix C# wchar_t* csvarout to be same as csout 2020-09-05 17:03:34 +01:00
William S Fulton bfddc50a6a Add C# support for void *VOID_INT_PTR member variables
Issue reported by Carlos Frederico Biscaya on swig-user mailing list.
2020-08-13 16:06:48 +01:00
William S Fulton 15a0681b11 Add note about wchar_t marshalling fix required for Windows 2019-07-25 18:57:10 +01:00