Debian Codegraph @

doc/SetChanErr.3

raw
1 '\"
2 '\" Copyright (c) 2005 Andreas Kupries <[email protected]>
3 '\"
4 '\" See the file "license.terms" for information on usage and redistribution
5 '\" of this file, and for a DISCLAIMER OF ALL WARRANTIES.
6 '\"
7 .TH Tcl_SetChannelError 3 8.5 Tcl "Tcl Library Procedures"
8 .so man.macros
9 .BS
10 '\" Note: do not modify the .SH NAME line immediately below!
11 .SH NAME
12 Tcl_SetChannelError, Tcl_SetChannelErrorInterp, Tcl_GetChannelError, Tcl_GetChannelErrorInterp \- functions to create/intercept Tcl errors by channel drivers.
13 .SH SYNOPSIS
14 .nf
15 \fB#include <tcl.h>\fR
16 .sp
17 void
18 \fBTcl_SetChannelError\fR(\fIchan, msg\fR)
19 .sp
20 void
21 \fBTcl_SetChannelErrorInterp\fR(\fIinterp, msg\fR)
22 .sp
23 void
24 \fBTcl_GetChannelError\fR(\fIchan, msgPtr\fR)
25 .sp
26 void
27 \fBTcl_GetChannelErrorInterp\fR(\fIinterp, msgPtr\fR)
28 .sp
29 .SH ARGUMENTS
30 .AS Tcl_Channel chan
31 .AP Tcl_Channel chan in
32 Refers to the Tcl channel whose bypass area is accessed.
33 .AP Tcl_Interp* interp in
34 Refers to the Tcl interpreter whose bypass area is accessed.
35 .AP Tcl_Obj* msg in
36 Error message put into a bypass area. A list of return options and values,
37 followed by a string message. Both message and the option/value information
38 are optional.
39 .AP Tcl_Obj** msgPtr out
40 Reference to a place where the message stored in the accessed bypass area can
41 be stored in.
42 .BE
43 .SH DESCRIPTION
44 .PP
45 The current definition of a Tcl channel driver does not permit the direct
46 return of arbitrary error messages, except for the setting and retrieval of
47 channel options. All other functions are restricted to POSIX error codes.
48 .PP
49 The functions described here overcome this limitation. Channel drivers are
50 allowed to use \fBTcl_SetChannelError\fR and \fBTcl_SetChannelErrorInterp\fR
51 to place arbitrary error messages in \fBbypass areas\fR defined for channels
52 and interpreters. And the generic I/O layer uses \fBTcl_GetChannelError\fR and
53 \fBTcl_GetChannelErrorInterp\fR to look for messages in the bypass areas and
54 arrange for their return as errors. The POSIX error codes set by a driver are
55 used now if and only if no messages are present.
56 .PP
57 \fBTcl_SetChannelError\fR stores error information in the bypass area of the
58 specified channel. The number of references to the \fBmsg\fR value goes up by
59 one. Previously stored information will be discarded, by releasing the
60 reference held by the channel. The channel reference must not be NULL.
61 .PP
62 \fBTcl_SetChannelErrorInterp\fR stores error information in the bypass area of
63 the specified interpreter. The number of references to the \fBmsg\fR value
64 goes up by one. Previously stored information will be discarded, by releasing
65 the reference held by the interpreter. The interpreter reference must not be
66 NULL.
67 .PP
68 \fBTcl_GetChannelError\fR places either the error message held in the bypass
69 area of the specified channel into \fImsgPtr\fR, or NULL; and resets the
70 bypass, that is, after an invocation all following invocations will return
71 NULL, until an intervening invocation of \fBTcl_SetChannelError\fR with a
72 non-NULL message. The \fImsgPtr\fR must not be NULL. The reference count of
73 the message is not touched. The reference previously held by the channel is
74 now held by the caller of the function and it is its responsibility to release
75 that reference when it is done with the value.
76 .PP
77 \fBTcl_GetChannelErrorInterp\fR places either the error message held in the
78 bypass area of the specified interpreter into \fImsgPtr\fR, or NULL; and
79 resets the bypass, that is, after an invocation all following invocations will
80 return NULL, until an intervening invocation of
81 \fBTcl_SetChannelErrorInterp\fR with a non-NULL message. The \fImsgPtr\fR must
82 not be NULL. The reference count of the message is not touched. The reference
83 previously held by the interpreter is now held by the caller of the function
84 and it is its responsibility to release that reference when it is done with
85 the value.
86 .PP
87 Which functions of a channel driver are allowed to use which bypass function
88 is listed below, as is which functions of the public channel API may leave a
89 messages in the bypass areas.
90 .IP \fBTcl_DriverCloseProc\fR
91 May use \fBTcl_SetChannelErrorInterp\fR, and only this function.
92 .IP \fBTcl_DriverInputProc\fR
93 May use \fBTcl_SetChannelError\fR, and only this function.
94 .IP \fBTcl_DriverOutputProc\fR
95 May use \fBTcl_SetChannelError\fR, and only this function.
96 .IP \fBTcl_DriverSeekProc\fR
97 May use \fBTcl_SetChannelError\fR, and only this function.
98 .IP \fBTcl_DriverWideSeekProc\fR
99 May use \fBTcl_SetChannelError\fR, and only this function.
100 .IP \fBTcl_DriverSetOptionProc\fR
101 Has already the ability to pass arbitrary error messages. Must \fInot\fR use
102 any of the new functions.
103 .IP \fBTcl_DriverGetOptionProc\fR
104 Has already the ability to pass arbitrary error messages. Must
105 \fInot\fR use any of the new functions.
106 .IP \fBTcl_DriverWatchProc\fR
107 Must \fInot\fR use any of the new functions. Is internally called and has no
108 ability to return any type of error whatsoever.
109 .IP \fBTcl_DriverBlockModeProc\fR
110 May use \fBTcl_SetChannelError\fR, and only this function.
111 .IP \fBTcl_DriverGetHandleProc\fR
112 Must \fInot\fR use any of the new functions. It is only a low-level function,
113 and not used by Tcl commands.
114 .IP \fBTcl_DriverHandlerProc\fR
115 Must \fInot\fR use any of the new functions. Is internally called and has no
116 ability to return any type of error whatsoever.
117 .PP
118 Given the information above the following public functions of the Tcl C API
119 are affected by these changes; when these functions are called, the channel
120 may now contain a stored arbitrary error message requiring processing by the
121 caller.
122 .DS
123 .ta 1.9i 4i
124 \fBTcl_Flush\fR \fBTcl_GetsObj\fR \fBTcl_Gets\fR
125 \fBTcl_ReadChars\fR \fBTcl_ReadRaw\fR \fBTcl_Read\fR
126 \fBTcl_Seek\fR \fBTcl_StackChannel\fR \fBTcl_Tell\fR
127 \fBTcl_WriteChars\fR \fBTcl_WriteObj\fR \fBTcl_WriteRaw\fR
128 \fBTcl_Write\fR
129 .DE
130 .PP
131 All other API functions are unchanged. In particular, the functions below
132 leave all their error information in the interpreter result.
133 .DS
134 .ta 1.9i 4i
135 \fBTcl_Close\fR \fBTcl_UnstackChannel\fR \fBTcl_UnregisterChannel\fR
136 .DE
137 .SH "SEE ALSO"
138 Tcl_Close(3), Tcl_OpenFileChannel(3), Tcl_SetErrno(3)
139 .SH KEYWORDS
140 channel driver, error messages, channel type