From a079a543a386bd6946e48a628d2f768b3057dcc0 Mon Sep 17 00:00:00 2001 From: ian Date: Sat, 18 Dec 2004 14:33:59 +0000 Subject: [PATCH] scriptinv supports xargs and adns uses them --- adns/adns.c | 6 +++--- base/chiark-tcl.h | 4 +++- base/scriptinv.c | 21 ++++++++++++++++----- dgram/dgram.c | 2 +- hbytes/hbytes.h | 4 +++- tuntap/tuntap.c | 2 +- 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/adns/adns.c b/adns/adns.c index 5f26d32..585ce39 100644 --- a/adns/adns.c +++ b/adns/adns.c @@ -604,9 +604,9 @@ int do_adns_asynch(ClientData cd, Tcl_Interp *ip, res= op.resolver; - rc= scriptinv_set_xa(&query->on_yes, ip,on_yes); if (rc) goto x_rc; - rc= scriptinv_set_xa(&query->on_no, ip,on_no); if (rc) goto x_rc; - rc= scriptinv_set_xa(&query->on_fail,ip,on_fail); if (rc) goto x_rc; + rc= scriptinv_set(&query->on_yes, ip,on_yes, xargs); if (rc) goto x_rc; + rc= scriptinv_set(&query->on_no, ip,on_no, xargs); if (rc) goto x_rc; + rc= scriptinv_set(&query->on_fail,ip,on_fail,xargs); if (rc) goto x_rc; query->xargs= xargs; Tcl_IncrRefCount(xargs); *result= query; diff --git a/base/chiark-tcl.h b/base/chiark-tcl.h index b49301f..875b239 100644 --- a/base/chiark-tcl.h +++ b/base/chiark-tcl.h @@ -202,11 +202,13 @@ void sockaddr_free(const SockAddr_Value*); typedef struct { /* semi-opaque - read only, and then only where commented */ Tcl_Interp *ip; /* valid, non-0 and useable if set */ Tcl_Obj *obj; /* non-0 iff set (but only test for 0/non-0) */ + Tcl_Obj *xargs; int llength; } ScriptToInvoke; void scriptinv_init(ScriptToInvoke *si); -int scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip, Tcl_Obj *newscript); +int scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip, + Tcl_Obj *newscript, Tcl_Obj *xargs); void scriptinv_cancel(ScriptToInvoke *si); /* then don't invoke */ /* no separate free function - just cancel */ diff --git a/base/scriptinv.c b/base/scriptinv.c index b27654e..1ac7e82 100644 --- a/base/scriptinv.c +++ b/base/scriptinv.c @@ -14,16 +14,22 @@ void scriptinv_cancel(ScriptToInvoke *si) { } } -int scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip, Tcl_Obj *newscript) { +int scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip, + Tcl_Obj *newscript, Tcl_Obj *xargs) { int rc; scriptinv_cancel(si); - rc= Tcl_ListObjLength(ip, newscript, &si->llength); - if (rc) return rc; - + rc= Tcl_ListObjLength(ip, newscript, &si->llength); if (rc) return rc; Tcl_IncrRefCount(newscript); + + if (xargs) { + rc= Tcl_ListObjLength(ip, xargs, &si->llength); if (rc) return rc; + Tcl_IncrRefCount(xargs); + } + si->obj= newscript; + si->xargs= xargs; si->ip= ip; return 0; } @@ -38,7 +44,12 @@ void scriptinv_invoke(ScriptToInvoke *si, int argc, Tcl_Obj **argv) { invoke= Tcl_DuplicateObj(si->obj); Tcl_IncrRefCount(invoke); - rc= Tcl_ListObjReplace(si->ip,invoke,si->llength,0,argc,argv); + if (si->xargs) { + rc= Tcl_ListObjAppendList(si->ip, invoke, si->xargs); + if (rc) goto x_rc; + } + + rc= Tcl_ListObjReplace(si->ip, invoke,si->llength,0, argc,argv); for (i=0; iscript, ip, newscript); + rc= scriptinv_set(&sock->script, ip, newscript, 0); if (rc) return rc; } diff --git a/hbytes/hbytes.h b/hbytes/hbytes.h index b49301f..875b239 100644 --- a/hbytes/hbytes.h +++ b/hbytes/hbytes.h @@ -202,11 +202,13 @@ void sockaddr_free(const SockAddr_Value*); typedef struct { /* semi-opaque - read only, and then only where commented */ Tcl_Interp *ip; /* valid, non-0 and useable if set */ Tcl_Obj *obj; /* non-0 iff set (but only test for 0/non-0) */ + Tcl_Obj *xargs; int llength; } ScriptToInvoke; void scriptinv_init(ScriptToInvoke *si); -int scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip, Tcl_Obj *newscript); +int scriptinv_set(ScriptToInvoke *si, Tcl_Interp *ip, + Tcl_Obj *newscript, Tcl_Obj *xargs); void scriptinv_cancel(ScriptToInvoke *si); /* then don't invoke */ /* no separate free function - just cancel */ diff --git a/tuntap/tuntap.c b/tuntap/tuntap.c index f45b3c9..9deec57 100644 --- a/tuntap/tuntap.c +++ b/tuntap/tuntap.c @@ -130,7 +130,7 @@ int do_tuntap_socket_raw_on_transmit(ClientData cd, Tcl_Interp *ip, cancel(sock); if (newscript) { - rc= scriptinv_set(&sock->script,ip,newscript); + rc= scriptinv_set(&sock->script,ip,newscript,0); if (rc) return rc; sock->mtu= mtu; -- 2.30.2