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().
This commit is contained in:
parent
15e5024d04
commit
37fcbb65d4
|
@ -3391,9 +3391,6 @@ PyInit__asyncio(void)
|
|||
if (module_init() < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (PyType_Ready(&FutureType) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (PyType_Ready(&FutureIterType) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -3403,9 +3400,6 @@ PyInit__asyncio(void)
|
|||
if (PyType_Ready(&TaskWakeupMethWrapper_Type) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (PyType_Ready(&TaskType) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
if (PyType_Ready(&PyRunningLoopHolder_Type) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -3415,16 +3409,13 @@ PyInit__asyncio(void)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(&FutureType);
|
||||
if (PyModule_AddObject(m, "Future", (PyObject *)&FutureType) < 0) {
|
||||
Py_DECREF(&FutureType);
|
||||
/* FutureType and TaskType are made ready by PyModule_AddType() calls below. */
|
||||
if (PyModule_AddType(m, &FutureType) < 0) {
|
||||
Py_DECREF(m);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(&TaskType);
|
||||
if (PyModule_AddObject(m, "Task", (PyObject *)&TaskType) < 0) {
|
||||
Py_DECREF(&TaskType);
|
||||
if (PyModule_AddType(m, &TaskType) < 0) {
|
||||
Py_DECREF(m);
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -63,13 +63,10 @@ PyInit__blake2(void)
|
|||
|
||||
/* BLAKE2b */
|
||||
Py_SET_TYPE(&PyBlake2_BLAKE2bType, &PyType_Type);
|
||||
if (PyType_Ready(&PyBlake2_BLAKE2bType) < 0) {
|
||||
if (PyModule_AddType(m, &PyBlake2_BLAKE2bType) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(&PyBlake2_BLAKE2bType);
|
||||
PyModule_AddObject(m, "blake2b", (PyObject *)&PyBlake2_BLAKE2bType);
|
||||
|
||||
d = PyBlake2_BLAKE2bType.tp_dict;
|
||||
ADD_INT(d, "SALT_SIZE", BLAKE2B_SALTBYTES);
|
||||
ADD_INT(d, "PERSON_SIZE", BLAKE2B_PERSONALBYTES);
|
||||
|
@ -83,13 +80,10 @@ PyInit__blake2(void)
|
|||
|
||||
/* BLAKE2s */
|
||||
Py_SET_TYPE(&PyBlake2_BLAKE2sType, &PyType_Type);
|
||||
if (PyType_Ready(&PyBlake2_BLAKE2sType) < 0) {
|
||||
if (PyModule_AddType(m, &PyBlake2_BLAKE2sType) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_INCREF(&PyBlake2_BLAKE2sType);
|
||||
PyModule_AddObject(m, "blake2s", (PyObject *)&PyBlake2_BLAKE2sType);
|
||||
|
||||
d = PyBlake2_BLAKE2sType.tp_dict;
|
||||
ADD_INT(d, "SALT_SIZE", BLAKE2S_SALTBYTES);
|
||||
ADD_INT(d, "PERSON_SIZE", BLAKE2S_PERSONALBYTES);
|
||||
|
|
|
@ -731,24 +731,11 @@ static PyTypeObject BZ2Decompressor_Type = {
|
|||
static int
|
||||
_bz2_exec(PyObject *module)
|
||||
{
|
||||
if (PyType_Ready(&BZ2Compressor_Type) < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (PyType_Ready(&BZ2Decompressor_Type) < 0) {
|
||||
if (PyModule_AddType(module, &BZ2Compressor_Type) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Py_INCREF(&BZ2Compressor_Type);
|
||||
if (PyModule_AddObject(module, "BZ2Compressor",
|
||||
(PyObject *)&BZ2Compressor_Type) < 0) {
|
||||
Py_DECREF(&BZ2Compressor_Type);
|
||||
return -1;
|
||||
}
|
||||
|
||||
Py_INCREF(&BZ2Decompressor_Type);
|
||||
if (PyModule_AddObject(module, "BZ2Decompressor",
|
||||
(PyObject *)&BZ2Decompressor_Type) < 0) {
|
||||
Py_INCREF(&BZ2Decompressor_Type);
|
||||
if (PyModule_AddType(module, &BZ2Decompressor_Type) < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
@ -1633,9 +1633,6 @@ PyInit__csv(void)
|
|||
PyObject *module;
|
||||
const StyleDesc *style;
|
||||
|
||||
if (PyType_Ready(&Dialect_Type) < 0)
|
||||
return NULL;
|
||||
|
||||
if (PyType_Ready(&Reader_Type) < 0)
|
||||
return NULL;
|
||||
|
||||
|
@ -1671,10 +1668,9 @@ PyInit__csv(void)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Add the Dialect type */
|
||||
Py_INCREF(&Dialect_Type);
|
||||
if (PyModule_AddObject(module, "Dialect", (PyObject *)&Dialect_Type))
|
||||
if (PyModule_AddType(module, &Dialect_Type)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Add the CSV exception object to the module. */
|
||||
get_csv_state(module)->error_obj = PyErr_NewException("_csv.Error", NULL, NULL);
|
||||
|
|
|
@ -4740,7 +4740,8 @@ PyInit__curses(void)
|
|||
SetDictInt("KEY_MAX", KEY_MAX);
|
||||
}
|
||||
|
||||
Py_INCREF(&PyCursesWindow_Type);
|
||||
PyModule_AddObject(m, "window", (PyObject *)&PyCursesWindow_Type);
|
||||
if (PyModule_AddType(m, &PyCursesWindow_Type) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
return m;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
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;
|
||||
|
|
|
@ -684,12 +684,8 @@ PyInit__io(void)
|
|||
state = get_io_state(m);
|
||||
state->initialized = 0;
|
||||
|
||||
#define ADD_TYPE(type, name) \
|
||||
if (PyType_Ready(type) < 0) \
|
||||
goto fail; \
|
||||
Py_INCREF(type); \
|
||||
if (PyModule_AddObject(m, name, (PyObject *)type) < 0) { \
|
||||
Py_DECREF(type); \
|
||||
#define ADD_TYPE(type) \
|
||||
if (PyModule_AddType(m, type) < 0) { \
|
||||
goto fail; \
|
||||
}
|
||||
|
||||
|
@ -717,54 +713,54 @@ PyInit__io(void)
|
|||
/* Concrete base types of the IO ABCs.
|
||||
(the ABCs themselves are declared through inheritance in io.py)
|
||||
*/
|
||||
ADD_TYPE(&PyIOBase_Type, "_IOBase");
|
||||
ADD_TYPE(&PyRawIOBase_Type, "_RawIOBase");
|
||||
ADD_TYPE(&PyBufferedIOBase_Type, "_BufferedIOBase");
|
||||
ADD_TYPE(&PyTextIOBase_Type, "_TextIOBase");
|
||||
ADD_TYPE(&PyIOBase_Type);
|
||||
ADD_TYPE(&PyRawIOBase_Type);
|
||||
ADD_TYPE(&PyBufferedIOBase_Type);
|
||||
ADD_TYPE(&PyTextIOBase_Type);
|
||||
|
||||
/* Implementation of concrete IO objects. */
|
||||
/* FileIO */
|
||||
PyFileIO_Type.tp_base = &PyRawIOBase_Type;
|
||||
ADD_TYPE(&PyFileIO_Type, "FileIO");
|
||||
ADD_TYPE(&PyFileIO_Type);
|
||||
|
||||
/* BytesIO */
|
||||
PyBytesIO_Type.tp_base = &PyBufferedIOBase_Type;
|
||||
ADD_TYPE(&PyBytesIO_Type, "BytesIO");
|
||||
ADD_TYPE(&PyBytesIO_Type);
|
||||
if (PyType_Ready(&_PyBytesIOBuffer_Type) < 0)
|
||||
goto fail;
|
||||
|
||||
/* StringIO */
|
||||
PyStringIO_Type.tp_base = &PyTextIOBase_Type;
|
||||
ADD_TYPE(&PyStringIO_Type, "StringIO");
|
||||
ADD_TYPE(&PyStringIO_Type);
|
||||
|
||||
#ifdef MS_WINDOWS
|
||||
/* WindowsConsoleIO */
|
||||
PyWindowsConsoleIO_Type.tp_base = &PyRawIOBase_Type;
|
||||
ADD_TYPE(&PyWindowsConsoleIO_Type, "_WindowsConsoleIO");
|
||||
ADD_TYPE(&PyWindowsConsoleIO_Type);
|
||||
#endif
|
||||
|
||||
/* BufferedReader */
|
||||
PyBufferedReader_Type.tp_base = &PyBufferedIOBase_Type;
|
||||
ADD_TYPE(&PyBufferedReader_Type, "BufferedReader");
|
||||
ADD_TYPE(&PyBufferedReader_Type);
|
||||
|
||||
/* BufferedWriter */
|
||||
PyBufferedWriter_Type.tp_base = &PyBufferedIOBase_Type;
|
||||
ADD_TYPE(&PyBufferedWriter_Type, "BufferedWriter");
|
||||
ADD_TYPE(&PyBufferedWriter_Type);
|
||||
|
||||
/* BufferedRWPair */
|
||||
PyBufferedRWPair_Type.tp_base = &PyBufferedIOBase_Type;
|
||||
ADD_TYPE(&PyBufferedRWPair_Type, "BufferedRWPair");
|
||||
ADD_TYPE(&PyBufferedRWPair_Type);
|
||||
|
||||
/* BufferedRandom */
|
||||
PyBufferedRandom_Type.tp_base = &PyBufferedIOBase_Type;
|
||||
ADD_TYPE(&PyBufferedRandom_Type, "BufferedRandom");
|
||||
ADD_TYPE(&PyBufferedRandom_Type);
|
||||
|
||||
/* TextIOWrapper */
|
||||
PyTextIOWrapper_Type.tp_base = &PyTextIOBase_Type;
|
||||
ADD_TYPE(&PyTextIOWrapper_Type, "TextIOWrapper");
|
||||
ADD_TYPE(&PyTextIOWrapper_Type);
|
||||
|
||||
/* IncrementalNewlineDecoder */
|
||||
ADD_TYPE(&PyIncrementalNewlineDecoder_Type, "IncrementalNewlineDecoder");
|
||||
ADD_TYPE(&PyIncrementalNewlineDecoder_Type);
|
||||
|
||||
/* Interned strings */
|
||||
#define ADD_INTERNED(name) \
|
||||
|
|
|
@ -1771,19 +1771,17 @@ PyInit__operator(void)
|
|||
if (m == NULL)
|
||||
return NULL;
|
||||
|
||||
if (PyType_Ready(&itemgetter_type) < 0)
|
||||
return NULL;
|
||||
Py_INCREF(&itemgetter_type);
|
||||
PyModule_AddObject(m, "itemgetter", (PyObject *)&itemgetter_type);
|
||||
PyTypeObject *types[] = {
|
||||
&itemgetter_type,
|
||||
&attrgetter_type,
|
||||
&methodcaller_type
|
||||
};
|
||||
|
||||
if (PyType_Ready(&attrgetter_type) < 0)
|
||||
for (size_t i = 0; i < Py_ARRAY_LENGTH(types); i++) {
|
||||
if (PyModule_AddType(m, types[i]) < 0) {
|
||||
return NULL;
|
||||
Py_INCREF(&attrgetter_type);
|
||||
PyModule_AddObject(m, "attrgetter", (PyObject *)&attrgetter_type);
|
||||
}
|
||||
}
|
||||
|
||||
if (PyType_Ready(&methodcaller_type) < 0)
|
||||
return NULL;
|
||||
Py_INCREF(&methodcaller_type);
|
||||
PyModule_AddObject(m, "methodcaller", (PyObject *)&methodcaller_type);
|
||||
return m;
|
||||
}
|
||||
|
|
|
@ -7993,10 +7993,6 @@ PyInit__pickle(void)
|
|||
return m;
|
||||
}
|
||||
|
||||
if (PyType_Ready(&Unpickler_Type) < 0)
|
||||
return NULL;
|
||||
if (PyType_Ready(&Pickler_Type) < 0)
|
||||
return NULL;
|
||||
if (PyType_Ready(&Pdata_Type) < 0)
|
||||
return NULL;
|
||||
if (PyType_Ready(&PicklerMemoProxyType) < 0)
|
||||
|
@ -8010,16 +8006,15 @@ PyInit__pickle(void)
|
|||
return NULL;
|
||||
|
||||
/* Add types */
|
||||
Py_INCREF(&Pickler_Type);
|
||||
if (PyModule_AddObject(m, "Pickler", (PyObject *)&Pickler_Type) < 0)
|
||||
if (PyModule_AddType(m, &Pickler_Type) < 0) {
|
||||
return NULL;
|
||||
Py_INCREF(&Unpickler_Type);
|
||||
if (PyModule_AddObject(m, "Unpickler", (PyObject *)&Unpickler_Type) < 0)
|
||||
}
|
||||
if (PyModule_AddType(m, &Unpickler_Type) < 0) {
|
||||
return NULL;
|
||||
Py_INCREF(&PyPickleBuffer_Type);
|
||||
if (PyModule_AddObject(m, "PickleBuffer",
|
||||
(PyObject *)&PyPickleBuffer_Type) < 0)
|
||||
}
|
||||
if (PyModule_AddType(m, &PyPickleBuffer_Type) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
st = _Pickle_GetState(m);
|
||||
|
||||
|
|
|
@ -390,11 +390,9 @@ PyInit__queue(void)
|
|||
if (PyModule_AddObject(m, "Empty", EmptyError) < 0)
|
||||
return NULL;
|
||||
|
||||
if (PyType_Ready(&PySimpleQueueType) < 0)
|
||||
return NULL;
|
||||
Py_INCREF(&PySimpleQueueType);
|
||||
if (PyModule_AddObject(m, "SimpleQueue", (PyObject *)&PySimpleQueueType) < 0)
|
||||
if (PyModule_AddType(m, &PySimpleQueueType) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
|
|
@ -2059,14 +2059,12 @@ static struct PyModuleDef _multibytecodecmodule = {
|
|||
PyMODINIT_FUNC
|
||||
PyInit__multibytecodec(void)
|
||||
{
|
||||
int i;
|
||||
PyObject *m;
|
||||
PyTypeObject *typelist[] = {
|
||||
&MultibyteIncrementalEncoder_Type,
|
||||
&MultibyteIncrementalDecoder_Type,
|
||||
&MultibyteStreamReader_Type,
|
||||
&MultibyteStreamWriter_Type,
|
||||
NULL
|
||||
&MultibyteStreamWriter_Type
|
||||
};
|
||||
|
||||
if (PyType_Ready(&MultibyteCodec_Type) < 0)
|
||||
|
@ -2076,12 +2074,10 @@ PyInit__multibytecodec(void)
|
|||
if (m == NULL)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; typelist[i] != NULL; i++) {
|
||||
if (PyType_Ready(typelist[i]) < 0)
|
||||
for (size_t i = 0; i < Py_ARRAY_LENGTH(typelist); i++) {
|
||||
if (PyModule_AddType(m, typelist[i]) < 0) {
|
||||
return NULL;
|
||||
Py_INCREF(typelist[i]);
|
||||
PyModule_AddObject(m, typelist[i]->tp_name,
|
||||
(PyObject *)typelist[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (PyErr_Occurred()) {
|
||||
|
|
|
@ -1860,12 +1860,10 @@ PyInit__overlapped(void)
|
|||
if (initialize_function_pointers() < 0)
|
||||
return NULL;
|
||||
|
||||
if (PyType_Ready(&OverlappedType) < 0)
|
||||
return NULL;
|
||||
|
||||
m = PyModule_Create(&overlapped_module);
|
||||
if (PyModule_AddObject(m, "Overlapped", (PyObject *)&OverlappedType) < 0)
|
||||
if (PyModule_AddType(m, &OverlappedType) < 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
d = PyModule_GetDict(m);
|
||||
|
||||
|
|
Loading…
Reference in New Issue