Commit Graph

188 Commits

Author SHA1 Message Date
William S Fulton 1f1f773131 Review fixes for the Uint8Array fragment test
Drop noblock=0 from the in typemap - remove_block() only tests for the
presence of the attribute, so noblock=0 strips the braces and the block is
merely put back by the JavaScript module. Omitting it says what was meant.

Correct the comments, which described a %{ ... %} delimited typemap this test
does not have, and note that only jsc and napi define the two names as macros.

Use angle brackets for the library %include and fix the assertIsEqual
parameter order, which was the reverse of every call site.

Closes #3523

Assisted-by: Claude Code (Opus 5)
2026-08-01 10:40:36 +01:00
Erez Geva 4b5c68d40f Add Javascript test for 'SWIG_FromUint8Array' and 'SWIG_ToUint8Array'
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2026-08-01 10:40:22 +01:00
William S Fulton 261f9909d9 [JavaScript] Fix node engine builds when node-addon-api is missing
NAPI_DIR was empty when node-addon-api is not installed, so
CXXFLAGS="... -I$(NAPI_DIR)" ended in a bare -I. That swallowed the -c
option generated by node-gyp, so g++ linked instead of compiled and
failed with an undefined reference to main. This broke the node engine,
which does not use node-addon-api at all:

  cd Examples/javascript/class && make check ENGINE=node

Configure now substitutes the complete option as NAPI_INCLUDE, either
empty or a well formed -I, so the makefiles need no special casing.
Detection of distro supplied headers also moves out of the npm
conditional, enabling napi with the Debian/Ubuntu node-addon-api package
and no npm. The test-suite Makefile no longer hardcodes an include
directory derived from 'npm config get prefix', which is bogus without
npm and is already worked out by configure.

Assisted-by: Claude Code (Opus 5)
2026-07-31 02:14:40 +01:00
William S Fulton 32a3e5b464 R: Honour %rename of enum items in the generated R code
R::enumvalueDeclaration built the enum item label passed to
defineEnumeration from the C++ name rather than sym:name, so %rename of an
enum item was not honoured in the generated R code. Use sym:name for the
label.

Add test coverage for %rename of an enum class and an enum item to the
cpp11_strongly_typed_enumerations runme of every target language that has
one, locking in the behaviour for the languages that were already correct.
The enum_thorough R runme now checks the renamed enum item too.

Assisted-by: Claude Code (Opus 4.8)
2026-07-15 00:24:05 +01:00
William S Fulton 3dda830ac9 Add char *& string typemaps to all languages and char_strings runme parity
A 'char *&' (a reference to a char pointer) was only marshalled as a string by
C#, D, Go, Java and PHP; every other language treated it as an opaque char **
pointer.  Add char *& string typemaps to the languages that were missing them,
so a char *& function argument, return value or variable is marshalled as a
string in every target language.  SWIG's const reference stripping means this
also covers char *const&.

- Lib/typemaps/strings.swg: add Char *& to the %typemaps_string in, freearg,
  out, typecheck and director typemaps.  This gives char *& to the languages
  that use the Unified Typemap Library (Python, Ruby, Perl, Tcl, Octave, Scilab,
  R and JavaScript).  The shared in typemap now casts &buf to $1_ltype so that a
  const char * reference hidden behind a typedef also compiles.
- Lib/lua/luatypemaps.swg, Lib/guile/typemaps.i, Lib/ocaml/ocaml.swg: these
  define their own char * string typemaps; give each char *& and const char *&
  in/out/freearg typemaps too.
- Lib/r/rtype.swg: the C wrapper returned the char *& string correctly but the R
  proxy wrapped it as an undefined _p_p_char S4 class; add char *& to the
  scoerceout char list so it is returned as a plain character value.

char_strings.i is now exercised by a runme in every target language, all testing
the same set of functions (get/set/pingpong/global variables and all four char *&
functions), giving complete char *& typemap coverage and testing.

Where a language genuinely cannot support part of the char array portion of the
test (a char[] global has no varin typemap in most scripting languages, a char[16]
parameter is bounds checked, and Guile/OCaml reject char[] parameters), that one
assertion is adapted or skipped with an inline comment; the char *& coverage is
complete everywhere.

Assisted-by: Claude Code (Opus 4.8)
2026-07-09 21:55:58 +01:00
William S Fulton ae17418e48 Go: fix invalid conversion for const char * hidden behind a typedef
The Go 'in' typemap for char * wrote the null terminator through $1, which
fails to compile as C++ when the matched type is const char *, as happens
with a typedef such as 'typedef const char *MyString'. Allocate and write
the terminator through a char * temp, assign to $1 via $1_ltype, and cast
in the freearg so a const char * buffer can still be freed. Freeing $1
(rather than the temp) keeps the freearg working when char * is remapped
with %apply SWIGTYPE[], which overrides the in typemap but not the freearg.

Add coverage to the common char_strings.i test, which is compiled for
every language, rather than a Go only test: a typedef'd const char * setter
plus a runtime assertion in each language that has a char_strings runme
(c, csharp, d, java, javascript, lua, perl5, php).

See #3290.

Assisted-by: Claude Code (Opus 4.8)
2026-07-09 21:55:58 +01:00
Erez Geva cd569d122a cdata.i changes and new test li_cdata_bytes
Fix guile cdata.

Add SWIG_BINSTR flag
- Add SWIG_FromBinCharPtrAndSize with the new flag
  To add languages that use Lib/cdata.i.
- python use binary string by using the new SWIG_BINSTR
  in SWIG_AsCharPtrAndSize and SWIG_FromBinCharPtrAndSize.

Languages that were changed to uses list
- Tcl use list of integers.
- scilab use list of uint8.
  And support passing list of numbers to C.

Add support to JavaScript
- use Uint8Array instead of strings.
- Add li_cdata_carrays. tests.
- Add li_cdata_bytes tests.
- Use Debian node-addon-api package location.
- napi folder location to Examples/test-suite/javascript/Makefile.in.
- Update documentation.

Update cdata.i documentation

This new cdata test focus on:
- Ensure we can receive proper data from C and pass proper data back to C.
- Use all possoble byte values , i.e. the full range of 0 to 255
  and ensure values 128 to 255 do not pass Unicode transformation (UTF-8/16).
- Ensure zero is a valid value and not a string null termination
  nor a modified UTF-8 which transform U+0000 to 0xC0 0x80.
- Check mutability of the cdata object.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2026-05-25 13:16:09 +01:00
William S Fulton 23a3f1de5b Final fixes and tweaks to std::function wrappers
- Add final CHANGES.current entry for std::function.
- Adjust example to how std::function should work going forwards.
2026-05-03 19:00:24 +01:00
William S Fulton d4868b0556 std::function refactor and test improvements
Move std::function implementation out of Lib/typemaps directory noting
that there are no typemaps for the implementation.

Rename _SWIG_call_std_function to SWIG_call_std_function to be standards
compliant.

Remove redundant %rename in cpp11_std_function testcase.

Add java and python runtime tests based on javascript test for cpp11_std_function testcase.

Add some observations on specialization bug when using std::function.
2026-05-03 19:00:24 +01:00
Momtchil Momtchev 379bf1054d Support wrapping std::function
- Split out (keep) std::function wrapping fix from pull request #3298.
- Add clang-format fixes.

Fixes #341.
Partially fixes #3297.

Enhances SwigType_variadic_replace to expand template packs (used in new std_function.i) to generate corrected wrapper code such as:
  SwigValueWrapper< Object< int,int,int > > arg1 ;
instead of incorrect code:
  SwigValueWrapper< Object< int,int ... > > arg1 ;

- Split out std::function wrapping fix from pull request 3298.
- Added clang-format fixes.
2026-05-03 19:00:24 +01:00
William S Fulton 5275850028 Try replicate issue described in #3337 2026-02-20 19:35:40 +00:00
Erez Geva 2bc9ede0c1 Add typecheck.
Add test with char_binary_rev_len 2 constructors.

Signed-off-by: Goh, Wei Sheng <wei.sheng.goh@intel.com>
2025-08-11 08:28:02 +01:00
Erez Geva be943d11a1
Add MinGW-W64 Ruby Github CI testing (#2981)
- Enhanced configure.
- Add Windows separator for calling ruby with multiple directories.
- Rename names in test cases which conflict with Windows headers used by Ruby.
- The three Ruby tests are testing Ruby with MinGW-w64 using Universal CRT.
- Also fixes recently disabled ruby test because of ::at_quick_exit compiler problem which was due to incorrect mixing of MINGW64 and UCRT64 runtimes  - closes #3237.

Note:

VER=''", ruby 3.4 comes from MSYS2 repository (MINGW-W64).

While VER='3.2', ruby 3.2 and VER='3.3', ruby 3.3 are installed on GitHub Windows runner.
2025-08-04 18:26:43 +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
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