From: Alex M. <al...@us...> - 2006-04-22 16:28:24
|
Update of /cvsroot/gmpy/gmpy/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11215/src Modified Files: gmpy.c gmpy.h Log Message: Test the monkeypatching of decimal.Decimal Index: gmpy.c =================================================================== RCS file: /cvsroot/gmpy/gmpy/src/gmpy.c,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** gmpy.c 30 Mar 2006 00:57:34 -0000 1.22 --- gmpy.c 22 Apr 2006 16:28:19 -0000 1.23 *************** *** 126,129 **** --- 126,133 ---- * two bugfixes, thanks to Simon Burton * + * 1.03: + * add support for Py_ssize_t for compatibility with Python 2.5 + * add support for __index__ in Python 2.5 + * */ #include "pymemcompat.h" *************** *** 370,374 **** PyObject *funky_arg=0, *extype, *exvalue, *extb; int i; ! int tlen = PyTuple_Size(args); if(tlen<min || tlen>max) return 0; PyErr_Fetch(&extype, &exvalue, &extb); --- 374,378 ---- PyObject *funky_arg=0, *extype, *exvalue, *extb; int i; ! Py_ssize_t tlen = PyTuple_Size(args); if(tlen<min || tlen>max) return 0; PyErr_Fetch(&extype, &exvalue, &extb); *************** *** 1054,1058 **** PympzObject *newob; unsigned char *cp; ! int len, i; assert(PyString_Check(s)); --- 1058,1063 ---- PympzObject *newob; unsigned char *cp; ! Py_ssize_t len; ! int i; assert(PyString_Check(s)); *************** *** 1123,1127 **** PympqObject *newob; unsigned char *cp; ! int len, i; assert(PyString_Check(stringarg)); --- 1128,1133 ---- PympqObject *newob; unsigned char *cp; ! Py_ssize_t len; ! int i; assert(PyString_Check(stringarg)); *************** *** 1256,1260 **** PympfObject *newob; unsigned char *cp; ! int precision, len, i; assert(PyString_Check(s)); --- 1262,1267 ---- PympfObject *newob; unsigned char *cp; ! Py_ssize_t len; ! int precision, i; assert(PyString_Check(s)); *************** *** 1453,1456 **** --- 1460,1475 ---- } + #if Py_TPFLAGS_HAVE_INDEX + static Py_ssize_t + Pympz_asindex(PympzObject *x) + { + if(notanint(x->z)) { + PyErr_SetString(PyExc_OverflowError, "mpz too large for ssize_t"); + return 0; + } + return mpz_get_si(x->z); + } + #endif + /* * mpf->int delegates via mpf->mpz->int for convenience; ditto mpq->int *************** *** 3152,3156 **** PympzObject *newob; PyObject *obj; ! int argc; if(options.debug) --- 3171,3175 ---- PympzObject *newob; PyObject *obj; ! Py_ssize_t argc; if(options.debug) *************** *** 5466,5469 **** --- 5485,5491 ---- 0, /* binaryfunc nb_inplace_floor_divide; */ 0, /* binaryfunc nb_inplace_true_divide; */ + #if Py_TPFLAGS_HAVE_INDEX + (lenfunc) Pympz_asindex, /* lenfunc nb_index; */ + #endif }; *************** *** 5722,5726 **** (setattrofunc) 0, /* tp_setattro */ (PyBufferProcs *) 0, /* tp_as_buffer */ ! 0, /* Py_TPFLAGS_HAVE_INPLACEOPS, tp_flags */ "GNU Multi Precision signed integer", }; --- 5744,5748 ---- (setattrofunc) 0, /* tp_setattro */ (PyBufferProcs *) 0, /* tp_as_buffer */ ! Py_TPFLAGS_HAVE_INDEX, /* tp_flags */ "GNU Multi Precision signed integer", }; Index: gmpy.h =================================================================== RCS file: /cvsroot/gmpy/gmpy/src/gmpy.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** gmpy.h 30 Mar 2006 00:57:34 -0000 1.5 --- gmpy.h 22 Apr 2006 16:28:19 -0000 1.6 *************** *** 24,27 **** --- 24,35 ---- #include "gmp.h" + /* ensure 2.5 compatibility */ + #if PY_VERSION_HEX < 0x02050000 + typedef int Py_ssize_t; + #endif + #ifndef Py_TPFLAGS_HAVE_INDEX + #define Py_TPFLAGS_HAVE_INDEX 0 + #endif + /* Header file for gmpy */ |