@@ -2492,7 +2492,7 @@ SimpleExtendsException(PyExc_Warning, ResourceWarning,
24922492#endif /* MS_WINDOWS */
24932493
24942494_PyInitError
2495- _PyExc_Init (PyObject * bltinmod )
2495+ _PyExc_Init (void )
24962496{
24972497#define PRE_INIT (TYPE ) \
24982498 if (!(_PyExc_ ## TYPE.tp_flags & Py_TPFLAGS_READY)) { \
@@ -2502,21 +2502,6 @@ _PyExc_Init(PyObject *bltinmod)
25022502 Py_INCREF(PyExc_ ## TYPE); \
25032503 }
25042504
2505- #define POST_INIT (TYPE ) \
2506- if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) { \
2507- return _Py_INIT_ERR("Module dictionary insertion problem."); \
2508- }
2509-
2510- #define INIT_ALIAS (NAME , TYPE ) \
2511- do { \
2512- Py_INCREF(PyExc_ ## TYPE); \
2513- Py_XDECREF(PyExc_ ## NAME); \
2514- PyExc_ ## NAME = PyExc_ ## TYPE; \
2515- if (PyDict_SetItemString(bdict, # NAME, PyExc_ ## NAME)) { \
2516- return _Py_INIT_ERR("Module dictionary insertion problem."); \
2517- } \
2518- } while (0)
2519-
25202505#define ADD_ERRNO (TYPE , CODE ) \
25212506 do { \
25222507 PyObject *_code = PyLong_FromLong(CODE); \
@@ -2526,8 +2511,6 @@ _PyExc_Init(PyObject *bltinmod)
25262511 Py_DECREF(_code); \
25272512 } while (0)
25282513
2529- PyObject * bdict ;
2530-
25312514 PRE_INIT (BaseException );
25322515 PRE_INIT (Exception );
25332516 PRE_INIT (TypeError );
@@ -2596,6 +2579,68 @@ _PyExc_Init(PyObject *bltinmod)
25962579 PRE_INIT (ProcessLookupError );
25972580 PRE_INIT (TimeoutError );
25982581
2582+ if (preallocate_memerrors () < 0 ) {
2583+ return _Py_INIT_ERR ("Could not preallocate MemoryError object" );
2584+ }
2585+
2586+ /* Add exceptions to errnomap */
2587+ if (!errnomap ) {
2588+ errnomap = PyDict_New ();
2589+ if (!errnomap ) {
2590+ return _Py_INIT_ERR ("Cannot allocate map from errnos to OSError subclasses" );
2591+ }
2592+ }
2593+
2594+ ADD_ERRNO (BlockingIOError , EAGAIN );
2595+ ADD_ERRNO (BlockingIOError , EALREADY );
2596+ ADD_ERRNO (BlockingIOError , EINPROGRESS );
2597+ ADD_ERRNO (BlockingIOError , EWOULDBLOCK );
2598+ ADD_ERRNO (BrokenPipeError , EPIPE );
2599+ #ifdef ESHUTDOWN
2600+ ADD_ERRNO (BrokenPipeError , ESHUTDOWN );
2601+ #endif
2602+ ADD_ERRNO (ChildProcessError , ECHILD );
2603+ ADD_ERRNO (ConnectionAbortedError , ECONNABORTED );
2604+ ADD_ERRNO (ConnectionRefusedError , ECONNREFUSED );
2605+ ADD_ERRNO (ConnectionResetError , ECONNRESET );
2606+ ADD_ERRNO (FileExistsError , EEXIST );
2607+ ADD_ERRNO (FileNotFoundError , ENOENT );
2608+ ADD_ERRNO (IsADirectoryError , EISDIR );
2609+ ADD_ERRNO (NotADirectoryError , ENOTDIR );
2610+ ADD_ERRNO (InterruptedError , EINTR );
2611+ ADD_ERRNO (PermissionError , EACCES );
2612+ ADD_ERRNO (PermissionError , EPERM );
2613+ ADD_ERRNO (ProcessLookupError , ESRCH );
2614+ ADD_ERRNO (TimeoutError , ETIMEDOUT );
2615+
2616+ return _Py_INIT_OK ();
2617+
2618+ #undef PRE_INIT
2619+ #undef ADD_ERRNO
2620+ }
2621+
2622+
2623+ /* Add exception types to the builtins module */
2624+ _PyInitError
2625+ _PyBuiltins_AddExceptions (PyObject * bltinmod )
2626+ {
2627+ #define POST_INIT (TYPE ) \
2628+ if (PyDict_SetItemString(bdict, # TYPE, PyExc_ ## TYPE)) { \
2629+ return _Py_INIT_ERR("Module dictionary insertion problem."); \
2630+ }
2631+
2632+ #define INIT_ALIAS (NAME , TYPE ) \
2633+ do { \
2634+ Py_INCREF(PyExc_ ## TYPE); \
2635+ Py_XDECREF(PyExc_ ## NAME); \
2636+ PyExc_ ## NAME = PyExc_ ## TYPE; \
2637+ if (PyDict_SetItemString(bdict, # NAME, PyExc_ ## NAME)) { \
2638+ return _Py_INIT_ERR("Module dictionary insertion problem."); \
2639+ } \
2640+ } while (0)
2641+
2642+ PyObject * bdict ;
2643+
25992644 bdict = PyModule_GetDict (bltinmod );
26002645 if (bdict == NULL ) {
26012646 return _Py_INIT_ERR ("exceptions bootstrapping error." );
@@ -2656,61 +2701,28 @@ _PyExc_Init(PyObject *bltinmod)
26562701 POST_INIT (BytesWarning );
26572702 POST_INIT (ResourceWarning );
26582703
2659- if (!errnomap ) {
2660- errnomap = PyDict_New ();
2661- if (!errnomap ) {
2662- return _Py_INIT_ERR ("Cannot allocate map from errnos to OSError subclasses" );
2663- }
2664- }
2665-
26662704 /* OSError subclasses */
26672705 POST_INIT (ConnectionError );
26682706
26692707 POST_INIT (BlockingIOError );
2670- ADD_ERRNO (BlockingIOError , EAGAIN );
2671- ADD_ERRNO (BlockingIOError , EALREADY );
2672- ADD_ERRNO (BlockingIOError , EINPROGRESS );
2673- ADD_ERRNO (BlockingIOError , EWOULDBLOCK );
26742708 POST_INIT (BrokenPipeError );
2675- ADD_ERRNO (BrokenPipeError , EPIPE );
2676- #ifdef ESHUTDOWN
2677- ADD_ERRNO (BrokenPipeError , ESHUTDOWN );
2678- #endif
26792709 POST_INIT (ChildProcessError );
2680- ADD_ERRNO (ChildProcessError , ECHILD );
26812710 POST_INIT (ConnectionAbortedError );
2682- ADD_ERRNO (ConnectionAbortedError , ECONNABORTED );
26832711 POST_INIT (ConnectionRefusedError );
2684- ADD_ERRNO (ConnectionRefusedError , ECONNREFUSED );
26852712 POST_INIT (ConnectionResetError );
2686- ADD_ERRNO (ConnectionResetError , ECONNRESET );
26872713 POST_INIT (FileExistsError );
2688- ADD_ERRNO (FileExistsError , EEXIST );
26892714 POST_INIT (FileNotFoundError );
2690- ADD_ERRNO (FileNotFoundError , ENOENT );
26912715 POST_INIT (IsADirectoryError );
2692- ADD_ERRNO (IsADirectoryError , EISDIR );
26932716 POST_INIT (NotADirectoryError );
2694- ADD_ERRNO (NotADirectoryError , ENOTDIR );
26952717 POST_INIT (InterruptedError );
2696- ADD_ERRNO (InterruptedError , EINTR );
26972718 POST_INIT (PermissionError );
2698- ADD_ERRNO (PermissionError , EACCES );
2699- ADD_ERRNO (PermissionError , EPERM );
27002719 POST_INIT (ProcessLookupError );
2701- ADD_ERRNO (ProcessLookupError , ESRCH );
27022720 POST_INIT (TimeoutError );
2703- ADD_ERRNO (TimeoutError , ETIMEDOUT );
27042721
2705- if (preallocate_memerrors () < 0 ) {
2706- return _Py_INIT_ERR ("Could not preallocate MemoryError object" );
2707- }
27082722 return _Py_INIT_OK ();
27092723
2710- #undef PRE_INIT
27112724#undef POST_INIT
27122725#undef INIT_ALIAS
2713- #undef ADD_ERRNO
27142726}
27152727
27162728void
0 commit comments