Skip to content

Commit e8ad856

Browse files
committed
Applied python2.5 build patch submitted on SF
svn path=/trunk/matplotlib/; revision=2778
1 parent ced976b commit e8ad856

File tree

4 files changed

+38
-29
lines changed

4 files changed

+38
-29
lines changed

CXX/Extensions.hxx

+3-3
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,9 @@ namespace Py
430430
virtual Object number_power( const Object &, const Object & );
431431

432432
// Buffer
433-
virtual int buffer_getreadbuffer( int, void** );
434-
virtual int buffer_getwritebuffer( int, void** );
435-
virtual int buffer_getsegcount( int* );
433+
virtual Py_ssize_t buffer_getreadbuffer( Py_ssize_t, void** );
434+
virtual Py_ssize_t buffer_getwritebuffer( Py_ssize_t, void** );
435+
virtual Py_ssize_t buffer_getsegcount( Py_ssize_t* );
436436

437437
private:
438438
void missing_method( void );

CXX/Objects.hxx

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@
1919
#include <utility>
2020
#include <typeinfo>
2121

22+
#if PY_VERSION_HEX < 0x02050000
23+
typedef int Py_ssize_t;
24+
# define PY_SSIZE_T_MAX INT_MAX
25+
# define PY_SSIZE_T_MIN INT_MIN
26+
#endif
27+
2228
namespace Py
2329
{
2430
typedef int sequence_index_type; // type of an index into a sequence

CXX/cxx_extensions.cxx

+26-23
Original file line numberDiff line numberDiff line change
@@ -149,15 +149,17 @@ extern "C"
149149
static PyObject* iternext_handler (PyObject*);
150150

151151
// Sequence methods
152-
static int sequence_length_handler(PyObject*);
152+
static Py_ssize_t sequence_length_handler(PyObject*);
153153
static PyObject* sequence_concat_handler(PyObject*,PyObject*);
154-
static PyObject* sequence_repeat_handler(PyObject*, int);
155-
static PyObject* sequence_item_handler(PyObject*, int);
156-
static PyObject* sequence_slice_handler(PyObject*, int, int);
157-
static int sequence_ass_item_handler(PyObject*, int, PyObject*);
158-
static int sequence_ass_slice_handler(PyObject*, int, int, PyObject*);
154+
static PyObject* sequence_repeat_handler(PyObject*, Py_ssize_t);
155+
static PyObject* sequence_item_handler(PyObject*, Py_ssize_t);
156+
static PyObject* sequence_slice_handler(PyObject*, Py_ssize_t,
157+
Py_ssize_t);
158+
static int sequence_ass_item_handler(PyObject*, Py_ssize_t, PyObject*);
159+
static int sequence_ass_slice_handler(PyObject*, Py_ssize_t,
160+
Py_ssize_t, PyObject*);
159161
// Mapping
160-
static int mapping_length_handler(PyObject*);
162+
static Py_ssize_t mapping_length_handler(PyObject*);
161163
static PyObject* mapping_subscript_handler(PyObject*, PyObject*);
162164
static int mapping_ass_subscript_handler(PyObject*, PyObject*, PyObject*);
163165

@@ -186,9 +188,9 @@ extern "C"
186188
static PyObject* number_power_handler(PyObject*, PyObject*, PyObject*);
187189

188190
// Buffer
189-
static int buffer_getreadbuffer_handler (PyObject*, int, void**);
190-
static int buffer_getwritebuffer_handler (PyObject*, int, void**);
191-
static int buffer_getsegcount_handler (PyObject*, int*);
191+
static Py_ssize_t buffer_getreadbuffer_handler (PyObject*, Py_ssize_t, void**);
192+
static Py_ssize_t buffer_getwritebuffer_handler (PyObject*, Py_ssize_t, void**);
193+
static Py_ssize_t buffer_getsegcount_handler (PyObject*, Py_ssize_t*);
192194
};
193195

194196

@@ -599,7 +601,7 @@ extern "C" PyObject* iternext_handler( PyObject *self )
599601

600602

601603
// Sequence methods
602-
extern "C" int sequence_length_handler( PyObject *self )
604+
extern "C" Py_ssize_t sequence_length_handler( PyObject *self )
603605
{
604606
try
605607
{
@@ -625,7 +627,7 @@ extern "C" PyObject* sequence_concat_handler( PyObject *self, PyObject *other )
625627
}
626628
}
627629

628-
extern "C" PyObject* sequence_repeat_handler( PyObject *self, int count )
630+
extern "C" PyObject* sequence_repeat_handler( PyObject *self, Py_ssize_t count )
629631
{
630632
try
631633
{
@@ -638,7 +640,7 @@ extern "C" PyObject* sequence_repeat_handler( PyObject *self, int count )
638640
}
639641
}
640642

641-
extern "C" PyObject* sequence_item_handler( PyObject *self, int index )
643+
extern "C" PyObject* sequence_item_handler( PyObject *self, Py_ssize_t index )
642644
{
643645
try
644646
{
@@ -651,7 +653,8 @@ extern "C" PyObject* sequence_item_handler( PyObject *self, int index )
651653
}
652654
}
653655

654-
extern "C" PyObject* sequence_slice_handler( PyObject *self, int first, int last )
656+
extern "C" PyObject* sequence_slice_handler( PyObject *self, Py_ssize_t first,
657+
Py_ssize_t last )
655658
{
656659
try
657660
{
@@ -664,7 +667,7 @@ extern "C" PyObject* sequence_slice_handler( PyObject *self, int first, int last
664667
}
665668
}
666669

667-
extern "C" int sequence_ass_item_handler( PyObject *self, int index, PyObject *value )
670+
extern "C" int sequence_ass_item_handler( PyObject *self, Py_ssize_t index, PyObject *value )
668671
{
669672
try
670673
{
@@ -677,7 +680,7 @@ extern "C" int sequence_ass_item_handler( PyObject *self, int index, PyObject *v
677680
}
678681
}
679682

680-
extern "C" int sequence_ass_slice_handler( PyObject *self, int first, int last, PyObject *value )
683+
extern "C" int sequence_ass_slice_handler( PyObject *self, Py_ssize_t first, Py_ssize_t last, PyObject *value )
681684
{
682685
try
683686
{
@@ -691,7 +694,7 @@ extern "C" int sequence_ass_slice_handler( PyObject *self, int first, int last,
691694
}
692695

693696
// Mapping
694-
extern "C" int mapping_length_handler( PyObject *self )
697+
extern "C" Py_ssize_t mapping_length_handler( PyObject *self )
695698
{
696699
try
697700
{
@@ -1018,7 +1021,7 @@ extern "C" PyObject* number_power_handler( PyObject *self, PyObject *x1, PyObjec
10181021
}
10191022

10201023
// Buffer
1021-
extern "C" int buffer_getreadbuffer_handler( PyObject *self, int index, void **pp )
1024+
extern "C" Py_ssize_t buffer_getreadbuffer_handler( PyObject *self, Py_ssize_t index, void **pp )
10221025
{
10231026
try
10241027
{
@@ -1031,7 +1034,7 @@ extern "C" int buffer_getreadbuffer_handler( PyObject *self, int index, void **p
10311034
}
10321035
}
10331036

1034-
extern "C" int buffer_getwritebuffer_handler( PyObject *self, int index, void **pp )
1037+
extern "C" Py_ssize_t buffer_getwritebuffer_handler( PyObject *self, Py_ssize_t index, void **pp )
10351038
{
10361039
try
10371040
{
@@ -1044,7 +1047,7 @@ extern "C" int buffer_getwritebuffer_handler( PyObject *self, int index, void **
10441047
}
10451048
}
10461049

1047-
extern "C" int buffer_getsegcount_handler( PyObject *self, int *count )
1050+
extern "C" Py_ssize_t buffer_getsegcount_handler( PyObject *self, Py_ssize_t *count )
10481051
{
10491052
try
10501053
{
@@ -1212,13 +1215,13 @@ Py::Object PythonExtensionBase::number_power( const Py::Object &, const Py::Obje
12121215

12131216

12141217
// Buffer
1215-
int PythonExtensionBase::buffer_getreadbuffer( int, void** )
1218+
Py_ssize_t PythonExtensionBase::buffer_getreadbuffer( Py_ssize_t, void** )
12161219
{ missing_method( buffer_getreadbuffer ); return -1; }
12171220

1218-
int PythonExtensionBase::buffer_getwritebuffer( int, void** )
1221+
Py_ssize_t PythonExtensionBase::buffer_getwritebuffer( Py_ssize_t, void** )
12191222
{ missing_method( buffer_getwritebuffer ); return -1; }
12201223

1221-
int PythonExtensionBase::buffer_getsegcount( int* )
1224+
Py_ssize_t PythonExtensionBase::buffer_getsegcount( Py_ssize_t* )
12221225
{ missing_method( buffer_getsegcount ); return -1; }
12231226

12241227
//--------------------------------------------------------------------------------

src/_image.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -1256,15 +1256,15 @@ _image_module::frombuffer(const Py::Tuple& args) {
12561256

12571257
imo->rowsIn = y;
12581258
imo->colsIn = x;
1259-
size_t NUMBYTES(imo->colsIn * imo->rowsIn * imo->BPP);
1259+
ssize_t NUMBYTES(imo->colsIn * imo->rowsIn * imo->BPP);
12601260

1261-
int buflen;
1261+
Py_ssize_t buflen;
12621262
const agg::int8u *rawbuf;
12631263
if (PyObject_AsReadBuffer(bufin, reinterpret_cast<const void**>(&rawbuf), &buflen) != 0)
12641264
throw Py::ValueError("Cannot get buffer from object.");
12651265

12661266
// Check buffer is required size.
1267-
if ((size_t)buflen != NUMBYTES)
1267+
if (buflen != NUMBYTES)
12681268
throw Py::ValueError("Buffer length must be width * height * 4.");
12691269

12701270
// Copy from input buffer to new buffer for agg.

0 commit comments

Comments
 (0)