Skip to content

Commit 4b6303a

Browse files
authored
Merge pull request #3453 from Starbuck5/math-minor-things
Simplify math module init
2 parents 04f4ad6 + fb8c30c commit 4b6303a

File tree

3 files changed

+6
-52
lines changed

3 files changed

+6
-52
lines changed

src_c/_pygame.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,6 @@ typedef enum {
670670
#define PYGAMEAPI_RWOBJECT_NUMSLOTS 5
671671
#define PYGAMEAPI_PIXELARRAY_NUMSLOTS 2
672672
#define PYGAMEAPI_COLOR_NUMSLOTS 5
673-
#define PYGAMEAPI_MATH_NUMSLOTS 2
674673
#define PYGAMEAPI_BASE_NUMSLOTS 30
675674
#define PYGAMEAPI_EVENT_NUMSLOTS 10
676675
#define PYGAMEAPI_WINDOW_NUMSLOTS 1

src_c/include/_pygame.h

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -509,26 +509,10 @@ typedef struct pgColorObject pgColorObject;
509509
#endif /* PYGAMEAPI_COLOR_INTERNAL */
510510

511511
/*
512-
* Math module
512+
* Geometry module
513513
*/
514-
#ifndef PYGAMEAPI_MATH_INTERNAL
515-
#define pgVector2_Check(x) \
516-
((x)->ob_type == (PyTypeObject *)PYGAMEAPI_GET_SLOT(math, 0))
517-
518-
#define pgVector3_Check(x) \
519-
((x)->ob_type == (PyTypeObject *)PYGAMEAPI_GET_SLOT(math, 1))
520-
/*
521-
#define pgVector2_New \
522-
(*(PyObject*(*)) \
523-
PYGAMEAPI_GET_SLOT(PyGAME_C_API, 1))
524-
*/
525-
#define import_pygame_math() IMPORT_PYGAME_MODULE(math)
526-
#endif /* PYGAMEAPI_MATH_INTERNAL */
527-
528514
#ifndef PYGAMEAPI_GEOMETRY_INTERNAL
529-
530515
#define import_pygame_geometry() IMPORT_PYGAME_MODULE(geometry)
531-
532516
#endif /* ~PYGAMEAPI_GEOMETRY_INTERNAL */
533517

534518
/*

src_c/math.c

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4625,9 +4625,7 @@ MODINIT_DEFINE(pg_math)
46254625
MODINIT_DEFINE(math)
46264626
#endif
46274627
{
4628-
PyObject *module, *apiobj;
4629-
static void *c_api[PYGAMEAPI_MATH_NUMSLOTS];
4630-
4628+
PyObject *module;
46314629
static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
46324630
"math",
46334631
DOC_MATH,
@@ -4638,14 +4636,6 @@ MODINIT_DEFINE(math)
46384636
NULL,
46394637
NULL};
46404638

4641-
/* initialize the extension types */
4642-
if ((PyType_Ready(&pgVector2_Type) < 0) ||
4643-
(PyType_Ready(&pgVector3_Type) < 0) ||
4644-
(PyType_Ready(&pgVectorIter_Type) < 0) ||
4645-
(PyType_Ready(&pgVectorElementwiseProxy_Type) < 0)) {
4646-
return NULL;
4647-
}
4648-
46494639
/* initialize the module */
46504640
module = PyModule_Create(&_module);
46514641

@@ -4654,29 +4644,10 @@ MODINIT_DEFINE(math)
46544644
}
46554645

46564646
/* add extension types to module */
4657-
if ((PyModule_AddObjectRef(module, "Vector2",
4658-
(PyObject *)&pgVector2_Type) < 0) ||
4659-
(PyModule_AddObjectRef(module, "Vector3",
4660-
(PyObject *)&pgVector3_Type) < 0) ||
4661-
(PyModule_AddObjectRef(module, "VectorElementwiseProxy",
4662-
(PyObject *)&pgVectorElementwiseProxy_Type) <
4663-
0) ||
4664-
(PyModule_AddObjectRef(module, "VectorIterator",
4665-
(PyObject *)&pgVectorIter_Type) < 0)) {
4666-
Py_DECREF(module);
4667-
return NULL;
4668-
}
4669-
4670-
/* export the C api */
4671-
c_api[0] = &pgVector2_Type;
4672-
c_api[1] = &pgVector3_Type;
4673-
/*
4674-
c_api[2] = pgVector_NEW;
4675-
c_api[3] = pgVectorCompatible_Check;
4676-
*/
4677-
apiobj = encapsulate_api(c_api, "math");
4678-
if (PyModule_AddObject(module, PYGAMEAPI_LOCAL_ENTRY, apiobj)) {
4679-
Py_XDECREF(apiobj);
4647+
if ((PyModule_AddType(module, &pgVector2_Type) < 0) ||
4648+
(PyModule_AddType(module, &pgVector3_Type) < 0) ||
4649+
(PyModule_AddType(module, &pgVectorElementwiseProxy_Type) < 0) ||
4650+
(PyModule_AddType(module, &pgVectorIter_Type) < 0)) {
46804651
Py_DECREF(module);
46814652
return NULL;
46824653
}

0 commit comments

Comments
 (0)