diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2013-01-23 14:54:19 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2013-01-23 14:54:19 (GMT) |
commit | 5ed89c6ce021c3a02c484f7800ec01fab6d5e3c3 (patch) | |
tree | 75d5eb2735b3c6b0431e3874187c373c3fa67f87 | |
parent | 8faee2bb6cd4206d77f37e8dffaae0adb9df40d0 (diff) | |
download | tk-5ed89c6ce021c3a02c484f7800ec01fab6d5e3c3.zip tk-5ed89c6ce021c3a02c484f7800ec01fab6d5e3c3.tar.gz tk-5ed89c6ce021c3a02c484f7800ec01fab6d5e3c3.tar.bz2 |
make TkBackgroundEvalObjv a static function, and eliminate the use of the deprecated SaveResult API from it.
-rw-r--r-- | generic/tkUtil.c | 83 | ||||
-rw-r--r-- | macosx/tkMacOSXDialog.c | 65 |
2 files changed, 65 insertions, 83 deletions
diff --git a/generic/tkUtil.c b/generic/tkUtil.c index 2a8240b..bfa5d5c 100644 --- a/generic/tkUtil.c +++ b/generic/tkUtil.c @@ -976,89 +976,6 @@ TkFindStateNumObj( } /* - * ---------------------------------------------------------------------- - * - * TkBackgroundEvalObjv -- - * - * Evaluate a command while ensuring that we do not affect the - * interpreters state. This is important when evaluating script - * during background tasks. - * - * Results: - * A standard Tcl result code. - * - * Side Effects: - * The interpreters variables and code may be modified by the script - * but the result will not be modified. - * - * ---------------------------------------------------------------------- - */ - -int -TkBackgroundEvalObjv( - Tcl_Interp *interp, - int objc, - Tcl_Obj *const *objv, - int flags) -{ - Tcl_DString errorInfo, errorCode; - Tcl_SavedResult state; - int n, r = TCL_OK; - - Tcl_DStringInit(&errorInfo); - Tcl_DStringInit(&errorCode); - - Tcl_Preserve(interp); - - /* - * Record the state of the interpreter - */ - - Tcl_SaveResult(interp, &state); - Tcl_DStringAppend(&errorInfo, - Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY), -1); - Tcl_DStringAppend(&errorCode, - Tcl_GetVar(interp, "errorCode", TCL_GLOBAL_ONLY), -1); - - /* - * Evaluate the command and handle any error. - */ - - for (n = 0; n < objc; ++n) { - Tcl_IncrRefCount(objv[n]); - } - r = Tcl_EvalObjv(interp, objc, objv, flags); - for (n = 0; n < objc; ++n) { - Tcl_DecrRefCount(objv[n]); - } - if (r == TCL_ERROR) { - Tcl_AddErrorInfo(interp, "\n (background event handler)"); - Tcl_BackgroundError(interp); - } - - Tcl_Release(interp); - - /* - * Restore the state of the interpreter - */ - - Tcl_SetVar(interp, "errorInfo", - Tcl_DStringValue(&errorInfo), TCL_GLOBAL_ONLY); - Tcl_SetVar(interp, "errorCode", - Tcl_DStringValue(&errorCode), TCL_GLOBAL_ONLY); - Tcl_RestoreResult(interp, &state); - - /* - * Clean up references. - */ - - Tcl_DStringFree(&errorInfo); - Tcl_DStringFree(&errorCode); - - return r; -} - -/* * Local Variables: * mode: c * c-basic-offset: 4 diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index d9e824a..bc11b96 100644 --- a/macosx/tkMacOSXDialog.c +++ b/macosx/tkMacOSXDialog.c @@ -14,6 +14,9 @@ #include "tkMacOSXPrivate.h" #include "tkFileFilter.h" +static int TkBackgroundEvalObjv(Tcl_Interp *interp, int objc, + Tcl_Obj *const *objv, int flags); + static const char *colorOptionStrings[] = { "-initialcolor", "-parent", "-title", NULL }; @@ -1057,6 +1060,68 @@ end: } /* + * ---------------------------------------------------------------------- + * + * TkBackgroundEvalObjv -- + * + * Evaluate a command while ensuring that we do not affect the + * interpreters state. This is important when evaluating script + * during background tasks. + * + * Results: + * A standard Tcl result code. + * + * Side Effects: + * The interpreters variables and code may be modified by the script + * but the result will not be modified. + * + * ---------------------------------------------------------------------- + */ + +int +TkBackgroundEvalObjv( + Tcl_Interp *interp, + int objc, + Tcl_Obj *const *objv, + int flags) +{ + Tcl_InterpState state; + int n, r = TCL_OK; + + /* + * Record the state of the interpreter. + */ + + Tcl_Preserve(interp); + state = Tcl_SaveInterpState(interp, TCL_OK); + + /* + * Evaluate the command and handle any error. + */ + + for (n = 0; n < objc; ++n) { + Tcl_IncrRefCount(objv[n]); + } + r = Tcl_EvalObjv(interp, objc, objv, flags); + for (n = 0; n < objc; ++n) { + Tcl_DecrRefCount(objv[n]); + } + if (r == TCL_ERROR) { + Tcl_AddErrorInfo(interp, "\n (background event handler)"); + Tcl_BackgroundError(interp); + } + + /* + * Restore the state of the interpreter. + */ + + (void) Tcl_RestoreInterpState(interp, state); + Tcl_Release(interp); + + return r; +} + +/* * Local Variables: * mode: objc * c-basic-offset: 4 |