Mercurial > cpython-lru_cache-weakref
comparison Python/errors.c @ 5405:b7871ca930ad legacy-trunk
Massive changes for separate thread state management.
All per-thread globals are moved into a struct which is manipulated
separately.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Mon, 05 May 1997 20:56:21 +0000 |
| parents | 1ea1f019268d |
| children | 422960523286 |
comparison
equal
deleted
inserted
replaced
| 5404:3780cce14f7d | 5405:b7871ca930ad |
|---|---|
| 53 #ifndef MS_WINDOWS | 53 #ifndef MS_WINDOWS |
| 54 extern char *strerror Py_PROTO((int)); | 54 extern char *strerror Py_PROTO((int)); |
| 55 #endif | 55 #endif |
| 56 #endif | 56 #endif |
| 57 | 57 |
| 58 /* Last exception stored */ | 58 void |
| 59 | 59 PyErr_Restore(type, value, traceback) |
| 60 static PyObject *last_exception; | 60 PyObject *type; |
| 61 static PyObject *last_exc_val; | |
| 62 | |
| 63 void | |
| 64 PyErr_Restore(exception, value, traceback) | |
| 65 PyObject *exception; | |
| 66 PyObject *value; | 61 PyObject *value; |
| 67 PyObject *traceback; | 62 PyObject *traceback; |
| 68 { | 63 { |
| 69 PyErr_Clear(); | 64 PyThreadState *tstate = PyThreadState_Get(); |
| 70 | 65 PyObject *oldtype, *oldvalue, *oldtraceback; |
| 71 last_exception = exception; | 66 |
| 72 last_exc_val = value; | 67 if (traceback != NULL && !PyTraceBack_Check(traceback)) { |
| 73 (void) PyTraceBack_Store(traceback); | 68 /* XXX Should never happen -- fatal error instead? */ |
| 74 Py_XDECREF(traceback); | 69 Py_DECREF(traceback); |
| 70 traceback = NULL; | |
| 71 } | |
| 72 | |
| 73 /* Save these in locals to safeguard against recursive | |
| 74 invocation through Py_XDECREF */ | |
| 75 oldtype = tstate->curexc_type; | |
| 76 oldvalue = tstate->curexc_value; | |
| 77 oldtraceback = tstate->curexc_traceback; | |
| 78 | |
| 79 tstate->curexc_type = type; | |
| 80 tstate->curexc_value = value; | |
| 81 tstate->curexc_traceback = traceback; | |
| 82 | |
| 83 Py_XDECREF(oldtype); | |
| 84 Py_XDECREF(oldvalue); | |
| 85 Py_XDECREF(oldtraceback); | |
| 75 } | 86 } |
| 76 | 87 |
| 77 void | 88 void |
| 78 PyErr_SetObject(exception, value) | 89 PyErr_SetObject(exception, value) |
| 79 PyObject *exception; | 90 PyObject *exception; |
| 103 | 114 |
| 104 | 115 |
| 105 PyObject * | 116 PyObject * |
| 106 PyErr_Occurred() | 117 PyErr_Occurred() |
| 107 { | 118 { |
| 108 return last_exception; | 119 PyThreadState *tstate = PyThreadState_Get(); |
| 109 } | 120 |
| 110 | 121 return tstate->curexc_type; |
| 111 void | 122 } |
| 112 PyErr_Fetch(p_exc, p_val, p_tb) | 123 |
| 113 PyObject **p_exc; | 124 void |
| 114 PyObject **p_val; | 125 PyErr_Fetch(p_type, p_value, p_traceback) |
| 115 PyObject **p_tb; | 126 PyObject **p_type; |
| 116 { | 127 PyObject **p_value; |
| 117 *p_exc = last_exception; | 128 PyObject **p_traceback; |
| 118 last_exception = NULL; | 129 { |
| 119 *p_val = last_exc_val; | 130 PyThreadState *tstate = PyThreadState_Get(); |
| 120 last_exc_val = NULL; | 131 |
| 121 *p_tb = PyTraceBack_Fetch(); | 132 *p_type = tstate->curexc_type; |
| 133 *p_value = tstate->curexc_value; | |
| 134 *p_traceback = tstate->curexc_traceback; | |
| 135 | |
| 136 tstate->curexc_type = NULL; | |
| 137 tstate->curexc_value = NULL; | |
| 138 tstate->curexc_traceback = NULL; | |
| 122 } | 139 } |
| 123 | 140 |
| 124 void | 141 void |
| 125 PyErr_Clear() | 142 PyErr_Clear() |
| 126 { | 143 { |
| 127 PyObject *tb; | 144 PyErr_Restore(NULL, NULL, NULL); |
| 128 Py_XDECREF(last_exception); | |
| 129 last_exception = NULL; | |
| 130 Py_XDECREF(last_exc_val); | |
| 131 last_exc_val = NULL; | |
| 132 /* Also clear interpreter stack trace */ | |
| 133 tb = PyTraceBack_Fetch(); | |
| 134 Py_XDECREF(tb); | |
| 135 } | 145 } |
| 136 | 146 |
| 137 /* Convenience functions to set a type error exception and return 0 */ | 147 /* Convenience functions to set a type error exception and return 0 */ |
| 138 | 148 |
| 139 int | 149 int |
| 140 PyErr_BadArgument() | 150 PyErr_BadArgument() |
| 141 { | 151 { |
| 142 PyErr_SetString(PyExc_TypeError, "illegal argument type for built-in operation"); | 152 PyErr_SetString(PyExc_TypeError, |
| 153 "illegal argument type for built-in operation"); | |
| 143 return 0; | 154 return 0; |
| 144 } | 155 } |
| 145 | 156 |
| 146 PyObject * | 157 PyObject * |
| 147 PyErr_NoMemory() | 158 PyErr_NoMemory() |
| 169 } | 180 } |
| 170 | 181 |
| 171 void | 182 void |
| 172 PyErr_BadInternalCall() | 183 PyErr_BadInternalCall() |
| 173 { | 184 { |
| 174 PyErr_SetString(PyExc_SystemError, "bad argument to internal function"); | 185 PyErr_SetString(PyExc_SystemError, |
| 186 "bad argument to internal function"); | |
| 175 } | 187 } |
| 176 | 188 |
| 177 | 189 |
| 178 #ifdef HAVE_STDARG_PROTOTYPES | 190 #ifdef HAVE_STDARG_PROTOTYPES |
| 179 PyObject * | 191 PyObject * |
