I'm trying to understand why this code causes a seg fault second time
through; the code is part of a setattr and is testing if the value is an
integer or has red, green and blue attributes. This code later goes on
to raise a ValueError if that's not the case.
if((i = PyArg_Parse(val ue,"i",&cv))){
c->value = cv;
c->valid = 1;
return 1;
}
rgb = PyObject_HasAtt rString(value," red")
&& PyObject_HasAtt rString(value," green")
&& PyObject_HasAtt rString(value," blue");
PyErr_Clear();
........
PyErr_SetString (PyExc_ValueErr or, "bad color value");
Both calls should fail and raise ValueError, but the second call causes
a seg fault in Python 2.3.4 (not in 2.2 and earlier).
In 2.3.4 I found that moving the PyErr_Clear() before the calculation of
rgb fixes the problem.
I assume the problem is that something in the rgb calculation is failing
because the python error flag is set. Is that a bug in the
implementation of PyObject_HasAtt rString or is it my fault for not
knowing which API calls need a cleared error flag?
--
Robin Becker
through; the code is part of a setattr and is testing if the value is an
integer or has red, green and blue attributes. This code later goes on
to raise a ValueError if that's not the case.
if((i = PyArg_Parse(val ue,"i",&cv))){
c->value = cv;
c->valid = 1;
return 1;
}
rgb = PyObject_HasAtt rString(value," red")
&& PyObject_HasAtt rString(value," green")
&& PyObject_HasAtt rString(value," blue");
PyErr_Clear();
........
PyErr_SetString (PyExc_ValueErr or, "bad color value");
Both calls should fail and raise ValueError, but the second call causes
a seg fault in Python 2.3.4 (not in 2.2 and earlier).
In 2.3.4 I found that moving the PyErr_Clear() before the calculation of
rgb fixes the problem.
I assume the problem is that something in the rgb calculation is failing
because the python error flag is set. Is that a bug in the
implementation of PyObject_HasAtt rString or is it my fault for not
knowing which API calls need a cleared error flag?
--
Robin Becker
Comment