diff -Nru python-gmpy-1.14/debian/changelog python-gmpy-1.15/debian/changelog --- python-gmpy-1.14/debian/changelog 2011-12-31 02:10:22.000000000 +0000 +++ python-gmpy-1.15/debian/changelog 2012-03-19 20:39:47.000000000 +0000 @@ -1,8 +1,14 @@ -python-gmpy (1.14-3build1) precise; urgency=low +python-gmpy (1.15-1) unstable; urgency=low - * Rebuild to drop python2.6 dependencies. + * New upstream release + * Updated Standards-Version to 3.9.3.0 (no changes needed) + * Updated the watch file to make it actually work (not sure if it really did + before) + * Updated debhelper compatibility level to 9 + * Changed the license symlink to be more specific + * Cleaned up the rules file - -- Matthias Klose Sat, 31 Dec 2011 02:10:22 +0000 + -- Martin Kelly Tue, 13 Mar 2012 23:31:03 -0400 python-gmpy (1.14-3) unstable; urgency=low diff -Nru python-gmpy-1.14/debian/compat python-gmpy-1.15/debian/compat --- python-gmpy-1.14/debian/compat 2010-10-20 20:29:32.000000000 +0000 +++ python-gmpy-1.15/debian/compat 2012-03-19 19:57:02.000000000 +0000 @@ -1 +1 @@ -5 +9 diff -Nru python-gmpy-1.14/debian/control python-gmpy-1.15/debian/control --- python-gmpy-1.14/debian/control 2011-03-26 09:36:04.000000000 +0000 +++ python-gmpy-1.15/debian/control 2012-03-20 23:54:08.000000000 +0000 @@ -2,11 +2,11 @@ Section: python Priority: optional Maintainer: Martin Kelly -Build-Depends: debhelper (>= 5.0.38), python-all-dev (>= 2.6.5), libgmp-dev -Standards-Version: 3.9.1.0 +Build-Depends: debhelper (>= 9), python-all-dev (>= 2.6.5), libgmp-dev +Standards-Version: 3.9.3.0 Homepage: http://code.google.com/p/gmpy/ Uploaders: Debian Python Modules Team -XS-Python-Version: >= 2.3 +X-Python-Version: >= 2.3 Package: python-gmpy Architecture: any diff -Nru python-gmpy-1.14/debian/copyright python-gmpy-1.15/debian/copyright --- python-gmpy-1.14/debian/copyright 2010-10-20 20:29:32.000000000 +0000 +++ python-gmpy-1.15/debian/copyright 2012-03-19 20:43:29.000000000 +0000 @@ -28,7 +28,7 @@ Copyright 2000 by Pearu Peterson On Debian systems, the complete text of the GNU Lesser General -Public License can be found in `/usr/share/common-licenses/LGPL'. +Public License can be found in `/usr/share/common-licenses/LGPL-2.1'. The Debian packaging is Copyright 2007-2010 Martin Kelly and -is licensed under the GPL, see `/usr/share/common-licenses/GPL'. +is licensed under the GPL, see `/usr/share/common-licenses/GPL-2'. diff -Nru python-gmpy-1.14/debian/rules python-gmpy-1.15/debian/rules --- python-gmpy-1.14/debian/rules 2010-10-20 20:29:32.000000000 +0000 +++ python-gmpy-1.15/debian/rules 2012-03-21 23:23:32.000000000 +0000 @@ -10,7 +10,9 @@ find . -name *\.py[co] -exec rm {} \; dh_clean -build: $(PYVERS:%=build-python%) +build: build-arch + +build-arch: $(PYVERS:%=build-python%) touch $@ build-python%: @@ -18,6 +20,8 @@ python$* setup.py build touch $@ +build-indep: + install: build $(PYVERS:%=install-python%) install-python%: diff -Nru python-gmpy-1.14/debian/watch python-gmpy-1.15/debian/watch --- python-gmpy-1.14/debian/watch 2010-12-21 16:45:06.000000000 +0000 +++ python-gmpy-1.15/debian/watch 2012-03-14 03:31:20.000000000 +0000 @@ -1,4 +1,3 @@ # Compulsory line, this is a version 3 file version=3 -opts="uversionmangle=s/(.*[0-9.])/$1/" \ -http://code.google.com/p/gmpy/downloads/list http://gmpy.googlecode.com/files/gmpy-(.*).zip +http://code.google.com/p/gmpy/downloads/list?can=1 .*/gmpy-(\d[\d\.]*)\.(?:zip|tgz|tbz2|txz|tar\.gz|tar\.bz2|tar\.xz) diff -Nru python-gmpy-1.14/PKG-INFO python-gmpy-1.15/PKG-INFO --- python-gmpy-1.14/PKG-INFO 2010-11-13 20:12:24.000000000 +0000 +++ python-gmpy-1.15/PKG-INFO 2012-01-11 20:52:52.000000000 +0000 @@ -1,23 +1,23 @@ -Metadata-Version: 1.0 -Name: gmpy -Version: 1.14 -Summary: MPIR/GMP interface to Python 2.4+ and 3.x -Home-page: http://code.google.com/p/gmpy/ -Author: Alex Martelli -Author-email: aleaxit@gmail.com -License: UNKNOWN -Description: UNKNOWN -Platform: UNKNOWN -Classifier: Development Status :: 5 - Production/Stable -Classifier: Intended Audience :: Developers -Classifier: Intended Audience :: Science/Research -Classifier: License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL) -Classifier: Natural Language :: English -Classifier: Operating System :: MacOS :: MacOS X -Classifier: Operating System :: Microsoft :: Windows -Classifier: Operating System :: POSIX -Classifier: Programming Language :: C -Classifier: Programming Language :: Python :: 2 -Classifier: Programming Language :: Python :: 3 -Classifier: Topic :: Scientific/Engineering :: Mathematics -Classifier: Topic :: Software Development :: Libraries :: Python Modules +Metadata-Version: 1.0 +Name: gmpy +Version: 1.15 +Summary: MPIR/GMP interface to Python 2.4+ and 3.x +Home-page: http://code.google.com/p/gmpy/ +Author: Case Van Horsen +Author-email: casevh@gmail.com +License: UNKNOWN +Description: UNKNOWN +Platform: UNKNOWN +Classifier: Development Status :: 5 - Production/Stable +Classifier: Intended Audience :: Developers +Classifier: Intended Audience :: Science/Research +Classifier: License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL) +Classifier: Natural Language :: English +Classifier: Operating System :: MacOS :: MacOS X +Classifier: Operating System :: Microsoft :: Windows +Classifier: Operating System :: POSIX +Classifier: Programming Language :: C +Classifier: Programming Language :: Python :: 2 +Classifier: Programming Language :: Python :: 3 +Classifier: Topic :: Scientific/Engineering :: Mathematics +Classifier: Topic :: Software Development :: Libraries :: Python Modules diff -Nru python-gmpy-1.14/setes.py python-gmpy-1.15/setes.py --- python-gmpy-1.14/setes.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/setes.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,20 +0,0 @@ -import sys -from distutils.core import setup, Extension - -if sys.version.find('MSC')==-1: - gmpy_ext = Extension('pysymbolicext', sources=['src/pysymbolicext.c'], - libraries=['gmp']) -else: - gmpy_ext = Extension('pysymbolicext', sources=['src/pysymbolicext.c'], - libraries=['gmp'],include_dirs=['./src']) - -setup (name = "pysymbolicext", - version = "0.2", - description = "PySymbolic Python/GMP extensions (Pollard's rho)", - author = "Pearu Peterson", - maintainer = "Alex Martelli", - maintainer_email = "aleaxit@gmail.com", - url = "http://code.google.com/p/gmpy/source/", - - ext_modules = [ gmpy_ext ] -) diff -Nru python-gmpy-1.14/setup.py python-gmpy-1.15/setup.py --- python-gmpy-1.14/setup.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/setup.py 2012-01-02 18:45:16.000000000 +0000 @@ -20,11 +20,12 @@ if sys.version.find('MSC') == -1: # Unix-like build (including MacOSX) incdirs = ['./src'] - dirord = ['/opt/local', '/usr/local'] + dirord = ['/usr', '/opt/local', '/usr/local'] for adir in dirord: lookin = '%s/include' % adir if os.path.isfile(lookin + '/' + mplib + '.h'): incdirs.append(lookin) + dirord = [adir] break for adir in dirord: lookin = '%s/lib' % adir @@ -41,12 +42,11 @@ libraries=[mplib]) setup (name = "gmpy", - version = "1.14", - maintainer = "Alex Martelli", - maintainer_email = "aleaxit@gmail.com", + version = "1.15", + maintainer = "Case Van Horsen", + maintainer_email = "casevh@gmail.com", url = "http://code.google.com/p/gmpy/", description = "MPIR/GMP interface to Python 2.4+ and 3.x", - # download_url = "http://http://prdownloads.sourceforge.net/gmpy/gmpy-sources-101.zip?download", classifiers = [ 'Development Status :: 5 - Production/Stable', diff -Nru python-gmpy-1.14/src/gmpy_basic.c python-gmpy-1.15/src/gmpy_basic.c --- python-gmpy-1.14/src/gmpy_basic.c 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/src/gmpy_basic.c 2012-01-02 18:45:16.000000000 +0000 @@ -33,7 +33,7 @@ #if PY_MAJOR_VERSION == 3 int overflow; #endif - unsigned int bits; + size_t bits; /* Try to make mpz + small_int faster */ @@ -225,7 +225,7 @@ #if PY_MAJOR_VERSION == 3 int overflow; #endif - unsigned int bits; + size_t bits; if(Pympz_Check(a)) { if(!(rz = Pympz_new())) @@ -417,7 +417,7 @@ PympqObject *rq = 0, *paq = 0, *pbq = 0; PympfObject *rf = 0, *paf = 0, *pbf = 0; long temp; - unsigned int bits; + size_t bits; #if PY_MAJOR_VERSION == 3 int overflow; #endif @@ -621,7 +621,7 @@ PympqObject *rq = 0, *paq = 0, *pbq = 0; PympfObject *rf = 0, *paf = 0, *pbf = 0; long temp; - unsigned int bits; + size_t bits; #if PY_MAJOR_VERSION == 3 int overflow; #endif @@ -853,7 +853,7 @@ PyObject *r = 0; PympqObject *rq = 0, *paq = 0, *pbq = 0; PympfObject *rf = 0, *paf = 0, *pbf = 0; - unsigned int bits; + size_t bits; if(Pympz_Check(b) && (mpz_sgn(Pympz_AS_MPZ(b)) == 0)) { PyErr_SetString(PyExc_ZeroDivisionError, "mpz division by zero"); @@ -1018,7 +1018,7 @@ PympqObject *rq = 0, *paq = 0, *pbq = 0; PympfObject *rf = 0, *paf = 0, *pbf = 0; long temp; - unsigned int bits; + size_t bits; #if PY_MAJOR_VERSION == 3 int overflow; #endif @@ -1254,7 +1254,7 @@ PympqObject *rq = 0, *paq = 0, *pbq = 0; PympfObject *rf = 0, *paf = 0, *pbf = 0; long temp; - unsigned int bits; + size_t bits, tempbits; #if PY_MAJOR_VERSION == 3 int overflow; #endif @@ -1455,11 +1455,11 @@ bits = paf->rebits; if(pbf->rebitsrebits; /* To prevent rounding errors, the working precision is increased. */ - temp = (paf->f->_mp_exp - pbf->f->_mp_exp) * GMP_NUMB_BITS + bits; + tempbits = (paf->f->_mp_exp - pbf->f->_mp_exp) * GMP_NUMB_BITS + bits; if(options.debug) { - fprintf(stderr, "Working precision %ld\n", temp); + fprintf(stderr, "Working precision %ld\n", tempbits); } - if (!(rf = Pympf_new(temp))) { + if (!(rf = Pympf_new(tempbits))) { Py_DECREF((PyObject*)paf); Py_DECREF((PyObject*)pbf); return NULL; } @@ -1497,7 +1497,7 @@ PympqObject *rq = 0, *paq = 0, *pbq = 0; PympfObject *qf = 0, *rf = 0, *paf = 0, *pbf = 0; long temp; - unsigned int bits; + size_t bits, tempbits; #if PY_MAJOR_VERSION == 3 int overflow; #endif @@ -1551,6 +1551,7 @@ PyErr_SetString(PyExc_ZeroDivisionError, "mpz divmod by zero"); Py_DECREF((PyObject*)rz); Py_DECREF((PyObject*)qz); + Py_DECREF(r); return NULL; } else { mpz_cdiv_qr_ui(qz->z, rz->z, Pympz_AS_MPZ(a), -temp); @@ -1624,17 +1625,21 @@ pbq = anyrational2Pympq(b); if(!paq || !pbq) { PyErr_SetString(PyExc_SystemError, "Can not convert rational to mpq"); - Py_XDECREF((PyObject*)paq); Py_XDECREF((PyObject*)pbq); + Py_XDECREF((PyObject*)paq); + Py_XDECREF((PyObject*)pbq); return NULL; } if(mpq_sgn(pbq->q)==0) { PyErr_SetString(PyExc_ZeroDivisionError, "mpq divmod by zero"); - Py_DECREF((PyObject*)paq); Py_DECREF((PyObject*)pbq); + Py_DECREF((PyObject*)paq); + Py_DECREF((PyObject*)pbq); return NULL; } if (!(rq = Pympq_new()) || !(qz = Pympz_new())) { - Py_XDECREF((PyObject*)rq); Py_XDECREF((PyObject*)qz); - Py_DECREF((PyObject*)paq); Py_DECREF((PyObject*)pbq); + Py_XDECREF((PyObject*)rq); + Py_XDECREF((PyObject*)qz); + Py_DECREF((PyObject*)paq); + Py_DECREF((PyObject*)pbq); return NULL; } mpq_div(rq->q, paq->q, pbq->q); @@ -1760,11 +1765,11 @@ bits = paf->rebits; if(pbf->rebitsrebits; /* To prevent rounding errors, the working precision is increased. */ - temp = (paf->f->_mp_exp - pbf->f->_mp_exp) * GMP_NUMB_BITS + bits; + tempbits = (paf->f->_mp_exp - pbf->f->_mp_exp) * GMP_NUMB_BITS + bits; if(options.debug) { - fprintf(stderr, "Working precision %ld\n", temp); + fprintf(stderr, "Working precision %ld\n", tempbits); } - if (!(qf = Pympf_new(temp)) || !(rf = Pympf_new(temp))) { + if (!(qf = Pympf_new(tempbits)) || !(rf = Pympf_new(tempbits))) { Py_XDECREF((PyObject*)qf); Py_XDECREF((PyObject*)rf); Py_DECREF((PyObject*)paf); Py_DECREF((PyObject*)pbf); return NULL; diff -Nru python-gmpy-1.14/src/gmpy.c python-gmpy-1.15/src/gmpy.c --- python-gmpy-1.14/src/gmpy.c 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/src/gmpy.c 2012-01-11 20:08:44.000000000 +0000 @@ -2,6 +2,7 @@ * * Python interface to the GMP or MPIR multiple precision library, * Copyright (C) 2000 - 2010 Alex Martelli + * Copyright (C) 2008 - 2012 Case Van Horsen * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -193,7 +194,7 @@ * Added % and divmod support to mpq and mpf (casevh) * Changed memory allocation functions to use PyMem (casevh) * Removed small number interning (casevh) - * Added tdivmod, cdivmod, and fdivmoc (casevh) + * Added tdivmod, cdivmod, and fdivmod (casevh) * Added more helper functions for mpmath (casevh) * Faster mpz<>PyLong conversion (casevh) * Faster hash(mpz) (casevh) @@ -218,6 +219,13 @@ * Fixed incorrect type declaration for options.debug (casevh) * Support wide hash result on Win64, new for Python 3.2 (casevh) * Fix repr(mpq) formatting when denominator was 1 (casevh) + * + * 1.15 + * Fix ref-count bug in divmod(x,0) (casevh) + * Fix crash in remove(n,1) (casevh) + * Discontinue use of custom memory allocator & PyMem (casevh) + * Modified directory search logic in setup.py (casevh) + * Allow base-62 conversion for mpz and mpf (casevh) */ #include "Python.h" @@ -235,11 +243,6 @@ #define GMPY_MODULE #include "gmpy.h" -/* Define the minimum memory amount allocated. 8 has historically been - * used, but 16 might be better for some applications or 64-bit systems. - */ -#define GMPY_ALLOC_MIN (2 * (GMP_NUMB_BITS >> 3)) - /* To prevent excessive memory usage, we don't want to save very large * numbers in the cache. The default value specified in the options * structure is 128 words (512 bytes on 32-bit platforms, 1024 bytes on @@ -373,9 +376,9 @@ #endif #undef GNU_MP_VER -char gmpy_version[] = "1.14"; +char gmpy_version[] = "1.15"; -char _gmpy_cvs[] = "$Id: gmpy.c 418 2010-10-27 04:45:35Z casevh $"; +char _gmpy_cvs[] = "$Id: gmpy.c 621 2012-01-03 06:33:46Z casevh $"; #define ALLOC_THRESHOLD 8192 @@ -384,19 +387,19 @@ if(S < ALLOC_THRESHOLD) { \ B = alloca(S); \ } else { \ - if(!(B = PyMem_Malloc(S))) { \ + if(!(B = malloc(S))) { \ PyErr_NoMemory(); \ return NULL; \ } \ } -#define TEMP_FREE(B, S) if(S >= ALLOC_THRESHOLD) PyMem_Free(B) +#define TEMP_FREE(B, S) if(S >= ALLOC_THRESHOLD) free(B) #else #define TEMP_ALLOC(B, S) \ - if(!(B = PyMem_Malloc(S))) { \ + if(!(B = malloc(S))) { \ PyErr_NoMemory(); \ return NULL; \ } -#define TEMP_FREE(B, S) PyMem_Free(B) +#define TEMP_FREE(B, S) free(B) #endif /* @@ -405,11 +408,11 @@ static PyObject *gmpy_module = NULL; static struct gmpy_options { - int debug; /* != 0 if debug messages desired on stderr */ - unsigned long minprec; /* min #of bits' precision on new mpf's built */ + int debug; /* != 0 if debug messages desired on stderr */ + long minprec; /* min #of bits' precision on new mpf's built */ int tagoff; /* 0 for full tags 'gmpy.mpz()', else 5 for 'mpz()' */ - int cache_size; /* size of cache, for all caches */ - int cache_obsize; /* maximum size of the objects that are cached */ + int cache_size; /* size of cache, for all caches */ + int cache_obsize; /* maximum size of the objects that are cached */ PyObject* fcoform; /* if non-NULL, format for float->mpf (via string) */ } options = { 0, 0, 5, 100, 128, 0 }; @@ -431,7 +434,7 @@ mpX_clear(Xcache[i]); \ in_Xcache = options.cache_size; \ } \ - Xcache = PyMem_Realloc(Xcache, sizeof(mpX_t)*options.cache_size); \ + Xcache = realloc(Xcache, sizeof(mpX_t)*options.cache_size); \ } DEFCACHE(mpz_t,zcache,in_zcache,set_zcache,mpz_clear) @@ -555,7 +558,7 @@ } in_pympzcache = options.cache_size; } - pympzcache = PyMem_Realloc(pympzcache, sizeof(PympzObject)*options.cache_size); + pympzcache = realloc(pympzcache, sizeof(PympzObject)*options.cache_size); } /* Cache Pympq objects directly */ @@ -576,7 +579,7 @@ } in_pympqcache = options.cache_size; } - pympqcache = PyMem_Realloc(pympqcache, sizeof(PympqObject)*options.cache_size); + pympqcache = realloc(pympqcache, sizeof(PympqObject)*options.cache_size); } /* forward declarations of type-objects and method-arrays for them */ #ifdef _MSC_VER @@ -586,7 +589,8 @@ PyMethodDef Pympz_methods []; PyMethodDef Pympq_methods []; PyMethodDef Pympf_methods []; -#else +#endif +#ifdef ignore_me static PyTypeObject Pympz_Type; static PyTypeObject Pympq_Type; static PyTypeObject Pympf_Type; @@ -894,7 +898,7 @@ } static PympfObject * -Pympf_new(unsigned int bits) +Pympf_new(size_t bits) { PympfObject * self; @@ -911,7 +915,7 @@ Pympz_dealloc(PympzObject *self) { if(options.debug) - fprintf(stderr, "Pympz_dealloc: %p\n", self); + fprintf(stderr, "Pympz_dealloc: %p\n", (void *)self); if(in_pympzcachez->_mp_alloc<=options.cache_obsize) { (pympzcache[in_pympzcache++]) = self; } else { @@ -924,7 +928,7 @@ Pympq_dealloc(PympqObject *self) { if(options.debug) - fprintf(stderr, "Pympq_dealloc: %p\n", self); + fprintf(stderr, "Pympq_dealloc: %p\n", (void *)self); if(in_pympqcacheq)->_mp_alloc <= options.cache_obsize && mpq_denref(self->q)->_mp_alloc <= options.cache_obsize) { @@ -939,7 +943,7 @@ Pympf_dealloc(PympfObject *self) { if(options.debug) - fprintf(stderr, "Pympf_dealloc: %p\n", self); + fprintf(stderr, "Pympf_dealloc: %p\n", (void *)self); mpf_clear(self->f); PyObject_Del(self); } /* Pympf_dealloc */ @@ -954,7 +958,7 @@ static void Pympf_normalize(PympfObject *i) { - long size, prec, toclear, temp; + Py_ssize_t temp, toclear, size, prec; mp_limb_t bit1, rem, carry; prec = mpf_get_prec(i->f); @@ -1017,7 +1021,7 @@ } static PympfObject * -Pympf2Pympf(PympfObject *f, unsigned int bits) +Pympf2Pympf(PympfObject *f, size_t bits) { PympfObject *newob; @@ -1058,7 +1062,7 @@ } static PympfObject * -PyInt2Pympf(PyObject *i, unsigned int bits) +PyInt2Pympf(PyObject *i, size_t bits) { PympfObject *newob; long li; @@ -1112,9 +1116,9 @@ /* forward...: */ static PyObject *f2q_internal(PympfObject* self, PympfObject* err, - unsigned int bits, int mayz); + size_t bits, int mayz); static PyObject* Pympf_f2q(PyObject *self, PyObject *args); -static PympfObject* anynum2Pympf(PyObject* obj, unsigned int bits); +static PympfObject* anynum2Pympf(PyObject* obj, size_t bits); static PympqObject * PyFloat2Pympq(PyObject *f) @@ -1140,17 +1144,18 @@ } /* forward */ -static PympfObject *PyStr2Pympf(PyObject *s, long base, unsigned int bits); +static PympfObject *PyStr2Pympf(PyObject *s, long base, size_t bits); static PympfObject * -PyFloat2Pympf(PyObject *f, unsigned int bits) +PyFloat2Pympf(PyObject *f, size_t bits) { PympfObject *newob = 0; assert(PyFloat_Check(f)); if(!bits) bits=double_mantissa; if(options.debug) - fprintf(stderr, "PyFloat2Pympf(%p,%d)\n", f, bits); + fprintf(stderr, "PyFloat2Pympf(%p,%"PY_FORMAT_SIZE_T"d)\n", + (void *)f, bits); if(options.fcoform) { /* 2-step float->mpf conversion process: first, get a @@ -1197,7 +1202,7 @@ } static PympfObject * -Pympz2Pympf(PyObject * obj, unsigned int bits) +Pympz2Pympf(PyObject * obj, size_t bits) { PympfObject *newob; @@ -1246,7 +1251,7 @@ } static PympfObject * -Pympq2Pympf(PyObject * obj, unsigned int bits) +Pympq2Pympf(PyObject * obj, size_t bits) { PympfObject *newob; @@ -1292,7 +1297,7 @@ * the above-seen dependencies; ditto long->mpq */ static PympfObject * -PyLong2Pympf(PyObject * obj, unsigned int bits) +PyLong2Pympf(PyObject * obj, size_t bits) { PympfObject *newob; PyObject *intermediate = (PyObject*)PyLong2Pympz(obj); @@ -1316,7 +1321,7 @@ /* * mpz conversion from string includes from-binary (base-256 LSB string - * of bytes) and 'true' from-string (bases 2 to 36; bases 8 and 16 are + * of bytes) and 'true' from-string (bases 2 to 62; bases 8 and 16 are * special -- decorations of leading 0/0x are allowed (not required). * * Binary form was previously (0.6) limited to >=0 values; now (0.7) @@ -1590,16 +1595,15 @@ /* * mpf conversion from string includes from-binary (base-256, format is - * explained later) and 'true' from-string (bases 2 to 36), where exponent + * explained later) and 'true' from-string (bases 2 to 62), where exponent * if any is denoted by 'e' if base<=10, else by '@', and is always decimal. */ static PympfObject * -PyStr2Pympf(PyObject *s, long base, unsigned int bits) +PyStr2Pympf(PyObject *s, long base, size_t bits) { PympfObject *newob; unsigned char *cp; - Py_ssize_t len; - int precision, i; + Py_ssize_t len, precision, i; PyObject *ascii_str = NULL; #if PY_MAJOR_VERSION >= 3 @@ -1637,7 +1641,7 @@ cp = (unsigned char*)PyString_AsString(ascii_str); } #endif - if(bits>0) { + if(bits != 0) { precision = bits; } else { /* precision to be defaulted or fetched */ if(base == 256) { /* it may be encoded for fetching */ @@ -1890,10 +1894,10 @@ static PyObject * Pympq2binary(PympqObject *x) { - int sizenum, sizeden, size, sizetemp; + size_t sizenum, sizeden, size, sizetemp; int negative=0; char *buffer; - int i; + size_t i; PyObject *s; assert(Pympq_Check( (PyObject *) x)); @@ -1942,7 +1946,7 @@ static char table[] = "0123456789abcdef"; char* p = strchr(table, tolower(hedi)); assert(hedi && p); - return p-table; + return (int) (p-table); } static char di256(int di1, int di2) { @@ -1955,13 +1959,13 @@ static PyObject * Pympf2binary(PympfObject *x) { - int size, hexdigs; + size_t size, hexdigs, lprec; char *buffer, *aux; - int i, j; + size_t i, j; PyObject *s; int sign, codebyte; mp_exp_t the_exp; - long lexp, lprec; + long lexp; int lexpodd, extrabyte; assert(Pympf_Check( (PyObject *) x)); @@ -2044,28 +2048,29 @@ j += 2; } - PyMem_Free(buffer); + free(buffer); return s; } /* - * format mpz into any base (2 to 36), optionally with + * format mpz into any base (2 to 62), optionally with * a "gmpy.mpz(...)" tag around it so it can be recovered * through a Python eval of the resulting string * Note: tag can be just mpz() if options.tagoff=5 */ static char* ztag = "gmpy.mpz("; static PyObject * -mpz_ascii(mpz_t z, int base, int with_tag) +mpz_ascii(mpz_t z, int base, int with_tag, int no_prefix) { PyObject *s; char *buffer, *p; mpz_t temp; - int minus, size; + size_t size; + int minus; - if((base != 0) && ((base < 2) || (base > 36))) { + if((base != 0) && ((base < 2) || (base > 62))) { PyErr_SetString(PyExc_ValueError, - "base must be either 0 or in the interval 2 ... 36"); + "base must be either 0 or in the interval 2 ... 62"); return NULL; } @@ -2097,17 +2102,19 @@ } if(minus) *(p++) = '-'; - if(base == 8) - *(p++) = '0'; - else if(base == 16) { - *(p++) = '0'; - *(p++) = 'x'; + if (!no_prefix) { + if(base == 8) + *(p++) = '0'; + else if(base == 16) { + *(p++) = '0'; + *(p++) = 'x'; + } } mpz_get_str(p, base, temp); /* Doesn't return number of characters */ p = buffer + strlen(buffer); /* Address of NULL byte */ #if PY_MAJOR_VERSION < 3 - if(with_tag && !mpz_fits_slong_p(temp)) + if(with_tag && !no_prefix && !mpz_fits_slong_p(temp)) *(p++) = 'L'; #endif if(with_tag) @@ -2119,19 +2126,19 @@ } static PyObject * -Pympz_ascii(PympzObject *self, int base, int with_tag) +Pympz_ascii(PympzObject *self, int base, int with_tag, int no_prefix) { #if PY_MAJOR_VERSION >= 3 PyObject *s, *t; assert(Pympz_Check( (PyObject *) self)); - t = mpz_ascii(self->z, base, with_tag); + t = mpz_ascii(self->z, base, with_tag, no_prefix); if(!t) return NULL; s = PyUnicode_FromString(PyBytes_AS_STRING(t)); Py_DECREF(t); return s; #else assert(Pympz_Check( (PyObject *) self)); - return mpz_ascii(self->z, base, with_tag); + return mpz_ascii(self->z, base, with_tag, no_prefix); #endif } @@ -2144,14 +2151,14 @@ Pympq_ascii(PympqObject *self, int base, int with_tag) { PyObject *result = 0; - PyObject *numstr = mpz_ascii(mpq_numref(self->q), base, 0); + PyObject *numstr = mpz_ascii(mpq_numref(self->q), base, 0, 0); PyObject *denstr = 0; PyObject *temp = 0; if(!numstr) return 0; if(with_tag || !qden_1(self->q)) { - denstr = mpz_ascii(mpq_denref(self->q), base, 0); + denstr = mpz_ascii(mpq_denref(self->q), base, 0, 0); if(!denstr) { Py_DECREF(numstr); return 0; @@ -2215,7 +2222,7 @@ #define OP_RAW 2 static char ftag[]="gmpy.mpf('"; /* - * format mpf into any base (2 to 36), optionally with + * format mpf into any base (2 to 62), optionally with * a "gmpy.mpf('...')" tag around it so it can be recovered * through a Python eval of the resulting string. * Note: tag can be just mpf() if options.tagoff=5 @@ -2251,9 +2258,9 @@ /* check arguments are valid */ assert(Pympf_Check((PyObject*)self)); - if(! ( (base==0) || ((base >= 2) && (base <= 36)))) { + if(! ( (base==0) || ((base >= 2) && (base <= 62)))) { PyErr_SetString(PyExc_ValueError, - "base must be either 0 or in the interval 2 ... 36"); + "base must be either 0 or in the interval 2 ... 62"); return NULL; } if(digits < 0) { @@ -2265,23 +2272,23 @@ buffer = mpf_get_str(0, &the_exp, base, digits, self->f); if(!*buffer) { /* need to use malloc here for uniformity with mpf_get_str */ - PyMem_Free(buffer); - buffer = PyMem_Malloc(2); + free(buffer); + buffer = malloc(2); strcpy(buffer, "0"); the_exp = 1; } if(optionflags & OP_RAW) { res = Py_BuildValue("(sii)", buffer, the_exp, self->rebits); - PyMem_Free(buffer); + free(buffer); return res; } else { /* insert formatting elements (decimal-point, leading or * trailing 0's, other indication of exponent...) */ - int buflen = strlen(buffer); + size_t buflen = strlen(buffer); /* account for the decimal point that is always inserted */ - int size = buflen+1; + size_t size = buflen+1; char expobuf[24]; char auprebuf[24]; int isfp=1; /* flag: fixed-point format (FP)? */ @@ -2292,7 +2299,7 @@ if(optionflags & OP_TAG) { size += strlen(ftag+options.tagoff) + 2; if(self->rebits != double_mantissa) { - sprintf(auprebuf,",%d",self->rebits); + sprintf(auprebuf,",%"PY_FORMAT_SIZE_T"d",self->rebits); size += strlen(auprebuf); } } @@ -2403,7 +2410,7 @@ *pd++ = ')'; } } - PyMem_Free(buffer); + free(buffer); #if PY_MAJOR_VERSION >= 3 temp = PyUnicode_FromString(PyBytes_AS_STRING(res)); Py_DECREF(res); @@ -2542,7 +2549,7 @@ } if(options.debug) - fprintf(stderr,"anynum2Pympq(%p)->%p\n", obj, newob); + fprintf(stderr,"anynum2Pympq(%p)->%p\n", (void *)obj, (void *)newob); return newob; } @@ -2574,7 +2581,7 @@ } if(options.debug) - fprintf(stderr,"anyrational2Pympq(%p)->%p\n", obj, newob); + fprintf(stderr,"anyrational2Pympq(%p)->%p\n", (void *)obj, (void *)newob); return newob; } @@ -2615,7 +2622,7 @@ } } if(options.debug) - fprintf(stderr,"anynum2Pympz(%p)->%p\n", obj, newob); + fprintf(stderr,"anynum2Pympz(%p)->%p\n", (void *)obj, (void *)newob); return newob; } @@ -2642,7 +2649,7 @@ newob = PyLong2Pympz(obj); } if(options.debug) - fprintf(stderr,"Pympz_From_Integer(%p)->%p\n", obj, newob); + fprintf(stderr,"Pympz_From_Integer(%p)->%p\n", (void *)obj, (void *)newob); if(!newob) { PyErr_SetString(PyExc_TypeError, "conversion error in Pympz_From_Integer"); @@ -2677,7 +2684,7 @@ } static PympfObject* -anynum2Pympf(PyObject* obj, unsigned int bits) +anynum2Pympf(PyObject* obj, size_t bits) { PympfObject* newob = 0; PympqObject* temp = 0; @@ -2721,8 +2728,8 @@ } if(options.debug) - fprintf(stderr, "anynum2Pympf(%p,%d)->%p (%d)\n", obj, - bits, newob, newob != 0 ? newob->rebits : -1); + fprintf(stderr, "anynum2Pympf(%p,%"PY_FORMAT_SIZE_T"d)->%p (%"PY_FORMAT_SIZE_T"d)\n", + (void *)obj, bits, (void *)newob, newob != 0 ? newob->rebits : -1); return newob; } @@ -2735,7 +2742,7 @@ { PympzObject* newob = Pympz_From_Integer(arg); if(options.debug) - fprintf(stderr, "mpz_conv_arg(%p)->%p\n", arg, newob); + fprintf(stderr, "mpz_conv_arg(%p)->%p\n", (void *)arg, (void *)newob); if(newob) { *ptr = (PyObject*)newob; @@ -2755,7 +2762,7 @@ { PympqObject* newob = anyrational2Pympq(arg); if(options.debug) - fprintf(stderr, "mpq_conv_arg(%p)->%p\n", arg, newob); + fprintf(stderr, "mpq_conv_arg(%p)->%p\n", (void *)arg, (void *)newob); if(newob) { *ptr = (PyObject*)newob; @@ -2777,7 +2784,7 @@ { PympfObject* newob = anynum2Pympf(arg,0); if(options.debug) - fprintf(stderr, "mpf_conv_arg(%p)->%p\n", arg, newob); + fprintf(stderr, "mpf_conv_arg(%p)->%p\n", (void *)arg, (void *)newob); if(newob) { *ptr = (PyObject*)newob; @@ -2794,13 +2801,13 @@ Pympz2str(PympzObject *self) { /* base-10, no tag */ - return Pympz_ascii(self, 10, 0); + return Pympz_ascii(self, 10, 0, 0); } static PyObject * Pympz2repr(PympzObject *self) { /* base-10, with tag */ - return Pympz_ascii(self, 10, 1); + return Pympz_ascii(self, 10, 1, 0); } /* str and repr implementations for mpq */ @@ -2885,8 +2892,8 @@ Pympf_copy(PyObject *self, PyObject *args) { PyObject *s; - unsigned int bits=0; - SELF_MPF_ONE_ARG("|I",&bits); + size_t bits=0; + SELF_MPF_ONE_ARG("|n",&bits); assert(Pympf_Check(self)); if(!bits) bits = ((PympfObject*)self)->rebits; @@ -3011,12 +3018,12 @@ /* produce digits for an mpz in requested base, default 10 */ static char doc_digitsm[]="\ x.digits([base]): returns Python string representing x in the\n\ -given base (2 to 36, default 10 if omitted or 0); leading '-'\n\ +given base (2 to 62, default 10 if omitted or 0); leading '-'\n\ is present if x<0, but no leading '+' if x>=0.\n\ "; static char doc_digitsg[]="\ digits(x[,base]): returns Python string representing x in the\n\ -given base (2 to 36, default 10 if omitted or 0); leading '-'\n\ +given base (2 to 62, default 10 if omitted or 0); leading '-'\n\ present if x<0, but no leading '+' if x>=0. x must be an mpz,\n\ or else gets coerced into one.\n\ "; @@ -3028,7 +3035,7 @@ PARSE_ONE_MPZ_OPT_CLONG(&base, "digits() expects 'mpz',['int'] arguments"); assert(Pympz_Check(self)); - s = Pympz_ascii((PympzObject*)self, base, 0); + s = Pympz_ascii((PympzObject*)self, base, 0, 1); Py_DECREF(self); return s; } @@ -3036,14 +3043,14 @@ /* return number-of-digits for an mpz in requested base, default 10 */ static char doc_numdigitsm[]="\ x.numdigits([base]): returns length of string representing x in\n\ -the given base (2 to 36, default 10 if omitted or 0); the value\n\ +the given base (2 to 62, default 10 if omitted or 0); the value\n\ returned may sometimes be 1 more than necessary; no provision\n\ for any 'sign' character, nor leading '0' or '0x' decoration,\n\ is made in the returned length.\n\ "; static char doc_numdigitsg[]="\ numdigits(x[,base]): returns length of string representing x in\n\ -the given base (2 to 36, default 10 if omitted or 0); the value\n\ +the given base (2 to 62, default 10 if omitted or 0); the value\n\ returned may sometimes be 1 more than necessary; no provision\n\ for any 'sign' character, nor leading '0' or '0x' decoration,\n\ is made in the returned length. x must be an mpz, or else gets\n\ @@ -3058,9 +3065,9 @@ PARSE_ONE_MPZ_OPT_CLONG(&base, "numdigits expects 'mpz',[base] arguments"); assert(Pympz_Check(self)); if(base==0) base=10; - if((base < 2) || (base > 36)) { + if((base < 2) || (base > 62)) { PyErr_SetString(PyExc_ValueError, - "base must be either 0 or in the interval 2 ... 36"); + "base must be either 0 or in the interval 2 ... 62"); Py_DECREF(self); return NULL; } @@ -3333,7 +3340,7 @@ { long bit_index; long bit_value=1; - int argc; + Py_ssize_t argc; PympzObject *s; argc = PyTuple_GET_SIZE(args); @@ -3746,7 +3753,7 @@ PympfObject *fself; if(options.debug) - fprintf(stderr, "Pympf_f2q: %p, %p\n", self, args); + fprintf(stderr, "Pympf_f2q: %p, %p\n", (void *)self, (void *)args); SELF_MPF_ONE_ARG_CONVERTED_OPT(&err); assert(Pympf_Check(self)); @@ -3756,7 +3763,7 @@ } static PyObject * -f2q_internal(PympfObject* self, PympfObject* err, unsigned int bits, int mayz) +f2q_internal(PympfObject* self, PympfObject* err, size_t bits, int mayz) { PympqObject *res = 0; int i, negative, errsign; @@ -3773,9 +3780,9 @@ mpf_set_si(err->f, 1); mpf_div_2exp(err->f, err->f, bits); } else if(errsign < 0) { - int ubits; + long ubits; mpf_floor(err->f, err->f); - ubits = (int)mpf_get_d(err->f); + ubits = mpf_get_d(err->f); mpf_set_si(err->f, 1); mpf_div_2exp(err->f, err->f, -ubits); } @@ -3888,10 +3895,10 @@ "gmpy.mpz(): base must be an integer"); return NULL; } - if((base!=0) && (base!=256) && ((base<2)||(base>36))) { + if((base!=0) && (base!=256) && ((base<2)||(base>62))) { PyErr_SetString(PyExc_ValueError, "base for gmpy.mpz must be 0, 256, or in the " - "interval 2 ... 36 ."); + "interval 2 ... 62 ."); return NULL; } } @@ -3938,7 +3945,7 @@ PympqObject *newob; PyObject *obj; int wasnumeric; - int argc; + Py_ssize_t argc; if(options.debug) fputs("Pygmpy_mpq() called...\n", stderr); @@ -4038,8 +4045,8 @@ { PympfObject *newob; PyObject *obj; - int argc; - unsigned int bits=0; + Py_ssize_t argc; + size_t bits=0; if(options.debug) fputs("Pygmpy_mpf() called...\n", stderr); @@ -4087,10 +4094,10 @@ "gmpy.mpf(): base must be an integer"); return NULL; } - if((base!=0) && (base!=256) && ((base<2)||(base>36))) { + if((base!=0) && (base!=256) && ((base<2)||(base>62))) { PyErr_SetString(PyExc_ValueError, "base for gmpy.mpf must be 0, 256, or in the " - "interval 2 ... 36 ."); + "interval 2 ... 62 ."); return NULL; } } @@ -4115,7 +4122,8 @@ if(options.debug) { fputs("Pygmpy_mpf: created mpf = ", stderr); mpf_out_str(stderr, 10, 0, newob->f); - fprintf(stderr," bits=%d (%d)\n", newob->rebits, bits); + fprintf(stderr," bits=%"PY_FORMAT_SIZE_T"d (%"PY_FORMAT_SIZE_T"d)\n", + newob->rebits, bits); } return (PyObject *) newob; @@ -4158,7 +4166,7 @@ Py_XDECREF((PyObject*)pb); \ Py_RETURN_NOTIMPLEMENTED; \ } \ - if (options.debug) fprintf(stderr, "Py" #NAME ": %p, %p\n", pa, pb); \ + if (options.debug) fprintf(stderr, "Py" #NAME ": %p, %p\n", (void *)pa, (void *)pb); \ if (!(r = Pympz_new())) { \ Py_DECREF((PyObject*)pa); \ Py_DECREF((PyObject*)pb); \ @@ -4167,7 +4175,7 @@ NAME(r->z, pa->z, pb->z); \ Py_DECREF((PyObject*)pa); \ Py_DECREF((PyObject*)pb); \ - if (options.debug) fprintf(stderr, "Py" #NAME "-> %p\n", r); \ + if (options.debug) fprintf(stderr, "Py" #NAME "-> %p\n", (void *)r); \ return (PyObject *) r; \ } @@ -4175,7 +4183,7 @@ static PyObject * \ Py##NAME(PyObject *a, PyObject *b) \ { \ - unsigned int bits, bbits; \ + size_t bits, bbits; \ PympfObject *r; \ PympfObject *pa = 0; \ PympfObject *pb = 0; \ @@ -4187,7 +4195,7 @@ return NULL; \ } \ NAME(r->f, ((PympfObject*)a)->f, ((PympfObject*)b)->f); \ - if (options.debug) fprintf(stderr, "Py" #NAME "-> %p", r); \ + if (options.debug) fprintf(stderr, "Py" #NAME "-> %p", (void *)r); \ Pympf_normalize(r); \ return (PyObject *) r; \ } else { \ @@ -4205,7 +4213,7 @@ Py_INCREF(r); \ return r; \ } \ - if (options.debug) fprintf(stderr, "Py" #NAME ": %p, %p", pa, pb); \ + if (options.debug) fprintf(stderr, "Py" #NAME ": %p, %p", (void *)pa, (void *)pb); \ if (!(r = Pympf_new(bits))) { \ Py_DECREF((PyObject*)pa); \ Py_DECREF((PyObject*)pb); \ @@ -4214,7 +4222,7 @@ NAME(r->f, pa->f, pb->f); \ Py_DECREF((PyObject*)pa); \ Py_DECREF((PyObject*)pb); \ - if (options.debug) fprintf(stderr, "Py" #NAME "-> %p", r); \ + if (options.debug) fprintf(stderr, "Py" #NAME "-> %p", (void *)r); \ Pympf_normalize(r); \ return (PyObject *) r; \ } \ @@ -4236,7 +4244,7 @@ Py_INCREF((PyObject*)r); \ return r; \ } \ - if (options.debug) fprintf(stderr, "Py" #NAME ": %p, %p", pa, pb); \ + if (options.debug) fprintf(stderr, "Py" #NAME ": %p, %p", (void *)pa, (void *)pb); \ if (!(r = Pympq_new())) { \ Py_DECREF((PyObject*)pa); \ Py_DECREF((PyObject*)pb); \ @@ -4245,7 +4253,7 @@ NAME(r->q, pa->q, pb->q); \ Py_DECREF((PyObject*)pa); \ Py_DECREF((PyObject*)pb); \ - if (options.debug) fprintf(stderr, "Py" #NAME "-> %p", r); \ + if (options.debug) fprintf(stderr, "Py" #NAME "-> %p", (void *)r); \ return (PyObject *) r; \ } @@ -4256,10 +4264,10 @@ Py##NAME(PympzObject *x) \ { \ PympzObject *r; \ - if (options.debug) fprintf(stderr, "Py" #NAME ": %p\n", x); \ + if (options.debug) fprintf(stderr, "Py" #NAME ": %p\n", (void *)x); \ if (!(r = Pympz_new())) return NULL; \ NAME(r->z, x->z); \ - if (options.debug) fprintf(stderr, "Py" #NAME "-> %p\n", r); \ + if (options.debug) fprintf(stderr, "Py" #NAME "-> %p\n", (void *)r); \ return (PyObject *) r; \ } @@ -4268,10 +4276,10 @@ Py##NAME(PympfObject *x) \ { \ PympfObject *r; \ - if (options.debug) fprintf(stderr, "Py" #NAME ": %p\n", x); \ + if (options.debug) fprintf(stderr, "Py" #NAME ": %p\n", (void *)x); \ if (!(r = Pympf_new(x->rebits))) return NULL; \ NAME(r->f, x->f); \ - if (options.debug) fprintf(stderr, "Py" #NAME "-> %p\n", r); \ + if (options.debug) fprintf(stderr, "Py" #NAME "-> %p\n", (void *)r); \ return (PyObject *) r; \ } @@ -4280,10 +4288,10 @@ Py##NAME(PympqObject *x) \ { \ PympqObject *r; \ - if (options.debug) fprintf(stderr, "Py" #NAME ": %p\n", x); \ + if (options.debug) fprintf(stderr, "Py" #NAME ": %p\n", (void *)x); \ if (!(r = Pympq_new())) return NULL; \ NAME(r->q, x->q); \ - if (options.debug) fprintf(stderr, "Py" #NAME "-> %p\n", r); \ + if (options.debug) fprintf(stderr, "Py" #NAME "-> %p\n", (void *)r); \ return (PyObject *) r; \ } @@ -4298,11 +4306,11 @@ Pympq_abs(PympqObject *x) { PympqObject *r; - if (options.debug) fprintf(stderr, "Pympq_abs: %p\n", x); + if (options.debug) fprintf(stderr, "Pympq_abs: %p\n", (void *)x); if (!(r = Pympq_new())) return NULL; mpq_set(r->q, x->q); mpz_abs(mpq_numref(r->q),mpq_numref(r->q)); - if (options.debug) fprintf(stderr, "Pympq_abs-> %p\n", r); + if (options.debug) fprintf(stderr, "Pympq_abs-> %p\n", (void *)r); return (PyObject *) r; } @@ -4357,7 +4365,7 @@ } if(options.debug) - fprintf(stderr, "Pympz_pow: %p, %p, %p\n", b, e, m); + fprintf(stderr, "Pympz_pow: %p, %p, %p\n", (void *)b, (void *)e, (void *)m); if(mpz_sgn(e->z) < 0) { PyErr_SetString(PyExc_ValueError, "mpz.pow with negative power"); @@ -4386,7 +4394,7 @@ } mpz_pow_ui(r->z, b->z, el); if(options.debug) - fprintf(stderr, "Pympz_pow (ui) -> %p\n", r); + fprintf(stderr, "Pympz_pow (ui) -> %p\n", (void *)r); } else { /* Modulo exponentiation */ int sign; mpz_t mm; @@ -4417,7 +4425,7 @@ mpz_add(r->z, r->z, m->z); } if(options.debug) - fprintf(stderr, "Pympz_pow -> %p\n", r); + fprintf(stderr, "Pympz_pow -> %p\n", (void *)r); } Py_XDECREF((PyObject*)b); Py_XDECREF((PyObject*)e); @@ -4448,7 +4456,7 @@ } if(options.debug) - fprintf(stderr, "Pympq_pow: %p, %p, %p\n", b, e, m); + fprintf(stderr, "Pympq_pow: %p, %p, %p\n", (void *)b, (void *)e, (void *)m); if((PyObject*)m != Py_None) { PyErr_SetString(PyExc_ValueError, "mpq.pow no modulo allowed"); @@ -4477,7 +4485,7 @@ esign = mpq_sgn(e->q); if(esign == 0) { if(options.debug) - fprintf(stderr, "Pympq_pow (ui,0) -> %p\n", r); + fprintf(stderr, "Pympq_pow (ui,0) -> %p\n", (void *)r); mpq_set_si(r->q, 1, 1); Py_DECREF((PyObject*)b); Py_DECREF((PyObject*)e); @@ -4534,7 +4542,7 @@ } } if(options.debug) - fprintf(stderr, "Pympq_pow (ui) -> %p\n", r); + fprintf(stderr, "Pympq_pow (ui) -> %p\n", (void *)r); Py_DECREF((PyObject*)b); Py_DECREF((PyObject*)e); return (PyObject*)r; @@ -4545,7 +4553,7 @@ { PympqObject *qb, *qe; PyObject *r; - unsigned int bits; + size_t bits; int iexpo; PympfObject *b = 0, *e = 0; @@ -4580,7 +4588,8 @@ if(bits > e->rebits) bits = e->rebits; if(options.debug) - fprintf(stderr, "Pympf_pow(%d): %p, %p, %p\n", bits, b, e, m); + fprintf(stderr, "Pympf_pow(%"PY_FORMAT_SIZE_T"d): %p, %p, %p\n", + bits, (void *)b, (void *)e, (void *)m); iexpo = (int)mpf_get_d(e->f); if(iexpo>0 && 0==mpf_cmp_si(e->f, iexpo)) { @@ -4810,10 +4819,10 @@ if(!PyArg_ParseTuple(args, "O&", Pympf_convert_arg, &self)) return NULL; \ } \ assert(Pympf_Check(self)); \ - if (options.debug) fprintf(stderr, "Py" #NAME ": %p\n", self); \ + if (options.debug) fprintf(stderr, "Py" #NAME ": %p\n", (void *)self); \ if (!(r = Pympf_new(((PympfObject*)self)->rebits))) return NULL; \ NAME(r->f, Pympf_AS_MPF(self)); \ - if (options.debug) fprintf(stderr, "Py" #NAME "-> %p\n", r); \ + if (options.debug) fprintf(stderr, "Py" #NAME "-> %p\n", (void *)r); \ Py_DECREF(self); \ Pympf_normalize(r); \ return (PyObject *) r; \ @@ -5013,12 +5022,12 @@ static PyObject * Pympz_oct(PympzObject *self) { - return Pympz_ascii(self, 8, 0); + return Pympz_ascii(self, 8, 0, 0); } static PyObject * Pympz_hex(PympzObject *self) { - return Pympz_ascii(self, 16, 0); + return Pympz_ascii(self, 16, 0, 0); } #endif @@ -5056,7 +5065,6 @@ Py_uhash_t hash = 0; Py_ssize_t exp = 0; size_t mbits = 0; - double notneeded; mpz_t hack; int sign; @@ -5077,7 +5085,7 @@ mbits = mpz_sizeinbase(hack, 2); /* Get the exponent as a power of 2. */ - notneeded = mpf_get_d_2exp(&exp, self->f); + mpf_get_d_2exp(&exp, self->f); /* Calculate the final hash. */ exp -= (Py_ssize_t)mbits; @@ -5567,8 +5575,8 @@ PARSE_TWO_MPZ(factor, "remove() expects 'mpz','mpz' arguments"); - if(mpz_sgn(Pympz_AS_MPZ(factor)) <= 0) { - PyErr_SetString(PyExc_ValueError, "factor must be > 0"); + if(mpz_cmp_si(Pympz_AS_MPZ(factor), 2) < 0) { + PyErr_SetString(PyExc_ValueError, "factor must be > 1"); Py_DECREF(self); Py_DECREF(factor); return NULL; @@ -6198,8 +6206,8 @@ } static PyObject *random_shuffle(PyObject* seq) { - int i, j; - int len = PySequence_Length(seq); + Py_ssize_t i, j; + Py_ssize_t len = PySequence_Length(seq); PyObject* result; mpz_t temp1, temp2; mpz_inoc(temp1); @@ -6882,70 +6890,6 @@ Pympf_methods, /* tp_methods */ }; - -static void * -gmpy_allocate(size_t size) -{ - void *res; - size_t usize=size; - if(usize%d )\n", (int)size, (int)usize); - if(!(res = PyMem_Malloc(usize))) - Py_FatalError("mp_allocate failure"); - - if(options.debug) - fprintf(stderr, "mp_allocate( %d->%d ) ->%8p\n", (int)size, (int)usize, res); - - return res; -} /* mp_allocate() */ - - -static void * -gmpy_reallocate(void *ptr, size_t old_size, size_t new_size) -{ - void *res; - size_t uold=old_size; - size_t unew=new_size; - if(uold= 3 diff -Nru python-gmpy-1.14/src/gmpy.h python-gmpy-1.15/src/gmpy.h --- python-gmpy-1.14/src/gmpy.h 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/src/gmpy.h 2012-01-02 18:45:16.000000000 +0000 @@ -20,7 +20,6 @@ #if defined(MS_WIN32) && defined(_MSC_VER) /* the __MPN determination in stock gmp.h doesn't work, so...: */ # define __MPN(x) __gmpn_##x -# define _GMP_H_HAVE_FILE # define _PROTO(x) x #define inline __inline #endif @@ -61,7 +60,7 @@ typedef struct { mpob ob; mpf_t f; - unsigned int rebits; + size_t rebits; } PympfObject; /* #define MPOBCAL(obj) ((mpob*)obj)->callable */ @@ -88,7 +87,7 @@ #define Pympf_new_NUM 5 #define Pympf_new_RETURN PympfObject * -#define Pympf_new_PROTO (unsigned int bits) +#define Pympf_new_PROTO (size_t bits) #define Pympz_dealloc_NUM 6 #define Pympz_dealloc_RETURN void diff -Nru python-gmpy-1.14/src/gmpy_misc.c python-gmpy-1.15/src/gmpy_misc.c --- python-gmpy-1.14/src/gmpy_misc.c 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/src/gmpy_misc.c 2012-01-02 18:45:16.000000000 +0000 @@ -161,9 +161,9 @@ Pygmpy_set_minprec(PyObject *self, PyObject *args) { long old = options.minprec; - int i; + long i; - ONE_ARG("set_minprec", "i", &i); + ONE_ARG("set_minprec", "l", &i); if(i<0) { PyErr_SetString(PyExc_ValueError, "minimum precision must be >= 0"); diff -Nru python-gmpy-1.14/src/gmpy_utility.c python-gmpy-1.15/src/gmpy_utility.c --- python-gmpy-1.14/src/gmpy_utility.c 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/src/gmpy_utility.c 2012-01-02 18:45:16.000000000 +0000 @@ -34,8 +34,7 @@ static void mpf_normalize(mpf_t op) { - long size, prec, toclear, temp; - int i; + Py_ssize_t size, prec, toclear, temp, i; mp_limb_t bit1, rem, carry; prec = mpf_get_prec(op); @@ -52,7 +51,7 @@ fprintf(stderr, "prec %ld size %ld toclear %ld carry %ld\n", prec, size, toclear, carry); for(i=0; i_mp_d[i]); + fprintf(stderr,"[%zd]=%lx\n", i, op->_mp_d[i]); } temp = toclear; if(temp>0) { @@ -73,7 +72,7 @@ } if(options.debug) { for(i=0; i_mp_d[i]); + fprintf(stderr,"[%zd]=%lx\n", i, op->_mp_d[i]); } } diff -Nru python-gmpy-1.14/src/pysymbolicext.c python-gmpy-1.15/src/pysymbolicext.c --- python-gmpy-1.14/src/pysymbolicext.c 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/src/pysymbolicext.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,443 +0,0 @@ -/* PySymbolic GMP extensions (in connection with gmpy). - - 1) Factoring with Pollard's rho method. - Copied relevant functions from demos/factorice.c of the GMP distribution, - and modified them to be used in Python. - -Copyright 2000 Pearu Peterson all rights reserved, -Pearu Peterson -Permission to use, modify, and distribute this software is given under the -terms of the LGPL. See http://www.fsf.org - -NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK. -$Revision: 1.2 $ -$Date: 2003/08/08 08:57:05 $ -Pearu Peterson - -Bug fix for more than 32 iterations in pollard_rho method. - (Patch courtesy rel...@osagesoftware.com) - -*/ -#include "Python.h" - -#include -#include -#include -#include - -#include "gmpy.h" - -static unsigned add[] = {4, 2, 4, 2, 4, 6, 2, 6}; - -#if defined (__hpux) || defined (__alpha) || defined (__svr4__) || defined (__SVR4) -/* HPUX lacks random(). DEC OSF/1 1.2 random() returns a double. */ -long mrand48 (); -static long -random () -{ - return mrand48 (); -} -#else -/* Glibc stdlib.h has "int32_t random();" which, on i386 at least, conflicts - with a redeclaration as "long". */ -#if defined(_MSC_VER) -long random() { return rand(); } -#endif -#ifndef __GLIBC__ -long random (); -#endif -#endif - -static void -res_append_si(PyObject *res,signed long int f,unsigned long int c) { - if (c) { - PyObject *pair = (PyObject *)PyTuple_New(2); - { - PyObject *z = (PyObject *)Pympz_new(); - mpz_set_si(Pympz_AS_MPZ(z),f); - PyTuple_SetItem(pair,0,z); - } - { - PyObject *z = (PyObject *)Pympz_new(); - mpz_set_ui(Pympz_AS_MPZ(z),c); - PyTuple_SetItem(pair,1,z); - } - PyList_Append(res,pair); - Py_DECREF(pair); - } -} - -static void -res_append(PyObject *res,unsigned long int f,unsigned long int c) { - if (c) { - PyObject *pair = (PyObject *)PyTuple_New(2); - { - PyObject *z = (PyObject *)Pympz_new(); - mpz_set_ui(Pympz_AS_MPZ(z),f); - PyTuple_SetItem(pair,0,z); - } - { - PyObject *z = (PyObject *)Pympz_new(); - mpz_set_ui(Pympz_AS_MPZ(z),c); - PyTuple_SetItem(pair,1,z); - } - PyList_Append(res,pair); - Py_DECREF(pair); - } -} - -static -void -res_append_mpz(PyObject *res,mpz_t f,unsigned long int c) { - if (c) { - PyObject *pair = (PyObject *)PyTuple_New(2); - { - PyObject *z = (PyObject *)Pympz_new(); - mpz_set(Pympz_AS_MPZ(z),f); - PyTuple_SetItem(pair,0,z); - } - { - PyObject *z = (PyObject *)Pympz_new(); - mpz_set_ui(Pympz_AS_MPZ(z),c); - PyTuple_SetItem(pair,1,z); - } - PyList_Append(res,pair); - Py_DECREF(pair); - } -} - -static -void -factor_using_division (mpz_t t, unsigned int limit, PyObject *res) -{ - mpz_t q, r; - unsigned long int f; - int ai; - unsigned *addv = add; - unsigned int failures; - - unsigned long int count; - - mpz_init (q); - mpz_init (r); - - - count = 0; - f = mpz_scan1 (t, 0); - mpz_fdiv_q_2exp (t, t, f); - res_append(res,2,f); - - count = 0; - for (;;) - { - mpz_tdiv_qr_ui (q, r, t, 3); - if (mpz_cmp_ui (r, 0) != 0) - break; - mpz_set (t, q); - count++; - } - res_append(res,3,count); - count = 0; - for (;;) - { - mpz_tdiv_qr_ui (q, r, t, 5); - if (mpz_cmp_ui (r, 0) != 0) - break; - mpz_set (t, q); - count++; - } - res_append(res,5,count); - - failures = 0; - f = 7; - ai = 0; - count = 0; - while (mpz_cmp_ui (t, 1) != 0) - { - mpz_tdiv_qr_ui (q, r, t, f); - if (mpz_cmp_ui (r, 0) != 0) - { - res_append(res,f,count); - count = 0; - f += addv[ai]; - if (mpz_cmp_ui (q, f) < 0) - break; - ai = (ai + 1) & 7; - failures++; - if (failures > limit) - break; - } - else - { - mpz_swap (t, q); - failures = 0; - count++; - } - } - res_append(res,f,count); - mpz_clear (q); - mpz_clear (r); -} - -static -void -factor_using_division_2kp (mpz_t t, unsigned int limit, unsigned long p, PyObject *res) -{ - mpz_t r; - mpz_t f; - unsigned int k; - unsigned long int count; - mpz_init (r); - mpz_init_set_ui (f, 2 * p); - mpz_add_ui (f, f, 1); - for (k = 1; k < limit; k++) - { - mpz_tdiv_r (r, t, f); - count = 0; - while (mpz_cmp_ui (r, 0) == 0) - { - mpz_tdiv_q (t, t, f); - mpz_tdiv_r (r, t, f); - count++; - } - res_append_mpz(res,f,count); - mpz_add_ui (f, f, 2 * p); - } - - mpz_clear (f); - mpz_clear (r); -} - -static -void -factor_using_pollard_rho (mpz_t n, int a_int, unsigned long p,PyObject *res) -{ - mpz_t x, x1, y, P; - mpz_t a; - mpz_t g; - mpz_t t1, t2; - mpz_t kz, lz, iz; - int c; - unsigned long int count; - - mpz_init (g); - mpz_init (t1); - mpz_init (t2); - - mpz_init_set_si (a, a_int); - mpz_init_set_si (y, 2); - mpz_init_set_si (x, 2); - mpz_init_set_si (x1, 2); - - mpz_init (iz); - mpz_init_set_si (kz, 1); - mpz_init_set_si (lz, 1); - mpz_init_set_ui (P, 1); - c = 0; - count = 0; - while (mpz_cmp_ui (n, 1) != 0) - { -S2: - if (p != 0) - { - mpz_powm_ui (x, x, p, n); mpz_add (x, x, a); - } - else - { - mpz_mul (x, x, x); mpz_add (x, x, a); mpz_mod (x, x, n); - } - mpz_sub (t1, x1, x); mpz_mul (t2, P, t1); mpz_mod (P, t2, n); - c++; - if (c == 20) - { - c = 0; - mpz_gcd (g, P, n); - if (mpz_cmp_ui (g, 1) != 0) - goto S4; - mpz_set (y, x); - } -/* S3: */ - mpz_sub_ui (kz, kz, 1); - if (mpz_cmp_ui(kz,0) > 0) - goto S2; - - mpz_gcd (g, P, n); - if (mpz_cmp_ui (g, 1) != 0) - goto S4; - - mpz_set (x1, x); - mpz_set (kz, lz); - mpz_mul_ui (lz, lz, 2); - - // for loop with integer index works fine for k < 2**31 - // using mpz_t allows unlimited range - for ( mpz_set (iz, kz); mpz_cmp_ui(iz,0) > 0; mpz_sub_ui (iz, iz, 1) ) - { - if (p != 0) - { - mpz_powm_ui (x, x, p, n); mpz_add (x, x, a); - } - else - { - mpz_mul (x, x, x); mpz_add (x, x, a); mpz_mod (x, x, n); - } - } - mpz_set (y, x); - c = 0; - goto S2; -S4: - do - { - if (p != 0) - { - mpz_powm_ui (y, y, p, n); mpz_add (y, y, a); - } - else - { - mpz_mul (y, y, y); mpz_add (y, y, a); mpz_mod (y, y, n); - } - mpz_sub (t1, x1, y); mpz_gcd (g, t1, n); - } - while (mpz_cmp_ui (g, 1) == 0); - - if (!mpz_probab_prime_p (g, 3)) - { - do - a_int = random (); - while (a_int == -2 || a_int == 0); - factor_using_pollard_rho (g, a_int, p, res); - break; - } - else - count ++; - - res_append_mpz(res,g,count); - count = 0; - mpz_fdiv_q (n, n, g); - mpz_mod (x, x, n); - mpz_mod (x1, x1, n); - mpz_mod (y, y, n); - if (mpz_probab_prime_p (n, 3)) - { - count++; - break; - } - } - res_append_mpz(res,n,count); - mpz_clear (iz); - mpz_clear (kz); - mpz_clear (lz); - mpz_clear (g); - mpz_clear (P); - mpz_clear (t2); - mpz_clear (t1); - mpz_clear (a); - mpz_clear (x1); - mpz_clear (x); - mpz_clear (y); -} - -static -void -factor (mpz_t t, unsigned long p,PyObject *res) -{ - unsigned int division_limit; - - /* Set the trial division limit according the size of t. */ - division_limit = mpz_sizeinbase (t, 2); - if (division_limit > 1000) - division_limit = 1000 * 1000; - else - division_limit = division_limit * division_limit; - - if (p != 0) - factor_using_division_2kp (t, division_limit / 10, p, res); - else - factor_using_division (t, division_limit, res); - - if (mpz_cmp_ui (t, 1) != 0) { - if (mpz_probab_prime_p (t, 3)) - res_append_mpz(res,t,1); - else - factor_using_pollard_rho (t, 1, p, res); - } -} - -static char doc_factor[] = -"factor(t,m=0) -> prime factors of t (modulo m)\n\ -\n\ -Prime decomposition of t (modulo m).\n\ -factor(t,m) returns a list of tuples (f,p) where p is the number\n\ -of prime factors f in term t. p is always positive.\n\ -t can be also zero or negative.\n\ -For m=0 the following condition holds\n\ - t == reduce(lambda r,pm:r*pm[0]**pm[1],factor(t),1L)."; -static PyObject * -Pysym_factor(PyObject *self, PyObject *args) -{ - mpz_t t; - unsigned long p; - PyObject *t_py = NULL; - PyObject *p_py = NULL; - PyObject *res = NULL; - if (!PyArg_ParseTuple(args, "O&|O&",\ - Pympz_convert_arg,&t_py,\ - Pympz_convert_arg,&p_py)) - return NULL; - - res = PyList_New(0); - if (p_py==NULL) - p = 0; - else - p = mpz_get_ui(Pympz_AS_MPZ(p_py)); - mpz_init_set(t,Pympz_AS_MPZ(t_py)); - - if (mpz_sgn(t)==0) { - res_append(res,0,1); - return res; - } - if (mpz_sgn(t)==-1) { - res_append_si(res,-1,1); - mpz_neg(t,t); - } - - factor(t,p,res); - - if (PyList_Size(res)==0) - res_append(res,1,1); - return res; -} - -static PyMethodDef Pysym_methods [] = -{ - { "factor", Pysym_factor, METH_VARARGS, doc_factor }, - { NULL, NULL} -}; - -#if PY_MAJOR_VERSION >= 3 - -static struct PyModuleDef Pysym_module = { - PyModuleDef_HEAD_INIT, - "pysymbolicext", - NULL, - -1, - Pysym_methods, - NULL, - NULL, - NULL, - NULL -}; - -#endif - -void -initpysymbolicext(void) -{ -#if PY_MAJOR_VERSION >= 3 - PyModule_Create(&Pysym_module); -#else - Py_InitModule("pysymbolicext", Pysym_methods); -#endif - import_gmpy(); -} - diff -Nru python-gmpy-1.14/test/gmpy_test_cvr.py python-gmpy-1.15/test/gmpy_test_cvr.py --- python-gmpy-1.14/test/gmpy_test_cvr.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/test/gmpy_test_cvr.py 2012-01-02 18:45:16.000000000 +0000 @@ -2,12 +2,12 @@ # relies on Tim Peters' "doctest.py" test-driver r''' ->>> print int(_g.gmp_version()[:3] in ('5.0', '4.3', '4.2', '4.1', '4.0', '')) +>>> print int(_g.gmp_version()[:3] in ('5.0', '4.3', '')) 1 ->>> print int(_g.mpir_version()[:3] in ('', '0.9', '1.0', '1.1', '1.2', '1.3', '2.0', '2.1')) +>>> print int(_g.mpir_version()[:3] in ('2.3', '2.4', '2.5', '')) 1 >>> _g.version() -'1.14' +'1.15' >>> int('gmpy.c' in _g._cvsid()) 1 ''' @@ -322,7 +322,7 @@ >>> _g.mpz('bi',99) Traceback (most recent call last): File "", line 1, in ? -ValueError: base for gmpy.mpz must be 0, 256, or in the interval 2 ... 36 . +ValueError: base for gmpy.mpz must be 0, 256, or in the interval 2 ... 62 . >>> _g.mpz(1,2) Traceback (most recent call last): File "", line 1, in ? @@ -374,7 +374,7 @@ >>> _g.mpf('ba',0,99) Traceback (most recent call last): File "", line 1, in ? -ValueError: base for gmpy.mpf must be 0, 256, or in the interval 2 ... 36 . +ValueError: base for gmpy.mpf must be 0, 256, or in the interval 2 ... 62 . >>> _g.mpf(1,2,3) Traceback (most recent call last): File "", line 1, in ? @@ -522,7 +522,7 @@ def _test(chat=None): if chat: - print "Unit tests for gmpy 1.14 (extra cover)" + print "Unit tests for gmpy 1.15 (extra cover)" print " running on Python", sys.version print if _g.gmp_version(): diff -Nru python-gmpy-1.14/test/gmpy_test_dec.py python-gmpy-1.15/test/gmpy_test_dec.py --- python-gmpy-1.14/test/gmpy_test_dec.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/test/gmpy_test_dec.py 2012-01-02 18:45:16.000000000 +0000 @@ -61,7 +61,7 @@ print " No point in testing, therefore -- please upgrade your Python!" return 0, 0 if chat: - print "Unit tests for gmpy 1.14 (decimal interoperation)" + print "Unit tests for gmpy 1.15 (decimal interoperation)" print " running on Python", sys.version print if _g.gmp_version(): diff -Nru python-gmpy-1.14/test/gmpy_test_mpf.py python-gmpy-1.15/test/gmpy_test_mpf.py --- python-gmpy-1.14/test/gmpy_test_mpf.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/test/gmpy_test_mpf.py 2012-01-02 18:45:16.000000000 +0000 @@ -299,7 +299,7 @@ >>> a.digits(1) Traceback (most recent call last): File "", line 1, in ? -ValueError: base must be either 0 or in the interval 2 ... 36 +ValueError: base must be either 0 or in the interval 2 ... 62 >>> a.digits(2,-1) Traceback (most recent call last): File "", line 1, in ? @@ -396,7 +396,7 @@ def _test(chat=None): if chat: - print "Unit tests for gmpy 1.14 (mpf functionality)" + print "Unit tests for gmpy 1.15 (mpf functionality)" print " running on Python %s" % sys.version print if _g.gmp_version(): diff -Nru python-gmpy-1.14/test/gmpy_test_mpq.py python-gmpy-1.15/test/gmpy_test_mpq.py --- python-gmpy-1.14/test/gmpy_test_mpq.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/test/gmpy_test_mpq.py 2012-01-02 18:45:16.000000000 +0000 @@ -195,7 +195,7 @@ ... print 'er4:',i,j,repr(aa),("mpq(%d,%d)"%(ai,aj)); break ... if aj==1 and repr(aa) != ("mpq(%d,%d)"%(ai,aj)): ... print 'er5:',i,j,repr(aa),"mpq(%d,%d)"%(ai,aj); break ->>> fmo='_g.mpq('+a.numer().digits(16)+','+a.denom().digits(16)+')' +>>> fmo='_g.mpq('+hex(a.numer())+','+hex(a.denom())+')' >>> fmo '_g.mpq(0x29,0x98)' >>> eval(fmo)==a @@ -314,7 +314,7 @@ def _test(chat=None): if chat: - print "Unit tests for gmpy 1.14 (mpq functionality)" + print "Unit tests for gmpy 1.15 (mpq functionality)" print " running on Python",sys.version print if _g.gmp_version(): diff -Nru python-gmpy-1.14/test/gmpy_test_mpz.py python-gmpy-1.15/test/gmpy_test_mpz.py --- python-gmpy-1.14/test/gmpy_test_mpz.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/test/gmpy_test_mpz.py 2012-01-02 18:45:16.000000000 +0000 @@ -580,21 +580,26 @@ mpz(587) >>> _g.mpz('1001001011',2).digits(2) '1001001011' ->>> for i in range(2,37): +>>> for i in range(2,63): ... print a.digits(i), ... if i%6==0: print ... 1111011 11120 1323 443 323 -234 0173 146 123 102 a3 -96 8b 83 0x7b 74 6f +234 173 146 123 102 a3 +96 8b 83 7b 74 6f 69 63 5i 5d 58 53 4n 4j 4f 4b 47 43 3u 3r 3o 3l 3i 3f ->>> print a.digits(37) +3C 39 36 33 30 2d +2b 2Z 2X 2V 2T 2R +2P 2N 2L 2J 2H 2F +2D 2B 29 27 25 23 +21 1z +>>> print a.digits(63) Traceback (innermost last): File "", line 1, in ? print a.digits(37) -ValueError: base must be either 0 or in the interval 2 ... 36 +ValueError: base must be either 0 or in the interval 2 ... 62 >>> _g.set_tagoff(0) 1 >>> a @@ -637,7 +642,7 @@ 573406620562849222387053L >>> divmod(z,a) (mpz(4661842443600400182008L), mpz(69)) ->>> for i in range(2,37): +>>> for i in range(2,63): ... print i,z.numdigits(i), ... if i%6==0: print ... @@ -647,6 +652,11 @@ 19 19 20 19 21 18 22 18 23 18 24 18 25 18 26 17 27 17 28 17 29 17 30 17 31 16 32 16 33 16 34 16 35 16 36 16 +37 16 38 16 39 15 40 15 41 15 42 15 +43 15 44 15 45 15 46 15 47 15 48 15 +49 15 50 14 51 14 52 14 53 14 54 14 +55 14 56 14 57 14 58 14 59 14 60 14 +61 14 62 14 >>> _g.numdigits(23) 2 >>> _g.numdigits(23,2) @@ -654,7 +664,7 @@ >>> _g.numdigits(23,99) Traceback (most recent call last): File "", line 1, in ? -ValueError: base must be either 0 or in the interval 2 ... 36 +ValueError: base must be either 0 or in the interval 2 ... 62 >>> hash(a) 123 >>> hash(b) @@ -783,7 +793,7 @@ >>> _g.remove(3,-1) Traceback (most recent call last): File "", line 1, in ? -ValueError: factor must be > 0 +ValueError: factor must be > 1 >>> _g.remove(3) Traceback (innermost last): ... @@ -892,7 +902,7 @@ del(__test__["special"]) if chat: - print "Unit tests for gmpy 1.14 (mpz functionality)" + print "Unit tests for gmpy 1.15 (mpz functionality)" print " running on Python %s" % sys.version print if _g.gmp_version(): diff -Nru python-gmpy-1.14/test/gmpy_test.py python-gmpy-1.15/test/gmpy_test.py --- python-gmpy-1.14/test/gmpy_test.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/test/gmpy_test.py 2012-01-02 18:45:16.000000000 +0000 @@ -1,6 +1,6 @@ r''' >>> gmpy.version() -'1.14' +'1.15' >>> ''' @@ -30,7 +30,7 @@ gmpy_test_mpq, gmpy_test_mpz, gmpy_test_dec) _g = gmpy -writeln("Unit tests for gmpy 1.14") +writeln("Unit tests for gmpy 1.15") writeln(" on Python %s" % sys.version) if _g.gmp_version(): writeln("Testing gmpy %s (GMP %s), default caching (%s, %s)" % ( diff -Nru python-gmpy-1.14/test/gmpy_test_rnd.py python-gmpy-1.15/test/gmpy_test_rnd.py --- python-gmpy-1.14/test/gmpy_test_rnd.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/test/gmpy_test_rnd.py 2012-01-02 18:45:16.000000000 +0000 @@ -124,7 +124,7 @@ def _test(chat=None): if chat: - print "Unit tests for gmpy 1.14 (rnd functionality)" + print "Unit tests for gmpy 1.15 (rnd functionality)" print " running on Python %s" % sys.version print if _g.gmp_version(): diff -Nru python-gmpy-1.14/test/gmpy_test_thr.py python-gmpy-1.15/test/gmpy_test_thr.py --- python-gmpy-1.14/test/gmpy_test_thr.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/test/gmpy_test_thr.py 2012-01-02 18:45:16.000000000 +0000 @@ -68,7 +68,7 @@ def _test(chat=None): if chat: - print "Unit tests for gmpy 1.14 (threading)" + print "Unit tests for gmpy 1.15 (threading)" print " running on Python", sys.version print if _g.gmp_version(): diff -Nru python-gmpy-1.14/test3/gmpy_test_cvr.py python-gmpy-1.15/test3/gmpy_test_cvr.py --- python-gmpy-1.14/test3/gmpy_test_cvr.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/test3/gmpy_test_cvr.py 2012-01-02 18:45:16.000000000 +0000 @@ -2,12 +2,12 @@ # relies on Tim Peters' "doctest.py" test-driver r''' ->>> _g.gmp_version()[:3] in ('5.0', '4.3', '4.2', '4.1', '4.0', '3.1', '') +>>> _g.gmp_version()[:3] in ('5.0', '4.3', '') True ->>> _g.mpir_version()[:3] in ('0.9', '1.0', '1.1', '1.2', '1.3', '2.0', '2.1', '') +>>> _g.mpir_version()[:3] in ( '2.3', '2.4', '2.5', '') True >>> _g.version() -'1.14' +'1.15' >>> int('gmpy.c' in _g._cvsid()) 1 ''' @@ -316,7 +316,7 @@ >>> _g.mpz('bi',99) Traceback (most recent call last): File "", line 1, in ? -ValueError: base for gmpy.mpz must be 0, 256, or in the interval 2 ... 36 . +ValueError: base for gmpy.mpz must be 0, 256, or in the interval 2 ... 62 . >>> _g.mpz(1,2) Traceback (most recent call last): File "", line 1, in ? @@ -368,7 +368,7 @@ >>> _g.mpf('ba',0,99) Traceback (most recent call last): File "", line 1, in ? -ValueError: base for gmpy.mpf must be 0, 256, or in the interval 2 ... 36 . +ValueError: base for gmpy.mpf must be 0, 256, or in the interval 2 ... 62 . >>> _g.mpf(1,2,3) Traceback (most recent call last): File "", line 1, in ? @@ -516,7 +516,7 @@ def _test(chat=None): if chat: - print("Unit tests for gmpy 1.14 (extra cover)") + print("Unit tests for gmpy 1.15 (extra cover)") print(" running on Python", sys.version) print() if _g.gmp_version(): diff -Nru python-gmpy-1.14/test3/gmpy_test_dec.py python-gmpy-1.15/test3/gmpy_test_dec.py --- python-gmpy-1.14/test3/gmpy_test_dec.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/test3/gmpy_test_dec.py 2012-01-02 18:45:16.000000000 +0000 @@ -86,7 +86,7 @@ print(" No point in testing, therefore -- please upgrade your Python!") return 0, 0 if chat: - print("Unit tests for gmpy 1.14 (decimal interoperation)") + print("Unit tests for gmpy 1.15 (decimal interoperation)") print(" running on Python", sys.version) print() if _g.gmp_version(): diff -Nru python-gmpy-1.14/test3/gmpy_test_mpf.py python-gmpy-1.15/test3/gmpy_test_mpf.py --- python-gmpy-1.14/test3/gmpy_test_mpf.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/test3/gmpy_test_mpf.py 2012-01-02 18:45:16.000000000 +0000 @@ -290,7 +290,7 @@ >>> a.digits(1) Traceback (most recent call last): File "", line 1, in ? -ValueError: base must be either 0 or in the interval 2 ... 36 +ValueError: base must be either 0 or in the interval 2 ... 62 >>> a.digits(2,-1) Traceback (most recent call last): File "", line 1, in ? @@ -399,7 +399,7 @@ def _test(chat=None): if chat: - print("Unit tests for gmpy 1.14 (mpf functionality)") + print("Unit tests for gmpy 1.15 (mpf functionality)") print(" running on Python %s" % sys.version) print() if _g.gmp_version(): diff -Nru python-gmpy-1.14/test3/gmpy_test_mpq.py python-gmpy-1.15/test3/gmpy_test_mpq.py --- python-gmpy-1.14/test3/gmpy_test_mpq.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/test3/gmpy_test_mpq.py 2012-01-02 18:45:16.000000000 +0000 @@ -220,7 +220,7 @@ ... print('er4:',i,j,repr(aa),("mpq(%d,%d)"%(ai,aj))); break ... if aj==1 and repr(aa) != ("mpq(%d,%d)"%(ai,aj)): ... print('er5:',i,j,repr(aa),"mpq(%d,%d)"%(ai,aj)); break ->>> fmo='_g.mpq('+a.numer().digits(16)+','+a.denom().digits(16)+')' +>>> fmo='_g.mpq('+hex(a.numer())+','+hex(a.denom())+')' >>> fmo '_g.mpq(0x29,0x98)' >>> eval(fmo)==a @@ -297,7 +297,7 @@ mpq(27,8) >>> _g.mpq(8,27)**_g.mpq('-2/3') mpq(9,4) ->>> print(float(_g.mpf('0.2')**2)) +>>> print(float("%.14f" % _g.mpf('0.2')**2)) 0.04 >>> print(float(_g.mpf('0.2')**-2)) 25.0 @@ -339,7 +339,7 @@ def _test(chat=None): if chat: - print("Unit tests for gmpy 1.14 (mpq functionality)") + print("Unit tests for gmpy 1.15 (mpq functionality)") print(" running on Python",sys.version) print() if _g.gmp_version(): diff -Nru python-gmpy-1.14/test3/gmpy_test_mpz.py python-gmpy-1.15/test3/gmpy_test_mpz.py --- python-gmpy-1.14/test3/gmpy_test_mpz.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/test3/gmpy_test_mpz.py 2012-01-02 18:45:16.000000000 +0000 @@ -599,7 +599,7 @@ mpz(587) >>> _g.mpz('1001001011',2).digits(2) '1001001011' ->>> for i in range(2,37): +>>> for i in range(2,63): ... print(a.digits(i)) ... 1111011 @@ -608,7 +608,7 @@ 443 323 234 -0173 +173 146 123 102 @@ -616,7 +616,7 @@ 96 8b 83 -0x7b +7b 74 6f 69 @@ -637,11 +637,37 @@ 3l 3i 3f ->>> print(a.digits(37)) +3C +39 +36 +33 +30 +2d +2b +2Z +2X +2V +2T +2R +2P +2N +2L +2J +2H +2F +2D +2B +29 +27 +25 +23 +21 +1z +>>> print(a.digits(63)) Traceback (innermost last): File "", line 1, in ? - print(a.digits(37)) -ValueError: base must be either 0 or in the interval 2 ... 36 + print(a.digits(63)) +ValueError: base must be either 0 or in the interval 2 ... 62 >>> _g.set_tagoff(0) 1 >>> a @@ -684,7 +710,7 @@ 573406620562849222387053 >>> divmod(z,a) (mpz(4661842443600400182008), mpz(69)) ->>> for i in range(2,37): +>>> for i in range(2,63): ... print(i,z.numdigits(i)) ... 2 79 @@ -722,6 +748,32 @@ 34 16 35 16 36 16 +37 16 +38 16 +39 15 +40 15 +41 15 +42 15 +43 15 +44 15 +45 15 +46 15 +47 15 +48 15 +49 15 +50 14 +51 14 +52 14 +53 14 +54 14 +55 14 +56 14 +57 14 +58 14 +59 14 +60 14 +61 14 +62 14 >>> _g.numdigits(23) 2 >>> _g.numdigits(23,2) @@ -729,7 +781,7 @@ >>> _g.numdigits(23,99) Traceback (most recent call last): File "", line 1, in ? -ValueError: base must be either 0 or in the interval 2 ... 36 +ValueError: base must be either 0 or in the interval 2 ... 62 >>> hash(a) 123 >>> hash(b) @@ -861,7 +913,7 @@ >>> _g.remove(3,-1) Traceback (most recent call last): File "", line 1, in ? -ValueError: factor must be > 0 +ValueError: factor must be > 1 >>> _g.remove(3) Traceback (innermost last): ... @@ -964,7 +1016,7 @@ def _test(chat=None): if chat: - print("Unit tests for gmpy 1.14 (mpz functionality)") + print("Unit tests for gmpy 1.15 (mpz functionality)") print(" running on Python %s" % sys.version) print() if _g.gmp_version(): diff -Nru python-gmpy-1.14/test3/gmpy_test.py python-gmpy-1.15/test3/gmpy_test.py --- python-gmpy-1.14/test3/gmpy_test.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/test3/gmpy_test.py 2012-01-02 18:45:16.000000000 +0000 @@ -1,6 +1,6 @@ r''' >>> gmpy.version() -'1.14' +'1.15' >>> ''' @@ -23,7 +23,7 @@ gmpy_test_mpq, gmpy_test_mpz, gmpy_test_dec) _g = gmpy -print("Unit tests for gmpy 1.14") +print("Unit tests for gmpy 1.15") print(" on Python %s" % sys.version) if _g.gmp_version(): print("Testing gmpy %s (GMP %s), default caching (%s, %s)" % ( diff -Nru python-gmpy-1.14/test3/gmpy_test_rnd.py python-gmpy-1.15/test3/gmpy_test_rnd.py --- python-gmpy-1.14/test3/gmpy_test_rnd.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/test3/gmpy_test_rnd.py 2012-01-02 18:45:16.000000000 +0000 @@ -74,9 +74,9 @@ enukotlpr >>> r('seed',sav) >>> for i in range(3): -... print(float(r('floa'))) +... print("%.12f" % float(r('floa'))) ... -0.44833278656 +0.448332786560 0.547296524048 0.895370483398 >>> r('seed',sav) @@ -127,7 +127,7 @@ def _test(chat=None): if chat: - print("Unit tests for gmpy 1.14 (rand functionality)") + print("Unit tests for gmpy 1.15 (rand functionality)") print(" running on Python %s" % sys.version) print("") if _g.gmp_version(): diff -Nru python-gmpy-1.14/test3/gmpy_test_thr.py python-gmpy-1.15/test3/gmpy_test_thr.py --- python-gmpy-1.14/test3/gmpy_test_thr.py 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/test3/gmpy_test_thr.py 2012-01-02 18:45:16.000000000 +0000 @@ -68,7 +68,7 @@ def _test(chat=None): if chat: - print("Unit tests for gmpy 1.14 (threading)") + print("Unit tests for gmpy 1.15 (threading)") print(" running on Python", sys.version) print() if _g.gmp_version(): diff -Nru python-gmpy-1.14/win_x64_sdk_build.txt python-gmpy-1.15/win_x64_sdk_build.txt --- python-gmpy-1.14/win_x64_sdk_build.txt 2010-11-06 20:42:22.000000000 +0000 +++ python-gmpy-1.15/win_x64_sdk_build.txt 2012-01-02 18:45:16.000000000 +0000 @@ -16,7 +16,10 @@ 4) Install the Microsoft Windows SDK. I used "Microsoft Windows SDK for Windows 7 and .NET Framework 3.5 Service Pack 1". It can be found at - "http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx". Use the + "http://msdn.microsoft.com/en-us/windowsserver/bb980924.aspx". This + version of the SDK provides compilers that are compatible with VS2008. + VS2008 is required for Python 2.6, 2.7, 3.1, and 3.2. Compiling Python + extensions with another version of the SDK is not supported. Use the version appropriate for your system: X86 for a 32-bit system or AMD64 for a 64-bit system. @@ -29,18 +32,18 @@ C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin -6) Create a directory to use for the build process. I used C:\src. +6) Create a directory to use for the build process. I use C:\src. mkdir c:\src 7) Download the GMPY and MPIR source code. This example uses - gmpy-1.12.zip and mpir-2.1.1.tar.gz. They should be unzipped - (or untarred) into c:\src. There should be c:\src\gmpy-1.12 - and c:\src\mpir-2.1.1 directories in c:\src. + gmpy-1.15.zip and mpir-2.5.0.tar.gz. They should be unzipped + (or untarred) into c:\src. There should be c:\src\gmpy-1.15 + and c:\src\mpir-2.5.0 directories in c:\src. 8) The file "yasm.rules" must be copied from - c:\src\mpir-2.1.1\build.vc9\ + c:\src\mpir-2.5.0\yasm\Mkfiles\vc9 to @@ -52,12 +55,15 @@ rem Use "vcvars32.bat" for a 32-bit build. "C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin\vcvars64.bat" + rem Set environment variable so yasm.exe can be found by the batch files. + set YASMPATH=C:\Program Files (x86)\Microsoft Visual Studio 9.0\VC\bin + rem Build mpir first. - cd C:\src\mpir-2.1.1\build.vc9 + cd C:\src\mpir-2.5.0\win rem Check contents of configure.bat to see allowed options. Verify that rem all tests pass. - rem 64-bit binaries were built with --cpu-k8. + rem 64-bit binaries were built with --cpu=k8. configure make make check @@ -65,13 +71,14 @@ rem Copy the required to a convenient location for gmpy. rem The files are located in "lib\Win32\release" for 32-bit rem build. + cd c:\src\mpir-2.5.0 mkdir c:\src\lib mkdir c:\src\include - xcopy /Y lib\x64\release\*.h c:\src\include\*.* - xcopy /Y lib\x64\release\*.??b c:\src\lib\*.* + xcopy /Y mpir.h c:\src\include\*.* + xcopy /Y win\mpir.lib c:\src\lib\*.* rem Done with mpir, now build gmpy. - cd c:\src\gmpy-1.12 + cd c:\src\gmpy-1.15 rem Convince setup.py to use the SDK tools. set MSSdk=1 @@ -83,5 +90,5 @@ rem Run the test suite python test\gmpy_test.py - rem (Optional) Build an installer, located in c:\src\gmpy-1.12\dist. + rem (Optional) Build an installer, located in c:\src\gmpy-1.15\dist. python setup.py bdist_wininst