Skip to content

Remove Python 2 code from C extensions #10507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/matplotlib/tri/_tri.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
* points below or above (including the same as) the contour level) and 6 that
* do. See the function get_exit_edge for details.
*/
#ifndef _TRI_H
#define _TRI_H
#ifndef MPL_TRI_H
#define MPL_TRI_H

#include "src/numpy_cpp.h"

Expand Down
24 changes: 4 additions & 20 deletions lib/matplotlib/tri/_tri_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,6 @@ static PyTypeObject* PyTrapezoidMapTriFinder_init_type(PyObject* m, PyTypeObject

extern "C" {

#if PY3K
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"_tri",
Expand All @@ -507,44 +506,29 @@ static struct PyModuleDef moduledef = {
NULL
};

#define INITERROR return NULL

PyMODINIT_FUNC PyInit__tri(void)

#else
#define INITERROR return

PyMODINIT_FUNC init_tri(void)
#endif

{
PyObject *m;

#if PY3K
m = PyModule_Create(&moduledef);
#else
m = Py_InitModule3("_tri", NULL, NULL);
#endif

if (m == NULL) {
INITERROR;
return NULL;
}

if (!PyTriangulation_init_type(m, &PyTriangulationType)) {
INITERROR;
return NULL;
}
if (!PyTriContourGenerator_init_type(m, &PyTriContourGeneratorType)) {
INITERROR;
return NULL;
}
if (!PyTrapezoidMapTriFinder_init_type(m, &PyTrapezoidMapTriFinderType)) {
INITERROR;
return NULL;
}

import_array();

#if PY3K
return m;
#endif
}

} // extern "C"
4 changes: 2 additions & 2 deletions src/_backend_agg.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/* _backend_agg.h
*/

#ifndef __BACKEND_AGG_H__
#define __BACKEND_AGG_H__
#ifndef MPL_BACKEND_AGG_H
#define MPL_BACKEND_AGG_H

#include <cmath>
#include <vector>
Expand Down
4 changes: 2 additions & 2 deletions src/_backend_agg_basic_types.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#ifndef __BACKEND_AGG_BASIC_TYPES_H__
#define __BACKEND_AGG_BASIC_TYPES_H__
#ifndef MPL_BACKEND_AGG_BASIC_TYPES_H
#define MPL_BACKEND_AGG_BASIC_TYPES_H

/* Contains some simple types from the Agg backend that are also used
by other modules */
Expand Down
31 changes: 5 additions & 26 deletions src/_backend_agg_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ static PyTypeObject *PyBufferRegion_init_type(PyObject *m, PyTypeObject *type)
type->tp_name = "matplotlib.backends._backend_agg.BufferRegion";
type->tp_basicsize = sizeof(PyBufferRegion);
type->tp_dealloc = (destructor)PyBufferRegion_dealloc;
type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_NEWBUFFER;
type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
type->tp_methods = methods;
type->tp_new = PyBufferRegion_new;
type->tp_as_buffer = &buffer_procs;
Expand Down Expand Up @@ -586,13 +586,8 @@ PyRendererAgg_get_content_extents(PyRendererAgg *self, PyObject *args, PyObject

static PyObject *PyRendererAgg_buffer_rgba(PyRendererAgg *self, PyObject *args, PyObject *kwds)
{
#if PY3K
return PyBytes_FromStringAndSize((const char *)self->x->pixBuffer,
self->x->get_width() * self->x->get_height() * 4);
#else
return PyBuffer_FromReadWriteMemory(self->x->pixBuffer,
self->x->get_width() * self->x->get_height() * 4);
#endif
}

int PyRendererAgg_get_buffer(PyRendererAgg *self, Py_buffer *buf, int flags)
Expand Down Expand Up @@ -705,7 +700,7 @@ static PyTypeObject *PyRendererAgg_init_type(PyObject *m, PyTypeObject *type)
type->tp_name = "matplotlib.backends._backend_agg.RendererAgg";
type->tp_basicsize = sizeof(PyRendererAgg);
type->tp_dealloc = (destructor)PyRendererAgg_dealloc;
type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_NEWBUFFER;
type->tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE;
type->tp_methods = methods;
type->tp_init = (initproc)PyRendererAgg_init;
type->tp_new = PyRendererAgg_new;
Expand All @@ -724,7 +719,6 @@ static PyTypeObject *PyRendererAgg_init_type(PyObject *m, PyTypeObject *type)

extern "C" {

#if PY3K
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"_backend_agg",
Expand All @@ -737,42 +731,27 @@ static struct PyModuleDef moduledef = {
NULL
};

#define INITERROR return NULL

PyMODINIT_FUNC PyInit__backend_agg(void)

#else
#define INITERROR return

PyMODINIT_FUNC init_backend_agg(void)
#endif

{
PyObject *m;

#if PY3K
m = PyModule_Create(&moduledef);
#else
m = Py_InitModule3("_backend_agg", NULL, NULL);
#endif

if (m == NULL) {
INITERROR;
return NULL;
}

import_array();

if (!PyRendererAgg_init_type(m, &PyRendererAggType)) {
INITERROR;
return NULL;
}

if (!PyBufferRegion_init_type(m, &PyBufferRegionType)) {
INITERROR;
return NULL;
}

#if PY3K
return m;
#endif
}

} // extern "C"
4 changes: 2 additions & 2 deletions src/_contour.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@
* different polygons. The S-most polygon must be started first, then the next
* S-most and so on until the N-most polygon is started in that quad.
*/
#ifndef _CONTOUR_H
#define _CONTOUR_H
#ifndef MPL_CONTOUR_H
#define MPL_CONTOUR_H

#include "src/numpy_cpp.h"
#include <stdint.h>
Expand Down
20 changes: 2 additions & 18 deletions src/_contour_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ static PyTypeObject* PyQuadContourGenerator_init_type(PyObject* m, PyTypeObject*

extern "C" {

#if PY3K
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"_contour",
Expand All @@ -167,38 +166,23 @@ static struct PyModuleDef moduledef = {
NULL
};

#define INITERROR return NULL

PyMODINIT_FUNC PyInit__contour(void)

#else
#define INITERROR return

PyMODINIT_FUNC init_contour(void)
#endif

{
PyObject *m;

#if PY3K
m = PyModule_Create(&moduledef);
#else
m = Py_InitModule3("_contour", NULL, NULL);
#endif

if (m == NULL) {
INITERROR;
return NULL;
}

if (!PyQuadContourGenerator_init_type(m, &PyQuadContourGeneratorType)) {
INITERROR;
return NULL;
}

import_array();

#if PY3K
return m;
#endif
}

} // extern "C"
4 changes: 2 additions & 2 deletions src/_image.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
*
*/

#ifndef _IMAGE_H
#define _IMAGE_H
#ifndef MPL_IMAGE_H
#define MPL_IMAGE_H

#include <vector>

Expand Down
6 changes: 3 additions & 3 deletions src/_image_resample.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* -*- mode: c++; c-basic-offset: 4 -*- */

#ifndef RESAMPLE_H
#define RESAMPLE_H
#ifndef MPL_RESAMPLE_H
#define MPL_RESAMPLE_H

#include "agg_image_accessors.h"
#include "agg_path_storage.h"
Expand Down Expand Up @@ -1010,4 +1010,4 @@ void resample(
}
}

#endif /* RESAMPLE_H */
#endif /* MPL_RESAMPLE_H */
25 changes: 2 additions & 23 deletions src/_image_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@
#include "py_converters.h"


#ifndef NPY_1_7_API_VERSION
#define NPY_ARRAY_C_CONTIGUOUS NPY_C_CONTIGUOUS
#endif


/**********************************************************************
* Free functions
* */
Expand Down Expand Up @@ -442,7 +437,6 @@ static PyMethodDef module_functions[] = {

extern "C" {

#if PY3K
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT,
"_image",
Expand All @@ -455,27 +449,14 @@ static struct PyModuleDef moduledef = {
NULL
};

#define INITERROR return NULL

PyMODINIT_FUNC PyInit__image(void)

#else
#define INITERROR return

PyMODINIT_FUNC init_image(void)
#endif

{
PyObject *m;

#if PY3K
m = PyModule_Create(&moduledef);
#else
m = Py_InitModule3("_image", module_functions, NULL);
#endif

if (m == NULL) {
INITERROR;
return NULL;
}

if (PyModule_AddIntConstant(m, "NEAREST", NEAREST) ||
Expand All @@ -496,14 +477,12 @@ PyMODINIT_FUNC init_image(void)
PyModule_AddIntConstant(m, "LANCZOS", LANCZOS) ||
PyModule_AddIntConstant(m, "BLACKMAN", BLACKMAN) ||
PyModule_AddIntConstant(m, "_n_interpolation", _n_interpolation)) {
INITERROR;
return NULL;
}

import_array();

#if PY3K
return m;
#endif
}

} // extern "C"
Loading