Skip to content

Commit 152ec5b

Browse files
committed
Remove most PY2 compatibility c code
1 parent 705cee0 commit 152ec5b

38 files changed

+9
-720
lines changed

src_c/_camera.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,6 @@ MODINIT_DEFINE(_camera)
19451945
* the module is not loaded.
19461946
*/
19471947

1948-
#if PY3
19491948
static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
19501949
"_camera",
19511950
DOC_PYGAMECAMERA,
@@ -1955,7 +1954,6 @@ MODINIT_DEFINE(_camera)
19551954
NULL,
19561955
NULL,
19571956
NULL};
1958-
#endif
19591957

19601958
import_pygame_base();
19611959
if (PyErr_Occurred()) {
@@ -1974,11 +1972,7 @@ MODINIT_DEFINE(_camera)
19741972
}
19751973

19761974
/* create the module */
1977-
#if PY3
19781975
module = PyModule_Create(&_module);
1979-
#else
1980-
module = Py_InitModule3("_camera", camera_builtins, DOC_PYGAMECAMERA);
1981-
#endif
19821976

19831977
Py_INCREF(&pgCamera_Type);
19841978
PyModule_AddObject(module, "CameraType", (PyObject *)&pgCamera_Type);

src_c/_freetype.c

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@
3535
*/
3636
static const Scale_t FACE_SIZE_NONE = {0, 0};
3737

38-
#if PY3
3938
static int
4039
_ft_traverse(PyObject *, visitproc, void *);
4140
static int
4241
_ft_clear(PyObject *);
43-
#endif
4442

4543
static PyObject *
4644
_ft_quit(PyObject *);
@@ -238,7 +236,6 @@ load_font_res(const char *filename)
238236
goto font_resource_end;
239237
}
240238

241-
#if PY3
242239
tmp = PyObject_GetAttrString(result, "name");
243240
if (tmp) {
244241
PyObject *closeret;
@@ -256,25 +253,6 @@ load_font_res(const char *filename)
256253
else {
257254
PyErr_Clear();
258255
}
259-
#else
260-
if (PyFile_Check(result)) {
261-
PyObject *closeret;
262-
263-
tmp = PyFile_Name(result);
264-
Py_INCREF(tmp);
265-
266-
if (!(closeret = PyObject_CallMethod(result, "close", NULL))) {
267-
Py_DECREF(result);
268-
Py_DECREF(tmp);
269-
result = NULL;
270-
goto font_resource_end;
271-
}
272-
Py_DECREF(closeret);
273-
274-
Py_DECREF(result);
275-
result = tmp;
276-
}
277-
#endif
278256

279257
font_resource_end:
280258
Py_XDECREF(pkgdatamodule);
@@ -354,9 +332,6 @@ objs_to_scale(PyObject *x, PyObject *y, Scale_t *size)
354332

355333
for (o = x, do_y = 1; o; o = (do_y--) ? y : 0) {
356334
if (!PyLong_Check(o) &&
357-
#if PY2
358-
!PyInt_Check(o) &&
359-
#endif
360335
!PyFloat_Check(o)) {
361336
if (y) {
362337
PyErr_Format(PyExc_TypeError,
@@ -475,11 +450,6 @@ obj_to_rotation(PyObject *o, void *p)
475450
if (PyLong_Check(o)) {
476451
;
477452
}
478-
#if PY2
479-
else if (PyInt_Check(o)) {
480-
;
481-
}
482-
#endif
483453
else {
484454
PyErr_Format(PyExc_TypeError, "integer rotation expected, got %s",
485455
Py_TYPE(o)->tp_name);
@@ -959,20 +929,7 @@ static PyObject *
959929
_ftfont_repr(pgFontObject *self)
960930
{
961931
if (pgFont_IS_ALIVE(self)) {
962-
#if PY3
963932
return PyUnicode_FromFormat("Font('%.1024U')", self->path);
964-
#else
965-
PyObject *str = PyUnicode_AsEncodedString(
966-
self->path, "raw_unicode_escape", "replace");
967-
PyObject *rval = 0;
968-
969-
if (str) {
970-
rval = PyString_FromFormat("Font('%.1024s')",
971-
PyString_AS_STRING(str));
972-
Py_DECREF(str);
973-
}
974-
return rval;
975-
#endif
976933
}
977934
return Text_FromFormat("<uninitialized Font object at %p>", (void *)self);
978935
}
@@ -2193,7 +2150,6 @@ _ft_get_default_font(PyObject *self, PyObject *args)
21932150
return Text_FromUTF8(DEFAULT_FONT_NAME);
21942151
}
21952152

2196-
#if PY3
21972153
static int
21982154
_ft_traverse(PyObject *mod, visitproc visit, void *arg)
21992155
{
@@ -2209,12 +2165,10 @@ _ft_clear(PyObject *mod)
22092165
}
22102166
return 0;
22112167
}
2212-
#endif
22132168

22142169
/****************************************************
22152170
* FREETYPE MODULE DECLARATION
22162171
****************************************************/
2217-
#if PY3
22182172
#ifndef PYPY_VERSION
22192173
struct PyModuleDef _freetypemodule = {
22202174
PyModuleDef_HEAD_INIT, MODULE_NAME, DOC_PYGAMEFREETYPE,
@@ -2227,9 +2181,6 @@ struct PyModuleDef _freetypemodule = {
22272181
-1 /* PyModule_GetState() not implemented */, _ft_methods, 0,
22282182
_ft_traverse, _ft_clear, 0};
22292183
#endif /* PYPY_VERSION */
2230-
#else /* PY2 */
2231-
_FreeTypeState _modstate;
2232-
#endif /* PY2 */
22332184

22342185
MODINIT_DEFINE(_freetype)
22352186
{
@@ -2266,12 +2217,7 @@ MODINIT_DEFINE(_freetype)
22662217
MODINIT_ERROR;
22672218
}
22682219

2269-
#if PY3
22702220
module = PyModule_Create(&_freetypemodule);
2271-
#else
2272-
/* TODO: DOC */
2273-
module = Py_InitModule3(MODULE_NAME, _ft_methods, DOC_PYGAMEFREETYPE);
2274-
#endif
22752221

22762222
if (!module) {
22772223
MODINIT_ERROR;

src_c/_sdl2/touch.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,6 @@ static PyMethodDef _touch_methods[] = {
129129
MODINIT_DEFINE(touch)
130130
{
131131
PyObject *module;
132-
#if PY3
133132
static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
134133
"touch",
135134
DOC_PYGAMESDL2TOUCH,
@@ -139,19 +138,13 @@ MODINIT_DEFINE(touch)
139138
NULL,
140139
NULL,
141140
NULL};
142-
#endif
143141
import_pygame_base();
144142
if (PyErr_Occurred()) {
145143
MODINIT_ERROR;
146144
}
147145

148146
/* create the module */
149-
#if PY3
150147
module = PyModule_Create(&_module);
151-
#else
152-
module = Py_InitModule3(MODPREFIX "touch", _touch_methods,
153-
DOC_PYGAMESDL2TOUCH);
154-
#endif
155148
if (module == NULL) {
156149
MODINIT_ERROR;
157150
}

src_c/base.c

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,8 @@ static int
148148
_pg_as_arrayinter_flags(Py_buffer *);
149149
static pgCapsuleInterface *
150150
_pg_new_capsuleinterface(Py_buffer *);
151-
#if PY3
152151
static void
153152
_pg_capsule_PyMem_Free(PyObject *);
154-
#endif
155153
static PyObject *
156154
_pg_shape_as_tuple(PyArrayInterface *);
157155
static PyObject *
@@ -658,35 +656,35 @@ pg_RGBAFromObj(PyObject *obj, Uint8 *RGBA)
658656
static PyObject *
659657
pg_get_error(PyObject *self)
660658
{
661-
#if IS_SDLv1 && PY3 && !defined(PYPY_VERSION)
659+
#if IS_SDLv1 && !defined(PYPY_VERSION)
662660
/* SDL 1's encoding is ambiguous */
663661
PyObject *obj;
664662
if ((obj = PyUnicode_DecodeUTF8(SDL_GetError(),
665663
strlen(SDL_GetError()), "strict")))
666664
return obj;
667665
PyErr_Clear();
668666
return PyUnicode_DecodeLocale(SDL_GetError(), "surrogateescape");
669-
#else /* IS_SDLv2 || !PY3 */
667+
#else /* IS_SDLv2 */
670668
return Text_FromUTF8(SDL_GetError());
671-
#endif /* IS_SDLv2 || !PY3 */
669+
#endif /* IS_SDLv2 */
672670
}
673671

674672
static PyObject *
675673
pg_set_error(PyObject *s, PyObject *args)
676674
{
677675
char *errstring = NULL;
678-
#if PY2 || defined(PYPY_VERSION)
676+
#if defined(PYPY_VERSION)
679677
if (!PyArg_ParseTuple(args, "es", "UTF-8", &errstring))
680678
return NULL;
681679

682680
SDL_SetError("%s", errstring);
683681
PyMem_Free(errstring);
684-
#else /* PY3 */
682+
#else
685683
if (!PyArg_ParseTuple(args, "s", &errstring)) {
686684
return NULL;
687685
}
688686
SDL_SetError("%s", errstring);
689-
#endif /* PY3 */
687+
#endif
690688
Py_RETURN_NONE;
691689
}
692690

@@ -774,11 +772,7 @@ pgBuffer_AsArrayStruct(Py_buffer *view_p)
774772
if (!cinter_p) {
775773
return 0;
776774
}
777-
#if PY3
778775
capsule = PyCapsule_New(cinter_p, 0, _pg_capsule_PyMem_Free);
779-
#else
780-
capsule = PyCObject_FromVoidPtr(cinter_p, PyMem_Free);
781-
#endif
782776
if (!capsule) {
783777
PyMem_Free(cinter_p);
784778
return 0;
@@ -823,13 +817,11 @@ _pg_new_capsuleinterface(Py_buffer *view_p)
823817
return cinter_p;
824818
}
825819

826-
#if PY3
827820
static void
828821
_pg_capsule_PyMem_Free(PyObject *capsule)
829822
{
830823
PyMem_Free(PyCapsule_GetPointer(capsule, 0));
831824
}
832-
#endif
833825

834826
static int
835827
_pg_as_arrayinter_flags(Py_buffer *view_p)
@@ -1545,11 +1537,7 @@ _pg_typestr_check(PyObject *op)
15451537
return -1;
15461538
}
15471539
if (PyUnicode_Check(op)) {
1548-
#if PY2
1549-
Py_ssize_t len = PyUnicode_GET_SIZE(op);
1550-
#else
15511540
Py_ssize_t len = PyUnicode_GET_LENGTH(op);
1552-
#endif
15531541
if (len != 3) {
15541542
PyErr_SetString(PyExc_ValueError,
15551543
"expected 'typestr' to be length 3");
@@ -2132,7 +2120,6 @@ MODINIT_DEFINE(base)
21322120
int ecode;
21332121
static void *c_api[PYGAMEAPI_BASE_NUMSLOTS];
21342122

2135-
#if PY3
21362123
static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
21372124
"base",
21382125
"",
@@ -2142,7 +2129,6 @@ MODINIT_DEFINE(base)
21422129
NULL,
21432130
NULL,
21442131
NULL};
2145-
#endif
21462132

21472133
if (!is_loaded) {
21482134
/* import need modules. Do this first so if there is an error
@@ -2161,11 +2147,7 @@ MODINIT_DEFINE(base)
21612147
}
21622148

21632149
/* create the module */
2164-
#if PY3
21652150
module = PyModule_Create(&_module);
2166-
#else
2167-
module = Py_InitModule3(MODPREFIX "base", _base_methods, DOC_PYGAME);
2168-
#endif
21692151
if (module == NULL) {
21702152
MODINIT_ERROR;
21712153
}

src_c/bufferproxy.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -640,14 +640,8 @@ static PyBufferProcs proxy_bufferprocs = {
640640
#define PROXY_BUFFERPROCS 0
641641
#endif
642642

643-
#if PY2
644-
#define PROXY_TPFLAGS \
645-
(Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC | \
646-
Py_TPFLAGS_HAVE_NEWBUFFER)
647-
#else
648643
#define PROXY_TPFLAGS \
649644
(Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC)
650-
#endif
651645

652646
static PyTypeObject pgBufproxy_Type = {
653647
PyVarObject_HEAD_INIT(NULL, 0) PROXY_TYPE_FULLNAME, /* tp_name */
@@ -836,7 +830,6 @@ MODINIT_DEFINE(bufferproxy)
836830
PyObject *apiobj;
837831
static void *c_api[PYGAMEAPI_BUFPROXY_NUMSLOTS];
838832

839-
#if PY3
840833
static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
841834
PROXY_MODNAME,
842835
bufferproxy_doc,
@@ -846,7 +839,6 @@ MODINIT_DEFINE(bufferproxy)
846839
NULL,
847840
NULL,
848841
NULL};
849-
#endif
850842

851843
/* imported needed apis */
852844
import_pygame_base();
@@ -862,12 +854,7 @@ MODINIT_DEFINE(bufferproxy)
862854
#define bufferproxy_docs ""
863855

864856
/* create the module */
865-
#if PY3
866857
module = PyModule_Create(&_module);
867-
#else
868-
module = Py_InitModule3(MODPREFIX PROXY_MODNAME, bufferproxy_methods,
869-
bufferproxy_doc);
870-
#endif
871858

872859
Py_INCREF(&pgBufproxy_Type);
873860
if (PyModule_AddObject(module, PROXY_TYPE_NAME,

src_c/camera.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
#include <linux/videodev2.h>
4848
#endif
4949

50-
#if defined(__WIN32__) && PY3
50+
#if defined(__WIN32__)
5151
#define PYGAME_WINDOWS_CAMERA 1
5252

5353
#include <mfapi.h>

src_c/cdrom.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,6 @@ MODINIT_DEFINE(cdrom)
576576
int ecode;
577577
static void *c_api[PYGAMEAPI_CDROM_NUMSLOTS];
578578

579-
#if PY3
580579
static struct PyModuleDef _module = {PyModuleDef_HEAD_INIT,
581580
"cdrom",
582581
DOC_PYGAMECDROM,
@@ -586,7 +585,6 @@ MODINIT_DEFINE(cdrom)
586585
NULL,
587586
NULL,
588587
NULL};
589-
#endif
590588

591589
/* imported needed apis; Do this first so if there is an error
592590
the module is not loaded.
@@ -602,12 +600,7 @@ MODINIT_DEFINE(cdrom)
602600
}
603601

604602
/* create the module */
605-
#if PY3
606603
module = PyModule_Create(&_module);
607-
#else
608-
module =
609-
Py_InitModule3(MODPREFIX "cdrom", _cdrom_methods, DOC_PYGAMECDROM);
610-
#endif
611604
if (module == NULL) {
612605
MODINIT_ERROR;
613606
}

0 commit comments

Comments
 (0)