Debian Codegraph @

test/assets/cproc-trace/4.15-take-channel

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