A bare #define at the start of a line in a brace delimited %fragment body is
consumed by the SWIG preprocessor and never reaches the generated wrapper. The
macro therefore only exists at SWIG level and code that SWIG does not macro
expand, such as a typemap delimited with %{ ... %}, is left referring to an
undefined name. Use %#define so the definition is emitted for the C compiler.
Fixes SWIG_FromCharPtrAndSize for Python, SWIG_FromBinaryCharPtrAndSize for
Octave, Perl, R and Ruby, SWIG_ToUint8Array and SWIG_FromUint8Array for
JavaScript, and the SWIG_AsVal_* and SWIG_From_* macros in the Scilab char,
short, signed char, unsigned char, unsigned long and long long files.
Lib/scilab/scipointer.swg is deliberately left alone. Its fragments are never
requested by any typemap, so they are only emitted as SWIG preprocessor
definitions; switching them to %#define drops SWIG_ConvertPtr and
SWIG_NewPointerObj from the generated code entirely. Fixing those needs the
definitions moving to a runtime insert, as the other target languages do.
Add a common test case charptr_fragment. It uses a %{ ... %} delimited typemap
so the macro name survives into the wrapper, which only compiles when the
library defines the macro for the C compiler. The target languages without
these macros wrap the same functions using their default typemaps. Verified
that the generated Python module fails to load before this change with an
undefined symbol for SWIG_FromCharPtrAndSize.
Follows on from #3522.
Assisted-by: Claude Code (Opus 5)
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
Use the full English word in the identifiers added by the previous
commit for cdata raw byte handling:
SWIG_BINSTR -> SWIG_BINARYSTR
SWIG_BINSTRMASK -> SWIG_BINARYSTRMASK
SWIG_AddBinMask -> SWIG_AddBinaryStrMask
SWIG_DelBinMask -> SWIG_DelBinaryStrMask
SWIG_IsBinStr -> SWIG_IsBinaryStr
SWIG_FromBinCharPtrAndSize -> SWIG_FromBinaryCharPtrAndSize
useBin (local variable) -> use_binary
Touches the constants in Lib/swigrun.swg, the SWIG_FromBinary*
macro defines in pystrings.swg, perlstrings.swg, rubystrings.swg,
octprimtypes.swg and rfragments.swg, and all call sites in
Lib/cdata.i and Lib/python/pystrings.swg.
Assisted-by: Claude Opus 4.7
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>
Added swig_assert.rb and started using it in some tests.
Added my patches to ruby.cxx, rubyrun.swg, rubystrings.swg
and rubytracking.swg [see: sourceforge]
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@9691 626c5289-ae23-0410-ae9c-e8d60b6d4f22
a warning message, and to raise an exception if the typemap is actually
invoked at runtime. This is needed to avoid problems for the case when
wrapping an extern char[] declaration, where the array size is truly
unknown.
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6151 626c5289-ae23-0410-ae9c-e8d60b6d4f22