Posted to tcl by patthoyts at Sun Jul 06 23:07:32 GMT 2008view raw

  1. static int
  2. BackgroundEvalObjv(Tcl_Interp *interp,
  3. int objc, Tcl_Obj *const *objv, int flags)
  4. {
  5. Tcl_DString errorInfo, errorCode;
  6. Tcl_SavedResult state;
  7. int r = TCL_OK;
  8.  
  9. Tcl_DStringInit(&errorInfo);
  10. Tcl_DStringInit(&errorCode);
  11.  
  12. /*
  13. * Record the state of the interpreter
  14. */
  15.  
  16. Tcl_SaveResult(interp, &state);
  17. Tcl_DStringAppend(&errorInfo,
  18. Tcl_GetVar(interp, "errorInfo", TCL_GLOBAL_ONLY), -1);
  19. Tcl_DStringAppend(&errorCode,
  20. Tcl_GetVar(interp, "errorCode", TCL_GLOBAL_ONLY), -1);
  21.  
  22. /*
  23. * Evaluate the command and handle any error.
  24. */
  25.  
  26. r = Tcl_EvalObjv(interp, objc, objv, flags);
  27. if (r == TCL_ERROR) {
  28. Tcl_AddErrorInfo(interp, "\n (background event handler)");
  29. Tcl_BackgroundError(interp);
  30. }
  31.  
  32. /*
  33. * Restore the state of the interpreter
  34. */
  35.  
  36. Tcl_SetVar(interp, "errorInfo",
  37. Tcl_DStringValue(&errorInfo), TCL_GLOBAL_ONLY);
  38. Tcl_SetVar(interp, "errorCode",
  39. Tcl_DStringValue(&errorCode), TCL_GLOBAL_ONLY);
  40. Tcl_RestoreResult(interp, &state);
  41.  
  42. /*
  43. * Clean up references.
  44. */
  45.  
  46. Tcl_DStringFree(&errorInfo);
  47. Tcl_DStringFree(&errorCode);
  48.  
  49. return r;
  50. }