#include "Python.h"
#include "pycore_audit.h"
#include "pycore_call.h"
#include "pycore_initconfig.h"
#include "pycore_pyerrors.h"
#include "pycore_pystate.h"
#include "pycore_structseq.h"
#include "pycore_sysmodule.h"
#include "pycore_traceback.h"
#ifdef MS_WINDOWS
# include <windows.h>
# include <winbase.h>
# include <stdlib.h>
#endif
static PyObject *
_PyErr_FormatV(PyThreadState *tstate, PyObject *exception,
const char *format, va_list vargs);
void
_PyErr_SetRaisedException(PyThreadState *tstate, PyObject *exc)
{ … }
static PyObject*
_PyErr_CreateException(PyObject *exception_type, PyObject *value)
{ … }
void
_PyErr_Restore(PyThreadState *tstate, PyObject *type, PyObject *value,
PyObject *traceback)
{ … }
void
PyErr_Restore(PyObject *type, PyObject *value, PyObject *traceback)
{ … }
void
PyErr_SetRaisedException(PyObject *exc)
{ … }
_PyErr_StackItem *
_PyErr_GetTopmostException(PyThreadState *tstate)
{ … }
static PyObject *
get_normalization_failure_note(PyThreadState *tstate, PyObject *exception, PyObject *value)
{ … }
void
_PyErr_SetObject(PyThreadState *tstate, PyObject *exception, PyObject *value)
{ … }
void
PyErr_SetObject(PyObject *exception, PyObject *value)
{ … }
void
_PyErr_SetKeyError(PyObject *arg)
{ … }
void
_PyErr_SetNone(PyThreadState *tstate, PyObject *exception)
{ … }
void
PyErr_SetNone(PyObject *exception)
{ … }
void
_PyErr_SetString(PyThreadState *tstate, PyObject *exception,
const char *string)
{ … }
void
PyErr_SetString(PyObject *exception, const char *string)
{ … }
PyObject* _Py_HOT_FUNCTION
PyErr_Occurred(void)
{ … }
int
PyErr_GivenExceptionMatches(PyObject *err, PyObject *exc)
{ … }
int
_PyErr_ExceptionMatches(PyThreadState *tstate, PyObject *exc)
{ … }
int
PyErr_ExceptionMatches(PyObject *exc)
{ … }
#ifndef Py_NORMALIZE_RECURSION_LIMIT
#define Py_NORMALIZE_RECURSION_LIMIT …
#endif
void
_PyErr_NormalizeException(PyThreadState *tstate, PyObject **exc,
PyObject **val, PyObject **tb)
{ … }
void
PyErr_NormalizeException(PyObject **exc, PyObject **val, PyObject **tb)
{ … }
PyObject *
_PyErr_GetRaisedException(PyThreadState *tstate) { … }
PyObject *
PyErr_GetRaisedException(void)
{ … }
void
_PyErr_Fetch(PyThreadState *tstate, PyObject **p_type, PyObject **p_value,
PyObject **p_traceback)
{ … }
void
PyErr_Fetch(PyObject **p_type, PyObject **p_value, PyObject **p_traceback)
{ … }
void
_PyErr_Clear(PyThreadState *tstate)
{ … }
void
PyErr_Clear(void)
{ … }
static PyObject*
get_exc_type(PyObject *exc_value)
{ … }
static PyObject*
get_exc_traceback(PyObject *exc_value)
{ … }
void
_PyErr_GetExcInfo(PyThreadState *tstate,
PyObject **p_type, PyObject **p_value, PyObject **p_traceback)
{ … }
PyObject*
_PyErr_GetHandledException(PyThreadState *tstate)
{ … }
PyObject*
PyErr_GetHandledException(void)
{ … }
void
_PyErr_SetHandledException(PyThreadState *tstate, PyObject *exc)
{ … }
void
PyErr_SetHandledException(PyObject *exc)
{ … }
void
PyErr_GetExcInfo(PyObject **p_type, PyObject **p_value, PyObject **p_traceback)
{ … }
void
PyErr_SetExcInfo(PyObject *type, PyObject *value, PyObject *traceback)
{ … }
PyObject*
_PyErr_StackItemToExcInfoTuple(_PyErr_StackItem *err_info)
{ … }
void
_PyErr_ChainExceptions(PyObject *typ, PyObject *val, PyObject *tb)
{ … }
void
_PyErr_ChainExceptions1(PyObject *exc)
{ … }
void
_PyErr_ChainStackItem(void)
{ … }
static PyObject *
_PyErr_FormatVFromCause(PyThreadState *tstate, PyObject *exception,
const char *format, va_list vargs)
{ … }
PyObject *
_PyErr_FormatFromCauseTstate(PyThreadState *tstate, PyObject *exception,
const char *format, ...)
{ … }
PyObject *
_PyErr_FormatFromCause(PyObject *exception, const char *format, ...)
{ … }
int
PyErr_BadArgument(void)
{ … }
PyObject *
PyErr_NoMemory(void)
{ … }
PyObject *
PyErr_SetFromErrnoWithFilenameObject(PyObject *exc, PyObject *filenameObject)
{ … }
PyObject *
PyErr_SetFromErrnoWithFilenameObjects(PyObject *exc, PyObject *filenameObject, PyObject *filenameObject2)
{ … }
PyObject *
PyErr_SetFromErrnoWithFilename(PyObject *exc, const char *filename)
{ … }
PyObject *
PyErr_SetFromErrno(PyObject *exc)
{ … }
#ifdef MS_WINDOWS
PyObject *PyErr_SetExcFromWindowsErrWithFilenameObject(
PyObject *exc,
int ierr,
PyObject *filenameObject)
{
return PyErr_SetExcFromWindowsErrWithFilenameObjects(exc, ierr,
filenameObject, NULL);
}
PyObject *PyErr_SetExcFromWindowsErrWithFilenameObjects(
PyObject *exc,
int ierr,
PyObject *filenameObject,
PyObject *filenameObject2)
{
PyThreadState *tstate = _PyThreadState_GET();
int len;
WCHAR *s_buf = NULL;
PyObject *message;
PyObject *args, *v;
DWORD err = (DWORD)ierr;
if (err==0) {
err = GetLastError();
}
len = FormatMessageW(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err,
MAKELANGID(LANG_NEUTRAL,
SUBLANG_DEFAULT),
(LPWSTR) &s_buf,
0,
NULL);
if (len==0) {
message = PyUnicode_FromFormat("Windows Error 0x%x", err);
s_buf = NULL;
} else {
while (len > 0 && (s_buf[len-1] <= L' ' || s_buf[len-1] == L'.'))
s_buf[--len] = L'\0';
message = PyUnicode_FromWideChar(s_buf, len);
}
if (message == NULL)
{
LocalFree(s_buf);
return NULL;
}
if (filenameObject == NULL) {
assert(filenameObject2 == NULL);
filenameObject = filenameObject2 = Py_None;
}
else if (filenameObject2 == NULL)
filenameObject2 = Py_None;
args = Py_BuildValue("(iOOiO)", 0, message, filenameObject, err, filenameObject2);
Py_DECREF(message);
if (args != NULL) {
v = PyObject_Call(exc, args, NULL);
Py_DECREF(args);
if (v != NULL) {
_PyErr_SetObject(tstate, (PyObject *) Py_TYPE(v), v);
Py_DECREF(v);
}
}
LocalFree(s_buf);
return NULL;
}
PyObject *PyErr_SetExcFromWindowsErrWithFilename(
PyObject *exc,
int ierr,
const char *filename)
{
PyObject *name = NULL;
if (filename) {
if ((DWORD)ierr == 0) {
ierr = (int)GetLastError();
}
name = PyUnicode_DecodeFSDefault(filename);
if (name == NULL) {
return NULL;
}
}
PyObject *ret = PyErr_SetExcFromWindowsErrWithFilenameObjects(exc,
ierr,
name,
NULL);
Py_XDECREF(name);
return ret;
}
PyObject *PyErr_SetExcFromWindowsErr(PyObject *exc, int ierr)
{
return PyErr_SetExcFromWindowsErrWithFilename(exc, ierr, NULL);
}
PyObject *PyErr_SetFromWindowsErr(int ierr)
{
return PyErr_SetExcFromWindowsErrWithFilename(PyExc_OSError,
ierr, NULL);
}
PyObject *PyErr_SetFromWindowsErrWithFilename(
int ierr,
const char *filename)
{
PyObject *name = NULL;
if (filename) {
if ((DWORD)ierr == 0) {
ierr = (int)GetLastError();
}
name = PyUnicode_DecodeFSDefault(filename);
if (name == NULL) {
return NULL;
}
}
PyObject *result = PyErr_SetExcFromWindowsErrWithFilenameObjects(
PyExc_OSError,
ierr, name, NULL);
Py_XDECREF(name);
return result;
}
#endif
static PyObject *
_PyErr_SetImportErrorSubclassWithNameFrom(
PyObject *exception, PyObject *msg,
PyObject *name, PyObject *path, PyObject* from_name)
{ … }
PyObject *
PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg,
PyObject *name, PyObject *path)
{ … }
PyObject *
_PyErr_SetImportErrorWithNameFrom(PyObject *msg, PyObject *name, PyObject *path, PyObject* from_name)
{ … }
PyObject *
PyErr_SetImportError(PyObject *msg, PyObject *name, PyObject *path)
{ … }
void
_PyErr_BadInternalCall(const char *filename, int lineno)
{ … }
#undef PyErr_BadInternalCall
void
PyErr_BadInternalCall(void)
{ … }
#define PyErr_BadInternalCall() …
static PyObject *
_PyErr_FormatV(PyThreadState *tstate, PyObject *exception,
const char *format, va_list vargs)
{ … }
PyObject *
PyErr_FormatV(PyObject *exception, const char *format, va_list vargs)
{ … }
PyObject *
_PyErr_Format(PyThreadState *tstate, PyObject *exception,
const char *format, ...)
{ … }
PyObject *
PyErr_Format(PyObject *exception, const char *format, ...)
{ … }
void
_PyErr_FormatNote(const char *format, ...)
{ … }
PyObject *
PyErr_NewException(const char *name, PyObject *base, PyObject *dict)
{ … }
PyObject *
PyErr_NewExceptionWithDoc(const char *name, const char *doc,
PyObject *base, PyObject *dict)
{ … }
PyDoc_STRVAR(UnraisableHookArgs__doc__,
"UnraisableHookArgs\n\
\n\
Type used to pass arguments to sys.unraisablehook.");
static PyTypeObject UnraisableHookArgsType;
static PyStructSequence_Field UnraisableHookArgs_fields[] = …;
static PyStructSequence_Desc UnraisableHookArgs_desc = …;
PyStatus
_PyErr_InitTypes(PyInterpreterState *interp)
{ … }
void
_PyErr_FiniTypes(PyInterpreterState *interp)
{ … }
static PyObject *
make_unraisable_hook_args(PyThreadState *tstate, PyObject *exc_type,
PyObject *exc_value, PyObject *exc_tb,
PyObject *err_msg, PyObject *obj)
{ … }
static int
write_unraisable_exc_file(PyThreadState *tstate, PyObject *exc_type,
PyObject *exc_value, PyObject *exc_tb,
PyObject *err_msg, PyObject *obj, PyObject *file)
{ … }
static int
write_unraisable_exc(PyThreadState *tstate, PyObject *exc_type,
PyObject *exc_value, PyObject *exc_tb, PyObject *err_msg,
PyObject *obj)
{ … }
PyObject*
_PyErr_WriteUnraisableDefaultHook(PyObject *args)
{ … }
static void
format_unraisable_v(const char *format, va_list va, PyObject *obj)
{ … }
void
PyErr_FormatUnraisable(const char *format, ...)
{ … }
static void
format_unraisable(PyObject *obj, const char *format, ...)
{ … }
void
PyErr_WriteUnraisable(PyObject *obj)
{ … }
void
PyErr_SyntaxLocation(const char *filename, int lineno)
{ … }
static void
PyErr_SyntaxLocationObjectEx(PyObject *filename, int lineno, int col_offset,
int end_lineno, int end_col_offset)
{ … }
void
PyErr_SyntaxLocationObject(PyObject *filename, int lineno, int col_offset) { … }
void
PyErr_RangedSyntaxLocationObject(PyObject *filename, int lineno, int col_offset,
int end_lineno, int end_col_offset) { … }
void
PyErr_SyntaxLocationEx(const char *filename, int lineno, int col_offset)
{ … }
void
_PyErr_RaiseSyntaxError(PyObject *msg, PyObject *filename, int lineno, int col_offset,
int end_lineno, int end_col_offset)
{ … }
int
_PyErr_EmitSyntaxWarning(PyObject *msg, PyObject *filename, int lineno, int col_offset,
int end_lineno, int end_col_offset)
{ … }
static PyObject *
err_programtext(FILE *fp, int lineno, const char* encoding)
{ … }
PyObject *
PyErr_ProgramText(const char *filename, int lineno)
{ … }
extern char* _PyTokenizer_FindEncodingFilename(int, PyObject *);
PyObject *
_PyErr_ProgramDecodedTextObject(PyObject *filename, int lineno, const char* encoding)
{ … }
PyObject *
PyErr_ProgramTextObject(PyObject *filename, int lineno)
{ … }