Commit Graph

4 Commits

Author SHA1 Message Date
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 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 662084aa06 Lua - Fix char pointers, wchar_t pointers and char arrays so that nil can be passed as a valid value
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@11963 626c5289-ae23-0410-ae9c-e8d60b6d4f22
2010-04-02 19:48:20 +00:00