Hello,
The fragment %fragment SWIG_FromWCharPtrAndSize in file swigwin-2.0.9\Lib\tcl\tclwstrings.swg needs to be corrected. No assignation is done to the out-pointer-variable.
[is code]
dstLen, &srcRead, &dstWrote, &dstChars);
if (alloc) *alloc = SWIG_NEWOBJ;
[new code]
dstLen, &srcRead, &dstWrote, &dstChars);
*cptr = (wchar_t*)dst;
if (alloc) *alloc = SWIG_NEWOBJ;
corrected file
The patch still applies (seems
tclwstrings.swg
hasn't changed since). However I tried to write a testcase (Examples/test-suite/tcl/li_cwstring_runme.tcl
) and the output seems completely garbled.I dug in some more and it seems wchar support in SWIG/Tcl is relies on the "system encoding" being wide characters. That may work on Microsoft Windows but won't on Linux systems (where the modern default seems to be pretty much universally UTF-8) - that's probably the case for most Unix-like systems too.
It looks like Tcl 8.7 may have public
Tcl_WCharToUtfDString()
and similar which sound perfect for this (https://tcl.tk/man/tcl8.7/TclLib/Utf.html). These are present for Tcl 8.5 and 8.6 (the two versions I have to hand) but are declared in headers undertcl-private/
so presumably not public APIs.I think given the state of this code, the simplicity of the patch, and the fact it's clear broken as it is (because
*cptr
doesn't get set) I'm going to bend the usual requirement for a testcase for any fix and just apply the patch - the patch can really only improve the situation. We couldn't have a testcase that was covered by CI anyway, since this feature doesn't work on Linux and we don't have Tcl testing in appveyor.Pushed as 663299281ebbadbe78781cc369dafd63c3fa3219.