Пример #1
0
        internal ConsoleThread(Interp i)
        {
            Name   = "ConsoleThread";
            interp = i;
            sbuf   = new System.Text.StringBuilder(100);

            out_Renamed = TclIO.getStdChannel(StdChannel.STDOUT);
            err         = TclIO.getStdChannel(StdChannel.STDERR);
        }
        private static void  makeSafe(Interp interp)
        {
            Channel chan;             // Channel to remove from safe interpreter.

            interp.hideUnsafeCommands();

            interp.isSafe = true;

            //  Unsetting variables : (which should not have been set
            //  in the first place, but...)

            // No env array in a safe slave.

            try
            {
                interp.unsetVar("env", TCL.VarFlag.GLOBAL_ONLY);
            }
            catch (TclException e)
            {
            }

            // Remove unsafe parts of tcl_platform

            try
            {
                interp.unsetVar("tcl_platform", "os", TCL.VarFlag.GLOBAL_ONLY);
            }
            catch (TclException e)
            {
            }
            try
            {
                interp.unsetVar("tcl_platform", "osVersion", TCL.VarFlag.GLOBAL_ONLY);
            }
            catch (TclException e)
            {
            }
            try
            {
                interp.unsetVar("tcl_platform", "machine", TCL.VarFlag.GLOBAL_ONLY);
            }
            catch (TclException e)
            {
            }
            try
            {
                interp.unsetVar("tcl_platform", "user", TCL.VarFlag.GLOBAL_ONLY);
            }
            catch (TclException e)
            {
            }

            // Unset path informations variables
            // (the only one remaining is [info nameofexecutable])

            try
            {
                interp.unsetVar("tclDefaultLibrary", TCL.VarFlag.GLOBAL_ONLY);
            }
            catch (TclException e)
            {
            }
            try
            {
                interp.unsetVar("tcl_library", TCL.VarFlag.GLOBAL_ONLY);
            }
            catch (TclException e)
            {
            }
            try
            {
                interp.unsetVar("tcl_pkgPath", TCL.VarFlag.GLOBAL_ONLY);
            }
            catch (TclException e)
            {
            }

            // Remove the standard channels from the interpreter; safe interpreters
            // do not ordinarily have access to stdin, stdout and stderr.
            //
            // NOTE: These channels are not added to the interpreter by the
            // Tcl_CreateInterp call, but may be added later, by another I/O
            // operation. We want to ensure that the interpreter does not have
            // these channels even if it is being made safe after being used for
            // some time..

            chan = TclIO.getStdChannel(StdChannel.STDIN);
            if (chan != null)
            {
                TclIO.unregisterChannel(interp, chan);
            }
            chan = TclIO.getStdChannel(StdChannel.STDOUT);
            if (chan != null)
            {
                TclIO.unregisterChannel(interp, chan);
            }
            chan = TclIO.getStdChannel(StdChannel.STDERR);
            if (chan != null)
            {
                TclIO.unregisterChannel(interp, chan);
            }
        }
Пример #3
0
            public override void  processIdleEvent()
            {
                // During the execution of this method, elements may be removed from
                // the errors list (because a TCL.CompletionCode.BREAK was returned by the bgerror
                // command, or because the interp was deleted). We remove this
                // BgError instance from the list first so that this instance won't
                // be deleted twice.

                SupportClass.VectorRemoveElement(Enclosing_Instance.errors, this);

                // Restore important state variables to what they were at
                // the time the error occurred.

                try
                {
                    Enclosing_Instance.interp.setVar("errorInfo", null, errorInfo, TCL.VarFlag.GLOBAL_ONLY);
                }
                catch (TclException e)
                {
                    // Ignore any TclException's, possibly caused by variable traces on
                    // the errorInfo variable. This is compatible with the behavior of
                    // the Tcl C API.
                }

                try
                {
                    Enclosing_Instance.interp.setVar("errorCode", null, errorCode, TCL.VarFlag.GLOBAL_ONLY);
                }
                catch (TclException e)
                {
                    // Ignore any TclException's, possibly caused by variable traces on
                    // the errorCode variable. This is compatible with the behavior of
                    // the Tcl C API.
                }

                // Make sure, that the interpreter will surive the invocation
                // of the bgerror command.

                Enclosing_Instance.interp.preserve();

                try
                {
                    // Invoke the bgerror command.

                    TclObject[] argv = new TclObject[2];
                    argv[0] = Enclosing_Instance.bgerrorCmdObj;
                    argv[1] = errorMsg;

                    Parser.evalObjv(Enclosing_Instance.interp, argv, 0, TCL.EVAL_GLOBAL);
                }
                catch (TclException e)
                {
                    switch (e.getCompletionCode())
                    {
                    case TCL.CompletionCode.ERROR:
                        try
                        {
                            Channel chan = TclIO.getStdChannel(StdChannel.STDERR);

                            if (Enclosing_Instance.interp.getResult().ToString().Equals("\"bgerror\" is an invalid command name or ambiguous abbreviation"))
                            {
                                chan.write(Enclosing_Instance.interp, errorInfo);
                                chan.write(Enclosing_Instance.interp, "\n");
                            }
                            else
                            {
                                chan.write(Enclosing_Instance.interp, "bgerror failed to handle background error.\n");
                                chan.write(Enclosing_Instance.interp, "    Original error: ");
                                chan.write(Enclosing_Instance.interp, errorMsg);
                                chan.write(Enclosing_Instance.interp, "\n");
                                chan.write(Enclosing_Instance.interp, "    Error in bgerror: ");
                                chan.write(Enclosing_Instance.interp, Enclosing_Instance.interp.getResult());
                                chan.write(Enclosing_Instance.interp, "\n");
                            }
                            chan.flush(Enclosing_Instance.interp);
                        }
                        catch (TclException e1)
                        {
                            // Ignore.
                        }
                        catch (System.IO.IOException e2)
                        {
                            // Ignore, too.
                        }
                        break;


                    case TCL.CompletionCode.BREAK:

                        for (int i = Enclosing_Instance.errors.Count - 1; i >= 0; i--)
                        {
                            BgError bgErr = (BgError)Enclosing_Instance.errors[i];
                            Enclosing_Instance.errors.RemoveAt(i);
                            bgErr.cancel();

                            bgErr.errorMsg.release();
                            bgErr.errorMsg = null;
                            bgErr.errorInfo.release();
                            bgErr.errorInfo = null;
                            bgErr.errorCode.release();
                            bgErr.errorCode = null;
                        }
                        break;
                    }
                }

                Enclosing_Instance.interp.release();

                errorMsg.release();
                errorMsg = null;
                errorInfo.release();
                errorInfo = null;
                errorCode.release();
                errorCode = null;
            }