Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5e23e2c

Browse files
committed
Remove C checks for PY3K macro.
1 parent 002be1f commit 5e23e2c

12 files changed

+26
-289
lines changed

lib/matplotlib/tri/_tri_wrapper.cpp

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,6 @@ static PyTypeObject* PyTrapezoidMapTriFinder_init_type(PyObject* m, PyTypeObject
494494

495495
extern "C" {
496496

497-
#if PY3K
498497
static struct PyModuleDef moduledef = {
499498
PyModuleDef_HEAD_INIT,
500499
"_tri",
@@ -507,44 +506,29 @@ static struct PyModuleDef moduledef = {
507506
NULL
508507
};
509508

510-
#define INITERROR return NULL
511-
512509
PyMODINIT_FUNC PyInit__tri(void)
513-
514-
#else
515-
#define INITERROR return
516-
517-
PyMODINIT_FUNC init_tri(void)
518-
#endif
519-
520510
{
521511
PyObject *m;
522512

523-
#if PY3K
524513
m = PyModule_Create(&moduledef);
525-
#else
526-
m = Py_InitModule3("_tri", NULL, NULL);
527-
#endif
528514

529515
if (m == NULL) {
530-
INITERROR;
516+
return NULL;
531517
}
532518

533519
if (!PyTriangulation_init_type(m, &PyTriangulationType)) {
534-
INITERROR;
520+
return NULL;
535521
}
536522
if (!PyTriContourGenerator_init_type(m, &PyTriContourGeneratorType)) {
537-
INITERROR;
523+
return NULL;
538524
}
539525
if (!PyTrapezoidMapTriFinder_init_type(m, &PyTrapezoidMapTriFinderType)) {
540-
INITERROR;
526+
return NULL;
541527
}
542528

543529
import_array();
544530

545-
#if PY3K
546531
return m;
547-
#endif
548532
}
549533

550534
} // extern "C"

src/_backend_agg_wrapper.cpp

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -586,13 +586,8 @@ PyRendererAgg_get_content_extents(PyRendererAgg *self, PyObject *args, PyObject
586586

587587
static PyObject *PyRendererAgg_buffer_rgba(PyRendererAgg *self, PyObject *args, PyObject *kwds)
588588
{
589-
#if PY3K
590589
return PyBytes_FromStringAndSize((const char *)self->x->pixBuffer,
591590
self->x->get_width() * self->x->get_height() * 4);
592-
#else
593-
return PyBuffer_FromReadWriteMemory(self->x->pixBuffer,
594-
self->x->get_width() * self->x->get_height() * 4);
595-
#endif
596591
}
597592

598593
int PyRendererAgg_get_buffer(PyRendererAgg *self, Py_buffer *buf, int flags)
@@ -724,7 +719,6 @@ static PyTypeObject *PyRendererAgg_init_type(PyObject *m, PyTypeObject *type)
724719

725720
extern "C" {
726721

727-
#if PY3K
728722
static struct PyModuleDef moduledef = {
729723
PyModuleDef_HEAD_INIT,
730724
"_backend_agg",
@@ -737,42 +731,27 @@ static struct PyModuleDef moduledef = {
737731
NULL
738732
};
739733

740-
#define INITERROR return NULL
741-
742734
PyMODINIT_FUNC PyInit__backend_agg(void)
743-
744-
#else
745-
#define INITERROR return
746-
747-
PyMODINIT_FUNC init_backend_agg(void)
748-
#endif
749-
750735
{
751736
PyObject *m;
752737

753-
#if PY3K
754738
m = PyModule_Create(&moduledef);
755-
#else
756-
m = Py_InitModule3("_backend_agg", NULL, NULL);
757-
#endif
758739

759740
if (m == NULL) {
760-
INITERROR;
741+
return NULL;
761742
}
762743

763744
import_array();
764745

765746
if (!PyRendererAgg_init_type(m, &PyRendererAggType)) {
766-
INITERROR;
747+
return NULL;
767748
}
768749

769750
if (!PyBufferRegion_init_type(m, &PyBufferRegionType)) {
770-
INITERROR;
751+
return NULL;
771752
}
772753

773-
#if PY3K
774754
return m;
775-
#endif
776755
}
777756

778757
} // extern "C"

src/_contour_wrapper.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ static PyTypeObject* PyQuadContourGenerator_init_type(PyObject* m, PyTypeObject*
154154

155155
extern "C" {
156156

157-
#if PY3K
158157
static struct PyModuleDef moduledef = {
159158
PyModuleDef_HEAD_INIT,
160159
"_contour",
@@ -167,38 +166,23 @@ static struct PyModuleDef moduledef = {
167166
NULL
168167
};
169168

170-
#define INITERROR return NULL
171-
172169
PyMODINIT_FUNC PyInit__contour(void)
173-
174-
#else
175-
#define INITERROR return
176-
177-
PyMODINIT_FUNC init_contour(void)
178-
#endif
179-
180170
{
181171
PyObject *m;
182172

183-
#if PY3K
184173
m = PyModule_Create(&moduledef);
185-
#else
186-
m = Py_InitModule3("_contour", NULL, NULL);
187-
#endif
188174

189175
if (m == NULL) {
190-
INITERROR;
176+
return NULL;
191177
}
192178

193179
if (!PyQuadContourGenerator_init_type(m, &PyQuadContourGeneratorType)) {
194-
INITERROR;
180+
return NULL;
195181
}
196182

197183
import_array();
198184

199-
#if PY3K
200185
return m;
201-
#endif
202186
}
203187

204188
} // extern "C"

src/_image_wrapper.cpp

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,6 @@ static PyMethodDef module_functions[] = {
437437

438438
extern "C" {
439439

440-
#if PY3K
441440
static struct PyModuleDef moduledef = {
442441
PyModuleDef_HEAD_INIT,
443442
"_image",
@@ -450,27 +449,14 @@ static struct PyModuleDef moduledef = {
450449
NULL
451450
};
452451

453-
#define INITERROR return NULL
454-
455452
PyMODINIT_FUNC PyInit__image(void)
456-
457-
#else
458-
#define INITERROR return
459-
460-
PyMODINIT_FUNC init_image(void)
461-
#endif
462-
463453
{
464454
PyObject *m;
465455

466-
#if PY3K
467456
m = PyModule_Create(&moduledef);
468-
#else
469-
m = Py_InitModule3("_image", module_functions, NULL);
470-
#endif
471457

472458
if (m == NULL) {
473-
INITERROR;
459+
return NULL;
474460
}
475461

476462
if (PyModule_AddIntConstant(m, "NEAREST", NEAREST) ||
@@ -491,14 +477,12 @@ PyMODINIT_FUNC init_image(void)
491477
PyModule_AddIntConstant(m, "LANCZOS", LANCZOS) ||
492478
PyModule_AddIntConstant(m, "BLACKMAN", BLACKMAN) ||
493479
PyModule_AddIntConstant(m, "_n_interpolation", _n_interpolation)) {
494-
INITERROR;
480+
return NULL;
495481
}
496482

497483
import_array();
498484

499-
#if PY3K
500485
return m;
501-
#endif
502486
}
503487

504488
} // extern "C"

src/_macosx.m

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@
55

66
#define PYOSINPUTHOOK_REPETITIVE 1 /* Remove this once Python is fixed */
77

8-
#if PY_MAJOR_VERSION >= 3
9-
#define PY3K 1
10-
#else
11-
#define PY3K 0
12-
#endif
13-
148
/* Proper way to check for the OS X version we are compiling for, from
159
http://developer.apple.com/documentation/DeveloperTools/Conceptual/cross_development */
1610
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
@@ -325,13 +319,8 @@ static CGFloat _get_device_scale(CGContextRef cr)
325319
static PyObject*
326320
FigureCanvas_repr(FigureCanvas* self)
327321
{
328-
#if PY3K
329322
return PyUnicode_FromFormat("FigureCanvas object %p wrapping NSView %p",
330323
(void*)self, (void*)(self->view));
331-
#else
332-
return PyString_FromFormat("FigureCanvas object %p wrapping NSView %p",
333-
(void*)self, (void*)(self->view));
334-
#endif
335324
}
336325

337326
static PyObject*
@@ -730,13 +719,8 @@ static CGFloat _get_device_scale(CGContextRef cr)
730719
static PyObject*
731720
FigureManager_repr(FigureManager* self)
732721
{
733-
#if PY3K
734722
return PyUnicode_FromFormat("FigureManager object %p wrapping NSWindow %p",
735723
(void*) self, (void*)(self->window));
736-
#else
737-
return PyString_FromFormat("FigureManager object %p wrapping NSWindow %p",
738-
(void*) self, (void*)(self->window));
739-
#endif
740724
}
741725

742726
static void
@@ -1197,11 +1181,7 @@ -(void)save_figure:(id)sender
11971181
static PyObject*
11981182
NavigationToolbar_repr(NavigationToolbar* self)
11991183
{
1200-
#if PY3K
12011184
return PyUnicode_FromFormat("NavigationToolbar object %p", (void*)self);
1202-
#else
1203-
return PyString_FromFormat("NavigationToolbar object %p", (void*)self);
1204-
#endif
12051185
}
12061186

12071187
static char NavigationToolbar_doc[] =
@@ -1741,11 +1721,7 @@ -(void)save_figure:(id)sender
17411721
static PyObject*
17421722
NavigationToolbar2_repr(NavigationToolbar2* self)
17431723
{
1744-
#if PY3K
17451724
return PyUnicode_FromFormat("NavigationToolbar2 object %p", (void*)self);
1746-
#else
1747-
return PyString_FromFormat("NavigationToolbar2 object %p", (void*)self);
1748-
#endif
17491725
}
17501726

17511727
static char NavigationToolbar2_doc[] =
@@ -1756,11 +1732,7 @@ -(void)save_figure:(id)sender
17561732
{
17571733
const char* message;
17581734

1759-
#if PY3K
17601735
if(!PyArg_ParseTuple(args, "y", &message)) return NULL;
1761-
#else
1762-
if(!PyArg_ParseTuple(args, "s", &message)) return NULL;
1763-
#endif
17641736

17651737
NSText* messagebox = self->messagebox;
17661738

@@ -1867,11 +1839,7 @@ -(void)save_figure:(id)sender
18671839
unsigned int n = [filename length];
18681840
unichar* buffer = malloc(n*sizeof(unichar));
18691841
[filename getCharacters: buffer];
1870-
#if PY3K
1871-
PyObject* string = PyUnicode_FromKindAndData(PyUnicode_2BYTE_KIND, buffer, n);
1872-
#else
1873-
PyObject* string = PyUnicode_FromUnicode(buffer, n);
1874-
#endif
1842+
PyObject* string = PyUnicode_FromKindAndData(PyUnicode_2BYTE_KIND, buffer, n);
18751843
free(buffer);
18761844
return string;
18771845
}
@@ -2853,13 +2821,8 @@ - (int)index
28532821
static PyObject*
28542822
Timer_repr(Timer* self)
28552823
{
2856-
#if PY3K
28572824
return PyUnicode_FromFormat("Timer object %p wrapping CFRunLoopTimerRef %p",
28582825
(void*) self, (void*)(self->timer));
2859-
#else
2860-
return PyString_FromFormat("Timer object %p wrapping CFRunLoopTimerRef %p",
2861-
(void*) self, (void*)(self->timer));
2862-
#endif
28632826
}
28642827

28652828
static char Timer_doc[] =
@@ -3090,8 +3053,6 @@ static bool verify_framework(void)
30903053
{NULL, NULL, 0, NULL}/* sentinel */
30913054
};
30923055

3093-
#if PY3K
3094-
30953056
static struct PyModuleDef moduledef = {
30963057
PyModuleDef_HEAD_INIT,
30973058
"_macosx",
@@ -3105,11 +3066,6 @@ static bool verify_framework(void)
31053066
};
31063067

31073068
PyObject* PyInit__macosx(void)
3108-
3109-
#else
3110-
3111-
void init_macosx(void)
3112-
#endif
31133069
{
31143070
PyObject *module;
31153071

@@ -3118,31 +3074,15 @@ void init_macosx(void)
31183074
|| PyType_Ready(&NavigationToolbarType) < 0
31193075
|| PyType_Ready(&NavigationToolbar2Type) < 0
31203076
|| PyType_Ready(&TimerType) < 0)
3121-
#if PY3K
31223077
return NULL;
3123-
#else
3124-
return;
3125-
#endif
31263078

31273079
NSApp = [NSApplication sharedApplication];
31283080

31293081
if (!verify_framework())
3130-
#if PY3K
31313082
return NULL;
3132-
#else
3133-
return;
3134-
#endif
31353083

3136-
#if PY3K
31373084
module = PyModule_Create(&moduledef);
31383085
if (module==NULL) return NULL;
3139-
#else
3140-
module = Py_InitModule4("_macosx",
3141-
methods,
3142-
"Mac OS X native backend",
3143-
NULL,
3144-
PYTHON_API_VERSION);
3145-
#endif
31463086

31473087
Py_INCREF(&FigureCanvasType);
31483088
Py_INCREF(&FigureManagerType);
@@ -3166,7 +3106,5 @@ void init_macosx(void)
31663106
name: NSWorkspaceDidLaunchApplicationNotification
31673107
object: nil];
31683108
[pool release];
3169-
#if PY3K
31703109
return module;
3171-
#endif
31723110
}

0 commit comments

Comments
 (0)