aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Objects/exceptions.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Objects/exceptions.c
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
downloadydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Objects/exceptions.c')
-rw-r--r--contrib/tools/python3/src/Objects/exceptions.c652
1 files changed, 326 insertions, 326 deletions
diff --git a/contrib/tools/python3/src/Objects/exceptions.c b/contrib/tools/python3/src/Objects/exceptions.c
index 3ca2e688e7..e67ecfab85 100644
--- a/contrib/tools/python3/src/Objects/exceptions.c
+++ b/contrib/tools/python3/src/Objects/exceptions.c
@@ -6,10 +6,10 @@
#define PY_SSIZE_T_CLEAN
#include <Python.h>
-#include "pycore_initconfig.h"
-#include "pycore_object.h"
-#include "structmember.h" // PyMemberDef
-#include "osdefs.h" // SEP
+#include "pycore_initconfig.h"
+#include "pycore_object.h"
+#include "structmember.h" // PyMemberDef
+#include "osdefs.h" // SEP
/* Compatibility aliases */
@@ -126,7 +126,7 @@ BaseException_repr(PyBaseExceptionObject *self)
/* Pickling support */
static PyObject *
-BaseException_reduce(PyBaseExceptionObject *self, PyObject *Py_UNUSED(ignored))
+BaseException_reduce(PyBaseExceptionObject *self, PyObject *Py_UNUSED(ignored))
{
if (self->args && self->dict)
return PyTuple_Pack(3, Py_TYPE(self), self->args, self->dict);
@@ -304,33 +304,33 @@ static PyGetSetDef BaseException_getset[] = {
};
-static inline PyBaseExceptionObject*
-_PyBaseExceptionObject_cast(PyObject *exc)
-{
- assert(PyExceptionInstance_Check(exc));
- return (PyBaseExceptionObject *)exc;
-}
-
-
+static inline PyBaseExceptionObject*
+_PyBaseExceptionObject_cast(PyObject *exc)
+{
+ assert(PyExceptionInstance_Check(exc));
+ return (PyBaseExceptionObject *)exc;
+}
+
+
PyObject *
-PyException_GetTraceback(PyObject *self)
-{
- PyBaseExceptionObject *base_self = _PyBaseExceptionObject_cast(self);
+PyException_GetTraceback(PyObject *self)
+{
+ PyBaseExceptionObject *base_self = _PyBaseExceptionObject_cast(self);
Py_XINCREF(base_self->traceback);
return base_self->traceback;
}
int
-PyException_SetTraceback(PyObject *self, PyObject *tb)
-{
- return BaseException_set_tb(_PyBaseExceptionObject_cast(self), tb, NULL);
+PyException_SetTraceback(PyObject *self, PyObject *tb)
+{
+ return BaseException_set_tb(_PyBaseExceptionObject_cast(self), tb, NULL);
}
PyObject *
-PyException_GetCause(PyObject *self)
-{
- PyObject *cause = _PyBaseExceptionObject_cast(self)->cause;
+PyException_GetCause(PyObject *self)
+{
+ PyObject *cause = _PyBaseExceptionObject_cast(self)->cause;
Py_XINCREF(cause);
return cause;
}
@@ -339,15 +339,15 @@ PyException_GetCause(PyObject *self)
void
PyException_SetCause(PyObject *self, PyObject *cause)
{
- PyBaseExceptionObject *base_self = _PyBaseExceptionObject_cast(self);
- base_self->suppress_context = 1;
- Py_XSETREF(base_self->cause, cause);
+ PyBaseExceptionObject *base_self = _PyBaseExceptionObject_cast(self);
+ base_self->suppress_context = 1;
+ Py_XSETREF(base_self->cause, cause);
}
PyObject *
-PyException_GetContext(PyObject *self)
-{
- PyObject *context = _PyBaseExceptionObject_cast(self)->context;
+PyException_GetContext(PyObject *self)
+{
+ PyObject *context = _PyBaseExceptionObject_cast(self)->context;
Py_XINCREF(context);
return context;
}
@@ -356,18 +356,18 @@ PyException_GetContext(PyObject *self)
void
PyException_SetContext(PyObject *self, PyObject *context)
{
- Py_XSETREF(_PyBaseExceptionObject_cast(self)->context, context);
+ Py_XSETREF(_PyBaseExceptionObject_cast(self)->context, context);
}
-#undef PyExceptionClass_Name
+#undef PyExceptionClass_Name
+
+const char *
+PyExceptionClass_Name(PyObject *ob)
+{
+ assert(PyExceptionClass_Check(ob));
+ return ((PyTypeObject*)ob)->tp_name;
+}
-const char *
-PyExceptionClass_Name(PyObject *ob)
-{
- assert(PyExceptionClass_Check(ob));
- return ((PyTypeObject*)ob)->tp_name;
-}
-
static struct PyMemberDef BaseException_members[] = {
{"__suppress_context__", T_BOOL,
offsetof(PyBaseExceptionObject, suppress_context)},
@@ -381,10 +381,10 @@ static PyTypeObject _PyExc_BaseException = {
sizeof(PyBaseExceptionObject), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)BaseException_dealloc, /*tp_dealloc*/
- 0, /*tp_vectorcall_offset*/
+ 0, /*tp_vectorcall_offset*/
0, /*tp_getattr*/
0, /*tp_setattr*/
- 0, /*tp_as_async*/
+ 0, /*tp_as_async*/
(reprfunc)BaseException_repr, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
@@ -417,7 +417,7 @@ static PyTypeObject _PyExc_BaseException = {
BaseException_new, /* tp_new */
};
/* the CPython API expects exceptions to be (PyObject *) - both a hold-over
-from the previous implementation and also allowing Python objects to be used
+from the previous implementation and also allowing Python objects to be used
in the API */
PyObject *PyExc_BaseException = (PyObject *)&_PyExc_BaseException;
@@ -738,7 +738,7 @@ ImportError_getstate(PyImportErrorObject *self)
/* Pickling support */
static PyObject *
-ImportError_reduce(PyImportErrorObject *self, PyObject *Py_UNUSED(ignored))
+ImportError_reduce(PyImportErrorObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *res;
PyObject *args;
@@ -887,7 +887,7 @@ oserror_init(PyOSErrorObject *self, PyObject **p_args,
/* self->filename will remain Py_None otherwise */
if (filename && filename != Py_None) {
- if (Py_IS_TYPE(self, (PyTypeObject *) PyExc_BlockingIOError) &&
+ if (Py_IS_TYPE(self, (PyTypeObject *) PyExc_BlockingIOError) &&
PyNumber_Check(filename)) {
/* BlockingIOError's 3rd argument can be the number of
* characters written.
@@ -988,7 +988,7 @@ OSError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (myerrno && PyLong_Check(myerrno) &&
errnomap && (PyObject *) type == PyExc_OSError) {
PyObject *newtype;
- newtype = PyDict_GetItemWithError(errnomap, myerrno);
+ newtype = PyDict_GetItemWithError(errnomap, myerrno);
if (newtype) {
assert(PyType_Check(newtype));
type = (PyTypeObject *) newtype;
@@ -1148,7 +1148,7 @@ OSError_str(PyOSErrorObject *self)
}
static PyObject *
-OSError_reduce(PyOSErrorObject *self, PyObject *Py_UNUSED(ignored))
+OSError_reduce(PyOSErrorObject *self, PyObject *Py_UNUSED(ignored))
{
PyObject *args = self->args;
PyObject *res = NULL, *tmp;
@@ -1209,14 +1209,14 @@ OSError_written_get(PyOSErrorObject *self, void *context)
static int
OSError_written_set(PyOSErrorObject *self, PyObject *arg, void *context)
{
- if (arg == NULL) {
- if (self->written == -1) {
- PyErr_SetString(PyExc_AttributeError, "characters_written");
- return -1;
- }
- self->written = -1;
- return 0;
- }
+ if (arg == NULL) {
+ if (self->written == -1) {
+ PyErr_SetString(PyExc_AttributeError, "characters_written");
+ return -1;
+ }
+ self->written = -1;
+ return 0;
+ }
Py_ssize_t n;
n = PyNumber_AsSsize_t(arg, PyExc_ValueError);
if (n == -1 && PyErr_Occurred())
@@ -1391,7 +1391,7 @@ SyntaxError_init(PySyntaxErrorObject *self, PyObject *args, PyObject *kwds)
* Only applies to SyntaxError instances, not to subclasses such
* as TabError or IndentationError (see issue #31161)
*/
- if (Py_IS_TYPE(self, (PyTypeObject *)PyExc_SyntaxError) &&
+ if (Py_IS_TYPE(self, (PyTypeObject *)PyExc_SyntaxError) &&
self->text && PyUnicode_Check(self->text) &&
_report_missing_parentheses(self) < 0) {
return -1;
@@ -1440,7 +1440,7 @@ my_basename(PyObject *name)
{
Py_ssize_t i, size, offset;
int kind;
- const void *data;
+ const void *data;
if (PyUnicode_READY(name))
return NULL;
@@ -1449,13 +1449,13 @@ my_basename(PyObject *name)
size = PyUnicode_GET_LENGTH(name);
offset = 0;
for(i=0; i < size; i++) {
- if (PyUnicode_READ(kind, data, i) == SEP) {
+ if (PyUnicode_READ(kind, data, i) == SEP) {
offset = i + 1;
- }
+ }
}
- if (offset != 0) {
+ if (offset != 0) {
return PyUnicode_Substring(name, offset, size);
- }
+ }
else {
Py_INCREF(name);
return name;
@@ -1773,9 +1773,9 @@ PyUnicodeDecodeError_GetEnd(PyObject *exc, Py_ssize_t *end)
int
-PyUnicodeTranslateError_GetEnd(PyObject *exc, Py_ssize_t *end)
+PyUnicodeTranslateError_GetEnd(PyObject *exc, Py_ssize_t *end)
{
- return PyUnicodeEncodeError_GetEnd(exc, end);
+ return PyUnicodeEncodeError_GetEnd(exc, end);
}
@@ -2282,12 +2282,12 @@ MemoryError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{
PyBaseExceptionObject *self;
- /* If this is a subclass of MemoryError, don't use the freelist
- * and just return a fresh object */
- if (type != (PyTypeObject *) PyExc_MemoryError) {
+ /* If this is a subclass of MemoryError, don't use the freelist
+ * and just return a fresh object */
+ if (type != (PyTypeObject *) PyExc_MemoryError) {
return BaseException_new(type, args, kwds);
- }
-
+ }
+
if (memerrors_freelist == NULL)
return BaseException_new(type, args, kwds);
/* Fetch object from freelist and revive it */
@@ -2307,15 +2307,15 @@ MemoryError_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static void
MemoryError_dealloc(PyBaseExceptionObject *self)
{
- BaseException_clear(self);
-
- if (!Py_IS_TYPE(self, (PyTypeObject *) PyExc_MemoryError)) {
- Py_TYPE(self)->tp_free((PyObject *)self);
- return;
- }
-
+ BaseException_clear(self);
+
+ if (!Py_IS_TYPE(self, (PyTypeObject *) PyExc_MemoryError)) {
+ Py_TYPE(self)->tp_free((PyObject *)self);
+ return;
+ }
+
_PyObject_GC_UNTRACK(self);
-
+
if (memerrors_numfree >= MEMERRORS_SAVE)
Py_TYPE(self)->tp_free((PyObject *)self);
else {
@@ -2325,7 +2325,7 @@ MemoryError_dealloc(PyBaseExceptionObject *self)
}
}
-static int
+static int
preallocate_memerrors(void)
{
/* We create enough MemoryErrors and then decref them, which will fill
@@ -2335,14 +2335,14 @@ preallocate_memerrors(void)
for (i = 0; i < MEMERRORS_SAVE; i++) {
errors[i] = MemoryError_new((PyTypeObject *) PyExc_MemoryError,
NULL, NULL);
- if (!errors[i]) {
- return -1;
- }
+ if (!errors[i]) {
+ return -1;
+ }
}
for (i = 0; i < MEMERRORS_SAVE; i++) {
Py_DECREF(errors[i]);
}
- return 0;
+ return 0;
}
static void
@@ -2517,242 +2517,242 @@ SimpleExtendsException(PyExc_Warning, ResourceWarning,
#endif
#endif /* MS_WINDOWS */
-PyStatus
-_PyExc_Init(void)
-{
-#define PRE_INIT(TYPE) \
- if (!(_PyExc_ ## TYPE.tp_flags & Py_TPFLAGS_READY)) { \
- if (PyType_Ready(&_PyExc_ ## TYPE) < 0) { \
- return _PyStatus_ERR("exceptions bootstrapping error."); \
- } \
- Py_INCREF(PyExc_ ## TYPE); \
- }
-
-#define ADD_ERRNO(TYPE, CODE) \
- do { \
- PyObject *_code = PyLong_FromLong(CODE); \
- assert(_PyObject_RealIsSubclass(PyExc_ ## TYPE, PyExc_OSError)); \
- if (!_code || PyDict_SetItem(errnomap, _code, PyExc_ ## TYPE)) { \
- Py_XDECREF(_code); \
- return _PyStatus_ERR("errmap insertion problem."); \
- } \
- Py_DECREF(_code); \
- } while (0)
-
- PRE_INIT(BaseException);
- PRE_INIT(Exception);
- PRE_INIT(TypeError);
- PRE_INIT(StopAsyncIteration);
- PRE_INIT(StopIteration);
- PRE_INIT(GeneratorExit);
- PRE_INIT(SystemExit);
- PRE_INIT(KeyboardInterrupt);
- PRE_INIT(ImportError);
- PRE_INIT(ModuleNotFoundError);
- PRE_INIT(OSError);
- PRE_INIT(EOFError);
- PRE_INIT(RuntimeError);
- PRE_INIT(RecursionError);
- PRE_INIT(NotImplementedError);
- PRE_INIT(NameError);
- PRE_INIT(UnboundLocalError);
- PRE_INIT(AttributeError);
- PRE_INIT(SyntaxError);
- PRE_INIT(IndentationError);
- PRE_INIT(TabError);
- PRE_INIT(LookupError);
- PRE_INIT(IndexError);
- PRE_INIT(KeyError);
- PRE_INIT(ValueError);
- PRE_INIT(UnicodeError);
- PRE_INIT(UnicodeEncodeError);
- PRE_INIT(UnicodeDecodeError);
- PRE_INIT(UnicodeTranslateError);
- PRE_INIT(AssertionError);
- PRE_INIT(ArithmeticError);
- PRE_INIT(FloatingPointError);
- PRE_INIT(OverflowError);
- PRE_INIT(ZeroDivisionError);
- PRE_INIT(SystemError);
- PRE_INIT(ReferenceError);
- PRE_INIT(MemoryError);
- PRE_INIT(BufferError);
- PRE_INIT(Warning);
- PRE_INIT(UserWarning);
- PRE_INIT(DeprecationWarning);
- PRE_INIT(PendingDeprecationWarning);
- PRE_INIT(SyntaxWarning);
- PRE_INIT(RuntimeWarning);
- PRE_INIT(FutureWarning);
- PRE_INIT(ImportWarning);
- PRE_INIT(UnicodeWarning);
- PRE_INIT(BytesWarning);
- PRE_INIT(ResourceWarning);
-
+PyStatus
+_PyExc_Init(void)
+{
+#define PRE_INIT(TYPE) \
+ if (!(_PyExc_ ## TYPE.tp_flags & Py_TPFLAGS_READY)) { \
+ if (PyType_Ready(&_PyExc_ ## TYPE) < 0) { \
+ return _PyStatus_ERR("exceptions bootstrapping error."); \
+ } \
+ Py_INCREF(PyExc_ ## TYPE); \
+ }
+
+#define ADD_ERRNO(TYPE, CODE) \
+ do { \
+ PyObject *_code = PyLong_FromLong(CODE); \
+ assert(_PyObject_RealIsSubclass(PyExc_ ## TYPE, PyExc_OSError)); \
+ if (!_code || PyDict_SetItem(errnomap, _code, PyExc_ ## TYPE)) { \
+ Py_XDECREF(_code); \
+ return _PyStatus_ERR("errmap insertion problem."); \
+ } \
+ Py_DECREF(_code); \
+ } while (0)
+
+ PRE_INIT(BaseException);
+ PRE_INIT(Exception);
+ PRE_INIT(TypeError);
+ PRE_INIT(StopAsyncIteration);
+ PRE_INIT(StopIteration);
+ PRE_INIT(GeneratorExit);
+ PRE_INIT(SystemExit);
+ PRE_INIT(KeyboardInterrupt);
+ PRE_INIT(ImportError);
+ PRE_INIT(ModuleNotFoundError);
+ PRE_INIT(OSError);
+ PRE_INIT(EOFError);
+ PRE_INIT(RuntimeError);
+ PRE_INIT(RecursionError);
+ PRE_INIT(NotImplementedError);
+ PRE_INIT(NameError);
+ PRE_INIT(UnboundLocalError);
+ PRE_INIT(AttributeError);
+ PRE_INIT(SyntaxError);
+ PRE_INIT(IndentationError);
+ PRE_INIT(TabError);
+ PRE_INIT(LookupError);
+ PRE_INIT(IndexError);
+ PRE_INIT(KeyError);
+ PRE_INIT(ValueError);
+ PRE_INIT(UnicodeError);
+ PRE_INIT(UnicodeEncodeError);
+ PRE_INIT(UnicodeDecodeError);
+ PRE_INIT(UnicodeTranslateError);
+ PRE_INIT(AssertionError);
+ PRE_INIT(ArithmeticError);
+ PRE_INIT(FloatingPointError);
+ PRE_INIT(OverflowError);
+ PRE_INIT(ZeroDivisionError);
+ PRE_INIT(SystemError);
+ PRE_INIT(ReferenceError);
+ PRE_INIT(MemoryError);
+ PRE_INIT(BufferError);
+ PRE_INIT(Warning);
+ PRE_INIT(UserWarning);
+ PRE_INIT(DeprecationWarning);
+ PRE_INIT(PendingDeprecationWarning);
+ PRE_INIT(SyntaxWarning);
+ PRE_INIT(RuntimeWarning);
+ PRE_INIT(FutureWarning);
+ PRE_INIT(ImportWarning);
+ PRE_INIT(UnicodeWarning);
+ PRE_INIT(BytesWarning);
+ PRE_INIT(ResourceWarning);
+
/* OSError subclasses */
- PRE_INIT(ConnectionError);
-
- PRE_INIT(BlockingIOError);
- PRE_INIT(BrokenPipeError);
- PRE_INIT(ChildProcessError);
- PRE_INIT(ConnectionAbortedError);
- PRE_INIT(ConnectionRefusedError);
- PRE_INIT(ConnectionResetError);
- PRE_INIT(FileExistsError);
- PRE_INIT(FileNotFoundError);
- PRE_INIT(IsADirectoryError);
- PRE_INIT(NotADirectoryError);
- PRE_INIT(InterruptedError);
- PRE_INIT(PermissionError);
- PRE_INIT(ProcessLookupError);
- PRE_INIT(TimeoutError);
-
- if (preallocate_memerrors() < 0) {
- return _PyStatus_ERR("Could not preallocate MemoryError object");
- }
-
- /* Add exceptions to errnomap */
+ PRE_INIT(ConnectionError);
+
+ PRE_INIT(BlockingIOError);
+ PRE_INIT(BrokenPipeError);
+ PRE_INIT(ChildProcessError);
+ PRE_INIT(ConnectionAbortedError);
+ PRE_INIT(ConnectionRefusedError);
+ PRE_INIT(ConnectionResetError);
+ PRE_INIT(FileExistsError);
+ PRE_INIT(FileNotFoundError);
+ PRE_INIT(IsADirectoryError);
+ PRE_INIT(NotADirectoryError);
+ PRE_INIT(InterruptedError);
+ PRE_INIT(PermissionError);
+ PRE_INIT(ProcessLookupError);
+ PRE_INIT(TimeoutError);
+
+ if (preallocate_memerrors() < 0) {
+ return _PyStatus_ERR("Could not preallocate MemoryError object");
+ }
+
+ /* Add exceptions to errnomap */
if (!errnomap) {
errnomap = PyDict_New();
- if (!errnomap) {
- return _PyStatus_ERR("Cannot allocate map from errnos to OSError subclasses");
- }
+ if (!errnomap) {
+ return _PyStatus_ERR("Cannot allocate map from errnos to OSError subclasses");
+ }
}
- ADD_ERRNO(BlockingIOError, EAGAIN);
- ADD_ERRNO(BlockingIOError, EALREADY);
- ADD_ERRNO(BlockingIOError, EINPROGRESS);
- ADD_ERRNO(BlockingIOError, EWOULDBLOCK);
- ADD_ERRNO(BrokenPipeError, EPIPE);
+ ADD_ERRNO(BlockingIOError, EAGAIN);
+ ADD_ERRNO(BlockingIOError, EALREADY);
+ ADD_ERRNO(BlockingIOError, EINPROGRESS);
+ ADD_ERRNO(BlockingIOError, EWOULDBLOCK);
+ ADD_ERRNO(BrokenPipeError, EPIPE);
#ifdef ESHUTDOWN
- ADD_ERRNO(BrokenPipeError, ESHUTDOWN);
+ ADD_ERRNO(BrokenPipeError, ESHUTDOWN);
+#endif
+ ADD_ERRNO(ChildProcessError, ECHILD);
+ ADD_ERRNO(ConnectionAbortedError, ECONNABORTED);
+ ADD_ERRNO(ConnectionRefusedError, ECONNREFUSED);
+ ADD_ERRNO(ConnectionResetError, ECONNRESET);
+ ADD_ERRNO(FileExistsError, EEXIST);
+ ADD_ERRNO(FileNotFoundError, ENOENT);
+ ADD_ERRNO(IsADirectoryError, EISDIR);
+ ADD_ERRNO(NotADirectoryError, ENOTDIR);
+ ADD_ERRNO(InterruptedError, EINTR);
+ ADD_ERRNO(PermissionError, EACCES);
+ ADD_ERRNO(PermissionError, EPERM);
+ ADD_ERRNO(ProcessLookupError, ESRCH);
+ ADD_ERRNO(TimeoutError, ETIMEDOUT);
+
+ return _PyStatus_OK();
+
+#undef PRE_INIT
+#undef ADD_ERRNO
+}
+
+
+/* Add exception types to the builtins module */
+PyStatus
+_PyBuiltins_AddExceptions(PyObject *bltinmod)
+{
+#define POST_INIT(TYPE) \
+ if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) { \
+ return _PyStatus_ERR("Module dictionary insertion problem."); \
+ }
+
+#define INIT_ALIAS(NAME, TYPE) \
+ do { \
+ Py_INCREF(PyExc_ ## TYPE); \
+ Py_XDECREF(PyExc_ ## NAME); \
+ PyExc_ ## NAME = PyExc_ ## TYPE; \
+ if (PyDict_SetItemString(bdict, # NAME, PyExc_ ## NAME)) { \
+ return _PyStatus_ERR("Module dictionary insertion problem."); \
+ } \
+ } while (0)
+
+ PyObject *bdict;
+
+ bdict = PyModule_GetDict(bltinmod);
+ if (bdict == NULL) {
+ return _PyStatus_ERR("exceptions bootstrapping error.");
+ }
+
+ POST_INIT(BaseException);
+ POST_INIT(Exception);
+ POST_INIT(TypeError);
+ POST_INIT(StopAsyncIteration);
+ POST_INIT(StopIteration);
+ POST_INIT(GeneratorExit);
+ POST_INIT(SystemExit);
+ POST_INIT(KeyboardInterrupt);
+ POST_INIT(ImportError);
+ POST_INIT(ModuleNotFoundError);
+ POST_INIT(OSError);
+ INIT_ALIAS(EnvironmentError, OSError);
+ INIT_ALIAS(IOError, OSError);
+#ifdef MS_WINDOWS
+ INIT_ALIAS(WindowsError, OSError);
#endif
- ADD_ERRNO(ChildProcessError, ECHILD);
- ADD_ERRNO(ConnectionAbortedError, ECONNABORTED);
- ADD_ERRNO(ConnectionRefusedError, ECONNREFUSED);
- ADD_ERRNO(ConnectionResetError, ECONNRESET);
- ADD_ERRNO(FileExistsError, EEXIST);
- ADD_ERRNO(FileNotFoundError, ENOENT);
- ADD_ERRNO(IsADirectoryError, EISDIR);
- ADD_ERRNO(NotADirectoryError, ENOTDIR);
- ADD_ERRNO(InterruptedError, EINTR);
- ADD_ERRNO(PermissionError, EACCES);
- ADD_ERRNO(PermissionError, EPERM);
- ADD_ERRNO(ProcessLookupError, ESRCH);
- ADD_ERRNO(TimeoutError, ETIMEDOUT);
-
- return _PyStatus_OK();
-
-#undef PRE_INIT
-#undef ADD_ERRNO
-}
-
-
-/* Add exception types to the builtins module */
-PyStatus
-_PyBuiltins_AddExceptions(PyObject *bltinmod)
-{
-#define POST_INIT(TYPE) \
- if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) { \
- return _PyStatus_ERR("Module dictionary insertion problem."); \
- }
-
-#define INIT_ALIAS(NAME, TYPE) \
- do { \
- Py_INCREF(PyExc_ ## TYPE); \
- Py_XDECREF(PyExc_ ## NAME); \
- PyExc_ ## NAME = PyExc_ ## TYPE; \
- if (PyDict_SetItemString(bdict, # NAME, PyExc_ ## NAME)) { \
- return _PyStatus_ERR("Module dictionary insertion problem."); \
- } \
- } while (0)
-
- PyObject *bdict;
-
- bdict = PyModule_GetDict(bltinmod);
- if (bdict == NULL) {
- return _PyStatus_ERR("exceptions bootstrapping error.");
- }
-
- POST_INIT(BaseException);
- POST_INIT(Exception);
- POST_INIT(TypeError);
- POST_INIT(StopAsyncIteration);
- POST_INIT(StopIteration);
- POST_INIT(GeneratorExit);
- POST_INIT(SystemExit);
- POST_INIT(KeyboardInterrupt);
- POST_INIT(ImportError);
- POST_INIT(ModuleNotFoundError);
- POST_INIT(OSError);
- INIT_ALIAS(EnvironmentError, OSError);
- INIT_ALIAS(IOError, OSError);
-#ifdef MS_WINDOWS
- INIT_ALIAS(WindowsError, OSError);
-#endif
- POST_INIT(EOFError);
- POST_INIT(RuntimeError);
- POST_INIT(RecursionError);
- POST_INIT(NotImplementedError);
- POST_INIT(NameError);
- POST_INIT(UnboundLocalError);
- POST_INIT(AttributeError);
- POST_INIT(SyntaxError);
- POST_INIT(IndentationError);
- POST_INIT(TabError);
- POST_INIT(LookupError);
- POST_INIT(IndexError);
- POST_INIT(KeyError);
- POST_INIT(ValueError);
- POST_INIT(UnicodeError);
- POST_INIT(UnicodeEncodeError);
- POST_INIT(UnicodeDecodeError);
- POST_INIT(UnicodeTranslateError);
- POST_INIT(AssertionError);
- POST_INIT(ArithmeticError);
- POST_INIT(FloatingPointError);
- POST_INIT(OverflowError);
- POST_INIT(ZeroDivisionError);
- POST_INIT(SystemError);
- POST_INIT(ReferenceError);
- POST_INIT(MemoryError);
- POST_INIT(BufferError);
- POST_INIT(Warning);
- POST_INIT(UserWarning);
- POST_INIT(DeprecationWarning);
- POST_INIT(PendingDeprecationWarning);
- POST_INIT(SyntaxWarning);
- POST_INIT(RuntimeWarning);
- POST_INIT(FutureWarning);
- POST_INIT(ImportWarning);
- POST_INIT(UnicodeWarning);
- POST_INIT(BytesWarning);
- POST_INIT(ResourceWarning);
-
- /* OSError subclasses */
- POST_INIT(ConnectionError);
-
- POST_INIT(BlockingIOError);
- POST_INIT(BrokenPipeError);
- POST_INIT(ChildProcessError);
- POST_INIT(ConnectionAbortedError);
- POST_INIT(ConnectionRefusedError);
- POST_INIT(ConnectionResetError);
- POST_INIT(FileExistsError);
- POST_INIT(FileNotFoundError);
- POST_INIT(IsADirectoryError);
- POST_INIT(NotADirectoryError);
- POST_INIT(InterruptedError);
- POST_INIT(PermissionError);
- POST_INIT(ProcessLookupError);
- POST_INIT(TimeoutError);
-
- return _PyStatus_OK();
-
-#undef POST_INIT
-#undef INIT_ALIAS
-}
-
+ POST_INIT(EOFError);
+ POST_INIT(RuntimeError);
+ POST_INIT(RecursionError);
+ POST_INIT(NotImplementedError);
+ POST_INIT(NameError);
+ POST_INIT(UnboundLocalError);
+ POST_INIT(AttributeError);
+ POST_INIT(SyntaxError);
+ POST_INIT(IndentationError);
+ POST_INIT(TabError);
+ POST_INIT(LookupError);
+ POST_INIT(IndexError);
+ POST_INIT(KeyError);
+ POST_INIT(ValueError);
+ POST_INIT(UnicodeError);
+ POST_INIT(UnicodeEncodeError);
+ POST_INIT(UnicodeDecodeError);
+ POST_INIT(UnicodeTranslateError);
+ POST_INIT(AssertionError);
+ POST_INIT(ArithmeticError);
+ POST_INIT(FloatingPointError);
+ POST_INIT(OverflowError);
+ POST_INIT(ZeroDivisionError);
+ POST_INIT(SystemError);
+ POST_INIT(ReferenceError);
+ POST_INIT(MemoryError);
+ POST_INIT(BufferError);
+ POST_INIT(Warning);
+ POST_INIT(UserWarning);
+ POST_INIT(DeprecationWarning);
+ POST_INIT(PendingDeprecationWarning);
+ POST_INIT(SyntaxWarning);
+ POST_INIT(RuntimeWarning);
+ POST_INIT(FutureWarning);
+ POST_INIT(ImportWarning);
+ POST_INIT(UnicodeWarning);
+ POST_INIT(BytesWarning);
+ POST_INIT(ResourceWarning);
+
+ /* OSError subclasses */
+ POST_INIT(ConnectionError);
+
+ POST_INIT(BlockingIOError);
+ POST_INIT(BrokenPipeError);
+ POST_INIT(ChildProcessError);
+ POST_INIT(ConnectionAbortedError);
+ POST_INIT(ConnectionRefusedError);
+ POST_INIT(ConnectionResetError);
+ POST_INIT(FileExistsError);
+ POST_INIT(FileNotFoundError);
+ POST_INIT(IsADirectoryError);
+ POST_INIT(NotADirectoryError);
+ POST_INIT(InterruptedError);
+ POST_INIT(PermissionError);
+ POST_INIT(ProcessLookupError);
+ POST_INIT(TimeoutError);
+
+ return _PyStatus_OK();
+
+#undef POST_INIT
+#undef INIT_ALIAS
+}
+
void
_PyExc_Fini(void)
{
@@ -2978,9 +2978,9 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
*/
static PyObject *print_prefix = NULL;
static PyObject *exec_prefix = NULL;
- Py_ssize_t text_len = PyUnicode_GET_LENGTH(self->text), match;
+ Py_ssize_t text_len = PyUnicode_GET_LENGTH(self->text), match;
int kind = PyUnicode_KIND(self->text);
- const void *data = PyUnicode_DATA(self->text);
+ const void *data = PyUnicode_DATA(self->text);
/* Ignore leading whitespace */
while (start < text_len) {
@@ -3001,12 +3001,12 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
return -1;
}
}
- match = PyUnicode_Tailmatch(self->text, print_prefix,
- start, text_len, -1);
- if (match == -1) {
- return -1;
- }
- if (match) {
+ match = PyUnicode_Tailmatch(self->text, print_prefix,
+ start, text_len, -1);
+ if (match == -1) {
+ return -1;
+ }
+ if (match) {
return _set_legacy_print_statement_msg(self, start);
}
@@ -3017,17 +3017,17 @@ _check_for_legacy_statements(PySyntaxErrorObject *self, Py_ssize_t start)
return -1;
}
}
- match = PyUnicode_Tailmatch(self->text, exec_prefix, start, text_len, -1);
- if (match == -1) {
- return -1;
- }
- if (match) {
- PyObject *msg = PyUnicode_FromString("Missing parentheses in call "
- "to 'exec'");
- if (msg == NULL) {
- return -1;
- }
- Py_XSETREF(self->msg, msg);
+ match = PyUnicode_Tailmatch(self->text, exec_prefix, start, text_len, -1);
+ if (match == -1) {
+ return -1;
+ }
+ if (match) {
+ PyObject *msg = PyUnicode_FromString("Missing parentheses in call "
+ "to 'exec'");
+ if (msg == NULL) {
+ return -1;
+ }
+ Py_XSETREF(self->msg, msg);
return 1;
}
/* Fall back to the default error message */