mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Merged revisions 79674 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r79674 | mark.dickinson | 2010-04-03 15:05:10 +0100 (Sat, 03 Apr 2010) | 3 lines Issue #8300: Let struct.pack use __index__ to convert and pack non-integers. Based on a patch by Meador Inge. ........
This commit is contained in:
parent
089b00cbc3
commit
c593577a4a
4 changed files with 50 additions and 4 deletions
|
@ -97,12 +97,27 @@ get_pylong(PyObject *v)
|
|||
{
|
||||
assert(v != NULL);
|
||||
if (!PyLong_Check(v)) {
|
||||
PyErr_SetString(StructError,
|
||||
"required argument is not an integer");
|
||||
return NULL;
|
||||
/* Not an integer; try to use __index__ to convert. */
|
||||
if (PyIndex_Check(v)) {
|
||||
v = PyNumber_Index(v);
|
||||
if (v == NULL)
|
||||
return NULL;
|
||||
if (!PyLong_Check(v)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"__index__ method "
|
||||
"returned non-integer");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
PyErr_SetString(StructError,
|
||||
"required argument is not an integer");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
else
|
||||
Py_INCREF(v);
|
||||
|
||||
Py_INCREF(v);
|
||||
return v;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue