From: Alex M. <al...@us...> - 2005-11-06 03:14:49
|
Update of /cvsroot/gmpy/gmpy/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12508/src Modified Files: gmpy.c gmpy.h Log Message: Brought up to date with latest GMP release and MacOSX 10.4's XCode Fixed memory leak in divm Index: gmpy.c =================================================================== RCS file: /cvsroot/gmpy/gmpy/src/gmpy.c,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** gmpy.c 23 Dec 2004 08:11:08 -0000 1.9 --- gmpy.c 6 Nov 2005 03:14:41 -0000 1.10 *************** *** 8,11 **** --- 8,12 ---- * addition of mpf's, &c: Alex Martelli (al...@ya..., Nov 2000). * cleanups & reorgs leading to 1.0: Alex Martelli (until Aug 2003) + * further cleanups and bugfixes leading to 1.01, Alex Martelli (Nov 2005) * * Some hacks by Gustavo Niemeyer <nie...@co...>. *************** *** 107,110 **** --- 108,114 ---- * SELF_ONE_ARG_CONVERTED (tx to Paul Rubin!) * + * 1.01: + * cleanups, ensure support for Python 2.4.1 on MacOSX 10.4/XCode 2.1 + * */ #include "pymemcompat.h" *************** *** 126,132 **** #define USE_ALLOCA 1 #define alloca _alloca #endif ! char gmpy_version[] = "1.0"; /* --- 130,138 ---- #define USE_ALLOCA 1 #define alloca _alloca + #undef staticforward + #define staticforward extern #endif ! char gmpy_version[] = "1.01"; /* *************** *** 1012,1016 **** len = PyString_Size(s); ! cp = PyString_AsString(s); if(256 == base) { --- 1018,1022 ---- len = PyString_Size(s); ! cp = (unsigned char*)PyString_AsString(s); if(256 == base) { *************** *** 1046,1050 **** } /* delegate rest to GMP's _set_str function */ ! if(-1 == mpz_set_str(newob->z, cp, base)) { PyErr_SetString(PyExc_ValueError, "invalid digits"); Py_DECREF((PyObject *) newob); --- 1052,1056 ---- } /* delegate rest to GMP's _set_str function */ ! if(-1 == mpz_set_str(newob->z, (char*)cp, base)) { PyErr_SetString(PyExc_ValueError, "invalid digits"); Py_DECREF((PyObject *) newob); *************** *** 1078,1082 **** len = PyString_Size(stringarg); ! cp = PyString_AsString(stringarg); if(256 == base) { --- 1084,1088 ---- len = PyString_Size(stringarg); ! cp = (unsigned char*)PyString_AsString(stringarg); if(256 == base) { *************** *** 1098,1102 **** return 0; } ! s = PyString_FromStringAndSize(cp+4, numlen); numerator = str2mpz(s,256); Py_DECREF(s); --- 1104,1108 ---- return 0; } ! s = PyString_FromStringAndSize((char*)cp+4, numlen); numerator = str2mpz(s,256); Py_DECREF(s); *************** *** 1109,1113 **** if(isnega) mpz_neg(numerator->z, numerator->z); ! s = PyString_FromStringAndSize(cp+4+numlen, len-4-numlen); denominator = str2mpz(s,256); Py_DECREF(s); --- 1115,1119 ---- if(isnega) mpz_neg(numerator->z, numerator->z); ! s = PyString_FromStringAndSize((char*)cp+4+numlen, len-4-numlen); denominator = str2mpz(s,256); Py_DECREF(s); *************** *** 1136,1142 **** /* trickily delegate the rest to GMP avoiding allocations/copies */ { ! char* whereslash = strchr(cp,'/'); if(whereslash) *whereslash = 0; ! if(-1 == mpz_set_str(mpq_numref(newob->q), cp, base)) { if(whereslash) *whereslash = '/'; PyErr_SetString(PyExc_ValueError, "invalid digits"); --- 1142,1148 ---- /* trickily delegate the rest to GMP avoiding allocations/copies */ { ! char* whereslash = strchr((char*)cp,'/'); if(whereslash) *whereslash = 0; ! if(-1 == mpz_set_str(mpq_numref(newob->q), (char*)cp, base)) { if(whereslash) *whereslash = '/'; PyErr_SetString(PyExc_ValueError, "invalid digits"); *************** *** 1184,1196 **** assert(PyString_Check(s)); len = PyString_Size(s); ! cp = PyString_AsString(s); ! ! /*** ! * fprintf(stderr, "len is %d, cb=%d\n", len, *cp); ! * fprintf(stderr, "the string is: "); ! * for(i=0; i<len; ++i) ! * fprintf(stderr, "%2.2x ", cp[i]); ! * fprintf(stderr,"\n"); ! ***/ if(bits>0) { --- 1190,1194 ---- assert(PyString_Check(s)); len = PyString_Size(s); ! cp = (unsigned char*)PyString_AsString(s); if(bits>0) { *************** *** 1213,1217 **** if(!(newob = Pympf_new(precision))) return NULL; ! if(256 == base) { /* --- 1211,1215 ---- if(!(newob = Pympf_new(precision))) return NULL; ! if(256 == base) { /* *************** *** 1232,1240 **** unsigned int expomag = 0; - /*** - * fprintf(stderr, "cb=%d, resusi=%d, exposi=%d, resuze=%d, precilen=%d\n", - * codebyte, resusign, exposign, resuzero, precilen); - ***/ - /* mpf zero has a very compact (1-byte) binary encoding!-) */ if(resuzero) { --- 1230,1233 ---- *************** *** 1285,1289 **** } /* delegate the rest to GMP */ ! if(-1 == mpf_set_str(newob->f, cp, base)) { PyErr_SetString(PyExc_ValueError, "invalid digits"); --- 1278,1282 ---- } /* delegate the rest to GMP */ ! if(-1 == mpf_set_str(newob->f, (char*)cp, base)) { PyErr_SetString(PyExc_ValueError, "invalid digits"); *************** *** 1596,1600 **** /* prepare codebyte */ sign = mpf_sgn(x->f); - /* fprintf(stderr, "sign is %d\n", sign); */ if(sign==0) { /* 0 -> single codebyte with 'zerovalue' bit set */ --- 1589,1592 ---- *************** *** 4306,4309 **** --- 4298,4304 ---- } } + Py_DECREF((PyObject*)num); + Py_DECREF((PyObject*)den); + Py_DECREF((PyObject*)mod); return (PyObject*)res; } else { *************** *** 4315,4318 **** --- 4310,4316 ---- PyErr_SetString(PyExc_ZeroDivisionError, "not invertible"); } + Py_DECREF((PyObject*)num); + Py_DECREF((PyObject*)den); + Py_DECREF((PyObject*)mod); Py_DECREF((PyObject*)res); return result; *************** *** 4435,4439 **** mpf_mul_ui(ix, ix, 2); /* Check for convergence */ ! if (!(mpf_cmp_si(r_i2, 0) && mpf_get_prec(r_i2) >= precision)) { mpf_mul(pi->f, pi->f, r_i4); mpf_div(pi->f, pi->f, r_i3); --- 4433,4438 ---- mpf_mul_ui(ix, ix, 2); /* Check for convergence */ ! if (!(mpf_cmp_si(r_i2, 0) && ! mpf_get_prec(r_i2) >= (unsigned)precision)) { mpf_mul(pi->f, pi->f, r_i4); mpf_div(pi->f, pi->f, r_i3); Index: gmpy.h =================================================================== RCS file: /cvsroot/gmpy/gmpy/src/gmpy.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** gmpy.h 8 Aug 2003 08:57:05 -0000 1.2 --- gmpy.h 6 Nov 2005 03:14:41 -0000 1.3 *************** *** 5,9 **** Created by Pearu Peterson <pe...@ce...>, November 2000. Edited by A. Martelli <al...@ya...>, December 2000. ! Version 1.0, August 2003. */ --- 5,9 ---- Created by Pearu Peterson <pe...@ce...>, November 2000. Edited by A. Martelli <al...@ya...>, December 2000. ! Version 1.01, November 2005. */ *************** *** 100,108 **** #ifdef GMPY_MODULE /* This section is used when compiling gmpy.c */ ! extern PyTypeObject Pympz_Type; #define Pympz_Check(v) (((PyObject*)v)->ob_type == &Pympz_Type) ! extern PyTypeObject Pympq_Type; #define Pympq_Check(v) (((PyObject*)v)->ob_type == &Pympq_Type) ! extern PyTypeObject Pympf_Type; #define Pympf_Check(v) (((PyObject*)v)->ob_type == &Pympf_Type) --- 100,108 ---- #ifdef GMPY_MODULE /* This section is used when compiling gmpy.c */ ! staticforward PyTypeObject Pympz_Type; #define Pympz_Check(v) (((PyObject*)v)->ob_type == &Pympz_Type) ! staticforward PyTypeObject Pympq_Type; #define Pympq_Check(v) (((PyObject*)v)->ob_type == &Pympq_Type) ! staticforward PyTypeObject Pympf_Type; #define Pympf_Check(v) (((PyObject*)v)->ob_type == &Pympf_Type) |