Message158816
| Author |
pitrou |
| Recipients |
brechtm, mark.dickinson, pitrou, skrah |
| Date |
2012年04月20日.11:07:07 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1334920027.81.0.87008687463.issue14630@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
> If we're accessing ob_digit[0] when Py_SIZE(x) == 0, that sounds like a
> bug to me.
_PyLong_Copy does.
It's ok as long as the object is int(0), because it's part of the small ints and its allocated size is one digit.
The following hack seems to fix the issue here. Perhaps we can simply fix _PyLong_Copy, but I wonder how many other parts of longobject.c rely on accessing ob_digit[0].
diff --git a/Objects/longobject.c b/Objects/longobject.c
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -4194,6 +4194,8 @@ long_subtype_new(PyTypeObject *type, PyO
n = Py_SIZE(tmp);
if (n < 0)
n = -n;
+ if (n == 0)
+ n = 1;
newobj = (PyLongObject *)type->tp_alloc(type, n);
if (newobj == NULL) {
Py_DECREF(tmp);
diff --git a/Objects/object.c b/Objects/object.c
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -1010,6 +1010,8 @@ PyObject **
tsize = ((PyVarObject *)obj)->ob_size;
if (tsize < 0)
tsize = -tsize;
+ if (tsize == 0 && PyLong_Check(obj))
+ tsize = 1;
size = _PyObject_VAR_SIZE(tp, tsize);
dictoffset += (long)size;
@@ -1090,6 +1092,8 @@ PyObject *
tsize = ((PyVarObject *)obj)->ob_size;
if (tsize < 0)
tsize = -tsize;
+ if (tsize == 0 && PyLong_Check(obj))
+ tsize = 1;
size = _PyObject_VAR_SIZE(tp, tsize);
dictoffset += (long)size; |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2012年04月20日 11:07:07 | pitrou | set | recipients:
+ pitrou, mark.dickinson, skrah, brechtm |
| 2012年04月20日 11:07:07 | pitrou | set | messageid: <1334920027.81.0.87008687463.issue14630@psf.upfronthosting.co.za> |
| 2012年04月20日 11:07:07 | pitrou | link | issue14630 messages |
| 2012年04月20日 11:07:07 | pitrou | create |
|