chiark
/
gitweb
/
~mdw
/
catacomb-python
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Return `long' objects when `int' is requested but the value won't fit.
[catacomb-python]
/
mp.c
diff --git
a/mp.c
b/mp.c
index 8f57ad12ec251dc8e56b848077d354687bfe6e6f..f5f43204a718256abc288f93db7c4aa7907e7804 100644
(file)
--- a/
mp.c
+++ b/
mp.c
@@
-163,7
+163,7
@@
PyObject *gf_pywrap(mp *x)
return ((PyObject *)z);
}
return ((PyObject *)z);
}
-int mp_tolong_checked(mp *x, long *l)
+int mp_tolong_checked(mp *x, long *l
, int must
)
{
static mp *longmin = 0, *longmax = 0;
int rc = -1;
{
static mp *longmin = 0, *longmax = 0;
int rc = -1;
@@
-172,8
+172,10
@@
int mp_tolong_checked(mp *x, long *l)
longmin = mp_fromlong(MP_NEW, LONG_MIN);
longmax = mp_fromlong(MP_NEW, LONG_MAX);
}
longmin = mp_fromlong(MP_NEW, LONG_MIN);
longmax = mp_fromlong(MP_NEW, LONG_MAX);
}
- if (MP_CMP(x, <, longmin) || MP_CMP(x, >, longmax))
- VALERR("mp out of range for int");
+ if (MP_CMP(x, <, longmin) || MP_CMP(x, >, longmax)) {
+ if (must) VALERR("mp out of range for int");
+ else goto end;
+ }
*l = mp_tolong(x);
rc = 0;
end:
*l = mp_tolong(x);
rc = 0;
end:
@@
-362,7
+364,7
@@
static PyObject *mp_pyid(PyObject *x) { RETURN_OBJ(x); }
PyObject *z = 0; \
long n; \
if (pre##binop(x, y, &xx, &yy)) RETURN_NOTIMPL; \
PyObject *z = 0; \
long n; \
if (pre##binop(x, y, &xx, &yy)) RETURN_NOTIMPL; \
- if (mp_tolong_checked(yy, &n
)) goto end;
\
+ if (mp_tolong_checked(yy, &n
, 1)) goto end;
\
if (n < 0) \
z = pre##_pywrap(mp_##rname(MP_NEW, xx, -n)); \
else \
if (n < 0) \
z = pre##_pywrap(mp_##rname(MP_NEW, xx, -n)); \
else \
@@
-483,8
+485,8
@@
static int mp_pynonzerop(PyObject *x) { return !MP_ZEROP(MP_X(x)); }
static PyObject *mp_pyint(PyObject *x)
{
long l;
static PyObject *mp_pyint(PyObject *x)
{
long l;
- if (
mp_tolong_checked(MP_X(x), &l)) return (0
);
-
return (PyInt_FromLong(l
));
+ if (
!mp_tolong_checked(MP_X(x), &l, 0)) return (PyInt_FromLong(l)
);
+
else return mp_topylong(MP_X(x
));
}
static PyObject *mp_pylong(PyObject *x)
{ return (mp_topylong(MP_X(x))); }
}
static PyObject *mp_pylong(PyObject *x)
{ return (mp_topylong(MP_X(x))); }