Use the usual C rule for NUL-terminated strings instead of discarding all the trailing NUL characters. This was unexpected (as buffers in C code are not necessarily always padded with NULs to their full length) and also inconsistent among languages as this was only done for those of them using typemaps/strings.swg but not for C# or Java, for example, which terminated the string at the first NUL even before this change. Notice that this patch couldn't use strlen() or wcslen() with possibly not NUL-terminated strings, so we had to add [our own equivalents of] strnlen() and wcsnlen() and use them instead. This required adding yet another parameter to string typemap macros, so update the example using them accordingly too.
37 lines
794 B
Text
37 lines
794 B
Text
%ensure_fragment(SWIG_AsWCharPtrAndSize)
|
|
%ensure_fragment(SWIG_FromWCharPtrAndSize)
|
|
|
|
|
|
%types(wchar_t *);
|
|
|
|
%fragment("SWIG_pwchar_descriptor","header") {
|
|
SWIGINTERN swig_type_info*
|
|
SWIG_pwchar_descriptor()
|
|
{
|
|
static int init = 0;
|
|
static swig_type_info* info = 0;
|
|
if (!init) {
|
|
info = SWIG_TypeQuery("_p_wchar_t");
|
|
init = 1;
|
|
}
|
|
return info;
|
|
}
|
|
}
|
|
|
|
%fragment("SWIG_wcsnlen","header",fragment="SWIG_FromWCharPtrAndSize") {
|
|
size_t
|
|
SWIG_wcsnlen(const wchar_t* s, size_t maxlen)
|
|
{
|
|
const wchar_t *p;
|
|
for (p = s; maxlen-- && *p; p++)
|
|
;
|
|
return p - s;
|
|
}
|
|
}
|
|
|
|
%include <typemaps/strings.swg>
|
|
%typemaps_string(%checkcode(UNISTRING), %checkcode(UNICHAR),
|
|
wchar_t, WChar, SWIG_AsWCharPtrAndSize, SWIG_FromWCharPtrAndSize,
|
|
wcslen, SWIG_wcsnlen,
|
|
"<wchar.h>", WCHAR_MIN, WCHAR_MAX)
|
|
|