@@ -2492,7 +2492,7 @@ SimpleExtendsException(PyExc_Warning, ResourceWarning,
2492
2492
#endif /* MS_WINDOWS */
2493
2493
2494
2494
_PyInitError
2495
- _PyExc_Init (PyObject * bltinmod )
2495
+ _PyExc_Init (void )
2496
2496
{
2497
2497
#define PRE_INIT (TYPE ) \
2498
2498
if (!(_PyExc_ ## TYPE.tp_flags & Py_TPFLAGS_READY)) { \
@@ -2502,21 +2502,6 @@ _PyExc_Init(PyObject *bltinmod)
2502
2502
Py_INCREF(PyExc_ ## TYPE); \
2503
2503
}
2504
2504
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
-
2520
2505
#define ADD_ERRNO (TYPE , CODE ) \
2521
2506
do { \
2522
2507
PyObject *_code = PyLong_FromLong(CODE); \
@@ -2526,8 +2511,6 @@ _PyExc_Init(PyObject *bltinmod)
2526
2511
Py_DECREF(_code); \
2527
2512
} while (0)
2528
2513
2529
- PyObject * bdict ;
2530
-
2531
2514
PRE_INIT (BaseException );
2532
2515
PRE_INIT (Exception );
2533
2516
PRE_INIT (TypeError );
@@ -2596,6 +2579,68 @@ _PyExc_Init(PyObject *bltinmod)
2596
2579
PRE_INIT (ProcessLookupError );
2597
2580
PRE_INIT (TimeoutError );
2598
2581
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
+
2599
2644
bdict = PyModule_GetDict (bltinmod );
2600
2645
if (bdict == NULL ) {
2601
2646
return _Py_INIT_ERR ("exceptions bootstrapping error." );
@@ -2656,61 +2701,28 @@ _PyExc_Init(PyObject *bltinmod)
2656
2701
POST_INIT (BytesWarning );
2657
2702
POST_INIT (ResourceWarning );
2658
2703
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
-
2666
2704
/* OSError subclasses */
2667
2705
POST_INIT (ConnectionError );
2668
2706
2669
2707
POST_INIT (BlockingIOError );
2670
- ADD_ERRNO (BlockingIOError , EAGAIN );
2671
- ADD_ERRNO (BlockingIOError , EALREADY );
2672
- ADD_ERRNO (BlockingIOError , EINPROGRESS );
2673
- ADD_ERRNO (BlockingIOError , EWOULDBLOCK );
2674
2708
POST_INIT (BrokenPipeError );
2675
- ADD_ERRNO (BrokenPipeError , EPIPE );
2676
- #ifdef ESHUTDOWN
2677
- ADD_ERRNO (BrokenPipeError , ESHUTDOWN );
2678
- #endif
2679
2709
POST_INIT (ChildProcessError );
2680
- ADD_ERRNO (ChildProcessError , ECHILD );
2681
2710
POST_INIT (ConnectionAbortedError );
2682
- ADD_ERRNO (ConnectionAbortedError , ECONNABORTED );
2683
2711
POST_INIT (ConnectionRefusedError );
2684
- ADD_ERRNO (ConnectionRefusedError , ECONNREFUSED );
2685
2712
POST_INIT (ConnectionResetError );
2686
- ADD_ERRNO (ConnectionResetError , ECONNRESET );
2687
2713
POST_INIT (FileExistsError );
2688
- ADD_ERRNO (FileExistsError , EEXIST );
2689
2714
POST_INIT (FileNotFoundError );
2690
- ADD_ERRNO (FileNotFoundError , ENOENT );
2691
2715
POST_INIT (IsADirectoryError );
2692
- ADD_ERRNO (IsADirectoryError , EISDIR );
2693
2716
POST_INIT (NotADirectoryError );
2694
- ADD_ERRNO (NotADirectoryError , ENOTDIR );
2695
2717
POST_INIT (InterruptedError );
2696
- ADD_ERRNO (InterruptedError , EINTR );
2697
2718
POST_INIT (PermissionError );
2698
- ADD_ERRNO (PermissionError , EACCES );
2699
- ADD_ERRNO (PermissionError , EPERM );
2700
2719
POST_INIT (ProcessLookupError );
2701
- ADD_ERRNO (ProcessLookupError , ESRCH );
2702
2720
POST_INIT (TimeoutError );
2703
- ADD_ERRNO (TimeoutError , ETIMEDOUT );
2704
2721
2705
- if (preallocate_memerrors () < 0 ) {
2706
- return _Py_INIT_ERR ("Could not preallocate MemoryError object" );
2707
- }
2708
2722
return _Py_INIT_OK ();
2709
2723
2710
- #undef PRE_INIT
2711
2724
#undef POST_INIT
2712
2725
#undef INIT_ALIAS
2713
- #undef ADD_ERRNO
2714
2726
}
2715
2727
2716
2728
void
0 commit comments