Commit Graph

165 Commits

Author SHA1 Message Date
William S Fulton ae445a8f3c [Lua] Fix flaky li_std_map test caused by garbage collected Struct objects
The IntStructPtrMap and IntStructConstPtrMap sections passed newly
constructed Struct objects straight into the map and kept no Lua
reference to them. These maps store just the raw pointers, so once the
incremental collector completed a cycle the Struct objects were deleted
and the maps were left holding dangling pointers. The following value
checks then read freed memory, which sporadically failed in CI with:

  li_std_map_runme.lua:68: ispmap:get(8)

Hold the Struct objects in a Lua table for the lifetime of the maps.

Confirmed as a use-after-free with valgrind and reproducible before the
fix by lowering the collector pause with collectgarbage("setpause", 105).

Assisted-by: Claude Code (Opus 5)
2026-08-01 09:42:44 +01:00
William S Fulton d3a20504be Fix multicharacter constants to have type int, not char
A character constant containing more than one character, e.g. 'ab', has
type int per both the C standard (6.4.4.4p10) and the C++ standard
([lex.ccon], which describes it as a "multicharacter literal"). SWIG
previously classified every character constant as char regardless of
length, which caused the generated wrapper accessor for a constant such
as #define X 'ab' to be declared char instead of int, silently
truncating the value.

The literal text is left untouched (SWIG does not evaluate constant
expressions), only the internal type tag changes, so the real compiler
that builds the generated wrapper still computes the (implementation
defined) value, exactly as it would for hand written C/C++ code.

Add a new C-only multichar_constant.i test case with per-language runme
files, and keep the new csharp/java char_constant runme files (which
had no coverage before) for the existing, unrelated character constant
checks.

Compiling a real multicharacter constant always triggers GCC's
-Wmultichar warning. #pragma GCC diagnostic ignored "-Wmultichar" does
not suppress it: this is a known, longstanding GCC C++ front-end bug
(gcc.gnu.org PR57241/PR53431, fixed in GCC 13) - verified locally that
it fails identically on GCC 11 and 12 regardless of file- or
function-level pragma scope, while working fine in C or with GCC 13+
or Clang (which also defines __GNUC__ but doesn't have this bug).

The new testcase avoids the warning entirely, with no build system
changes needed:

- The %inline global variable imulti_ab uses the real literal (guarded
  by the pragma) wherever that's known to work, and otherwise falls
  back to reconstructing the identical value GCC's own packing of
  'ab' produces (most significant byte first) without writing a
  multicharacter literal at all - the same symbol name and type either
  way, so the generated accessor links correctly regardless of which
  branch was compiled.
- The #define-driven MULTICHAR_AB constant (whose registration code is
  auto-generated per target language, so a similar fallback isn't
  portable to hand-write once for every language) is skipped entirely
  for octave and javascript's node/napi/v8 engines, the only
  configurations that always compile the generated wrapper as C++
  regardless of SWIG's own -c/-c++ mode (their runtime APIs require
  it) and so would otherwise still hit the GCC bug above.

Verified against both GCC 13 (default) and GCC 11 (matching the actual
CI toolchain that originally failed) across all configured languages.

Assisted-by: Claude Code (Sonnet 5)
2026-07-29 19:46:45 +01:00
Erez Geva d1d459d9f1
Fix apply_signed_char test (#3502)
Add is_char_signed() to skip the tests in Lua.
As test fails if char is unsigned.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2026-07-22 23:06:16 +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 294c944c10 [Lua] Restore Lua 5.1 and LuaJIT compatibility for non-director wrapping
the new Lua directors feature uses lua_setuservalue, added in Lua 5.2.
Removing the LUA_VERSION_NUM-guarded compatibility defines for lua_rawlen,
lua_pushglobaltable and lua_rawsetp/lua_rawgetp from Lib/lua/luarun.swg.

LuaJIT implements the Lua 5.1 API and, per its own documentation, is
"API+ABI-compatible with Lua 5.1, which prevents implementing features
that would otherwise break the Lua/C API and ABI" (https://luajit.org/extensions.html,
"Extensions from Lua 5.2" section) - so it never defines these Lua 5.2 additions.
Noticed when rebuilding obs-studio's LuaJIT-based Lua bindings against SWIG master.

Restore those compatibility defines, scoped to 5.1 and later only (the old
Lua 5.0-only shims are not restored).

Also revert an incidental ok!=LUA_OK comparison introduced by #3394
back to ok!=0, since LUA_OK isn't defined pre-5.2 either and luaL_dostring()
already returns 0 on success on every Lua version.

Fix the examples and test-suite where they themselves used Lua 5.2 only
features: LUA_OK in Examples/lua/embed/embed.c, _ENV in helpers.lua, and
string.format("%c", ...) in li_cdata_bytes, which yields an empty string for a
NUL byte in Lua 5.1 as strlen() is applied to the formatted result, so
string.char() is used instead.

Directors continue to require Lua 5.2 or later and are unaffected by this
change; the Lua 5.1 director test failures are addressed separately.

Assisted-by: Claude Code (Sonnet 5)
2026-07-14 20:15:39 +01:00
William S Fulton f156c99907 Fix protected/private nested class referenced in generated upcast helper
Reported on the swig-devel mailing list during early testing of swig-4.5,
where CrossWire SWORD's Perl bindings (GBFHTMLHREF::MyUserData deriving
from BasicFilterUserData) failed to build: a protected or private nested
class deriving from a class used elsewhere in the wrapped API could produce
a runtime upcast helper function referencing the nested class by its
inaccessible qualified name, a C++ compile error. No target language ever
wraps a non-public nested class, so typepass.cxx now simply skips
registering it for the cast table. Fixes it for Lua too, which hits the
same bug as Perl/Python/Ruby/Tcl despite having full nested class support,
since Java/C# are structurally immune (they don't use SWIG's generic
runtime type table at all). Added regression tests to nested_scope.i and
director_protected.i (covering directors/dirprot), with a runtime check in
every director_protected runme confirming polymorphic dispatch through the
wrapped base still works correctly.

Assisted-by: Claude Code (Sonnet 5)
2026-07-11 21:02:49 +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 d43ee445e0
Rename the near function to cmp_flt function that compare float numbers (#3490)
And move it to helpers.
Although Lua uses C floating math.
The actual used C floating functions in Lua
 might be different from the actual floating functions
 used in the original C code, which may lead to a slightly
 different floating number.
So for calculated floating numbers we should use the cmp_flt function in the assert.

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2026-07-09 18:27:35 +01:00
Olly Betts 9140467c2d Improve handling of NULL vs nullptr vs 0 vs 0L
For some target languages (Octave, Python and Ruby), SWIG has previously
treated nullptr or NULL as an integer 0 if used in a situation where
the type wasn't known to be a pointer.

For nullptr this is never helpful, because it has type nullptr_t which
does not implicitly convert to 0, so we no longer do this.

For NULL it's rather dubious - C and C++ allow NULL to be defined as
integer 0, so `int i = NULL` may work and is occassionally seen in real
code, but it is semantically wrong.  Also GCC and clang define NULL to a
magic value and by default will warn about such misuse, so it's likely
to be less common than before they did this.  So now SWIG only converts
NULL to 0 if used in a context where we know the underlying type is an
arithmetic type.

Using an integer zero (or equivalent value such as 0L) for a NULL
pointer is valid, and SWIG will still treat it as a NULL pointer if used
in a context where know the type is a pointer.  This is now done based
on the value of the integer constant so also applies to 0L (previously
it was only done if the value was written in the code as literally `0`).

Fixes: #3472
2026-06-29 14:36:06 +12:00
William S Fulton b78dba177a Inherit constructors named through a typedef base
C++11 inheriting constructors (using Base::Base;) now work when the immediate
base class is named through a typedef, a chain of typedefs, a typedef whose
template argument is itself a typedef, a scope-qualified or namespaced name, or
a type-template parameter used directly as the base class (the mixin idiom).

The inheriting constructor's using-declaration qualifier is normalized in the
typepass stage; the inheriting base is then found by identity in the resolved base
class list and the base class' constructors are used to implement the inherited
constructors.

An inheriting-constructor using declaration whose qualifier is not an immediate
base class is reported with Warning 329 (uses base '...' which is not an
immediate base of '...') rather than the generic Warning 315.

Closes #2951)

Assisted-by: Claude Opus 4.8
2026-06-17 01:47:06 +01:00
William S Fulton 978f675ad7 Fix spurious Warning 315 for a member using-declaration through a typedef base with a constructor
When a base class declares a constructor of its own, the constructor shares the
base class name.  Resolving a typedef that names the base to its scope looked the
base class name up through the derived class' inherited scope and found the base
constructor ahead of the class itself, so no typedef scope alias was created and a
later 'using base_type::member;' was reported as Warning 315 and the member
silently dropped.

Skip constructor nodes (including the using-declaration nodes that inherit base
constructors, which also carry the class name) when resolving a typedef to its
scope, so the class node is found instead.

Resolving the typedef now goes through Swig_symbol_clookup_check, whose
using-declaration chase loop was missing the self-reference guard that
Swig_symbol_clookup already has.  Add it to avoid infinite recursion (a stack
overflow and crash) on a self-referential using declaration; the existing test
Examples/test-suite/using2.i, with a top-level 'using ::baz;', exercises this.

Assisted-by: Claude Opus 4.8 (1M context)
2026-06-17 01:47:06 +01:00
Erez Geva d483ae428b
Improve Lua test syntax (#3463)
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2026-06-01 23:23:41 +01:00
Erez Geva a1b3ca81ca More Lua tests (#3405)
- Add Lua examples
- Add and fix unused Lua tests
- Add lua_module_global complementary test of lua_no_module_global
- Add Lua test-suite runme files

Enable friends_nested and minherit inline test code for Lua via the
SWIGLUA guards.
2026-05-31 15:09:53 +01:00
William S Fulton afa12401f3 Lua review follow-ups
- lua.cxx: clarify old_compatible_names comment; the flag is no longer user-controllable.
- director_enum_runme.lua: restore catch_undef_globs() lost in the import.lua rewrite.
- cpp17_string_view_runme.lua: drop redundant require_to_globs return-value capture.

Assisted-by: Claude Opus 4.7
2026-05-30 17:24:17 +01:00
Erez Geva 74ff929bd4 Remove Lua 5.0 and Lua 5.1 and Lua options
- configure.ac
  - Use minimum version 5.2 for Lua
  - Add lua 5.5, it was released in dec 2025
  - Syntax improvements
- GHA CI
  - Remove 'default' Lua version, it is confusing.
    Just select the version explicitly.
  - Add Lua 5.4 test, we need to test all supported versions 5.2, 5.3 and 5.4
    Lua 5.5 is not available on Ubuntu yet.
- Lua documentation Doc/Manual/Lua.html
  - Update version to 5.2
  - Remove mention to older SWIG version,
    whom wishes to go to the very old history can look on CHANGES.
  - Add references on missing operators in Lua.
- _ENV exist from Lua 5.2.
- Remove old compatibility code from Lib/lua/luarun.swg.
- Remove LUA_VERSION_NUM from Lua C wrapping code.
  It was used for old Lua 5.0 and Lua 5.1.
- Remove _VERSION from Lua tests.
  Note: _VERSION remains a keyword and developers may use it in interface files!
- Remove Example/lua/import.lua and Examples/test-suite/lua/import.lua
  as they are not used or needed any longer.
  - Remove old Lua import.
- Add Examples/test-suite/lua/helpers.lua
  - include it in all tests in test-suite.
  - Add catch "undefined" global variables enable function.
  - Add import_to_globs function.
    To add module functions, variables and classes to global scope.
- Remove the -squash-bases option as it is broken
  The der.new_func from the example
  in the document,  "29.3.18.3 Inheritance",
  pass from base object to derived object
  regardless of using the flag or not.
- Remove -no-old-metatable-bindings as it is deprecated in the last 12 years

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2026-05-30 17:24:17 +01:00
William S Fulton 0c291fa448 Fix one-byte buffer overflow in cdata.i memmove
The cdata.i (const void *BYTES, size_t LENGTH) typemap took LENGTH from
SWIG_AsCharPtrAndSize, whose psize includes a trailing NUL (data length
+ 1). When the destination buffer is sized exactly to the data, memmove
wrote one byte past the end. Confirmed with valgrind: "Invalid write of
size 1, 0 bytes after a block of size 512".

- Make SWIG_AsCharPtrAndSize binary aware in the languages that use the
  generic Lib/cdata.i (Python, Perl, Ruby, Octave, R): when the caller
  passes SWIG_BINARYSTR it now reports the exact byte count, not data
  + 1. Non cdata callers are unaffected as they never set the flag.
- Lua li_cdata_bytes tests looped to 0x99 instead of 0xff, verifying
  only 154 of the 256 byte values; corrected to 0xff.
- Tcl cdata.i passed an int * to Tcl_GetSizeIntFromObj, which expects
  a Tcl_Size * on Tcl 8.7 and 9; use Tcl_Size and reject values that
  are not a byte.
- CHANGES.current: document the cdata type change and the overflow fix.

Assisted-by: Claude Opus 4.7
2026-05-25 13:17:15 +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 ebd01b75c0 Remove need for additional %rename for std::function
When using D, JavaScript, Lua, PHP, R

Perhaps some better language specific uses of %namewarn/%keywordwarn
for keyword handling could instead be implemented??
2026-05-03 19:00:24 +01:00
William S Fulton 4433e444b8 shared_ptr tests cleanup
- Add changes entry for new Lua shared_ptr support.
- Rename director_smartptr test to director_shared_ptr.
- Reimplement cpp11_shared_ptr test cases so that they are run by all
  languages (in common.mk instead of being in chosen language's Makefile.in files).
  This makes sure missing tests are run by all languages that support
  shared_ptr.
2026-03-26 08:37:18 +00:00
Christophe Calmejane ae916b4bb6 Add support for shared_ptr for Lua
- Added lua smart pointers typemaps (boost and std)
- Handling nullptr case for typecheck without memory allocation
- Handling feature:smartptr
- Remove redundant shared_ptr testcase entries in lua test-suite
- Added unit tests for lua smart pointers

Closes #3387
2026-03-26 08:37:00 +00:00
Erez Geva b8eb972799
Add more Lua director tests (#3379)
Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
Co-authored-by: Christophe Calmejane <christophe.calmejane@l-acoustics.com>
2026-03-24 08:25:59 +00:00
Christophe Calmejane 9a60f9573f
Task/std unordered map set lua (#3386)
* Added lua unit tests for std::unordered_map std::unordered_set

* Added lua typemaps for std::unordered_map and std::unordered_set
2026-03-23 19:46:49 +00:00
William S Fulton 87961d1fb0 Added support for nested classes for lua (NCS_Full)
Updated doc and added unit test

This is a squashed merge and clang-format and html fixup of #3306
Closes #3306
2026-03-20 18:57:51 +00:00
Erez Geva a59f62f597
Remove Lua thread test (#3374)
Lua do not support multithreading.
Only Coroutines, see:
https://www.lua.org/pil/9.html

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2026-03-11 07:16:22 +00:00
Christophe Calmejane 95904761fd
Support for std::array and std::set for lua (#3305)
Added std::array and std::set for lua
2026-03-05 21:51:51 +00:00
Erez Geva 15cb4159fe
Add a minimal director test (#3346)
* Add a minimal director test

The purpose of this test is to provide
 the minimal test the prove a language
 support the director feature.

The test does not replace any of the other director tests.
But merely a starting point.

* alphabetical order fix

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
Co-authored-by: William S Fulton <wsf@fultondesigns.co.uk>
2026-02-24 08:58:50 +00:00
Erez Geva 786931dc6f
Lua improvements (#3342)
* Improve Lua

- Add missing section in document table of contents
- Add director tests
- Remove unused code from lua.cxx

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>

---------

Signed-off-by: Erez Geva <ErezGeva2@gmail.com>
2026-02-23 08:23:04 +00:00
Christophe Calmejane 1c20901001 Added unit tests for lua directors 2025-12-12 07:16:42 +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 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
Armin Brauns e2c3e568fd Add Lua test case for long long 2024-12-05 15:38:08 +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 9bf4842002 C++ reference errors when passing in a 'NULL' change of behaviour.
Most languages now use "NullReferenceError" in the error message
where they previously used "ValueError". Also exception changes:

Guile:    "swig-null-reference-error" instead of "swig-value-error"
MzScheme: "swig-null-reference-error" instead of "swig-value-error"
PHP:      zend_ce_type_error instead of zend_ce_value_error
Python:   Consistently raises TypeError instead of a mix of ValueError
          and TypeError.
Ruby:     Consistently raises NullReferenceError instead of a mix of
          ArgumentError and NullReferenceErrorError.

The consistent raising of a TypeError instead of ValueError for Python
ensures that incorrectly passing 'None' into a C++ reference argument
will correctly convert the error into a NotImplemented error for
the rich comparisons implementations per PEP 207. Fixes #2987

Note that the li_constraints checking implementation for the NONNULL
typemap for pointers also makes the same error change from
SWIG_ValueError to SWIG_NullReferenceError.

The D typemaps use SWIG_DNullReferenceException instead of
SWIG_DIllegalArgumentException, although this ultimately has no change
as the same D Exception is still thrown.
2024-09-14 13:03:36 +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 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 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
Olly Betts aa2a7f258e Fix passing a Lua number for C++ std::string
Order of evaluation of C++ function arguments is not defined, and if
lua_rawlen() was called before lua_tostring() then it would return 0
(because the value was still a number) and an empty string would be
passed.

The same issue affects std::string_view too, but that's not been in
a release yet.

The new testcases fail without the fix with GCC 12.2 on x86-64 Linux.
2023-05-30 17:54:19 +12:00
Olly Betts 427d41b547 Expand std::string_view test coverage
Fill in cases which weren't being tested for some target languages.
2023-05-26 16:19:05 +12:00
Olly Betts 8a73e25fe2 argcargv.i: NULL terminate argv with empty input
Fixes needed for: C# R
2023-05-23 10:12:49 +12:00