Skip to content

Commit 81219db

Browse files
Consistent use of PY3K #define everywhere.
1 parent 78ed16a commit 81219db

10 files changed

Lines changed: 79 additions & 90 deletions

File tree

src/_backend_agg.cpp

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Py::Object
102102
BufferRegion::to_string(const Py::Tuple &args)
103103
{
104104
// owned=true to prevent memory leak
105-
#if PY_MAJOR_VERSION >= 3
105+
#if PY3K
106106
return Py::Bytes(PyBytes_FromStringAndSize((const char*)data, height*stride), true);
107107
#else
108108
return Py::String(PyString_FromStringAndSize((const char*)data, height*stride), true);
@@ -156,7 +156,7 @@ BufferRegion::to_string_argb(const Py::Tuple &args)
156156
unsigned char tmp;
157157
size_t i, j;
158158

159-
#if PY_MAJOR_VERSION >= 3
159+
#if PY3K
160160
PyObject* str = PyBytes_FromStringAndSize((const char*)data, height * stride);
161161
if (PyBytes_AsStringAndSize(str, (char**)&begin, &length))
162162
{
@@ -1994,7 +1994,7 @@ RendererAgg::write_rgba(const Py::Tuple& args)
19941994
bool close_file = false;
19951995
Py::Object py_fileobj = Py::Object(args[0]);
19961996

1997-
#if PY_MAJOR_VERSION >= 3
1997+
#if PY3K
19981998
int fd = PyObject_AsFileDescriptor(py_fileobj.ptr());
19991999
PyErr_Clear();
20002000
#endif
@@ -2014,7 +2014,7 @@ RendererAgg::write_rgba(const Py::Tuple& args)
20142014
}
20152015
close_file = true;
20162016
}
2017-
#if PY_MAJOR_VERSION >= 3
2017+
#if PY3K
20182018
else if (fd != -1)
20192019
{
20202020
if (write(fd, pixBuffer, NUMBYTES) != (ssize_t)NUMBYTES)
@@ -2087,7 +2087,11 @@ RendererAgg::tostring_rgb(const Py::Tuple& args)
20872087
}
20882088

20892089
//todo: how to do this with native CXX
2090+
#if PY3K
2091+
PyObject* o = Py_BuildValue("y#", buf_tmp, row_len * height);
2092+
#else
20902093
PyObject* o = Py_BuildValue("s#", buf_tmp, row_len * height);
2094+
#endif
20912095

20922096
delete [] buf_tmp;
20932097
return Py::asObject(o);
@@ -2123,7 +2127,12 @@ RendererAgg::tostring_argb(const Py::Tuple& args)
21232127
}
21242128

21252129
//todo: how to do this with native CXX
2130+
2131+
#if PY3K
2132+
PyObject* o = Py_BuildValue("y#", buf_tmp, row_len * height);
2133+
#else
21262134
PyObject* o = Py_BuildValue("s#", buf_tmp, row_len * height);
2135+
#endif
21272136
delete [] buf_tmp;
21282137
return Py::asObject(o);
21292138
}
@@ -2162,9 +2171,11 @@ RendererAgg::tostring_bgra(const Py::Tuple& args)
21622171
}
21632172

21642173
//todo: how to do this with native CXX
2165-
PyObject* o = Py_BuildValue("s#",
2166-
buf_tmp,
2167-
row_len * height);
2174+
#if PY3K
2175+
PyObject* o = Py_BuildValue("y#", buf_tmp, row_len * height);
2176+
#else
2177+
PyObject* o = Py_BuildValue("s#", buf_tmp, row_len * height);
2178+
#endif
21682179
delete [] buf_tmp;
21692180
return Py::asObject(o);
21702181
}
@@ -2183,10 +2194,10 @@ RendererAgg::buffer_rgba(const Py::Tuple& args)
21832194
int row_len = width * 4;
21842195
int start = row_len * starth + startw * 4;
21852196
/* PY3KTODO: Buffers are different */
2186-
#if PY_MAJOR_VERSION >= 3
2197+
#if PY3K
21872198
return Py::asObject(PyByteArray_FromStringAndSize(
2188-
(const char *)pixBuffer + start,
2189-
row_len*height - start));
2199+
(const char *)pixBuffer + start,
2200+
row_len*height - start));
21902201
#else
21912202
return Py::asObject(PyBuffer_FromMemory(pixBuffer + start, row_len*height - start));
21922203
#endif
@@ -2427,7 +2438,7 @@ void RendererAgg::init_type()
24272438
}
24282439

24292440
extern "C"
2430-
#if PY_MAJOR_VERSION >= 3
2441+
#if PY3K
24312442
PyMODINIT_FUNC
24322443
PyInit__backend_agg(void)
24332444
#else
@@ -2444,7 +2455,7 @@ init_backend_agg(void)
24442455
static _backend_agg_module* _backend_agg = NULL;
24452456
_backend_agg = new _backend_agg_module;
24462457

2447-
#if PY_MAJOR_VERSION >= 3
2458+
#if PY3K
24482459
return _backend_agg->module().ptr();
24492460
#endif
24502461
}

src/_image.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ Image::color_conv(const Py::Tuple& args)
223223
int format = Py::Int(args[0]);
224224
PyObject* py_buffer = NULL;
225225
int row_len = colsOut * 4;
226-
#if PY_MAJOR_VERSION >= 3
226+
#if PY3K
227227
unsigned char* buf = (unsigned char *)malloc(row_len * rowsOut);
228228
if (buf == NULL)
229229
throw Py::MemoryError("Image::color_conv could not allocate memory");
@@ -259,7 +259,7 @@ Image::color_conv(const Py::Tuple& args)
259259
throw Py::ValueError("Image::color_conv unknown format");
260260
}
261261

262-
#if PY_MAJOR_VERSION >= 3
262+
#if PY3K
263263
py_buffer = PyByteArray_FromStringAndSize((char *)buf, row_len * rowsOut);
264264
if (py_buffer == NULL) {
265265
free(buf);
@@ -1944,7 +1944,7 @@ _image_module::pcolor2(const Py::Tuple& args)
19441944
return Py::asObject(imo);
19451945
}
19461946

1947-
#if PY_MAJOR_VERSION >= 3
1947+
#if PY3K
19481948
PyMODINIT_FUNC
19491949
PyInit__image(void)
19501950
#else
@@ -1980,7 +1980,7 @@ init_image(void)
19801980
d["ASPECT_FREE"] = Py::Int(Image::ASPECT_FREE);
19811981
d["ASPECT_PRESERVE"] = Py::Int(Image::ASPECT_PRESERVE);
19821982

1983-
#if PY_MAJOR_VERSION >= 3
1983+
#if PY3K
19841984
return _image->module().ptr();
19851985
#endif
19861986
}

src/_macosx.m

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ static int _get_snap(GraphicsContext* self, enum e_snap_mode* mode)
506506
static PyObject*
507507
GraphicsContext_repr(GraphicsContext* self)
508508
{
509-
#if PY_MAJOR_VERSION >= 3
509+
#if PY3K
510510
return PyUnicode_FromFormat("GraphicsContext object %p wrapping the Quartz 2D graphics context %p", (void*)self, (void*)(self->cr));
511511
#else
512512
return PyString_FromFormat("GraphicsContext object %p wrapping the Quartz 2D graphics context %p", (void*)self, (void*)(self->cr));
@@ -2251,7 +2251,7 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
22512251
#else
22522252
ATSFontRef font = 0;
22532253
#endif
2254-
#if PY_MAJOR_VERSION >= 3
2254+
#if PY3K
22552255
PyObject* ascii = NULL;
22562256
#endif
22572257

@@ -2434,41 +2434,7 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
24342434
for (i = 0; i < n; i++)
24352435
{
24362436
PyObject* item = PyList_GET_ITEM(family, i);
2437-
#if PY_MAJOR_VERSION >= 3
2438-
ascii = PyUnicode_AsASCIIString(item);
2439-
if(!ascii) return 0;
2440-
temp = PyBytes_AS_STRING(ascii);
2441-
#else
2442-
if(!PyString_Check(item)) return 0;
2443-
temp = PyString_AS_STRING(item);
2444-
#endif
2445-
for (j = 0; j < NMAP; j++)
2446-
{ if (!strcmp(map[j].name, temp))
2447-
{ temp = psnames[map[j].index][k];
2448-
break;
2449-
}
2450-
}
2451-
/* If the font name is not found in mapping, we assume */
2452-
/* that the user specified the Postscript name directly */
2453-
2454-
/* Check if this font can be found on the system */
2455-
string = CFStringCreateWithCString(kCFAllocatorDefault,
2456-
temp,
2457-
kCFStringEncodingMacRoman);
2458-
#ifdef COMPILING_FOR_10_5
2459-
font = CTFontCreateWithName(string, size, NULL);
2460-
#else
2461-
font = ATSFontFindFromPostScriptName(string, kATSOptionFlagsDefault);
2462-
#endif
2463-
2464-
CFRelease(string);
2465-
2466-
if(font)
2467-
{
2468-
name = temp;
2469-
break;
2470-
}
2471-
#if PY_MAJOR_VERSION >= 3
2437+
#if PY3K
24722438
Py_DECREF(ascii);
24732439
ascii = NULL;
24742440
#endif
@@ -2487,7 +2453,7 @@ static CGRect _find_enclosing_rect(CGPoint points[3])
24872453
#ifndef COMPILING_FOR_10_5
24882454
CGContextSelectFont(cr, name, size, kCGEncodingMacRoman);
24892455
#endif
2490-
#if PY_MAJOR_VERSION >= 3
2456+
#if PY3K
24912457
Py_XDECREF(ascii);
24922458
#endif
24932459
return font;
@@ -2989,7 +2955,7 @@ static void _data_provider_release(void* info, const void* data, size_t size)
29892955
CGDataProviderRef provider;
29902956
double rect[4] = {0.0, 0.0, self->size.width, self->size.height};
29912957

2992-
#if PY_MAJOR_VERSION >= 3
2958+
#if PY3K
29932959
if (!PyBytes_Check(image))
29942960
{
29952961
PyErr_SetString(PyExc_RuntimeError, "image is not a byte array");
@@ -3017,7 +2983,7 @@ static void _data_provider_release(void* info, const void* data, size_t size)
30172983
}
30182984

30192985
Py_INCREF(image);
3020-
#if PY_MAJOR_VERSION >= 3
2986+
#if PY3K
30212987
n = PyByteArray_GET_SIZE(image);
30222988
data = PyByteArray_AS_STRING(image);
30232989
#else
@@ -3296,7 +3262,7 @@ static void _data_provider_release(void* info, const void* data, size_t size)
32963262
static PyObject*
32973263
FigureCanvas_repr(FigureCanvas* self)
32983264
{
3299-
#if PY_MAJOR_VERSION >= 3
3265+
#if PY3K
33003266
return PyUnicode_FromFormat("FigureCanvas object %p wrapping NSView %p",
33013267
(void*)self, (void*)(self->view));
33023268
#else
@@ -3766,7 +3732,7 @@ static void _data_provider_release(void* info, const void* data, size_t size)
37663732
static PyObject*
37673733
FigureManager_repr(FigureManager* self)
37683734
{
3769-
#if PY_MAJOR_VERSION >= 3
3735+
#if PY3K
37703736
return PyUnicode_FromFormat("FigureManager object %p wrapping NSWindow %p",
37713737
(void*) self, (void*)(self->window));
37723738
#else
@@ -4157,7 +4123,7 @@ -(void)save_figure:(id)sender
41574123
static PyObject*
41584124
NavigationToolbar_repr(NavigationToolbar* self)
41594125
{
4160-
#if PY_MAJOR_VERSION >= 3
4126+
#if PY3K
41614127
return PyUnicode_FromFormat("NavigationToolbar object %p", (void*)self);
41624128
#else
41634129
return PyString_FromFormat("NavigationToolbar object %p", (void*)self);
@@ -4268,7 +4234,7 @@ -(void)save_figure:(id)sender
42684234
{
42694235
if(states[i]==1)
42704236
{
4271-
#if PY_MAJOR_VERSION >= 3
4237+
#if PY3K
42724238
PyList_SET_ITEM(list, j, PyLong_FromLong(i));
42734239
#else
42744240
PyList_SET_ITEM(list, j, PyInt_FromLong(i));
@@ -4686,7 +4652,7 @@ -(void)save_figure:(id)sender
46864652
static PyObject*
46874653
NavigationToolbar2_repr(NavigationToolbar2* self)
46884654
{
4689-
#if PY_MAJOR_VERSION >= 3
4655+
#if PY3K
46904656
return PyUnicode_FromFormat("NavigationToolbar2 object %p", (void*)self);
46914657
#else
46924658
return PyString_FromFormat("NavigationToolbar2 object %p", (void*)self);
@@ -5611,7 +5577,7 @@ - (int)index
56115577
static PyObject*
56125578
Timer_repr(Timer* self)
56135579
{
5614-
#if PY_MAJOR_VERSION >= 3
5580+
#if PY3K
56155581
return PyUnicode_FromFormat("Timer object %p wrapping CFRunLoopTimerRef %p",
56165582
(void*) self, (void*)(self->timer));
56175583
#else
@@ -5792,7 +5758,7 @@ static void timer_callback(CFRunLoopTimerRef timer, void* info)
57925758
{NULL, NULL, 0, NULL}/* sentinel */
57935759
};
57945760

5795-
#if PY_MAJOR_VERSION >= 3
5761+
#if PY3K
57965762

57975763
static struct PyModuleDef moduledef = {
57985764
PyModuleDef_HEAD_INIT,
@@ -5822,13 +5788,13 @@ void init_macosx(void)
58225788
|| PyType_Ready(&NavigationToolbarType) < 0
58235789
|| PyType_Ready(&NavigationToolbar2Type) < 0
58245790
|| PyType_Ready(&TimerType) < 0)
5825-
#if PY_MAJOR_VERSION >= 3
5791+
#if PY3K
58265792
return NULL;
58275793
#else
58285794
return;
58295795
#endif
58305796

5831-
#if PY_MAJOR_VERSION >= 3
5797+
#if PY3K
58325798
module = PyModule_Create(&moduledef);
58335799
if (module==NULL) return NULL;
58345800
#else

src/_path.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,7 +1481,7 @@ _path_module::cleanup_path(const Py::Tuple& args)
14811481
return result;
14821482
}
14831483

1484-
#if PY_MAJOR_VERSION >= 3
1484+
#if PY3K
14851485
extern "C"
14861486
PyMODINIT_FUNC
14871487
PyInit__path(void)
@@ -1496,7 +1496,7 @@ init_path(void)
14961496

14971497
import_array();
14981498

1499-
#if PY_MAJOR_VERSION >= 3
1499+
#if PY3K
15001500
return _path->module().ptr();
15011501
#endif
15021502
}

0 commit comments

Comments
 (0)