Commit Graph

474 Commits

Author SHA1 Message Date
William S Fulton 29acbcebcc typecheck typemaps for STRING LENGTH added to changes file
Keep typemaps for STRING LENGTH grouped together for C# and Java.
2025-08-11 08:28:27 +01:00
Erez Geva 0c613c7f06 string-length typemaps typecheck
Use SWIG_TYPECHECK_STRING as typemaps represent string.
Add typecheck to Go, Java, C# and D languages.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2025-08-11 08:28:02 +01:00
Erez Geva cb68446ece Fix Length & string reverse order typemap.
And add it to missing languages: C#, Java, Lua, PHP.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2025-07-28 17:07:42 +02:00
Olly Betts 491994c836 Use NULL instead of SWIG_NULLPTR
This was added in an attempt to avoid warnings from a static analysis
tool which wants us to use nullptr instead of NULL, but we can't do so
unconditionally while continuing to support C++98.

SWIG_NULLPTR is ugly, verbose and non-standard and NULL is still
standard C++ so we've decided to just use NULL instead.  Users of tools
which don't like NULL can just suppress this warning for SWIG-generated
code.

Closes #3165
Closes #3166
2025-07-02 08:43:32 +01:00
William S Fulton f91a9cb8e4 Use SWIG_NOEXCEPT for deprecated dynamic exception specifications
SWIG_NOEXCEPT is generated instead of throw() which is deprecated in
c++11. If c++11 or later is being used, then this macro expands to
noexcept instead of throw().

Affects director code only.

Also fix up some testcase to not use throw() when using c++11 or later.
Tested with clang and -Wdeprecated-dynamic-exception-spec as gcc
doesn't seem to warn for this deprecation.

Closes #3027
2025-04-29 22:41:09 +01:00
William S Fulton ef0d38bffd Support JDK 21 and std::list
Fixes removeFirst() and removeLast() incompatibilities with methods
of the same name in the Java base class java.util.AbstractSequentialList
which were added in JDK 21 as part of JEP-431.

configure.ac has been modified to detect the version of JDK/Java for use
in testing the test-suite via the JAVA_VERSION_MAJOR variable.

Needed to continue testing removeFirst(), removeLast(), addFirst(), addLast().

Closes #3156
2025-04-02 22:56:11 +01:00
William S Fulton aaeef05f72 Fix javac -Xlint warning [this-escape] - JDK 21 in STL containers
[this-escape] possible 'this' escape before subclass is fully initialized
in std::list, std::vector, std::set, std::unordered_set constructors.
2025-04-02 22:55:18 +01:00
William S Fulton 37caf2e664 warning fix for cdata Java wrappers for visual c++ 2025-04-02 22:54:39 +01:00
William S Fulton af65817279 Fix javac -Xlint warnings:
- [cast] redundant cast in std::unordered_map wrappers put method
- [rawtypes] found raw type in std::list constructor wrapper
2025-04-02 22:54:39 +01:00
dmytro.luchyk 644c860de9 remove redundant casts to const char* after using GetStringUTFChars function
Closes #3143
2025-03-31 17:37:44 +13:00
William S Fulton cbff768feb Add the %interface_additional macro
New macro added to the family of %interface macros. This new macro
is for adding additional interfaces for the generated interface to
extend/derive from.

Closes #1188
2024-09-11 20:05:30 +01:00
William S Fulton 51b281eff0 Add the Java constantsmodifiers pragma 2024-08-09 19:27:42 +01:00
William S Fulton ba9b0a35ab Merge branch 'char_binary_java_fix-tidyup'
* char_binary_java_fix-tidyup:
  Move SWIGStringWithLengthHelper to csharphead.swg
  cdata whitespace/cosmetic fixups
  cdata doc updates
  Rename `typemaps/cdata_struct.swg` to `typemaps/cdata_begin.swg`. And `typemaps/cdata.swg` to `typemaps/cdata.swg`. Move `cdata_apply.swg` content to `typemaps/cdata.swg`.
  Group the C# marshalling of STRING-LENGTH typemap  into C# class named SWIGStringWithLengthHelper.
  Leave Length & string reverse order typemap in typemaps/strings.swg
  Support old C# as "LPUTF8Str" was add in 2017.
  Improve documentation. Follow @wsfulton reviews.
  Use a dummy for MzScheme and untested OCaml cdate. To prevent compilation error.
  Further fixing follow reviews.
  Reorganise raw data typemap,  so typemaps folder contain only common part. Improve document.
  Inline SWIG_string_to_utf8_bytes SWIG_utf8_bytes_to_string code
  Fixes of STRING/BYTES LENGTH typemaps.

 Conflicts:
	CHANGES.current
2024-06-13 10:53:19 +01:00
Erez Geva 300e5e313b Rename `typemaps/cdata_struct.swg` to `typemaps/cdata_begin.swg`.
And `typemaps/cdata.swg` to `typemaps/cdata.swg`.
Move `cdata_apply.swg` content to `typemaps/cdata.swg`.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2024-06-07 08:19:20 +01:00
William S Fulton 946e4ccf18 Add nspacemove example for STL types
Java's nested iterator class in std::map, std::set, std::unordered_map,
std::unordered_set needs to be public instead of protected for
access to work when moving STL types into different Java packages.
2024-06-01 08:04:14 +01:00
William S Fulton 24a66e6125 Add const std::unique_ptr & input typemaps 2024-03-06 21:46:58 +00:00
William S Fulton 846b40793e Add non-const std::unique_ptr & input typemaps 2024-03-06 21:46:58 +00:00
William S Fulton 5712ce6464 std::unique_ptr return by reference typemaps added 2024-03-06 21:46:58 +00:00
William S Fulton 3f1e40d2f4 Add std::unique_ptr && output typemaps
Move semantics are not supported by default.
They behave as if a lvalue reference was returned.
2024-03-06 21:46:58 +00:00
William S Fulton ae22a97f1b Movable std::unique_ptr - add std::unique_ptr && typemaps
Closes #2650
2024-03-06 21:46:58 +00:00
Erez Geva affbd5893d Reorganise raw data typemap,
so typemaps folder contain only common part.
Improve document.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2024-02-29 11:58:05 +01:00
William S Fulton 81345bd3a5 Inline SWIG_string_to_utf8_bytes SWIG_utf8_bytes_to_string code
- Also fixes null handling.
    - Don't swallow exceptions.
    - Use default encoding for consistency across all of the Java wrappers.
      Note, the encoding can be changed via the 'in' typemap, eg:

    %typemap(javain, throws="java.io.IllegalCharsetNameException")  (const char *STRING, size_t LENGTH) %{($javainput == null) ? null : $javainput.getBytes("UTF-8")%}
2024-02-29 02:09:09 +01:00
Erez Geva 1bf59e0bbc Fixes of STRING/BYTES LENGTH typemaps.
Fix Java STRING LENGTH typemap.
Use string type in static typed languages (Java, C#, D and Go).

Add BYTES LENGTH typemap and apply it for binary data.
Use byte type in static typed languages.

Add li_cdata_cpp, li_cdata and char_binary
 tests for most of languages(apart from R and experimental).

Fix the director_binary_string test and add it to C#, D, Go,
 Perl, PHP, Python, Ruby and octave.

Update documents.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2024-02-29 02:09:09 +01:00
Olly Betts ccf4f6ec72 Sort out directorout typemaps for std::string_view
With Perl the returned string is still being corrupted (the testcase
flags this as "TODO" for Perl's test harness).

Warnings aren't currently emitted for Perl, Ruby or Tcl as I'm not
seeing where in the UTL maze the directorout typemap actually gets
defined.
2023-12-21 10:59:44 +13:00
Olly Betts 3a437b2017 Remove deprecated map and vector specialisation macros
These have done nothing except emit a warning saying they are no
longer required for a long time.

One exception is guile and mzscheme still define non-trivial
specialize_std_map_on_* - it seems they were missed for some
reason, but the same improved machinery which meant these macros
are no longer required for other target languages should apply
to them too.
2023-12-03 09:55:35 +13:00
William S Fulton 5aaacd0496 Fix redundant cast warning in Java std::map wrapper put method 2023-10-11 08:23:16 +01:00
William S Fulton 280b3a908e Java STL changes to use Java int, support 64-bit size_t
std::vector::capacity and std::vector::reserve signature changes.

Java api changes from:
  public long capacity() { ... }
  public void reserve(long n) { ... }
to:
  public int capacity() { ... }
  public void reserve(int n) { ... }
to fit in with the usual Java convention of using int for container
indexing and sizing.

The original api for std::vector::reserve can be also be made available via
%extend to add in an overloaded method as follows:

  %include <std_vector.i>
  %extend std::vector {
    void reserve(jlong n) throw (std::length_error, std::out_of_range) {
      if (n < 0)
        throw std::out_of_range("vector reserve size must be positive");
      self->reserve(n);
    }
  }

This change is partially driven by the need to seamlessly support the full
64-bit range for size_t generically, apart from the customisations for the
STL containers, by using:

  %apply unsigned long long { size_t };
  %apply const unsigned long long & { const size_t & };

Similarly for std::array::size.

Also enhance docs for applying unsigned long long typemaps for 64-bit
size_t.
2023-10-06 19:42:39 +01:00
William S Fulton 7bba06b03e Java - SWIGWORDSIZE64 for long type
Defining SWIGWORDSIZE64 now applies the (unsigned) long long
typemaps to (unsigned) long for a better match on systems
where long is 64-bits.

Although size_t typemaps are now applied from the int typemaps instead
of the long typemaps, identical code is generated and the mapping is
still to the Java signed long type.

Closes #646
Closes #649

Running the test-suite as follows on a 64-bit long system:

  env SWIG_FEATURES=-DSWIGWORDSIZE64 make check-java-test-suite

passes, except for a few tests which fail where they expect the
default Java type to be int or long instead of long or BigInteger
respectively.

Also arrays_java.i results in:
  invalid conversion from ‘long int*’ to ‘long long int*’ [-fpermissive]
  invalid conversion from ‘long int**’ to ‘long long int**’ [-fpermissive]
2023-10-05 21:30:30 +01:00
William S Fulton 76fdf2c355 std::map wrappers and non-default constructible
Fix and test Guile, MzScheme, Java, Javascript
Octave is also failing.
2023-09-15 19:17:34 +01:00
Olly Betts fcf0d7deab Tweak comment formatting 2023-05-23 09:20:31 +12:00
Olly Betts 1594a89afa [Java] Handle empty Java array 2023-05-22 14:08:13 +12:00
Olly Betts fcdd63dba5 Remove redundant NULL checks before free()
See 7ec2f89fe2
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 1a31e9dc0c [java] Suppress removal warnings for finalize()
The "deprecation" warning has been changed to a "removal" warning
with newer JDK versions.  This needs to be addressed, but meanwhile
it makes running the testsuite unusably noisy so suppressing it
seems more helpful than not.

Closes: #2556
2023-05-12 08:48:20 +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
Myroslava Stopets 2f22c09269 Added usage of nullptr instead of NULL 2023-02-08 01:16:42 +02:00
William S Fulton 4c86f45c54 Fix for Java 7 - std::set and std::unordered_set 2022-10-15 14:57:30 +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 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 0634883089 SWIGTYPE && input typemaps now assume object has been moved - Java
Implementation tweak - better RAII.
SWIGTYPE && null pointer check.
2022-08-31 19:40:13 +01:00
William S Fulton ec965840ce Cosmetic stray semi-colon removal after %typemap 2022-08-20 15:29:49 +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 bf761998ed SWIGTYPE && input typemaps now assume object has been moved
Change these typemaps to assume that after a function call,
the parameter has been moved. The parameter's proxy class
that owns the C++ object thus has the underlying pointer set
to null so the object cannot be used again and the object is deleted.

Scrap new javarelease typemap and move contents into javabody typemap.
2022-07-17 15:15:24 +01:00
William S Fulton 6b361bf050 Add Java support for std::unique<T> for input parameters.
This works by transferring ownership of the underlying C++ memory
from the target language proxy class to an instance of the unique_ptr
which is passed to the wrapped function via std::move.

The proxy class has a new swigRelease() method which sets the
underlying C++ pointer for the proxy class to null, so working
in much the same way as std::unique_ptr::release(). Any attempt at
using the proxy class will be the same as if the delete() function
has been called on the proxy class. That is, using a C++ null pointer,
when a non-null pointer is usually expected.

This commit relies on the previous commit that uses std::move
on the temporary variable used for the wrapped function's input parameter
as std::unique_ptr is not copyable, it has move-only semantics.
2022-07-17 15:15:24 +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