File tree 14 files changed +26
-116
lines changed
14 files changed +26
-116
lines changed Original file line number Diff line number Diff line change @@ -5740,15 +5740,9 @@ _ctypes_add_objects(PyObject *mod)
5740
5740
{
5741
5741
#define MOD_ADD (name , expr ) \
5742
5742
do { \
5743
- PyObject *obj = (expr); \
5744
- if (obj == NULL) { \
5743
+ if (PyModule_Add(mod, name, (expr)) < 0) { \
5745
5744
return -1; \
5746
5745
} \
5747
- if (PyModule_AddObjectRef(mod, name, obj) < 0) { \
5748
- Py_DECREF(obj); \
5749
- return -1; \
5750
- } \
5751
- Py_DECREF(obj); \
5752
5746
} while (0)
5753
5747
5754
5748
MOD_ADD ("_pointer_type_cache" , Py_NewRef (_ctypes_ptrtype_cache ));
Original file line number Diff line number Diff line change @@ -2189,7 +2189,6 @@ hashlib_init_constructors(PyObject *module)
2189
2189
*/
2190
2190
PyModuleDef * mdef ;
2191
2191
PyMethodDef * fdef ;
2192
- PyObject * proxy ;
2193
2192
PyObject * func , * name_obj ;
2194
2193
_hashlibstate * state = get_hashlib_state (module );
2195
2194
@@ -2224,17 +2223,8 @@ hashlib_init_constructors(PyObject *module)
2224
2223
}
2225
2224
}
2226
2225
2227
- proxy = PyDictProxy_New (state -> constructs );
2228
- if (proxy == NULL ) {
2229
- return -1 ;
2230
- }
2231
-
2232
- int rc = PyModule_AddObjectRef (module , "_constructors" , proxy );
2233
- Py_DECREF (proxy );
2234
- if (rc < 0 ) {
2235
- return -1 ;
2236
- }
2237
- return 0 ;
2226
+ return PyModule_Add (module , "_constructors" ,
2227
+ PyDictProxy_New (state -> constructs ));
2238
2228
}
2239
2229
2240
2230
static int
Original file line number Diff line number Diff line change @@ -1756,22 +1756,12 @@ static int
1756
1756
_json_exec (PyObject * module )
1757
1757
{
1758
1758
PyObject * PyScannerType = PyType_FromSpec (& PyScannerType_spec );
1759
- if (PyScannerType == NULL ) {
1760
- return -1 ;
1761
- }
1762
- int rc = PyModule_AddObjectRef (module , "make_scanner" , PyScannerType );
1763
- Py_DECREF (PyScannerType );
1764
- if (rc < 0 ) {
1759
+ if (PyModule_Add (module , "make_scanner" , PyScannerType ) < 0 ) {
1765
1760
return -1 ;
1766
1761
}
1767
1762
1768
1763
PyObject * PyEncoderType = PyType_FromSpec (& PyEncoderType_spec );
1769
- if (PyEncoderType == NULL ) {
1770
- return -1 ;
1771
- }
1772
- rc = PyModule_AddObjectRef (module , "make_encoder" , PyEncoderType );
1773
- Py_DECREF (PyEncoderType );
1774
- if (rc < 0 ) {
1764
+ if (PyModule_Add (module , "make_encoder" , PyEncoderType ) < 0 ) {
1775
1765
return -1 ;
1776
1766
}
1777
1767
Original file line number Diff line number Diff line change @@ -3195,12 +3195,7 @@ do { \
3195
3195
3196
3196
#define ADD_ULONG_CONSTANT (module , name , value ) \
3197
3197
do { \
3198
- PyObject *o = PyLong_FromUnsignedLong(value); \
3199
- if (!o) \
3200
- goto error; \
3201
- int res = PyModule_AddObjectRef(module, name, o); \
3202
- Py_DECREF(o); \
3203
- if (res < 0) { \
3198
+ if (PyModule_Add(module, name, PyLong_FromUnsignedLong(value)) < 0) { \
3204
3199
goto error; \
3205
3200
} \
3206
3201
} while (0)
Original file line number Diff line number Diff line change @@ -5773,13 +5773,7 @@ static int
5773
5773
sslmodule_add_option (PyObject * m , const char * name , uint64_t value )
5774
5774
{
5775
5775
Py_BUILD_ASSERT (sizeof (unsigned long long ) >= sizeof (value ));
5776
- PyObject * obj = PyLong_FromUnsignedLongLong (value );
5777
- if (obj == NULL ) {
5778
- return -1 ;
5779
- }
5780
- int res = PyModule_AddObjectRef (m , name , obj );
5781
- Py_DECREF (obj );
5782
- return res ;
5776
+ return PyModule_Add (m , name , PyLong_FromUnsignedLongLong (value ));
5783
5777
}
5784
5778
5785
5779
Original file line number Diff line number Diff line change @@ -692,13 +692,11 @@ _PyTestCapi_Init_Mem(PyObject *mod)
692
692
693
693
PyObject * v ;
694
694
#ifdef WITH_PYMALLOC
695
- v = Py_NewRef ( Py_True ) ;
695
+ v = Py_True ;
696
696
#else
697
- v = Py_NewRef ( Py_False ) ;
697
+ v = Py_False ;
698
698
#endif
699
- int rc = PyModule_AddObjectRef (mod , "WITH_PYMALLOC" , v );
700
- Py_DECREF (v );
701
- if (rc < 0 ) {
699
+ if (PyModule_AddObjectRef (mod , "WITH_PYMALLOC" , v ) < 0 ) {
702
700
return -1 ;
703
701
}
704
702
Original file line number Diff line number Diff line change @@ -516,13 +516,7 @@ static PyFunction_WatchCallback func_watcher_callbacks[NUM_TEST_FUNC_WATCHERS] =
516
516
static int
517
517
add_func_event (PyObject * module , const char * name , PyFunction_WatchEvent event )
518
518
{
519
- PyObject * value = PyLong_FromLong (event );
520
- if (value == NULL ) {
521
- return -1 ;
522
- }
523
- int ok = PyModule_AddObjectRef (module , name , value );
524
- Py_DECREF (value );
525
- return ok ;
519
+ return PyModule_Add (module , name , PyLong_FromLong (event ));
526
520
}
527
521
528
522
static PyObject *
Original file line number Diff line number Diff line change @@ -137,13 +137,7 @@ init_module(PyObject *module, module_state *state)
137
137
}
138
138
139
139
double d = _PyTime_AsSecondsDouble (state -> initialized );
140
- PyObject * initialized = PyFloat_FromDouble (d );
141
- if (initialized == NULL ) {
142
- return -1 ;
143
- }
144
- int rc = PyModule_AddObjectRef (module , "_module_initialized" , initialized );
145
- Py_DECREF (initialized );
146
- if (rc < 0 ) {
140
+ if (PyModule_Add (module , "_module_initialized" , PyFloat_FromDouble (d )) < 0 ) {
147
141
return -1 ;
148
142
}
149
143
Original file line number Diff line number Diff line change @@ -1812,16 +1812,13 @@ add_errors_module(PyObject *mod)
1812
1812
goto error ;
1813
1813
}
1814
1814
1815
- int rc = PyModule_AddObjectRef (errors_module , "codes" , codes_dict );
1816
- Py_CLEAR (codes_dict );
1817
- if (rc < 0 ) {
1818
- goto error ;
1815
+ if (PyModule_Add (errors_module , "codes" , codes_dict ) < 0 ) {
1816
+ Py_DECREF (rev_codes_dict );
1817
+ return -1 ;
1819
1818
}
1820
1819
1821
- rc = PyModule_AddObjectRef (errors_module , "messages" , rev_codes_dict );
1822
- Py_CLEAR (rev_codes_dict );
1823
- if (rc < 0 ) {
1824
- goto error ;
1820
+ if (PyModule_Add (errors_module , "messages" , rev_codes_dict ) < 0 ) {
1821
+ return -1 ;
1825
1822
}
1826
1823
1827
1824
return 0 ;
Original file line number Diff line number Diff line change @@ -7425,9 +7425,7 @@ socket_exec(PyObject *m)
7425
7425
sock_free_api (capi );
7426
7426
goto error ;
7427
7427
}
7428
- int rc = PyModule_AddObjectRef (m , PySocket_CAPI_NAME , capsule );
7429
- Py_DECREF (capsule );
7430
- if (rc < 0 ) {
7428
+ if (PyModule_Add (m , PySocket_CAPI_NAME , capsule ) < 0 ) {
7431
7429
goto error ;
7432
7430
}
7433
7431
@@ -8818,13 +8816,7 @@ socket_exec(PyObject *m)
8818
8816
};
8819
8817
int i ;
8820
8818
for (i = 0 ; i < Py_ARRAY_LENGTH (codes ); ++ i ) {
8821
- PyObject * tmp = PyLong_FromUnsignedLong (codes [i ]);
8822
- if (tmp == NULL ) {
8823
- goto error ;
8824
- }
8825
- int rc = PyModule_AddObjectRef (m , names [i ], tmp );
8826
- Py_DECREF (tmp );
8827
- if (rc < 0 ) {
8819
+ if (PyModule_Add (m , names [i ], PyLong_FromUnsignedLong (codes [i ])) < 0 ) {
8828
8820
goto error ;
8829
8821
}
8830
8822
}
Original file line number Diff line number Diff line change @@ -1496,13 +1496,7 @@ unicodedata_exec(PyObject *module)
1496
1496
}
1497
1497
1498
1498
/* Export C API */
1499
- PyObject * capsule = unicodedata_create_capi ();
1500
- if (capsule == NULL ) {
1501
- return -1 ;
1502
- }
1503
- int rc = PyModule_AddObjectRef (module , "_ucnhash_CAPI" , capsule );
1504
- Py_DECREF (capsule );
1505
- if (rc < 0 ) {
1499
+ if (PyModule_Add (module , "_ucnhash_CAPI" , unicodedata_create_capi ()) < 0 ) {
1506
1500
return -1 ;
1507
1501
}
1508
1502
return 0 ;
Original file line number Diff line number Diff line change @@ -565,15 +565,9 @@ static struct PyMethodDef msvcrt_functions[] = {
565
565
};
566
566
567
567
static int
568
- insertptr (PyObject * mod , char * name , void * value )
568
+ insertptr (PyObject * mod , const char * name , void * value )
569
569
{
570
- PyObject * v = PyLong_FromVoidPtr (value );
571
- if (v == NULL ) {
572
- return -1 ;
573
- }
574
- int rc = PyModule_AddObjectRef (mod , name , v );
575
- Py_DECREF (v );
576
- return rc ;
570
+ return PyModule_Add (mod , name , PyLong_FromVoidPtr (value ));
577
571
}
578
572
579
573
#define INSERTINT (MOD , NAME , VAL ) do { \
@@ -646,12 +640,7 @@ exec_module(PyObject* m)
646
640
_VC_CRT_MINOR_VERSION ,
647
641
_VC_CRT_BUILD_VERSION ,
648
642
_VC_CRT_RBUILD_VERSION );
649
- if (version == NULL ) {
650
- return -1 ;
651
- }
652
- int st = PyModule_AddObjectRef (m , "CRT_ASSEMBLY_VERSION" , version );
653
- Py_DECREF (version );
654
- if (st < 0 ) {
643
+ if (PyModule_Add (m , "CRT_ASSEMBLY_VERSION" , version ) < 0 ) {
655
644
return -1 ;
656
645
}
657
646
#endif
Original file line number Diff line number Diff line change @@ -2079,15 +2079,9 @@ static struct PyMethodDef winreg_methods[] = {
2079
2079
} while (0)
2080
2080
2081
2081
static int
2082
- inskey (PyObject * mod , char * name , HKEY key )
2082
+ inskey (PyObject * mod , const char * name , HKEY key )
2083
2083
{
2084
- PyObject * v = PyLong_FromVoidPtr (key );
2085
- if (v == NULL ) {
2086
- return -1 ;
2087
- }
2088
- int rc = PyModule_AddObjectRef (mod , name , v );
2089
- Py_DECREF (v );
2090
- return rc ;
2084
+ return PyModule_Add (mod , name , PyLong_FromVoidPtr (key ));
2091
2085
}
2092
2086
2093
2087
#define ADD_KEY (VAL ) do { \
Original file line number Diff line number Diff line change @@ -3844,14 +3844,9 @@ imp_module_exec(PyObject *module)
3844
3844
{
3845
3845
const wchar_t * mode = _Py_GetConfig ()-> check_hash_pycs_mode ;
3846
3846
PyObject * pyc_mode = PyUnicode_FromWideChar (mode , -1 );
3847
- if (pyc_mode == NULL ) {
3847
+ if (PyModule_Add ( module , "check_hash_based_pycs" , pyc_mode ) < 0 ) {
3848
3848
return -1 ;
3849
3849
}
3850
- if (PyModule_AddObjectRef (module , "check_hash_based_pycs" , pyc_mode ) < 0 ) {
3851
- Py_DECREF (pyc_mode );
3852
- return -1 ;
3853
- }
3854
- Py_DECREF (pyc_mode );
3855
3850
3856
3851
return 0 ;
3857
3852
}
You can’t perform that action at this time.
0 commit comments