Commit Graph

174 Commits

Author SHA1 Message Date
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 df87bbe437 inout_typemaps test rework
Use more distinct numbers, now consistent across all languages
2024-10-06 08:57:41 +01:00
William S Fulton d7c90c8f8f Rename inout testcase to inout_typemaps
inout is a D keyword
2024-10-06 00:11:40 +01:00
William S Fulton baa725e5ff Python shebang modernisation for python3
PEP-394 recommends specifying python2 or python3 in shebangs unless the
script is known to only run in an activated virtual environment.

PEP-394 also says distributors may not provide the python command.
Newer versions of Ubuntu, at least, no longer provide python unless the
python-is-python3 package is explicitly installed.

Removed some shebangs from testcases (the test-suite does not need them).
2024-09-22 22:11:33 +01:00
Olly Betts f2bcc41d48 [javascript] Fix v8 support and add CI coverage
Update the v8 support to work with recent v8 releases.

Fix bitrot in the testsuite and examples so they pass for v8.

Adjust configure probes so we can successfully probe for v8 without
assistance on Debian and Ubuntu (and probably other platforms; those
are just the two I've tested, and both use multiarch library
directories which weren't being allowed for).

Closes #3028
See #2537
2024-09-20 09:47:27 +12:00
Olly Betts a06fc05303 [js] Clean up obsolete V8_VERSION machinery
This is no longer needed since we dropped support for the ancient
V8 versions which didn't provide version macros, but I missed
removing it in my previous cleanup in
48eba82ac8.
2024-09-18 18:28:59 +12:00
Vadim Zeitlin 5a1d7ae035 Fix JS keyword rename test to actually test for renaming
Assigning to a property in JS always works, as it just creates a new
property if there is no existing one, and so can't be used for testing
for its existence.

Set the property value in C code and try accessing it from JS instead.

Also check that not only the property with the expected name exists, but
also that the property with the renamed name does not.

See #2943.
2024-09-10 09:27:11 +12:00
Vadim Zeitlin 08c3c368f4 Test that member with keyword names don't get renamed in JS
Check that the fix in the parent commit actually works.
2024-07-18 22:25:30 +02:00
VZ 6b0d355e4d
Fix running preproc_include test with JS+node more than once (#2936)
At least when building in a separate build directory, building this test
second time fails due to a syntax error in the makefile created by
node-gyp which happens because it doesn't handle dependencies with
spaces in them correctly.

Fix this by simply avoiding using such dependencies when using node-gyp,
this is not a big loss as the goal here is to test SWIG preprocessor and
not JS backend itself, and the preprocessor is still tested with the
other languages.

Closes #2930.
2024-06-26 07:18:44 +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
Vadim Zeitlin cd39cf132c Fix returning null from functions with output parameters in Python
Null pointers returned from functions also using output parameters or C
strings typemaps were lost because the generated code didn't distinguish
between Py_None corresponding to them and Py_None indicating the return
value of a "void" function.

This doesn't seem to be easy to solve properly because the function
return type and output parameters typemaps are independent and there is
no way to customize the behaviour of the latter depending on the former.

So we do it using a hack involving a global variable which is always 0
and is passed to SWIG_Python_AppendOutput() from non-void functions, but
is shadowed by a local variable with the same name set to 1 in the void
ones. This allows us to only discard Py_None if it corresponds to a void
function return value.

This is obviously ugly, but requires only minimal changes, doesn't
impose much extra run-time overhead and is MT-safe (unlike any solution
involving changing global variables).

Also add a unit test checking for this for Python and for JS, where the
same function already worked correctly (unlike in some other languages,
including at least Ruby and PHP).

Closes #2905.
2024-06-15 23:11:46 +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 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
William S Fulton 9878130004 Correct code in javascript testcase for jsc
Fixes...
~/swig/github/swig/Examples/test-suite/javascript (master *>)$ make -s cpp17_nested_namespaces.cpptest ENGINE=jsc
checking javascript (jsc) testcase cpp17_nested_namespaces (with run test)
./cpp17_nested_namespaces_runme.js:6:TypeError: function is not a constructor (evaluating 'new cpp17_nested_namespaces.createA1Struct()')
2024-05-29 08:28:11 +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
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
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 158fbdc760 Improve friend function documentation
Add unqualified friend example in docs as a testcase
2024-01-15 18:52:05 +00: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 bd2dcf920c Correct attempts to not run tests in Javascript and Octave 2023-08-14 22:54:40 +01:00
William S Fulton 87e2e4b47c Remove trace output from Javascript testcase 2023-06-28 07:30:40 +01:00
Momtchil Momtchev ceed54758a Javascript Node-API support added
Closes #2545
2023-06-28 07:24:51 +01:00
Olly Betts d05e2709dc
Merge pull request #2629 from mmomtchev/js-run-tests-last-batch
add the last bulk batch of Python tests to JS
2023-06-02 16:50:53 +12:00
Olly Betts db922b5e4e
Merge pull request #2626 from mmomtchev/js-default-args
[JS] remove hacks and implement default arguments
2023-06-02 08:37:58 +12:00
Momtchil Momtchev 62d17187d1 fix the JSC incompatibilities 2023-06-01 13:47:39 +02:00
Momtchil Momtchev 303b00cb01 add the last bulk batch of Python tests to JS 2023-06-01 13:29:05 +02:00
Momtchil Momtchev bc6d6ed11a batch of JS run tests 2023-05-31 18:46:34 +02:00
Momtchil Momtchev f10eef462d add overload + extend + default args run test 2023-05-31 15:42:13 +02:00
Momtchil Momtchev 721a4808b8 remove hacks and implement default arguments 2023-05-31 13:22:35 +02:00
Momtchil Momtchev bcfeed0ea1 add more JS run tests 2023-05-30 20:12:55 +02:00
Olly Betts 0c40ac59f1 Merge branch 'v8-packed-obj' 2023-05-30 17:49:49 +12:00
Momtchil Momtchev de3c2fea95 fix JSC too 2023-05-29 21:02:42 +02:00
Momtchil Momtchev b99790c6db remove debugging leftovers 2023-05-29 20:19:38 +02:00
Momtchil Momtchev 2ccf3c3050 fix member pointers 2023-05-29 20:17:31 +02:00
Momtchil Momtchev d3e91b8273 another batch of run tests 2023-05-29 17:18:43 +02:00
Momtchil Momtchev 0d8ce6e031 add two Python tests 2023-05-29 12:42:59 +02:00
Momtchil Momtchev 92dfc5de2e first batch of tests 2023-05-29 12:39:51 +02:00
Olly Betts f8f47723a8 Add missing newlines at end on new files 2023-05-29 12:45:57 +12:00
Momtchil Momtchev a1e7441fad add a missing rename 2023-05-27 17:44:02 +02:00
Momtchil Momtchev 40d277ed31 try using finally as JS keyword 2023-05-27 17:31:59 +02:00
Momtchil Momtchev 1317583471 add two Python unit tests to JS 2023-05-26 16:54:41 +02:00