summaryrefslogtreecommitdiffstats
path: root/Objects/longobject.c
diff options
context:
space:
mode:
authorMark Dickinson <dickinsm@gmail.com>2010-03-13 11:34:40 (GMT)
committerMark Dickinson <dickinsm@gmail.com>2010-03-13 11:34:40 (GMT)
commitd59b41641e7f800a65f4241d05710b774cafa04f (patch)
tree1a859128a25416a27c391421f9cdae3676c240e3 /Objects/longobject.c
parentfe427fee6c77f2a2b8c7c1ad0fec14d8638a9db0 (diff)
downloadcpython-d59b41641e7f800a65f4241d05710b774cafa04f.zip
cpython-d59b41641e7f800a65f4241d05710b774cafa04f.tar.gz
cpython-d59b41641e7f800a65f4241d05710b774cafa04f.tar.bz2
Issue #8014: Fix PyLong_As<c-integer-type> methods not to produce an
internal error on non-integer input: they now raise TypeError instead. This is needed for attributes declared via PyMemberDefs.
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r--Objects/longobject.c25
1 files changed, 20 insertions, 5 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index ce87084..d182e7c 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -435,10 +435,15 @@ PyLong_AsSsize_t(PyObject *vv) {
Py_ssize_t i;
int sign;
- if (vv == NULL || !PyLong_Check(vv)) {
+ if (vv == NULL) {
PyErr_BadInternalCall();
return -1;
}
+ if (!PyLong_Check(vv)) {
+ PyErr_SetString(PyExc_TypeError, "an integer is required");
+ return -1;
+ }
+
v = (PyLongObject *)vv;
i = Py_SIZE(v);
switch (i) {
@@ -485,10 +490,15 @@ PyLong_AsUnsignedLong(PyObject *vv)
unsigned long x, prev;
Py_ssize_t i;
- if (vv == NULL || !PyLong_Check(vv)) {
+ if (vv == NULL) {
PyErr_BadInternalCall();
- return (unsigned long) -1;
+ return (unsigned long)-1;
+ }
+ if (!PyLong_Check(vv)) {
+ PyErr_SetString(PyExc_TypeError, "an integer is required");
+ return (unsigned long)-1;
}
+
v = (PyLongObject *)vv;
i = Py_SIZE(v);
x = 0;
@@ -523,10 +533,15 @@ PyLong_AsSize_t(PyObject *vv)
size_t x, prev;
Py_ssize_t i;
- if (vv == NULL || !PyLong_Check(vv)) {
+ if (vv == NULL) {
PyErr_BadInternalCall();
- return (unsigned long) -1;
+ return (size_t) -1;
+ }
+ if (!PyLong_Check(vv)) {
+ PyErr_SetString(PyExc_TypeError, "an integer is required");
+ return (size_t)-1;
}
+
v = (PyLongObject *)vv;
i = Py_SIZE(v);
x = 0;