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

Skip to content

Commit 21c4f9e

Browse files
authored
Merge pull request #10507 from QuLogic/py3-c-ext
Remove Python 2 code from C extensions
2 parents 42055ad + d32e079 commit 21c4f9e

30 files changed

Lines changed: 75 additions & 397 deletions

lib/matplotlib/tri/_tri.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@
6060
* points below or above (including the same as) the contour level) and 6 that
6161
* do. See the function get_exit_edge for details.
6262
*/
63-
#ifndef _TRI_H
64-
#define _TRI_H
63+
#ifndef MPL_TRI_H
64+
#define MPL_TRI_H
6565

6666
#include "src/numpy_cpp.h"
6767

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.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
/* _backend_agg.h
44
*/
55

6-
#ifndef __BACKEND_AGG_H__
7-
#define __BACKEND_AGG_H__
6+
#ifndef MPL_BACKEND_AGG_H
7+
#define MPL_BACKEND_AGG_H
88

99
#include <cmath>
1010
#include <vector>

src/_backend_agg_basic_types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef __BACKEND_AGG_BASIC_TYPES_H__
2-
#define __BACKEND_AGG_BASIC_TYPES_H__
1+
#ifndef MPL_BACKEND_AGG_BASIC_TYPES_H
2+
#define MPL_BACKEND_AGG_BASIC_TYPES_H
33

44
/* Contains some simple types from the Agg backend that are also used
55
by other modules */

src/_backend_agg_wrapper.cpp

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static PyTypeObject *PyBufferRegion_init_type(PyObject *m, PyTypeObject *type)
134134
type->tp_name = "matplotlib.backends._backend_agg.BufferRegion";
135135
type->tp_basicsize = sizeof(PyBufferRegion);
136136
type->tp_dealloc = (destructor)PyBufferRegion_dealloc;
137-
type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_NEWBUFFER;
137+
type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
138138
type->tp_methods = methods;
139139
type->tp_new = PyBufferRegion_new;
140140
type->tp_as_buffer = &buffer_procs;
@@ -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)
@@ -705,7 +700,7 @@ static PyTypeObject *PyRendererAgg_init_type(PyObject *m, PyTypeObject *type)
705700
type->tp_name = "matplotlib.backends._backend_agg.RendererAgg";
706701
type->tp_basicsize = sizeof(PyRendererAgg);
707702
type->tp_dealloc = (destructor)PyRendererAgg_dealloc;
708-
type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_NEWBUFFER;
703+
type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
709704
type->tp_methods = methods;
710705
type->tp_init = (initproc)PyRendererAgg_init;
711706
type->tp_new = PyRendererAgg_new;
@@ -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.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@
139139
* different polygons. The S-most polygon must be started first, then the next
140140
* S-most and so on until the N-most polygon is started in that quad.
141141
*/
142-
#ifndef _CONTOUR_H
143-
#define _CONTOUR_H
142+
#ifndef MPL_CONTOUR_H
143+
#define MPL_CONTOUR_H
144144

145145
#include "src/numpy_cpp.h"
146146
#include <stdint.h>

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.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
*/
66

7-
#ifndef _IMAGE_H
8-
#define _IMAGE_H
7+
#ifndef MPL_IMAGE_H
8+
#define MPL_IMAGE_H
99

1010
#include <vector>
1111

src/_image_resample.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* -*- mode: c++; c-basic-offset: 4 -*- */
22

3-
#ifndef RESAMPLE_H
4-
#define RESAMPLE_H
3+
#ifndef MPL_RESAMPLE_H
4+
#define MPL_RESAMPLE_H
55

66
#include "agg_image_accessors.h"
77
#include "agg_path_storage.h"
@@ -1010,4 +1010,4 @@ void resample(
10101010
}
10111011
}
10121012

1013-
#endif /* RESAMPLE_H */
1013+
#endif /* MPL_RESAMPLE_H */

src/_image_wrapper.cpp

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,6 @@
44
#include "py_converters.h"
55

66

7-
#ifndef NPY_1_7_API_VERSION
8-
#define NPY_ARRAY_C_CONTIGUOUS NPY_C_CONTIGUOUS
9-
#endif
10-
11-
127
/**********************************************************************
138
* Free functions
149
* */
@@ -442,7 +437,6 @@ static PyMethodDef module_functions[] = {
442437

443438
extern "C" {
444439

445-
#if PY3K
446440
static struct PyModuleDef moduledef = {
447441
PyModuleDef_HEAD_INIT,
448442
"_image",
@@ -455,27 +449,14 @@ static struct PyModuleDef moduledef = {
455449
NULL
456450
};
457451

458-
#define INITERROR return NULL
459-
460452
PyMODINIT_FUNC PyInit__image(void)
461-
462-
#else
463-
#define INITERROR return
464-
465-
PyMODINIT_FUNC init_image(void)
466-
#endif
467-
468453
{
469454
PyObject *m;
470455

471-
#if PY3K
472456
m = PyModule_Create(&moduledef);
473-
#else
474-
m = Py_InitModule3("_image", module_functions, NULL);
475-
#endif
476457

477458
if (m == NULL) {
478-
INITERROR;
459+
return NULL;
479460
}
480461

481462
if (PyModule_AddIntConstant(m, "NEAREST", NEAREST) ||
@@ -496,14 +477,12 @@ PyMODINIT_FUNC init_image(void)
496477
PyModule_AddIntConstant(m, "LANCZOS", LANCZOS) ||
497478
PyModule_AddIntConstant(m, "BLACKMAN", BLACKMAN) ||
498479
PyModule_AddIntConstant(m, "_n_interpolation", _n_interpolation)) {
499-
INITERROR;
480+
return NULL;
500481
}
501482

502483
import_array();
503484

504-
#if PY3K
505485
return m;
506-
#endif
507486
}
508487

509488
} // extern "C"

0 commit comments

Comments
 (0)