mirror of https://github.com/swig/swig.git
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)
|
||
|---|---|---|
| .. | ||
| argcargv.i | ||
| arrays_javascript.i | ||
| ccomplex.i | ||
| cdata.i | ||
| cmalloc.i | ||
| complex.i | ||
| exception.i | ||
| factory.i | ||
| javascript.swg | ||
| javascriptcode.swg | ||
| javascriptcomplex.swg | ||
| javascriptfragments.swg | ||
| javascriptinit.swg | ||
| javascriptprimtypes.swg | ||
| javascriptrun.swg | ||
| javascriptruntime.swg | ||
| javascriptstrings.swg | ||
| javascripttypemaps.swg | ||
| javascriptuint8array.swg | ||
| nodejs_buffer.i | ||
| std_auto_ptr.i | ||
| std_common.i | ||
| std_complex.i | ||
| std_deque.i | ||
| std_except.i | ||
| std_map.i | ||
| std_pair.i | ||
| std_string.i | ||
| std_unique_ptr.i | ||
| std_vector.i | ||
| stl.i | ||
| swigmove.i | ||
| typemaps.i | ||