mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Several fixes reported by jim F.
This commit is contained in:
parent
2a7f58de1c
commit
4669fb474b
1 changed files with 28 additions and 31 deletions
|
@ -671,7 +671,7 @@ PySequence_GetItem(s, i)
|
||||||
|
|
||||||
if(i < 0)
|
if(i < 0)
|
||||||
{
|
{
|
||||||
if(0 > (l=m->sq_length(s))) return NULL;
|
if(! m->sq_length || 0 > (l=m->sq_length(s))) return NULL;
|
||||||
i += l;
|
i += l;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -689,13 +689,17 @@ PySequence_GetSlice(s, i1, i2)
|
||||||
|
|
||||||
if(! s) return Py_ReturnNullError();
|
if(! s) return Py_ReturnNullError();
|
||||||
|
|
||||||
if(! ((m=s->ob_type->tp_as_sequence) && m->sq_length && m->sq_slice))
|
if(! ((m=s->ob_type->tp_as_sequence) && m->sq_slice))
|
||||||
return Py_ReturnMethodError("__getslice__");
|
return Py_ReturnMethodError("__getslice__");
|
||||||
|
|
||||||
if(0 > (l=m->sq_length(s))) return NULL;
|
if(i1 < 0 || i2 < 0)
|
||||||
|
{
|
||||||
|
|
||||||
if(i1 < 0) i1 += l;
|
if(! m->sq_length || 0 > (l=m->sq_length(s))) return NULL;
|
||||||
if(i2 < 0) i2 += l;
|
|
||||||
|
if(i1 < 0) i1 += l;
|
||||||
|
if(i2 < 0) i2 += l;
|
||||||
|
}
|
||||||
|
|
||||||
return m->sq_slice(s,i1,i2);
|
return m->sq_slice(s,i1,i2);
|
||||||
}
|
}
|
||||||
|
@ -802,16 +806,8 @@ PySequence_Tuple(s)
|
||||||
|
|
||||||
for(i=0; i < l; i++)
|
for(i=0; i < l; i++)
|
||||||
{
|
{
|
||||||
if((item=PySequence_GetItem(s,i)))
|
if(((item=PySequence_GetItem(s,i))) ||
|
||||||
{
|
PyTuple_SetItem(t,i,item) == -1)
|
||||||
if(PyTuple_SetItem(t,i,item) == -1)
|
|
||||||
{
|
|
||||||
Py_DECREF(item);
|
|
||||||
Py_DECREF(t);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
Py_DECREF(t);
|
Py_DECREF(t);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -826,25 +822,20 @@ PySequence_List(s)
|
||||||
{
|
{
|
||||||
int l, i;
|
int l, i;
|
||||||
PyObject *t, *item;
|
PyObject *t, *item;
|
||||||
|
|
||||||
if(! s) return Py_ReturnNullError();
|
if(! s) return Py_ReturnNullError();
|
||||||
|
|
||||||
Py_TRY((l=PySequence_Length(s)) != -1);
|
Py_TRY((l=PySequence_Length(s)) != -1);
|
||||||
Py_TRY(t=PyList_New(l));
|
Py_TRY(t=PyList_New(l));
|
||||||
|
|
||||||
for(i=0; i < l; i++)
|
for(i=0; i < l; i++)
|
||||||
{
|
{
|
||||||
if((item=PySequence_GetItem(s,i)))
|
if((item=PySequence_GetItem(s,i)) ||
|
||||||
{
|
PyList_SetItem(t,i,item) == -1)
|
||||||
if(PyList_SetItem(t,i,item) == -1)
|
{
|
||||||
{
|
Py_DECREF(t);
|
||||||
Py_DECREF(item);
|
return NULL;
|
||||||
Py_DECREF(t);
|
}
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Py_DECREF(t);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
@ -946,7 +937,10 @@ PyMapping_HasKeyString(o, key)
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
|
|
||||||
v=PyMapping_GetItemString(o,key);
|
v=PyMapping_GetItemString(o,key);
|
||||||
if(v) return 1;
|
if(v) {
|
||||||
|
Py_DECREF(v);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -959,7 +953,10 @@ PyMapping_HasKey(o, key)
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
|
|
||||||
v=PyObject_GetItem(o,key);
|
v=PyObject_GetItem(o,key);
|
||||||
if(v) return 1;
|
if(v) {
|
||||||
|
Py_DECREF(v);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue