| 1 |
/* ---------------------------------------------------------------------- */ |
| 2 |
|
| 3 |
#define ns__aproc0 "::aproc" |
| 4 |
static void c__aproc0(Tcl_Channel x) |
| 5 |
{ |
| 6 |
|
| 7 |
} |
| 8 |
|
| 9 |
static int |
| 10 |
tcl__aproc0(ClientData cd, Tcl_Interp *interp, Tcl_Size oc, Tcl_Obj *CONST ov[]) |
| 11 |
{ |
| 12 |
Tcl_Channel _x; |
| 13 |
|
| 14 |
if (oc != 2) { |
| 15 |
Tcl_WrongNumArgs(interp, 1, ov, "x"); |
| 16 |
return TCL_ERROR; |
| 17 |
} |
| 18 |
|
| 19 |
/* (take-channel x) - - -- --- ----- -------- */ |
| 20 |
{ |
| 21 |
int mode; |
| 22 |
_x = Tcl_GetChannel(interp, Tcl_GetString (ov[1]), &mode); |
| 23 |
if (_x == NULL) return TCL_ERROR; |
| 24 |
if (Tcl_IsChannelShared (_x)) { |
| 25 |
Tcl_SetObjResult(interp, Tcl_NewStringObj("channel is shared", -1)); |
| 26 |
return TCL_ERROR; |
| 27 |
} |
| 28 |
{ |
| 29 |
/* Disable event processing for the channel, both by |
| 30 |
* removing any registered handler, and forcing interest |
| 31 |
* to none. This also disables the processing of pending |
| 32 |
* events which are ready to fire for the given |
| 33 |
* channel. If we do not do this, events will hit the |
| 34 |
* detached channel and potentially wreck havoc on our |
| 35 |
* memory and eventually badly hurt us... |
| 36 |
*/ |
| 37 |
Tcl_DriverWatchProc *watchProc; |
| 38 |
Tcl_ClearChannelHandlers(_x); |
| 39 |
watchProc = Tcl_ChannelWatchProc(Tcl_GetChannelType(_x)); |
| 40 |
if (watchProc) { |
| 41 |
(*watchProc)(Tcl_GetChannelInstanceData(_x), 0); |
| 42 |
} |
| 43 |
/* Next some fiddling with the reference count to prevent |
| 44 |
* the unregistration from killing it. We basically record |
| 45 |
* it as globally known before removing it from the |
| 46 |
* current interpreter |
| 47 |
*/ |
| 48 |
Tcl_RegisterChannel((Tcl_Interp *) NULL, _x); |
| 49 |
Tcl_UnregisterChannel(interp, _x); |
| 50 |
} } |
| 51 |
|
| 52 |
/* Call - - -- --- ----- -------- */ |
| 53 |
c__aproc0(_x); |
| 54 |
|
| 55 |
/* (void return) - - -- --- ----- -------- */ |
| 56 |
return TCL_OK; |
| 57 |
} |