pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/37fcbb65d4589fbb5a72153e9338cf8e6495f64f

bpo-40024: Update C extension modules to use PyModule_AddType() (GH-1… · python/cpython@37fcbb6 · GitHub
Skip to content

Commit 37fcbb6

Browse files
authored
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().
1 parent 15e5024 commit 37fcbb6

12 files changed

Lines changed: 67 additions & 134 deletions

File tree

Modules/_asynciomodule.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3391,9 +3391,6 @@ PyInit__asyncio(void)
33913391
if (module_init() < 0) {
33923392
return NULL;
33933393
}
3394-
if (PyType_Ready(&FutureType) < 0) {
3395-
return NULL;
3396-
}
33973394
if (PyType_Ready(&FutureIterType) < 0) {
33983395
return NULL;
33993396
}
@@ -3403,9 +3400,6 @@ PyInit__asyncio(void)
34033400
if (PyType_Ready(&TaskWakeupMethWrapper_Type) < 0) {
34043401
return NULL;
34053402
}
3406-
if (PyType_Ready(&TaskType) < 0) {
3407-
return NULL;
3408-
}
34093403
if (PyType_Ready(&PyRunningLoopHolder_Type) < 0) {
34103404
return NULL;
34113405
}
@@ -3415,16 +3409,13 @@ PyInit__asyncio(void)
34153409
return NULL;
34163410
}
34173411

3418-
Py_INCREF(&FutureType);
3419-
if (PyModule_AddObject(m, "Future", (PyObject *)&FutureType) < 0) {
3420-
Py_DECREF(&FutureType);
3412+
/* FutureType and TaskType are made ready by PyModule_AddType() calls below. */
3413+
if (PyModule_AddType(m, &FutureType) < 0) {
34213414
Py_DECREF(m);
34223415
return NULL;
34233416
}
34243417

3425-
Py_INCREF(&TaskType);
3426-
if (PyModule_AddObject(m, "Task", (PyObject *)&TaskType) < 0) {
3427-
Py_DECREF(&TaskType);
3418+
if (PyModule_AddType(m, &TaskType) < 0) {
34283419
Py_DECREF(m);
34293420
return NULL;
34303421
}

Modules/_blake2/blake2module.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,10 @@ PyInit__blake2(void)
6363

6464
/* BLAKE2b */
6565
Py_SET_TYPE(&PyBlake2_BLAKE2bType, &PyType_Type);
66-
if (PyType_Ready(&PyBlake2_BLAKE2bType) < 0) {
66+
if (PyModule_AddType(m, &PyBlake2_BLAKE2bType) < 0) {
6767
return NULL;
6868
}
6969

70-
Py_INCREF(&PyBlake2_BLAKE2bType);
71-
PyModule_AddObject(m, "blake2b", (PyObject *)&PyBlake2_BLAKE2bType);
72-
7370
d = PyBlake2_BLAKE2bType.tp_dict;
7471
ADD_INT(d, "SALT_SIZE", BLAKE2B_SALTBYTES);
7572
ADD_INT(d, "PERSON_SIZE", BLAKE2B_PERSONALBYTES);
@@ -83,13 +80,10 @@ PyInit__blake2(void)
8380

8481
/* BLAKE2s */
8582
Py_SET_TYPE(&PyBlake2_BLAKE2sType, &PyType_Type);
86-
if (PyType_Ready(&PyBlake2_BLAKE2sType) < 0) {
83+
if (PyModule_AddType(m, &PyBlake2_BLAKE2sType) < 0) {
8784
return NULL;
8885
}
8986

90-
Py_INCREF(&PyBlake2_BLAKE2sType);
91-
PyModule_AddObject(m, "blake2s", (PyObject *)&PyBlake2_BLAKE2sType);
92-
9387
d = PyBlake2_BLAKE2sType.tp_dict;
9488
ADD_INT(d, "SALT_SIZE", BLAKE2S_SALTBYTES);
9589
ADD_INT(d, "PERSON_SIZE", BLAKE2S_PERSONALBYTES);

Modules/_bz2module.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -731,24 +731,11 @@ static PyTypeObject BZ2Decompressor_Type = {
731731
static int
732732
_bz2_exec(PyObject *module)
733733
{
734-
if (PyType_Ready(&BZ2Compressor_Type) < 0) {
735-
return -1;
736-
}
737-
if (PyType_Ready(&BZ2Decompressor_Type) < 0) {
738-
return -1;
739-
}
740-
741-
Py_INCREF(&BZ2Compressor_Type);
742-
if (PyModule_AddObject(module, "BZ2Compressor",
743-
(PyObject *)&BZ2Compressor_Type) < 0) {
744-
Py_DECREF(&BZ2Compressor_Type);
734+
if (PyModule_AddType(module, &BZ2Compressor_Type) < 0) {
745735
return -1;
746736
}
747737

748-
Py_INCREF(&BZ2Decompressor_Type);
749-
if (PyModule_AddObject(module, "BZ2Decompressor",
750-
(PyObject *)&BZ2Decompressor_Type) < 0) {
751-
Py_INCREF(&BZ2Decompressor_Type);
738+
if (PyModule_AddType(module, &BZ2Decompressor_Type) < 0) {
752739
return -1;
753740
}
754741

Modules/_csv.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,9 +1633,6 @@ PyInit__csv(void)
16331633
PyObject *module;
16341634
const StyleDesc *style;
16351635

1636-
if (PyType_Ready(&Dialect_Type) < 0)
1637-
return NULL;
1638-
16391636
if (PyType_Ready(&Reader_Type) < 0)
16401637
return NULL;
16411638

@@ -1671,10 +1668,9 @@ PyInit__csv(void)
16711668
return NULL;
16721669
}
16731670

1674-
/* Add the Dialect type */
1675-
Py_INCREF(&Dialect_Type);
1676-
if (PyModule_AddObject(module, "Dialect", (PyObject *)&Dialect_Type))
1671+
if (PyModule_AddType(module, &Dialect_Type)) {
16771672
return NULL;
1673+
}
16781674

16791675
/* Add the CSV exception object to the module. */
16801676
get_csv_state(module)->error_obj = PyErr_NewException("_csv.Error", NULL, NULL);

Modules/_cursesmodule.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4740,7 +4740,8 @@ PyInit__curses(void)
47404740
SetDictInt("KEY_MAX", KEY_MAX);
47414741
}
47424742

4743-
Py_INCREF(&PyCursesWindow_Type);
4744-
PyModule_AddObject(m, "window", (PyObject *)&PyCursesWindow_Type);
4743+
if (PyModule_AddType(m, &PyCursesWindow_Type) < 0) {
4744+
return NULL;
4745+
}
47454746
return m;
47464747
}

Modules/_datetimemodule.c

Lines changed: 14 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6386,18 +6386,20 @@ PyInit__datetime(void)
63866386
if (m == NULL)
63876387
return NULL;
63886388

6389-
if (PyType_Ready(&PyDateTime_DateType) < 0)
6390-
return NULL;
6391-
if (PyType_Ready(&PyDateTime_DateTimeType) < 0)
6392-
return NULL;
6393-
if (PyType_Ready(&PyDateTime_DeltaType) < 0)
6394-
return NULL;
6395-
if (PyType_Ready(&PyDateTime_TimeType) < 0)
6396-
return NULL;
6397-
if (PyType_Ready(&PyDateTime_TZInfoType) < 0)
6398-
return NULL;
6399-
if (PyType_Ready(&PyDateTime_TimeZoneType) < 0)
6400-
return NULL;
6389+
PyTypeObject *types[] = {
6390+
&PyDateTime_DateType,
6391+
&PyDateTime_DateTimeType,
6392+
&PyDateTime_TimeType,
6393+
&PyDateTime_DeltaType,
6394+
&PyDateTime_TZInfoType,
6395+
&PyDateTime_TimeZoneType
6396+
};
6397+
6398+
for (size_t i = 0; i < Py_ARRAY_LENGTH(types); i++) {
6399+
if (PyModule_AddType(m, types[i]) < 0) {
6400+
return NULL;
6401+
}
6402+
}
64016403

64026404
/* timedelta values */
64036405
d = PyDateTime_DeltaType.tp_dict;
@@ -6515,25 +6517,6 @@ PyInit__datetime(void)
65156517
PyModule_AddIntMacro(m, MINYEAR);
65166518
PyModule_AddIntMacro(m, MAXYEAR);
65176519

6518-
Py_INCREF(&PyDateTime_DateType);
6519-
PyModule_AddObject(m, "date", (PyObject *) &PyDateTime_DateType);
6520-
6521-
Py_INCREF(&PyDateTime_DateTimeType);
6522-
PyModule_AddObject(m, "datetime",
6523-
(PyObject *)&PyDateTime_DateTimeType);
6524-
6525-
Py_INCREF(&PyDateTime_TimeType);
6526-
PyModule_AddObject(m, "time", (PyObject *) &PyDateTime_TimeType);
6527-
6528-
Py_INCREF(&PyDateTime_DeltaType);
6529-
PyModule_AddObject(m, "timedelta", (PyObject *) &PyDateTime_DeltaType);
6530-
6531-
Py_INCREF(&PyDateTime_TZInfoType);
6532-
PyModule_AddObject(m, "tzinfo", (PyObject *) &PyDateTime_TZInfoType);
6533-
6534-
Py_INCREF(&PyDateTime_TimeZoneType);
6535-
PyModule_AddObject(m, "timezone", (PyObject *) &PyDateTime_TimeZoneType);
6536-
65376520
x = PyCapsule_New(&CAPI, PyDateTime_CAPSULE_NAME, NULL);
65386521
if (x == NULL)
65396522
return NULL;

Modules/_io/_iomodule.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -684,12 +684,8 @@ PyInit__io(void)
684684
state = get_io_state(m);
685685
state->initialized = 0;
686686

687-
#define ADD_TYPE(type, name) \
688-
if (PyType_Ready(type) < 0) \
689-
goto fail; \
690-
Py_INCREF(type); \
691-
if (PyModule_AddObject(m, name, (PyObject *)type) < 0) { \
692-
Py_DECREF(type); \
687+
#define ADD_TYPE(type) \
688+
if (PyModule_AddType(m, type) < 0) { \
693689
goto fail; \
694690
}
695691

@@ -717,54 +713,54 @@ PyInit__io(void)
717713
/* Concrete base types of the IO ABCs.
718714
(the ABCs themselves are declared through inheritance in io.py)
719715
*/
720-
ADD_TYPE(&PyIOBase_Type, "_IOBase");
721-
ADD_TYPE(&PyRawIOBase_Type, "_RawIOBase");
722-
ADD_TYPE(&PyBufferedIOBase_Type, "_BufferedIOBase");
723-
ADD_TYPE(&PyTextIOBase_Type, "_TextIOBase");
716+
ADD_TYPE(&PyIOBase_Type);
717+
ADD_TYPE(&PyRawIOBase_Type);
718+
ADD_TYPE(&PyBufferedIOBase_Type);
719+
ADD_TYPE(&PyTextIOBase_Type);
724720

725721
/* Implementation of concrete IO objects. */
726722
/* FileIO */
727723
PyFileIO_Type.tp_base = &PyRawIOBase_Type;
728-
ADD_TYPE(&PyFileIO_Type, "FileIO");
724+
ADD_TYPE(&PyFileIO_Type);
729725

730726
/* BytesIO */
731727
PyBytesIO_Type.tp_base = &PyBufferedIOBase_Type;
732-
ADD_TYPE(&PyBytesIO_Type, "BytesIO");
728+
ADD_TYPE(&PyBytesIO_Type);
733729
if (PyType_Ready(&_PyBytesIOBuffer_Type) < 0)
734730
goto fail;
735731

736732
/* StringIO */
737733
PyStringIO_Type.tp_base = &PyTextIOBase_Type;
738-
ADD_TYPE(&PyStringIO_Type, "StringIO");
734+
ADD_TYPE(&PyStringIO_Type);
739735

740736
#ifdef MS_WINDOWS
741737
/* WindowsConsoleIO */
742738
PyWindowsConsoleIO_Type.tp_base = &PyRawIOBase_Type;
743-
ADD_TYPE(&PyWindowsConsoleIO_Type, "_WindowsConsoleIO");
739+
ADD_TYPE(&PyWindowsConsoleIO_Type);
744740
#endif
745741

746742
/* BufferedReader */
747743
PyBufferedReader_Type.tp_base = &PyBufferedIOBase_Type;
748-
ADD_TYPE(&PyBufferedReader_Type, "BufferedReader");
744+
ADD_TYPE(&PyBufferedReader_Type);
749745

750746
/* BufferedWriter */
751747
PyBufferedWriter_Type.tp_base = &PyBufferedIOBase_Type;
752-
ADD_TYPE(&PyBufferedWriter_Type, "BufferedWriter");
748+
ADD_TYPE(&PyBufferedWriter_Type);
753749

754750
/* BufferedRWPair */
755751
PyBufferedRWPair_Type.tp_base = &PyBufferedIOBase_Type;
756-
ADD_TYPE(&PyBufferedRWPair_Type, "BufferedRWPair");
752+
ADD_TYPE(&PyBufferedRWPair_Type);
757753

758754
/* BufferedRandom */
759755
PyBufferedRandom_Type.tp_base = &PyBufferedIOBase_Type;
760-
ADD_TYPE(&PyBufferedRandom_Type, "BufferedRandom");
756+
ADD_TYPE(&PyBufferedRandom_Type);
761757

762758
/* TextIOWrapper */
763759
PyTextIOWrapper_Type.tp_base = &PyTextIOBase_Type;
764-
ADD_TYPE(&PyTextIOWrapper_Type, "TextIOWrapper");
760+
ADD_TYPE(&PyTextIOWrapper_Type);
765761

766762
/* IncrementalNewlineDecoder */
767-
ADD_TYPE(&PyIncrementalNewlineDecoder_Type, "IncrementalNewlineDecoder");
763+
ADD_TYPE(&PyIncrementalNewlineDecoder_Type);
768764

769765
/* Interned strings */
770766
#define ADD_INTERNED(name) \

Modules/_operator.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,19 +1771,17 @@ PyInit__operator(void)
17711771
if (m == NULL)
17721772
return NULL;
17731773

1774-
if (PyType_Ready(&itemgetter_type) < 0)
1775-
return NULL;
1776-
Py_INCREF(&itemgetter_type);
1777-
PyModule_AddObject(m, "itemgetter", (PyObject *)&itemgetter_type);
1778-
1779-
if (PyType_Ready(&attrgetter_type) < 0)
1780-
return NULL;
1781-
Py_INCREF(&attrgetter_type);
1782-
PyModule_AddObject(m, "attrgetter", (PyObject *)&attrgetter_type);
1774+
PyTypeObject *types[] = {
1775+
&itemgetter_type,
1776+
&attrgetter_type,
1777+
&methodcaller_type
1778+
};
1779+
1780+
for (size_t i = 0; i < Py_ARRAY_LENGTH(types); i++) {
1781+
if (PyModule_AddType(m, types[i]) < 0) {
1782+
return NULL;
1783+
}
1784+
}
17831785

1784-
if (PyType_Ready(&methodcaller_type) < 0)
1785-
return NULL;
1786-
Py_INCREF(&methodcaller_type);
1787-
PyModule_AddObject(m, "methodcaller", (PyObject *)&methodcaller_type);
17881786
return m;
17891787
}

Modules/_pickle.c

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7993,10 +7993,6 @@ PyInit__pickle(void)
79937993
return m;
79947994
}
79957995

7996-
if (PyType_Ready(&Unpickler_Type) < 0)
7997-
return NULL;
7998-
if (PyType_Ready(&Pickler_Type) < 0)
7999-
return NULL;
80007996
if (PyType_Ready(&Pdata_Type) < 0)
80017997
return NULL;
80027998
if (PyType_Ready(&PicklerMemoProxyType) < 0)
@@ -8010,16 +8006,15 @@ PyInit__pickle(void)
80108006
return NULL;
80118007

80128008
/* Add types */
8013-
Py_INCREF(&Pickler_Type);
8014-
if (PyModule_AddObject(m, "Pickler", (PyObject *)&Pickler_Type) < 0)
8009+
if (PyModule_AddType(m, &Pickler_Type) < 0) {
80158010
return NULL;
8016-
Py_INCREF(&Unpickler_Type);
8017-
if (PyModule_AddObject(m, "Unpickler", (PyObject *)&Unpickler_Type) < 0)
8011+
}
8012+
if (PyModule_AddType(m, &Unpickler_Type) < 0) {
80188013
return NULL;
8019-
Py_INCREF(&PyPickleBuffer_Type);
8020-
if (PyModule_AddObject(m, "PickleBuffer",
8021-
(PyObject *)&PyPickleBuffer_Type) < 0)
8014+
}
8015+
if (PyModule_AddType(m, &PyPickleBuffer_Type) < 0) {
80228016
return NULL;
8017+
}
80238018

80248019
st = _Pickle_GetState(m);
80258020

Modules/_queuemodule.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,9 @@ PyInit__queue(void)
390390
if (PyModule_AddObject(m, "Empty", EmptyError) < 0)
391391
return NULL;
392392

393-
if (PyType_Ready(&PySimpleQueueType) < 0)
394-
return NULL;
395-
Py_INCREF(&PySimpleQueueType);
396-
if (PyModule_AddObject(m, "SimpleQueue", (PyObject *)&PySimpleQueueType) < 0)
393+
if (PyModule_AddType(m, &PySimpleQueueType) < 0) {
397394
return NULL;
395+
}
398396

399397
return m;
400398
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy