From: Kevin Walzer on 9 Jan 2010 22:53 I'm trying to create an async process to run in Wish via a binary extension. Using various "printf" statements, I can tell that things are going smoothly, right up to the moment when I call Tcl_Eval: then things simply return without running. Here's the relevant part of the async function: static Tcl_AsyncHandler my_asyncEvalHandler; static Tcl_Interp *myInterp; char *myAsyncProc[80]; char *myExportData[80]; ..... strcpy(myAsyncProc, msgStr); Tcl_AsyncMark(my_asyncEvalHandler); ..... /* Called by Tcl_Async infrastructure when safe to evaluate a script. */ int my_asyncEval(ClientData clientData, Tcl_Interp *interp, int code) { Tcl_InterpState state; Tcl_Interp *currentInterp; currentInterp = interp ? interp : myInterp; // many times get null passed in state = Tcl_SaveInterpState(currentInterp, code); Tcl_Eval(currentInterp, myAsyncProc); Tcl_RestoreInterpState(currentInterp, state); printf("the code is %d\n", code); return code; } int Tclservices_Init (Tcl_Interp *interp) { if (Tcl_InitStubs(interp, "8.5", 0) == NULL) { return TCL_ERROR; } if (Tk_InitStubs(interp, "8.5", 0) == NULL) { return TCL_ERROR; } myInterp = Tcl_CreateInterp(); my_asyncEvalHandler = Tcl_AsyncCreate(my_asyncEval, NULL); if (Tcl_PkgProvide(interp, "tclservices", "1.0") != TCL_OK) { return TCL_ERROR; } return TCL_OK; } The command that's supposed to run in Wish is as follows: pack [text .t] proc tcl-perform-service {} { set txt [clipboard get] puts "the txt is $txt" ..t insert end $txt } But it never runs. No crash, just no operation. Is there some special hook that I need to use to get the interpreter associated with Wish? Is that not the same as the "interp" in the code above? TIA, Kevin -- Kevin Walzer Code by Kevin http://www.codebykevin.com
From: Alexandre Ferrieux on 10 Jan 2010 11:52 On Jan 10, 4:53 am, Kevin Walzer <k...(a)codebykevin.com> wrote: > > I'm trying to create an async process to run in Wish via a binary > extension. Using various "printf" statements, I can tell that things > are going smoothly, right up to the moment when I call Tcl_Eval: then > things simply return without running. > But it never runs. No crash, just no operation. > Is there some special hook that I need to use to get the interpreter > associated with Wish? Is that not the same as the "interp" in the code > above? No. When your ext is loaded, the tclsh/wish process already has a running interp. So basically I suspect your building a secondary interp collides with various assumptions in the core (see the mention of thread-binding in Async.3). But why in the first place are you creating that secondary interp ? If you only want to avoid touching the state of the main interp, there's Tcl_SaveInterpState... -Alex
From: Harald Oehlmann on 11 Jan 2010 11:01 On 10 Jan., 04:53, Kevin Walzer <k...(a)codebykevin.com> wrote: > I'm trying to create an async process to run in Wish via a binary > extension. Using various "printf" statements, I can tell that things > are going smoothly, right up to the moment when I call Tcl_Eval: then > things simply return without running. Hi Kevin, sorry, I did not get what you want to do ;-( Eventually, you have a command which arises asyncroneously in a tcl extension (like in a device driver) and you want to execute it in the current interpreter. To do this, you may use a custom event. Post a custum event to the event queue. Then you get a callback, when your event should be processed. Now, you may savely call Eval in the scope of the current interpreter. I have documented an example some time ago in the lower part of: http://wiki.tcl.tk/17195 Hope this helps, Harald
|
Pages: 1 Prev: Looking for a textmode ui ... Next: buy ephedrine online |