Commit Graph

315 Commits

Author SHA1 Message Date
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 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 54ac29eb01 Update php tests for additionally generated classes/functions 2026-07-11 01:45:15 +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 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
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
William S Fulton 5275850028 Try replicate issue described in #3337 2026-02-20 19:35:40 +00:00
William S Fulton 69a25600d8 Multiple typedefs involving references fix
If a typedef to a typedef of a reference was wrapped, uncompilable code was
generated. Was previously okay with just a single typedef to a reference.
2025-11-01 12:03:07 +00:00
Olly Betts e57f9bfa2e [PHP] Actually fix the deprecated (double) cast
Fixes #3274
2025-10-20 21:07:20 +13:00
Olly Betts b124f593ce [PHP] Fix testsuite error with PHP 8.5
Error was:

Non-canonical cast (double) is deprecated, use the (float) cast instead
2025-10-20 18:06:27 +13:00
Jim Easterbrook 2a5b60da84 [Python] Fix handling of "default" typemap
Fix handling of "default" typemap applied to method which takes a
single argument when "-builtin" option is used.

Fixes #2786
Closes #2790
Closes #3241
Closes #3243

Co-authored by @ojwb who also suggested it in discussion of #2790.
2025-08-13 18:49:38 +01: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
Olly Betts 3f4ed82945 Improve parsing of expressions related to functions calls
For example, the following no longer give parse errors:  `g().d()`,
`g().D`, `(f(1) < g(2))`, `sizeof f(a,b)`

Partly addresses #3197
2025-06-17 14:59:54 +12:00
Olly Betts 31668d98e1 Fix warnings from cpp11_auto_variable_runme.php 2025-06-08 09:58:30 +12:00
Olly Betts 6dbf867d23 Fix handling of corner cases by previous change
Don't collapse runs of whitespace to a single space, instead replace
each whitespace with one space.

Leave the expression as-is if it contains one or more double quotes
as we don't want to change the value of string literals, and any
expression containing double quotes won't currently work in the context
where we need to replace newlines anyway.

Fixes #3127 better
2025-03-03 11:22:37 +13: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 60a476982a Run inout testcase for all languages except D 2024-10-05 23:29:34 +01:00
Olly Betts d80ce85819 Handle arbitrary expressions as a subscript
We don't actually need to parse expressions in this context so we can
just skip to the matching closing square bracket.
2024-09-30 09:25:00 +13:00
Olly Betts a111df5650 Enable part of testcase which now works
Looks like handling of this was fixed by
3ef3f39516.
2024-09-28 15:35:40 +12:00
Olly Betts 0f7278ea92 Fix PHP testsuite warning 2024-09-26 11:12:40 +12:00
Olly Betts 6567c5d186 Add support for C99 _Bool
SWIG now treats _Bool as an alias for the bool keyword when in C mode.
2024-09-25 06:23:48 +12:00
Olly Betts 2c4ff2f4d6 [php] Fix warning from string_constants testcase 2024-09-22 08:12:45 +12:00
Olly Betts 9f685e03f0 Add regression test for old bug fix
We don't seem to have anything in the testsuite which exercises this
case.

There's some special handling of casts applied to string literals in the
parser which was committed as part of the fix for this, but removing it
doesn't seem to cause anything to fail (not even this testcase which
it reportedly fixed), and a wide character version seems to work without
any equivalent special handling.  Maybe other things have changed since
which fixed this case without needing special cast handling.  Deserves
further investigation.
2024-09-21 09:04:27 +12: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
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
Olly Betts 7a8c9fdfa8 Straighten out handling of char and string constants
Fixes #904
Fixes #1907
Fixes #2579
Fixes #2990
2024-08-17 16:12:45 +12:00
Olly Betts 4299e893da Fix parsing of octal string escapes
We now stop when the next character is digit 8 or 9, and stop after 3
octal digits even if the next character is an octal digit.
2024-08-15 14:38:52 +12:00
Olly Betts 8d1ac40dc6 Fix wrapping of string with control characters
Fix wrapping of string constants containing bytes 0-8, 11, 12 or 14-31
followed by a digit '0' to '7'.  We were emitting these bytes as a one
or two character octal escape sequence which when interpreted would
include the following character.
2024-08-01 14:36:43 +12:00
Olly Betts 3452d08cd8 Support parsing `noexcept(X)` in expressions
Missing C++11 feature.
2024-07-26 12:31:44 +12: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
Olly Betts a5de191402 Improve support for C++11 alignof(T)
Support alignof(T) for arbitrary type T, and deduce the type of
alignof(T) as size_t.
2024-06-06 12:44:46 +12:00
Olly Betts 57ed628035 Improve parsing of sizeof(X)
Support parsing `sizeof(X)` for any expression or type X by skipping
balanced parentheses.  We don't need to actually parse X since the type
of sizeof is always size_t.

Fixes #2919
2024-06-06 10:36:12 +12:00
Olly Betts 0ce05c33e9 Improve alternative operator names support
Handle alternative operator names in C++ preprocessor expressions.
Handle full set of alternative operator names in C++ expressions
(previously only "and", "or" and "not" were understood).

Fixes #2914
2024-05-30 11:38:32 +12:00
Olly Betts a7eca8b415 Support __VA_OPT__
Fixes #1574
2024-03-28 12:46:58 +13:00
Olly Betts f037a5994e Fix typo in recent preproc testcase change 2024-03-28 10:50:55 +13: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
Olly Betts ed30a80d7f [php] Add runme for testcase constant_expr 2024-02-26 12:45:45 +13:00
Olly Betts 4b433543fc [php] Add runme for li_stdint testcase 2024-02-26 12:05:14 +13:00
Olly Betts 4bebdf4430 Improve type deduction for enum value in expression 2024-02-15 21:29:05 +13:00
Olly Betts 4dc621d804 Fix type deduction for certain cases
Fix type deduction for certain cases involving C-style casts, or
which are syntactically like a C-style cast applied to an unary
operator, such as: (7)*6

See #2796
2024-02-13 17:05:55 +13:00
Olly Betts 39e8508dfc Fix handling of enum initialised by typedef-ed cast
Regression introduced in 4.2.0.

Fixes #2796
2024-02-13 10:56:09 +13:00