@@ -150,11 +150,8 @@ MPZ_abs(MPZ_Object *u)
150150 return res ;
151151}
152152
153- /* Maps 1-byte integer to digit character for bases up to 36 and
154- from 37 up to 62, respectively. */
155- static const char * num_to_text36 = "0123456789abcdefghijklmnopqrstuvwxyz" ;
156- static const char * num_to_text62 = ("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
157- "abcdefghijklmnopqrstuvwxyz" );
153+ /* Maps 1-byte integer to digit character for bases up to 36. */
154+ static const char * num_to_text = "0123456789abcdefghijklmnopqrstuvwxyz" ;
158155
159156static const char * mpz_tag = "mpz(" ;
160157static int OPT_TAG = 0x1 ;
@@ -163,9 +160,8 @@ static int OPT_PREFIX = 0x2;
163160static PyObject *
164161MPZ_to_str (MPZ_Object * u , int base , int options )
165162{
166- if (base < 2 || base > 62 ) {
167- PyErr_SetString (PyExc_ValueError ,
168- "base must be in the interval [2, 62]" );
163+ if (base < 2 || base > 36 ) {
164+ PyErr_SetString (PyExc_ValueError , "mpz base must be >= 2 and <= 36" );
169165 return NULL ;
170166 }
171167
@@ -209,9 +205,6 @@ MPZ_to_str(MPZ_Object *u, int base, int options)
209205 return PyErr_NoMemory ();
210206 /* LCOV_EXCL_STOP */
211207 }
212-
213- const char * num_to_text = base > 36 ? num_to_text62 : num_to_text36 ;
214-
215208 for (size_t i = 0 ; i < len ; i ++ ) {
216209 * p = num_to_text [* p ];
217210 p ++ ;
@@ -266,9 +259,9 @@ const unsigned char gmp_digit_value_tab[] =
266259static MPZ_Object *
267260MPZ_from_str (PyObject * obj , int base )
268261{
269- if (base != 0 && (base < 2 || base > 62 )) {
262+ if (base != 0 && (base < 2 || base > 36 )) {
270263 PyErr_SetString (PyExc_ValueError ,
271- "base must be 0 or in the interval [2, 62] " );
264+ "mpz base must be >= 2 and <= 36, or 0 " );
272265 return NULL ;
273266 }
274267
@@ -339,11 +332,6 @@ MPZ_from_str(PyObject *obj, int base)
339332 }
340333
341334 const unsigned char * digit_value = gmp_digit_value_tab ;
342-
343- if (base > 36 ) {
344- digit_value += 208 ;
345- }
346-
347335 Py_ssize_t new_len = len ;
348336
349337 for (Py_ssize_t i = 0 ; i < len ; i ++ ) {
@@ -2136,7 +2124,7 @@ gmp_parse_pyargs(const gmp_pyargs *fnargs, int argidx[], PyObject *const *args,
21362124}
21372125
21382126static PyObject *
2139- vectorcall (PyObject * type , PyObject * const * args , size_t nargsf ,
2127+ vectorcall (PyObject * type , PyObject * const * args , size_t nargsf ,
21402128 PyObject * kwnames )
21412129{
21422130 Py_ssize_t nargs = PyVectorcall_NARGS (nargsf );
@@ -2177,28 +2165,28 @@ str(PyObject *self)
21772165 return MPZ_to_str ((MPZ_Object * )self , 10 , 0 );
21782166}
21792167
2180- #define Number_Check (op ) (PyFloat_Check((op)) \
2181- || PyComplex_Check((op)))
2168+ #define Number_Check (op ) (PyFloat_Check((op)) || PyComplex_Check((op)))
21822169
2183- #define CHECK_OP (u , a ) \
2184- if (MPZ_Check(a)) { \
2185- u = (MPZ_Object *)a; \
2186- Py_INCREF(u); \
2187- } \
2188- else if (PyLong_Check(a)) { \
2189- u = MPZ_from_int(a); \
2190- if (!u) { \
2191- goto end; \
2192- } \
2193- } \
2194- else if (Number_Check(a)) { \
2195- goto numbers; \
2196- } \
2197- else { \
2198- goto fallback; \
2170+ #define CHECK_OP (u , a ) \
2171+ if (MPZ_Check(a)) { \
2172+ u = (MPZ_Object *)a; \
2173+ Py_INCREF(u); \
2174+ } \
2175+ else if (PyLong_Check(a)) { \
2176+ u = MPZ_from_int(a); \
2177+ if (!u) { \
2178+ goto end; \
2179+ } \
2180+ } \
2181+ else if (Number_Check(a)) { \
2182+ goto numbers; \
2183+ } \
2184+ else { \
2185+ goto fallback; \
21992186 }
22002187
2201- static PyObject * to_float (PyObject * self );
2188+ static PyObject *
2189+ to_float (PyObject * self );
22022190
22032191static PyObject *
22042192richcompare (PyObject * self , PyObject * other , int op )
@@ -3362,7 +3350,7 @@ static struct PyModuleDef gmp_module = {
33623350};
33633351
33643352PyDoc_STRVAR (gmp_info__doc__ ,
3365- "gmp.gmplib_info\n\
3353+ "gmp.gmplib_info\n\
33663354\n\
33673355A named tuple that holds information about GNU GMP\n\
33683356and it's internal representation of integers.\n\
0 commit comments