summaryrefslogtreecommitdiffstats
path: root/Modules/_datetimemodule.c
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na92@gmail.com>2020-03-24 22:08:51 (GMT)
committerGitHub <noreply@github.com>2020-03-24 22:08:51 (GMT)
commit37fcbb65d4589fbb5a72153e9338cf8e6495f64f (patch)
treee0c1e2f0b9d5673779ec74b71fef3fc158158ae1 /Modules/_datetimemodule.c
parent15e5024d04fc89d948ae761d88048bc58a56b650 (diff)
downloadcpython-37fcbb65d4589fbb5a72153e9338cf8e6495f64f.zip
cpython-37fcbb65d4589fbb5a72153e9338cf8e6495f64f.tar.gz
cpython-37fcbb65d4589fbb5a72153e9338cf8e6495f64f.tar.bz2
bpo-40024: Update C extension modules to use PyModule_AddType() (GH-19119)
Update _asyncio, _bz2, _csv, _curses, _datetime, _io, _operator, _pickle, _queue, blake2, multibytecodec and overlapped C extension modules to use PyModule_AddType().
Diffstat (limited to 'Modules/_datetimemodule.c')
-rw-r--r--Modules/_datetimemodule.c45
1 files changed, 14 insertions, 31 deletions
diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c
index 4c985b3..f7c1b69 100644
--- a/Modules/_datetimemodule.c
+++ b/Modules/_datetimemodule.c
@@ -6386,18 +6386,20 @@ PyInit__datetime(void)
if (m == NULL)
return NULL;
- if (PyType_Ready(&PyDateTime_DateType) < 0)
- return NULL;
- if (PyType_Ready(&PyDateTime_DateTimeType) < 0)
- return NULL;
- if (PyType_Ready(&PyDateTime_DeltaType) < 0)
- return NULL;
- if (PyType_Ready(&PyDateTime_TimeType) < 0)
- return NULL;
- if (PyType_Ready(&PyDateTime_TZInfoType) < 0)
- return NULL;
- if (PyType_Ready(&PyDateTime_TimeZoneType) < 0)
- return NULL;
+ PyTypeObject *types[] = {
+ &PyDateTime_DateType,
+ &PyDateTime_DateTimeType,
+ &PyDateTime_TimeType,
+ &PyDateTime_DeltaType,
+ &PyDateTime_TZInfoType,
+ &PyDateTime_TimeZoneType
+ };
+
+ for (size_t i = 0; i < Py_ARRAY_LENGTH(types); i++) {
+ if (PyModule_AddType(m, types[i]) < 0) {
+ return NULL;
+ }
+ }
/* timedelta values */
d = PyDateTime_DeltaType.tp_dict;
@@ -6515,25 +6517,6 @@ PyInit__datetime(void)
PyModule_AddIntMacro(m, MINYEAR);
PyModule_AddIntMacro(m, MAXYEAR);
- Py_INCREF(&PyDateTime_DateType);
- PyModule_AddObject(m, "date", (PyObject *) &PyDateTime_DateType);
-
- Py_INCREF(&PyDateTime_DateTimeType);
- PyModule_AddObject(m, "datetime",
- (PyObject *)&PyDateTime_DateTimeType);
-
- Py_INCREF(&PyDateTime_TimeType);
- PyModule_AddObject(m, "time", (PyObject *) &PyDateTime_TimeType);
-
- Py_INCREF(&PyDateTime_DeltaType);
- PyModule_AddObject(m, "timedelta", (PyObject *) &PyDateTime_DeltaType);
-
- Py_INCREF(&PyDateTime_TZInfoType);
- PyModule_AddObject(m, "tzinfo", (PyObject *) &PyDateTime_TZInfoType);
-
- Py_INCREF(&PyDateTime_TimeZoneType);
- PyModule_AddObject(m, "timezone", (PyObject *) &PyDateTime_TimeZoneType);
-
x = PyCapsule_New(&CAPI, PyDateTime_CAPSULE_NAME, NULL);
if (x == NULL)
return NULL;