| 1 |
#ifndef Py_INTERNAL_PYERRORS_H |
| 2 |
#define Py_INTERNAL_PYERRORS_H |
| 3 |
#ifdef __cplusplus |
| 4 |
extern "C" { |
| 5 |
#endif |
| 6 |
|
| 7 |
#ifndef Py_BUILD_CORE |
| 8 |
# error "this header requires Py_BUILD_CORE define" |
| 9 |
#endif |
| 10 |
|
| 11 |
|
| 12 |
/* Error handling definitions */ |
| 13 |
|
| 14 |
extern _PyErr_StackItem* _PyErr_GetTopmostException(PyThreadState *tstate); |
| 15 |
extern PyObject* _PyErr_GetHandledException(PyThreadState *); |
| 16 |
extern void _PyErr_SetHandledException(PyThreadState *, PyObject *); |
| 17 |
extern void _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, PyObject **); |
| 18 |
|
| 19 |
// Export for '_testinternalcapi' shared extension |
| 20 |
PyAPI_FUNC(void) _PyErr_SetKeyError(PyObject *); |
| 21 |
|
| 22 |
|
| 23 |
// Like PyErr_Format(), but saves current exception as __context__ and |
| 24 |
// __cause__. |
| 25 |
// Export for '_sqlite3' shared extension. |
| 26 |
PyAPI_FUNC(PyObject*) _PyErr_FormatFromCause( |
| 27 |
PyObject *exception, |
| 28 |
const char *format, /* ASCII-encoded string */ |
| 29 |
... |
| 30 |
); |
| 31 |
|
| 32 |
extern int _PyException_AddNote( |
| 33 |
PyObject *exc, |
| 34 |
PyObject *note); |
| 35 |
|
| 36 |
extern int _PyErr_CheckSignals(void); |
| 37 |
|
| 38 |
/* Support for adding program text to SyntaxErrors */ |
| 39 |
|
| 40 |
// Export for test_peg_generator |
| 41 |
PyAPI_FUNC(PyObject*) _PyErr_ProgramDecodedTextObject( |
| 42 |
PyObject *filename, |
| 43 |
int lineno, |
| 44 |
const char* encoding); |
| 45 |
|
| 46 |
extern PyObject* _PyUnicodeTranslateError_Create( |
| 47 |
PyObject *object, |
| 48 |
Py_ssize_t start, |
| 49 |
Py_ssize_t end, |
| 50 |
const char *reason /* UTF-8 encoded string */ |
| 51 |
); |
| 52 |
|
| 53 |
extern void _Py_NO_RETURN _Py_FatalErrorFormat( |
| 54 |
const char *func, |
| 55 |
const char *format, |
| 56 |
...); |
| 57 |
|
| 58 |
extern PyObject* _PyErr_SetImportErrorWithNameFrom( |
| 59 |
PyObject *, |
| 60 |
PyObject *, |
| 61 |
PyObject *, |
| 62 |
PyObject *); |
| 63 |
extern int _PyErr_SetModuleNotFoundError(PyObject *name); |
| 64 |
|
| 65 |
|
| 66 |
/* runtime lifecycle */ |
| 67 |
|
| 68 |
extern PyStatus _PyErr_InitTypes(PyInterpreterState *); |
| 69 |
extern void _PyErr_FiniTypes(PyInterpreterState *); |
| 70 |
|
| 71 |
|
| 72 |
/* other API */ |
| 73 |
|
| 74 |
static inline PyObject* _PyErr_Occurred(PyThreadState *tstate) |
| 75 |
{ |
| 76 |
assert(tstate != NULL); |
| 77 |
if (tstate->current_exception == NULL) { |
| 78 |
return NULL; |
| 79 |
} |
| 80 |
return (PyObject *)Py_TYPE(tstate->current_exception); |
| 81 |
} |
| 82 |
|
| 83 |
static inline void _PyErr_ClearExcState(_PyErr_StackItem *exc_state) |
| 84 |
{ |
| 85 |
Py_CLEAR(exc_state->exc_value); |
| 86 |
} |
| 87 |
|
| 88 |
extern PyObject* _PyErr_StackItemToExcInfoTuple( |
| 89 |
_PyErr_StackItem *err_info); |
| 90 |
|
| 91 |
extern void _PyErr_Fetch( |
| 92 |
PyThreadState *tstate, |
| 93 |
PyObject **type, |
| 94 |
PyObject **value, |
| 95 |
PyObject **traceback); |
| 96 |
|
| 97 |
PyAPI_FUNC(PyObject*) _PyErr_GetRaisedException(PyThreadState *tstate); |
| 98 |
|
| 99 |
PyAPI_FUNC(int) _PyErr_ExceptionMatches( |
| 100 |
PyThreadState *tstate, |
| 101 |
PyObject *exc); |
| 102 |
|
| 103 |
PyAPI_FUNC(void) _PyErr_SetRaisedException(PyThreadState *tstate, PyObject *exc); |
| 104 |
|
| 105 |
extern void _PyErr_Restore( |
| 106 |
PyThreadState *tstate, |
| 107 |
PyObject *type, |
| 108 |
PyObject *value, |
| 109 |
PyObject *traceback); |
| 110 |
|
| 111 |
extern void _PyErr_SetObject( |
| 112 |
PyThreadState *tstate, |
| 113 |
PyObject *type, |
| 114 |
PyObject *value); |
| 115 |
|
| 116 |
extern void _PyErr_ChainStackItem(void); |
| 117 |
extern void _PyErr_ChainExceptions1Tstate(PyThreadState *, PyObject *); |
| 118 |
|
| 119 |
PyAPI_FUNC(void) _PyErr_Clear(PyThreadState *tstate); |
| 120 |
|
| 121 |
extern void _PyErr_SetNone(PyThreadState *tstate, PyObject *exception); |
| 122 |
|
| 123 |
extern PyObject* _PyErr_NoMemory(PyThreadState *tstate); |
| 124 |
|
| 125 |
extern int _PyErr_EmitSyntaxWarning(PyObject *msg, PyObject *filename, int lineno, int col_offset, |
| 126 |
int end_lineno, int end_col_offset); |
| 127 |
extern void _PyErr_RaiseSyntaxError(PyObject *msg, PyObject *filename, int lineno, int col_offset, |
| 128 |
int end_lineno, int end_col_offset); |
| 129 |
|
| 130 |
PyAPI_FUNC(void) _PyErr_SetString( |
| 131 |
PyThreadState *tstate, |
| 132 |
PyObject *exception, |
| 133 |
const char *string); |
| 134 |
|
| 135 |
/* |
| 136 |
* Set an exception with the error message decoded from the current locale |
| 137 |
* encoding (LC_CTYPE). |
| 138 |
* |
| 139 |
* Exceptions occurring in decoding take priority over the desired exception. |
| 140 |
* |
| 141 |
* Exported for '_ctypes' shared extensions. |
| 142 |
*/ |
| 143 |
PyAPI_FUNC(void) _PyErr_SetLocaleString( |
| 144 |
PyObject *exception, |
| 145 |
const char *string); |
| 146 |
|
| 147 |
PyAPI_FUNC(PyObject*) _PyErr_Format( |
| 148 |
PyThreadState *tstate, |
| 149 |
PyObject *exception, |
| 150 |
const char *format, |
| 151 |
...); |
| 152 |
|
| 153 |
PyAPI_FUNC(PyObject*) _PyErr_FormatV( |
| 154 |
PyThreadState *tstate, |
| 155 |
PyObject *exception, |
| 156 |
const char *format, |
| 157 |
va_list vargs); |
| 158 |
|
| 159 |
extern void _PyErr_NormalizeException( |
| 160 |
PyThreadState *tstate, |
| 161 |
PyObject **exc, |
| 162 |
PyObject **val, |
| 163 |
PyObject **tb); |
| 164 |
|
| 165 |
extern PyObject* _PyErr_FormatFromCauseTstate( |
| 166 |
PyThreadState *tstate, |
| 167 |
PyObject *exception, |
| 168 |
const char *format, |
| 169 |
...); |
| 170 |
|
| 171 |
extern PyObject* _PyExc_CreateExceptionGroup( |
| 172 |
const char *msg, |
| 173 |
PyObject *excs); |
| 174 |
|
| 175 |
extern PyObject* _PyExc_PrepReraiseStar( |
| 176 |
PyObject *orig, |
| 177 |
PyObject *excs); |
| 178 |
|
| 179 |
extern int _PyErr_CheckSignalsTstate(PyThreadState *tstate); |
| 180 |
|
| 181 |
extern void _Py_DumpExtensionModules(int fd, PyInterpreterState *interp); |
| 182 |
extern PyObject* _Py_CalculateSuggestions(PyObject *dir, PyObject *name); |
| 183 |
extern PyObject* _Py_Offer_Suggestions(PyObject* exception); |
| 184 |
|
| 185 |
// Export for '_testinternalcapi' shared extension |
| 186 |
PyAPI_FUNC(Py_ssize_t) _Py_UTF8_Edit_Cost(PyObject *str_a, PyObject *str_b, |
| 187 |
Py_ssize_t max_cost); |
| 188 |
|
| 189 |
// Export for '_json' shared extension |
| 190 |
PyAPI_FUNC(void) _PyErr_FormatNote(const char *format, ...); |
| 191 |
|
| 192 |
/* Context manipulation (PEP 3134) */ |
| 193 |
|
| 194 |
Py_DEPRECATED(3.12) extern void _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *); |
| 195 |
|
| 196 |
// implementation detail for the codeop module. |
| 197 |
// Exported for test.test_peg_generator.test_c_parser |
| 198 |
PyAPI_DATA(PyTypeObject) _PyExc_IncompleteInputError; |
| 199 |
#define PyExc_IncompleteInputError ((PyObject *)(&_PyExc_IncompleteInputError)) |
| 200 |
|
| 201 |
extern int _PyUnicodeError_GetParams( |
| 202 |
PyObject *self, |
| 203 |
PyObject **obj, |
| 204 |
Py_ssize_t *objlen, |
| 205 |
Py_ssize_t *start, |
| 206 |
Py_ssize_t *end, |
| 207 |
Py_ssize_t *slen, |
| 208 |
int as_bytes); |
| 209 |
|
| 210 |
#ifdef __cplusplus |
| 211 |
} |
| 212 |
#endif |
| 213 |
#endif /* !Py_INTERNAL_PYERRORS_H */ |