mirror of
https://github.com/python/cpython.git
synced 2025-12-09 02:35:14 +00:00
PyObject_Compare can now return an error. Unfortunately, there are a
few places where we don't know how to test for them without losing speed; don't know yet how to handle that.
This commit is contained in:
parent
7e8d26d78c
commit
5b2121b25f
1 changed files with 8 additions and 0 deletions
|
|
@ -184,6 +184,7 @@ lookdict(mp, key, hash)
|
||||||
{
|
{
|
||||||
return ep;
|
return ep;
|
||||||
}
|
}
|
||||||
|
/* XXX What if PyObject_Compare returned an exception? */
|
||||||
/* Derive incr from sum, just to make it more arbitrary. Note that
|
/* Derive incr from sum, just to make it more arbitrary. Note that
|
||||||
incr must not be 0, or we will get into an infinite loop.*/
|
incr must not be 0, or we will get into an infinite loop.*/
|
||||||
incr = (sum ^ (sum >> 3)) & mask;
|
incr = (sum ^ (sum >> 3)) & mask;
|
||||||
|
|
@ -209,6 +210,7 @@ lookdict(mp, key, hash)
|
||||||
PyObject_Compare(ep->me_key, key) == 0)) {
|
PyObject_Compare(ep->me_key, key) == 0)) {
|
||||||
return ep;
|
return ep;
|
||||||
}
|
}
|
||||||
|
/* XXX What if PyObject_Compare returned an exception? */
|
||||||
/* Cycle through GF(2^n)-{0} */
|
/* Cycle through GF(2^n)-{0} */
|
||||||
incr = incr << 1;
|
incr = incr << 1;
|
||||||
if (incr > mask)
|
if (incr > mask)
|
||||||
|
|
@ -738,10 +740,12 @@ characterize(a, b, pval)
|
||||||
if (a->ma_table[i].me_value != NULL) {
|
if (a->ma_table[i].me_value != NULL) {
|
||||||
PyObject *key = a->ma_table[i].me_key;
|
PyObject *key = a->ma_table[i].me_key;
|
||||||
PyObject *aval, *bval;
|
PyObject *aval, *bval;
|
||||||
|
/* XXX What if PyObject_Compare raises an exception? */
|
||||||
if (diff != NULL && PyObject_Compare(key, diff) > 0)
|
if (diff != NULL && PyObject_Compare(key, diff) > 0)
|
||||||
continue;
|
continue;
|
||||||
aval = a->ma_table[i].me_value;
|
aval = a->ma_table[i].me_value;
|
||||||
bval = PyDict_GetItem((PyObject *)b, key);
|
bval = PyDict_GetItem((PyObject *)b, key);
|
||||||
|
/* XXX What if PyObject_Compare raises an exception? */
|
||||||
if (bval == NULL || PyObject_Compare(aval, bval) != 0)
|
if (bval == NULL || PyObject_Compare(aval, bval) != 0)
|
||||||
{
|
{
|
||||||
diff = key;
|
diff = key;
|
||||||
|
|
@ -766,9 +770,13 @@ dict_compare(a, b)
|
||||||
return 1; /* b is shorter */
|
return 1; /* b is shorter */
|
||||||
/* Same length -- check all keys */
|
/* Same length -- check all keys */
|
||||||
adiff = characterize(a, b, &aval);
|
adiff = characterize(a, b, &aval);
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return -1;
|
||||||
if (adiff == NULL)
|
if (adiff == NULL)
|
||||||
return 0; /* a is a subset with the same length */
|
return 0; /* a is a subset with the same length */
|
||||||
bdiff = characterize(b, a, &bval);
|
bdiff = characterize(b, a, &bval);
|
||||||
|
if (PyErr_Occurred())
|
||||||
|
return -1;
|
||||||
/* bdiff == NULL would be impossible now */
|
/* bdiff == NULL would be impossible now */
|
||||||
res = PyObject_Compare(adiff, bdiff);
|
res = PyObject_Compare(adiff, bdiff);
|
||||||
if (res == 0)
|
if (res == 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue