@@ -29,43 +29,9 @@ PERFORMANCE OF THIS SOFTWARE.
2929
3030******************************************************************/
3131
32- /* Error handling -- see also run.c */
33-
34- /* New error handling interface.
35-
36- The following problem exists (existed): methods of built-in modules
37- are called with 'self' and 'args' arguments, but without a context
38- argument, so they have no way to raise a specific exception.
39- The same is true for the object implementations: no context argument.
40- The old convention was to set 'errno' and to return NULL.
41- The caller (usually call_function() in eval.c) detects the NULL
42- return value and then calls puterrno(ctx) to turn the errno value
43- into a true exception. Problems with this approach are:
44- - it used standard errno values to indicate Python-specific errors,
45- but this means that when such an error code is reported by a system
46- call (e.g., in module posix), the user gets a confusing message
47- - errno is a global variable, which makes extensions to a multi-
48- threading environment difficult; e.g., in IRIX, multi-threaded
49- programs must use the function oserror() instead of looking in errno
50- - there is no portable way to add new error numbers for specic
51- situations -- the value space for errno is reserved to the OS, yet
52- the way to turn module-specific errors into a module-specific
53- exception requires module-specific values for errno
54- - there is no way to add a more situation-specific message to an
55- error.
56-
57- The new interface solves all these problems. To return an error, a
58- built-in function calls err_set(exception), err_setval(exception,
59- value) or err_setstr(exception, string), and returns NULL. These
60- functions save the value for later use by puterrno(). To adapt this
61- scheme to a multi-threaded environment, only the implementation of
62- err_setval() has to be changed.
63- */
64-
65- #include "allobjects.h"
66- #include "traceback.h"
32+ /* Error handling */
6733
68- #include <errno.h>
34+ #include "Python.h"
6935
7036#ifdef SYMANTEC__CFM68K__
7137#pragma lib_export on
@@ -77,135 +43,135 @@ PERFORMANCE OF THIS SOFTWARE.
7743 XXX PROBLEM: some positive errors have a meaning for MacOS,
7844 but some library routines set Unix error numbers...
7945*/
80- extern char * PyMac_StrError PROTO ((int ));
46+ extern char * PyMac_StrError Py_PROTO ((int ));
8147#undef strerror
8248#define strerror PyMac_StrError
8349#endif
8450#endif /* macintosh */
8551
8652#ifndef __STDC__
8753#ifndef MS_WINDOWS
88- extern char * strerror PROTO ((int ));
54+ extern char * strerror Py_PROTO ((int ));
8955#endif
9056#endif
9157
92- /* Last exception stored by err_setval() */
58+ /* Last exception stored */
9359
94- static object * last_exception ;
95- static object * last_exc_val ;
60+ static PyObject * last_exception ;
61+ static PyObject * last_exc_val ;
9662
9763void
98- err_restore (exception , value , traceback )
99- object * exception ;
100- object * value ;
101- object * traceback ;
64+ PyErr_Restore (exception , value , traceback )
65+ PyObject * exception ;
66+ PyObject * value ;
67+ PyObject * traceback ;
10268{
103- err_clear ();
69+ PyErr_Clear ();
10470
10571 last_exception = exception ;
10672 last_exc_val = value ;
107- (void ) tb_store (traceback );
108- XDECREF (traceback );
73+ (void ) PyTraceBack_Store (traceback );
74+ Py_XDECREF (traceback );
10975}
11076
11177void
112- err_setval (exception , value )
113- object * exception ;
114- object * value ;
78+ PyErr_SetObject (exception , value )
79+ PyObject * exception ;
80+ PyObject * value ;
11581{
116- XINCREF (exception );
117- XINCREF (value );
118- err_restore (exception , value , (object * )NULL );
82+ Py_XINCREF (exception );
83+ Py_XINCREF (value );
84+ PyErr_Restore (exception , value , (PyObject * )NULL );
11985}
12086
12187void
122- err_set (exception )
123- object * exception ;
88+ PyErr_SetNone (exception )
89+ PyObject * exception ;
12490{
125- err_setval (exception , (object * )NULL );
91+ PyErr_SetObject (exception , (PyObject * )NULL );
12692}
12793
12894void
129- err_setstr (exception , string )
130- object * exception ;
95+ PyErr_SetString (exception , string )
96+ PyObject * exception ;
13197 const char * string ;
13298{
133- object * value = newstringobject (string );
134- err_setval (exception , value );
135- XDECREF (value );
99+ PyObject * value = PyString_FromString (string );
100+ PyErr_SetObject (exception , value );
101+ Py_XDECREF (value );
136102}
137103
138104
139- object *
140- err_occurred ()
105+ PyObject *
106+ PyErr_Occurred ()
141107{
142108 return last_exception ;
143109}
144110
145111void
146- err_fetch (p_exc , p_val , p_tb )
147- object * * p_exc ;
148- object * * p_val ;
149- object * * p_tb ;
112+ PyErr_Fetch (p_exc , p_val , p_tb )
113+ PyObject * * p_exc ;
114+ PyObject * * p_val ;
115+ PyObject * * p_tb ;
150116{
151117 * p_exc = last_exception ;
152118 last_exception = NULL ;
153119 * p_val = last_exc_val ;
154120 last_exc_val = NULL ;
155- * p_tb = tb_fetch ();
121+ * p_tb = PyTraceBack_Fetch ();
156122}
157123
158124void
159- err_clear ()
125+ PyErr_Clear ()
160126{
161- object * tb ;
162- XDECREF (last_exception );
127+ PyObject * tb ;
128+ Py_XDECREF (last_exception );
163129 last_exception = NULL ;
164- XDECREF (last_exc_val );
130+ Py_XDECREF (last_exc_val );
165131 last_exc_val = NULL ;
166132 /* Also clear interpreter stack trace */
167- tb = tb_fetch ();
168- XDECREF (tb );
133+ tb = PyTraceBack_Fetch ();
134+ Py_XDECREF (tb );
169135}
170136
171137/* Convenience functions to set a type error exception and return 0 */
172138
173139int
174- err_badarg ()
140+ PyErr_BadArgument ()
175141{
176- err_setstr ( TypeError , "illegal argument type for built-in operation" );
142+ PyErr_SetString ( PyExc_TypeError , "illegal argument type for built-in operation" );
177143 return 0 ;
178144}
179145
180- object *
181- err_nomem ()
146+ PyObject *
147+ PyErr_NoMemory ()
182148{
183- err_set ( MemoryError );
149+ PyErr_SetNone ( PyExc_MemoryError );
184150 return NULL ;
185151}
186152
187- object *
188- err_errno (exc )
189- object * exc ;
153+ PyObject *
154+ PyErr_SetFromErrno (exc )
155+ PyObject * exc ;
190156{
191- object * v ;
157+ PyObject * v ;
192158 int i = errno ;
193159#ifdef EINTR
194- if (i == EINTR && sigcheck ())
160+ if (i == EINTR && PyErr_CheckSignals ())
195161 return NULL ;
196162#endif
197- v = mkvalue ("(is)" , i , strerror (i ));
163+ v = Py_BuildValue ("(is)" , i , strerror (i ));
198164 if (v != NULL ) {
199- err_setval (exc , v );
200- DECREF (v );
165+ PyErr_SetObject (exc , v );
166+ Py_DECREF (v );
201167 }
202168 return NULL ;
203169}
204170
205171void
206- err_badcall ()
172+ PyErr_BadInternalCall ()
207173{
208- err_setstr ( SystemError , "bad argument to internal function" );
174+ PyErr_SetString ( PyExc_SystemError , "bad argument to internal function" );
209175}
210176
211177
0 commit comments