From: SourceForge.net <no...@so...> - 2005-03-17 14:16:24
|
Feature Requests item #1162223, was opened at 2005-03-13 00:22 Message generated for change (Comment added) made by seryakov You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=719009&aid=1162223&group_id=130646 Category: None Group: None Status: Open Resolution: None Priority: 5 Submitted By: Stephen Deasey (sdeasey) Assigned to: Stephen Deasey (sdeasey) Summary: Tcl Callbacks Initial Comment: The server offers a dual C/Tcl interface. There are a number of of places where Tcl code needs to be executed by the C core, or the core doesn't know whether a callback is C or Tcl. I've attached the patch naviserver-4.1-tclcallbacks.patch. It extracts the Tcl callback infrastructure from tclsched.c into tclcallbacks.c and makes it a public interface. Here it is: Ns_TclNewCallback() Ns_TclNewCallbackObj() Ns_TclEvalCallback() Ns_TclCallbackProc() Ns_TclFreeCallback() Ns_TclCallbackArgProc() It provides a standard interface for Tcl callbacks throughout the server, handling interp allocation, introspection, evaluation and cleanup. Also, tclcallbacks.c is somewhat analogous to callbacks.c, and so the generic ns_atexit etc. callbacks which were in tclsched.c have been moved to the tclcallbacks file. The first set of code to be converted to the new interface is tclsched.c itself, and I've converted to using Ns_ParseObjv() while I was in there. File size has dropped ~250 lines. One thing I'm wondering about is whether the Ns_TclEvalCallback() routine should take extra args to send to the Tcl proc. There seems to be no standard scheme for ordering the args so there still needs to be a way to manually construct the command, which is why the members of the Ns_TclCallback struct are public. But for this very reason, it might be worth providing a standard way to do this so all future callbacks are consistent. It would be nice in the future to come up with some way of registereing these callback points such that you don't have to create an ns_info subcommand for example manually. It should be possible for loadable modules to register their callback points and have them show up in the right place. ---------------------------------------------------------------------- >Comment By: Vlad Seryakov (seryakov) Date: 2005-03-17 14:16 Message: Logged In: YES user_id=184124 Yes, let's start slowly, we know the direction we are going, let 's do it step by step starting with simple things. We can have generic Tcl callbacks already and all new callbacks will use it and we will see how flexible this mechanism is. ---------------------------------------------------------------------- Comment By: Stephen Deasey (sdeasey) Date: 2005-03-17 11:28 Message: Logged In: YES user_id=87254 Yes, I forgot to mention that Tcl callbacks are a little more general than those for C in callbacks.c. Those take a single arg which is the context you registered with the proc, and return void. Tcl callbacks on the other hand can return a result which at the C level gets appended to a dstring if you pass that in. The members of the Ns_TclCallback structure are public so that you can construct a command and args in any format. This is the question I was asking originally: should there be a default recomended way to do this? So for example Ns_TclEvalCallback() might take varargs cstrings, which if passed would be added to the tcl command to execute: command ?cbarg1? ?cbarg2? ?context? Where cbarg2 and cbarg2 are specific to the type of callback and context is what was registered with the proc by the Tcl programmer. Unfortunately that wouldn't cover all the bases as some of the existing APIs do weird things like place callback specific args after the context or if no context was passed, always append an empty string. For new callbacks, something standard like the above scheme should be used. If you look at the patch for virtual hosting you'll see that two new Tcl callbacks were created and they contain simillar boiler plate. This makes me think that maybe there should be something like an [ns_addcallback serverroot myrootproc mycontext] interface. It's a little more complicated than that because some callbacks are singular, like the serverroot proc, and some are plural, like filters. So maybe the thing to do is get some experience with this simple version and then expand it later... ---------------------------------------------------------------------- Comment By: Vlad Seryakov (seryakov) Date: 2005-03-13 00:46 Message: Logged In: YES user_id=184124 It looks good, unified callback interface would be better but Tcl filters. traces, requestprocs uses different arguments/parameters and currently the only way to get info about them to use ns_info interface and Ns_ArgProc interface. Tcl_Callback are for simple proc/args callbacks, filters is special case, see if you can convert them. But i am for this change. ---------------------------------------------------------------------- Comment By: Stephen Deasey (sdeasey) Date: 2005-03-13 00:30 Message: Logged In: YES user_id=87254 I've attached a patch which converts the tclrequest.c file to use the new callback API as an example. It also uses the Ns_ParseObjv() API, and I've removed support for the legacy conn variable. It removes ~200 lines and all utility functions. The callback API provides default Ns_ArgProc introspection, but this will be much nicer when combined with Vlad's RFE 1161597 :-) ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=719009&aid=1162223&group_id=130646 |