summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2011-06-06 21:56:23 (GMT)
committerdgp <dgp@users.sourceforge.net>2011-06-06 21:56:23 (GMT)
commita17cc6e7864857dc63ad66ea35f82244d1addeef (patch)
tree05ea88391e7c605bfd393af9b27984b77049cc66 /generic
parent96d0f850a44c11b73df5d7ca2f775a03d4ecf085 (diff)
downloadtk-a17cc6e7864857dc63ad66ea35f82244d1addeef.zip
tk-a17cc6e7864857dc63ad66ea35f82244d1addeef.tar.gz
tk-a17cc6e7864857dc63ad66ea35f82244d1addeef.tar.bz2
Restore proper NUL output to the [console]. [Bug 2546087]
Diffstat (limited to 'generic')
-rw-r--r--generic/tkConsole.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/generic/tkConsole.c b/generic/tkConsole.c
index 13e755e..b7314b0 100644
--- a/generic/tkConsole.c
+++ b/generic/tkConsole.c
@@ -534,7 +534,22 @@ ConsoleOutput(instanceData, buf, toWrite, errorCode)
Tcl_Interp *consoleInterp = info->consoleInterp;
if (consoleInterp && !Tcl_InterpDeleted(consoleInterp)) {
+ Tcl_DString ds;
+ Tcl_Encoding utf8 = Tcl_GetEncoding(NULL, "utf-8");
+
+ /*
+ * Not checking for utf8 == NULL. Did not check for TCL_ERROR
+ * from Tcl_SetChannelOption() in Tk_InitConsoleChannels() either.
+ * Assumption is utf-8 Tcl_Encoding is reliably present.
+ */
+
+ CONST char *bytes
+ = Tcl_ExternalToUtfDString(utf8, buf, toWrite, &ds);
+ int numBytes = Tcl_DStringLength(&ds);
Tcl_Obj *cmd = Tcl_NewStringObj("tk::ConsoleOutput", -1);
+
+ Tcl_FreeEncoding(utf8);
+
if (data->type == TCL_STDERR) {
Tcl_ListObjAppendElement(NULL, cmd,
Tcl_NewStringObj("stderr", -1));
@@ -542,7 +557,10 @@ ConsoleOutput(instanceData, buf, toWrite, errorCode)
Tcl_ListObjAppendElement(NULL, cmd,
Tcl_NewStringObj("stdout", -1));
}
- Tcl_ListObjAppendElement(NULL, cmd, Tcl_NewStringObj(buf, toWrite));
+ Tcl_ListObjAppendElement(NULL, cmd,
+ Tcl_NewStringObj(bytes, numBytes));
+
+ Tcl_DStringFree(&ds);
Tcl_IncrRefCount(cmd);
Tcl_GlobalEvalObj(consoleInterp, cmd);
Tcl_DecrRefCount(cmd);