Skip to content

Commit

Permalink
Merge 8.7"
Browse files Browse the repository at this point in the history
  • Loading branch information
apnadkarni committed Sep 29, 2023
2 parents bd10908 + e2e75c4 commit f5219a0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 19 deletions.
32 changes: 21 additions & 11 deletions generic/tclEvent.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ static int inExit = 0;

static int subsystemsInitialized = 0;

static const char ENCODING_ERROR[] = "\n\t(encoding error in stderr)";

/*
* This variable contains the application wide exit handler. It will be called
* by Tcl_Exit instead of the C-runtime exit if this variable is set to a
Expand Down Expand Up @@ -294,9 +296,13 @@ HandleBgErrors(
Tcl_WriteChars(errChannel,
"error in background error handler:\n", -1);
if (valuePtr) {
Tcl_WriteObj(errChannel, valuePtr);
if (Tcl_WriteObj(errChannel, valuePtr) < 0) {
Tcl_WriteChars(errChannel, ENCODING_ERROR, -1);
}
} else {
Tcl_WriteObj(errChannel, Tcl_GetObjResult(interp));
if (Tcl_WriteObj(errChannel, Tcl_GetObjResult(interp)) < 0) {
Tcl_WriteChars(errChannel, ENCODING_ERROR, -1);
}
}
Tcl_WriteChars(errChannel, "\n", 1);
Tcl_Flush(errChannel);
Expand Down Expand Up @@ -483,18 +489,22 @@ TclDefaultBgErrorHandlerObjCmd(
if (Tcl_FindCommand(interp, "bgerror", NULL,
TCL_GLOBAL_ONLY) == NULL) {
Tcl_RestoreInterpState(interp, saved);
Tcl_WriteObj(errChannel, Tcl_GetVar2Ex(interp,
"errorInfo", NULL, TCL_GLOBAL_ONLY));
if (Tcl_WriteObj(errChannel, Tcl_GetVar2Ex(interp,
"errorInfo", NULL, TCL_GLOBAL_ONLY)) < 0) {
Tcl_WriteChars(errChannel, ENCODING_ERROR, -1);
}
Tcl_WriteChars(errChannel, "\n", -1);
} else {
Tcl_DiscardInterpState(saved);
Tcl_WriteChars(errChannel,
"bgerror failed to handle background error.\n", -1);
Tcl_WriteChars(errChannel, " Original error: ", -1);
Tcl_WriteObj(errChannel, tempObjv[1]);
Tcl_WriteChars(errChannel, "\n", -1);
Tcl_WriteChars(errChannel, " Error in bgerror: ", -1);
Tcl_WriteObj(errChannel, resultPtr);
Tcl_WriteChars(errChannel, "bgerror failed to handle"
" background error.\n Original error: ", -1);
if (Tcl_WriteObj(errChannel, tempObjv[1]) < 0) {
Tcl_WriteChars(errChannel, ENCODING_ERROR, -1);
}
Tcl_WriteChars(errChannel, "\n Error in bgerror: ", -1);
if (Tcl_WriteObj(errChannel, resultPtr) < 0) {
Tcl_WriteChars(errChannel, ENCODING_ERROR, -1);
}
Tcl_WriteChars(errChannel, "\n", -1);
}
Tcl_DecrRefCount(resultPtr);
Expand Down
33 changes: 25 additions & 8 deletions generic/tclMain.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
*/

static const char DEFAULT_PRIMARY_PROMPT[] = "% ";
static const char ENCODING_ERROR[] = "\n\t(encoding error in stderr)";

/*
* This file can be compiled on Windows in UNICODE mode, as well as on all
Expand Down Expand Up @@ -249,7 +250,9 @@ Tcl_SourceRCFile(
if (Tcl_EvalFile(interp, fullName) != TCL_OK) {
chan = Tcl_GetStdChannel(TCL_STDERR);
if (chan) {
Tcl_WriteObj(chan, Tcl_GetObjResult(interp));
if (Tcl_WriteObj(chan, Tcl_GetObjResult(interp)) < 0) {
Tcl_WriteChars(chan, ENCODING_ERROR, -1);
}
Tcl_WriteChars(chan, "\n", 1);
}
}
Expand Down Expand Up @@ -375,7 +378,9 @@ Tcl_MainEx(
if (chan) {
Tcl_WriteChars(chan,
"application-specific initialization failed: ", -1);
Tcl_WriteObj(chan, Tcl_GetObjResult(interp));
if (Tcl_WriteObj(chan, Tcl_GetObjResult(interp)) < 0) {
Tcl_WriteChars(chan, ENCODING_ERROR, -1);
}
Tcl_WriteChars(chan, "\n", 1);
}
}
Expand Down Expand Up @@ -415,7 +420,9 @@ Tcl_MainEx(
Tcl_DecrRefCount(keyPtr);

if (valuePtr) {
Tcl_WriteObj(chan, valuePtr);
if (Tcl_WriteObj(chan, valuePtr) < 0) {
Tcl_WriteChars(chan, ENCODING_ERROR, -1);
}
}
Tcl_WriteChars(chan, "\n", 1);
Tcl_DecrRefCount(options);
Expand Down Expand Up @@ -528,7 +535,9 @@ Tcl_MainEx(
if (code != TCL_OK) {
chan = Tcl_GetStdChannel(TCL_STDERR);
if (chan) {
Tcl_WriteObj(chan, Tcl_GetObjResult(interp));
if (Tcl_WriteObj(chan, Tcl_GetObjResult(interp)) < 0) {
Tcl_WriteChars(chan, ENCODING_ERROR, -1);
}
Tcl_WriteChars(chan, "\n", 1);
}
} else if (is.tty) {
Expand All @@ -537,7 +546,9 @@ Tcl_MainEx(
(void)Tcl_GetStringFromObj(resultPtr, &length);
chan = Tcl_GetStdChannel(TCL_STDOUT);
if ((length > 0) && chan) {
Tcl_WriteObj(chan, resultPtr);
if (Tcl_WriteObj(chan, resultPtr) < 0) {
Tcl_WriteChars(chan, ENCODING_ERROR, -1);
}
Tcl_WriteChars(chan, "\n", 1);
}
Tcl_DecrRefCount(resultPtr);
Expand Down Expand Up @@ -802,7 +813,9 @@ StdinProc(
chan = Tcl_GetStdChannel(TCL_STDERR);

if (chan != NULL) {
Tcl_WriteObj(chan, Tcl_GetObjResult(interp));
if (Tcl_WriteObj(chan, Tcl_GetObjResult(interp)) < 0) {
Tcl_WriteChars(chan, ENCODING_ERROR, -1);
}
Tcl_WriteChars(chan, "\n", 1);
}
} else if (isPtr->tty) {
Expand All @@ -812,7 +825,9 @@ StdinProc(
Tcl_IncrRefCount(resultPtr);
(void)Tcl_GetStringFromObj(resultPtr, &length);
if ((length > 0) && (chan != NULL)) {
Tcl_WriteObj(chan, resultPtr);
if (Tcl_WriteObj(chan, resultPtr) < 0) {
Tcl_WriteChars(chan, ENCODING_ERROR, -1);
}
Tcl_WriteChars(chan, "\n", 1);
}
Tcl_DecrRefCount(resultPtr);
Expand Down Expand Up @@ -883,7 +898,9 @@ Prompt(
"\n (script that generates prompt)");
chan = Tcl_GetStdChannel(TCL_STDERR);
if (chan != NULL) {
Tcl_WriteObj(chan, Tcl_GetObjResult(interp));
if (Tcl_WriteObj(chan, Tcl_GetObjResult(interp)) < 0) {
Tcl_WriteChars(chan, ENCODING_ERROR, -1);
}
Tcl_WriteChars(chan, "\n", 1);
}
goto defaultPrompt;
Expand Down

0 comments on commit f5219a0

Please sign in to comment.