Commit Graph

736 Commits

Author SHA1 Message Date
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
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 83be871eec Remove unused JAVA_TOOLS_JAR make variable 2025-04-02 22:55:18 +01:00
William S Fulton c2ad64d0a8 Java compiler lint warnings fixes in test code
Fixes:
[cast] redundant cast
[rawtypes] found raw type
[serial] serializable class has no definition of serialVersionUID

Also suppress warning: auxiliary class TargetLanguageBase in ./inherit_target_language.java should not be accessed from outside its own source file
2025-04-02 22:52:30 +01:00
William S Fulton a16e3cb8ce Add Java compiler linting checks javac -Xlint 2025-04-02 22:52:30 +01:00
William S Fulton 26b0911a74 Add support for $n special variable expansion in the names of typemap local variables
For example:

  %typemap(in) int MYINT (int $1_temp) { ... }

$1_temp is typically expanded to arg1_temp, arg2_temp etc depending on
which argument the typemap is applied to.
2025-02-19 20:44:40 +00:00
Olly Betts 0b4496a735 Fix testsuite SWIG warnings; enable SWIG -Werror
SWIG/mzscheme (aka racket) is excluded for now as it currently has a lot
of testsuite warnings and is slated for removal in 4.4.0 anyway.

Closes #3034
2024-10-22 10:30:52 +13:00
William S Fulton 5c5911ee3b Assignable fixes for reference member variables
Fix incorrect variable setters being generated when wrapping
reference member variables. A setter is no longer generated if the
type of the reference member variable is non-assignable.

Fixes #2866
2024-09-19 19:52:14 +01:00
Olly Betts e02efe25db Merge branch 'fbo/indus_doc_csharp' 2024-09-15 09:59:05 +12:00
William S Fulton 61dffc06d1 %interface regression fix for multiple inheritance and common bases
Regressio introduced in 7592722.

Closes #2875
2024-09-07 20:07:17 +01:00
William S Fulton e511df0026 Further fixes for handling friends in deeply nested mixes of templates and classes
The appropriate namespace for friends declared in a class/template were
not always being correctly determined when %template is used in nested
hierarchies. Further improvements to previous commit.
2024-09-04 08:24:00 +01:00
William S Fulton 4564a60915 Fix duplicate friend wrappers for friend declarations in nested classes.
We need to modify the scope that friends are declared in to the
namespace that of the outermost class is declared in. The friend is
not declared within a class, it must be a namespace. Add missing
implementations of the "prev_symtab" so that it is set in every
class and then use this for picking up the appropriate scope for
declaring the friend in.

Closes #2845
2024-09-04 08:24:00 +01:00
William S Fulton 3b01f3fd91 Add testcase for using declaration and extend for flattening class
Closes #1581
2024-09-04 08:22:01 +01:00
Olly Betts 61e54ab054 Improve handling of zero bytes in string literals
Many of the target languages don't handle this currently.  Those
that don't support this in their strings never will, but others
can probably be fixed.

Fixes #2996
Fixes #2997
2024-08-30 11:07:15 +12:00
William S Fulton 51b281eff0 Add the Java constantsmodifiers pragma 2024-08-09 19:27:42 +01:00
William S Fulton 37013523af Doxygen comments formatting fixes for multi-line comments
Also remove stray static method comments from being incorrectly
generated into the PINVOKE class.

Add some missing multi-line tests for static methods, variables and
constants.
2024-07-30 00:00:12 +01:00
Erez Geva 5951390be7
Java director_thread forget to call stop. (#2959)
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2024-07-17 07:17:10 +01:00
William S Fulton 3556c41b98 Add more missing primary template definition testing 2024-06-28 19:32:09 +01:00
Vadim Zeitlin dbdbbe3fdf Allow suppressing progress messages when running test suite
Use $(ECHO_PROGRESS) instead of the hard-coded "echo" to allow setting
ECHO_PROGRESS=: on make command line to suppress the (many hundreds of)
messages given when running every unit test.

This makes it much easier to see any warnings given during the test
suite execution.
2024-06-25 07:54:57 +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
William S Fulton 63f03c2ef2 Merge branch 'fix_2872'
* fix_2872:
  Rename internal flag to fvirtual:ignore
  Whitespace corrections
  Adding virtual destructors.
  Adding test case for #2872.
  add_member_for_using_declaration now ignore's the feature:ignore flag if it was set by fvirtual. This fixes #2872.

Conflicts:
	CHANGES.current

Closes #2872
Closes #2873
2024-06-05 08:08:45 +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 59827e7191 Fix %nspace and %nspacemove for nested classes and enums in a class
For example:

  %nspace Space::OuterClass80;
  namespace Space {
    struct OuterClass80 {
      struct InnerClass80 {
        struct BottomClass80 {};
      };
      enum InnerEnum80 { ie80a, ie80b };
    };
  }

Previously the following were additionally required for some languages:

  %nspace Space::OuterClass80::InnerClass80;
  %nspace Space::OuterClass80::InnerClass80::Bottom80;

Now the appropriate nspace setting is taken from the outer class.

A new warning has also been introduced to check and correct conflicting
nspace usage, for example if the following is additionally added:

  %nspacemove(AnotherSpace) Space::OuterClass80::InnerClass80;

The following warning appears as an inner class can't be moved outside
of the outer class:

  Warning 406: Ignoring nspace setting (AnotherSpace) for 'Space::OuterClass80::InnerClass80',
  Warning 406: as it conflicts with the nspace setting (Space) for outer class 'Space::OuterClass80'.

This really helps with %nspacemove as now one can simply move an outer
class to another namespace, like this:

  %nspacemove(AnotherSpace) Space::OuterClass80;

and all the nested classes will automatically also be moved
into the appropriate namespace.
2024-06-01 08:04:08 +01:00
William S Fulton 5035473e9b Enhance %nspace with %nspacemove for moving symbols into a different target language namespace
%nspacemove moves a class or enum into a different target language 'namespace'.

This builds on top of %nspace and so is currently only implemented in
C#, D, Java, Javascript and Lua.

Javascript also supports %nspace for functions and variables in a
namespace with a non-standard implementation; %nspacemove is not
fully working yet for Javascript.

Issue #2782
2024-06-01 08:02:49 +01:00
William S Fulton 6f0442829f nspacemove testcase
This is currently an identical copy of nspace and will be modified for
%nspacemove.
2024-05-29 08:28:11 +01:00
leake d38bd3298c Adding test case for #2872. 2024-04-27 09:19:09 -07: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
William S Fulton 9441c9513c Add missing use of move constructor
instead of copy constructor when passing movable types by value.
Additional enhancement when passing movable types to constructors.

Enhancement to e777b054d5.
2024-03-06 21:46:58 +00:00
William S Fulton dcc1471dd3 Add missing use of move constructor
instead of copy constructor when passing movable types. This was
previously implemented only for parameters passed to a global function
or static member function and is now extended to member methods.

Enhancement to e777b054d5.
2024-03-06 21:46:58 +00:00
Olly Betts ec56bff28d [java] Suppress System.runFinalization() removal warnings
These need to be addressed, but meanwhile it makes running the testsuite
with OpenJDK 21 or newer unhelpfully noisy so suppressing it seems more
helpful than not.

Closes: #2819
2024-03-01 10:42:22 +13: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
William S Fulton feaabb0d2a template templated static methods support
Fix compilation errors in generated code when instantiating a templated
static method within a template (non-static methods and constructors were
always okay). For example:

  template <typename T> class X {
    template <class InputIterator>
      static void fn(InputIterator first, InputIterator last) { ... }
  };
  class SimpleIterator { ... };

  %extend X<int> {
    %template(fn) fn<SimpleIterator>;
  }

The problem being fixed here is an extended method was generated when it
should not have been as for other %template instantiations within a
template - the template can be called directly.

Test includes variadic static method templates in a template, including
method overloading..
2024-02-28 22:32:04 +00:00
William S Fulton 293b9547a2 Add a variadic templated constructor in template test 2024-02-10 00:02:09 +00:00
William S Fulton c1258b89ae Fix assert handling template templated variadic methods
Closes #2794
2024-02-10 00:02:03 +00:00
William S Fulton 8435f4eefa Add test for templated template methods 2024-02-09 23:36:18 +00:00
William S Fulton 3be670e8db Fix assertion handling upcasting when using %shared_ptr on some templates.
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
2024-01-30 22:24:42 +00:00
William S Fulton 0a16044a27 Wrap friend functions that are defined or declared within a namespace
Previously unqualified friend definitions/declarations in a namespace were
ignored.
2024-01-15 19:18:13 +00:00
William S Fulton 158fbdc760 Improve friend function documentation
Add unqualified friend example in docs as a testcase
2024-01-15 18:52:05 +00:00
Olly Betts ccaf46262a Expand director_string_runme.*
Fill in parts which were missing for some target languages.
2023-12-21 10:59:44 +13: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 5f8b9135cc Fix director_classes testcase failures on x86
Adjust the floating point constants to be 1.125 and 2.25 (which
can be exactly represented in base-2 floating point) instead of
1.1 and 2.2 (which can't).  This avoids problems on platforms where
floating point calculations suffer from excess precision, the most
commonly used of which is x86 when using 387 FP instructions.
2023-11-19 21:45:30 +13:00
Olly Betts 3ce0174a0c Fix random doubled spaces in code 2023-11-17 09:49:36 +13:00
William S Fulton e8d3c74590 Improvements to $typemap() special variable replacement overrides
In $typemap(), the $n special variables are replaced by the appropriate
value for the type associated with the typemap calling $typemap().
The (undocumented) special variable overrides now also support
controlling what the $n special variables are replaced with from the
calling typemap, for example:

  %typemap(in) std::pair<std::string, int> {
    int& input_value_second = $1.second;
    $typemap(in, int, 1=input_value_second);
    ...
  }

replaces $1 in the int typemap with input_value_second instead of
whatever is the default for the target language (a variable that holds
the int value after marshalling from the target language).

This additional functionality might make it possible to replace the C++
templates used in the UTL with a much simpler system of typemaps utilising
$typemap(). See follow on commit to typemaps.c.
2023-11-03 09:07:51 +00: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
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 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