Commit 1879a2af authored by Tres Seaver's avatar Tres Seaver

Remove use of bare 'PyLong_AsLongLong()'.

Replace with 'PyLong_AsLongLongOverflow'.

Toward a fix for #32.
parent afa8c4eb
......@@ -77,6 +77,7 @@ static void PyVar_Assign(PyObject **v, PyObject *e) { Py_XDECREF(*v); *v=e;}
#error "PY_LONG_LONG required but not defined"
#endif
#ifdef NEED_LONG_LONG_KEYS
static int
longlong_check(PyObject *ob)
{
......@@ -84,25 +85,19 @@ longlong_check(PyObject *ob)
return 1;
if (PyLong_Check(ob)) {
#if PY_VERSION_HEX < 0x02070000
/* check magnitude */
PY_LONG_LONG val = PyLong_AsLongLong(ob);
if (val == -1 && PyErr_Occurred())
goto overflow;
#else
int overflow;
(void)PyLong_AsLongLongAndOverflow(ob, &overflow);
if (overflow)
goto overflow;
#endif
return 1;
}
return 0;
overflow:
PyErr_SetString(PyExc_ValueError, "long integer out of range");
PyErr_SetString(PyExc_ValueError,
"longlong_check: long integer out of range");
return 0;
}
#endif
static PyObject *
longlong_as_object(PY_LONG_LONG val)
......@@ -111,10 +106,8 @@ longlong_as_object(PY_LONG_LONG val)
return PyLong_FromLongLong(val);
return INT_FROM_LONG((long)val);
}
#endif
#ifdef NEED_LONG_LONG_KEYS
static int
longlong_convert(PyObject *ob, PY_LONG_LONG *value)
{
......@@ -134,18 +127,10 @@ longlong_convert(PyObject *ob, PY_LONG_LONG *value)
else
{
PY_LONG_LONG val;
#if PY_VERSION_HEX < 0x02070000
/* check magnitude */
val = PyLong_AsLongLong(ob);
if (val == -1 && PyErr_Occurred())
goto overflow;
#else
int overflow;
val = PyLong_AsLongLongAndOverflow(ob, &overflow);
if (overflow)
goto overflow;
#endif
(*value) = val;
return 1;
}
......@@ -153,7 +138,7 @@ overflow:
PyErr_SetString(PyExc_ValueError, "long integer out of range");
return 0;
}
#endif
#endif /* NEED_LONG_LONG_SUPPORT */
/* Various kinds of BTree and Bucket structs are instances of
......
......@@ -7,14 +7,10 @@
#define VALUE_PARSE "L"
#define COPY_VALUE_TO_OBJECT(O, K) O=longlong_as_object(K)
#define COPY_VALUE_FROM_ARG(TARGET, ARG, STATUS) \
if (INT_CHECK(ARG)) TARGET=INT_AS_LONG(ARG); else \
if (longlong_check(ARG)) TARGET=PyLong_AsLongLong(ARG); else \
if (PyLong_Check(ARG)) { \
PyErr_SetString(PyExc_ValueError, "long integer out of range"); \
(STATUS)=0; (TARGET)=0; } \
else { \
PyErr_SetString(PyExc_TypeError, "expected integer value"); \
(STATUS)=0; (TARGET)=0; }
if (!longlong_convert((ARG), &TARGET)) \
{ \
(STATUS)=0; (TARGET)=0; \
}
#else
#define VALUE_TYPE int
#define VALUE_PARSE "i"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment