Skip to content

Commit a93e751

Browse files
committed
Use PyModule_AddType
Not exhaustive, but gets in most places it's immediately practical to.
1 parent c36a71a commit a93e751

File tree

9 files changed

+11
-68
lines changed

9 files changed

+11
-68
lines changed

src_c/_freetype.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,11 +2368,6 @@ MODINIT_DEFINE(_freetype)
23682368
return NULL;
23692369
}
23702370

2371-
/* type preparation */
2372-
if (PyType_Ready(&pgFont_Type) < 0) {
2373-
return NULL;
2374-
}
2375-
23762371
module = PyModule_Create(&_freetypemodule);
23772372

23782373
if (!module) {
@@ -2383,8 +2378,7 @@ MODINIT_DEFINE(_freetype)
23832378
FREETYPE_MOD_STATE(module)->cache_size = 0;
23842379
FREETYPE_MOD_STATE(module)->resolution = PGFT_DEFAULT_RESOLUTION;
23852380

2386-
if (PyModule_AddObjectRef(module, FONT_TYPE_NAME,
2387-
(PyObject *)&pgFont_Type)) {
2381+
if (PyModule_AddType(module, &pgFont_Type)) {
23882382
Py_DECREF(module);
23892383
return NULL;
23902384
}

src_c/_sdl2/controller.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -584,14 +584,7 @@ MODINIT_DEFINE(controller)
584584
return NULL;
585585
}
586586

587-
if (PyType_Ready(&pgController_Type) < 0) {
588-
return NULL;
589-
}
590-
591-
Py_INCREF(&pgController_Type);
592-
if (PyModule_AddObject(module, "Controller",
593-
(PyObject *)&pgController_Type)) {
594-
Py_DECREF(&pgController_Type);
587+
if (PyModule_AddType(module, &pgController_Type)) {
595588
Py_DECREF(module);
596589
return NULL;
597590
}

src_c/bufferproxy.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -591,11 +591,6 @@ MODINIT_DEFINE(bufferproxy)
591591
return NULL;
592592
}
593593

594-
/* prepare exported types */
595-
if (PyType_Ready(&pgBufferProxy_Type) < 0) {
596-
return NULL;
597-
}
598-
599594
#define bufferproxy_docs ""
600595

601596
/* create the module */
@@ -604,8 +599,7 @@ MODINIT_DEFINE(bufferproxy)
604599
return NULL;
605600
}
606601

607-
if (PyModule_AddObjectRef(module, "BufferProxy",
608-
(PyObject *)&pgBufferProxy_Type)) {
602+
if (PyModule_AddType(module, &pgBufferProxy_Type)) {
609603
Py_DECREF(module);
610604
return NULL;
611605
}

src_c/color.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2516,18 +2516,13 @@ MODINIT_DEFINE(color)
25162516
return NULL;
25172517
}
25182518

2519-
/* type preparation */
2520-
if (PyType_Ready(&pgColor_Type) < 0) {
2521-
goto error;
2522-
}
2523-
25242519
/* create the module */
25252520
module = PyModule_Create(&_module);
25262521
if (!module) {
25272522
goto error;
25282523
}
25292524

2530-
if (PyModule_AddObjectRef(module, "Color", (PyObject *)&pgColor_Type)) {
2525+
if (PyModule_AddType(module, &pgColor_Type)) {
25312526
goto error;
25322527
}
25332528
if (PyModule_AddObjectRef(module, "THECOLORS", _COLORDICT)) {

src_c/geometry.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,17 @@ MODINIT_DEFINE(geometry)
2727
return NULL;
2828
}
2929

30-
if (PyType_Ready(&pgCircle_Type) < 0) {
31-
return NULL;
32-
}
33-
34-
if (PyType_Ready(&pgLine_Type) < 0) {
35-
return NULL;
36-
}
37-
3830
module = PyModule_Create(&_module);
3931
if (!module) {
4032
return NULL;
4133
}
4234

43-
if (PyModule_AddObjectRef(module, "Circle", (PyObject *)&pgCircle_Type)) {
35+
if (PyModule_AddType(module, &pgCircle_Type)) {
4436
Py_DECREF(module);
4537
return NULL;
4638
}
4739

48-
if (PyModule_AddObjectRef(module, "Line", (PyObject *)&pgLine_Type)) {
40+
if (PyModule_AddType(module, &pgLine_Type)) {
4941
Py_DECREF(module);
5042
return NULL;
5143
}

src_c/newbuffer.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -853,14 +853,6 @@ MODINIT_DEFINE(newbuffer)
853853
NULL,
854854
NULL};
855855

856-
/* prepare exported types */
857-
if (PyType_Ready(&Py_buffer_Type) < 0) {
858-
return NULL;
859-
}
860-
if (PyType_Ready(&BufferMixin_Type) < 0) {
861-
return NULL;
862-
}
863-
864856
#define bufferproxy_docs ""
865857

866858
/* create the module */
@@ -869,13 +861,11 @@ MODINIT_DEFINE(newbuffer)
869861
return NULL;
870862
}
871863

872-
if (PyModule_AddObjectRef(module, "BufferMixin",
873-
(PyObject *)&BufferMixin_Type)) {
864+
if (PyModule_AddType(module, &BufferMixin_Type)) {
874865
Py_DECREF(module);
875866
return NULL;
876867
}
877-
if (PyModule_AddObjectRef(module, "Py_buffer",
878-
(PyObject *)&Py_buffer_Type)) {
868+
if (PyModule_AddType(module, &Py_buffer_Type)) {
879869
Py_DECREF(module);
880870
return NULL;
881871
}

src_c/pixelarray.c

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,18 +1926,12 @@ MODINIT_DEFINE(pixelarray)
19261926
return NULL;
19271927
}
19281928

1929-
/* type preparation */
1930-
if (PyType_Ready(&pgPixelArray_Type)) {
1931-
return NULL;
1932-
}
1933-
19341929
/* create the module */
19351930
module = PyModule_Create(&_module);
19361931
if (!module) {
19371932
return NULL;
19381933
}
1939-
if (PyModule_AddObjectRef(module, "PixelArray",
1940-
(PyObject *)&pgPixelArray_Type)) {
1934+
if (PyModule_AddType(module, &pgPixelArray_Type)) {
19411935
Py_DECREF(module);
19421936
return NULL;
19431937
}

src_c/time.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -743,18 +743,13 @@ MODINIT_DEFINE(time)
743743
return NULL;
744744
}
745745

746-
/* type preparation */
747-
if (PyType_Ready(&PyClock_Type) < 0) {
748-
return NULL;
749-
}
750-
751746
/* create the module */
752747
module = PyModule_Create(&_module);
753748
if (!module) {
754749
return NULL;
755750
}
756751

757-
if (PyModule_AddObjectRef(module, "Clock", (PyObject *)&PyClock_Type)) {
752+
if (PyModule_AddType(module, &PyClock_Type)) {
758753
Py_DECREF(module);
759754
return NULL;
760755
}

src_c/window.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,17 +1491,13 @@ MODINIT_DEFINE(window)
14911491
return NULL;
14921492
}
14931493

1494-
if (PyType_Ready(&pgWindow_Type) < 0) {
1495-
return NULL;
1496-
}
1497-
14981494
/* create the module */
14991495
module = PyModule_Create(&_module);
15001496
if (module == 0) {
15011497
return NULL;
15021498
}
15031499

1504-
if (PyModule_AddObjectRef(module, "Window", (PyObject *)&pgWindow_Type)) {
1500+
if (PyModule_AddType(module, &pgWindow_Type)) {
15051501
Py_DECREF(module);
15061502
return NULL;
15071503
}

0 commit comments

Comments
 (0)