]> granicus.if.org Git - python/commitdiff
Several fixes reported by jim F.
authorGuido van Rossum <guido@python.org>
Wed, 2 Apr 1997 05:31:09 +0000 (05:31 +0000)
committerGuido van Rossum <guido@python.org>
Wed, 2 Apr 1997 05:31:09 +0000 (05:31 +0000)
Objects/abstract.c

index cac767fbfee6a201e1b4a6f0675744c1ff749cfe..e668b0859d816a0cd2913b61c0dedf55bd23f0d0 100644 (file)
@@ -671,7 +671,7 @@ PySequence_GetItem(s, i)
 
   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;
     }
       
@@ -689,13 +689,17 @@ PySequence_GetSlice(s, i1, i2)
 
   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__");  
 
-  if(0 > (l=m->sq_length(s))) return NULL;
+  if(i1 < 0 || i2 < 0)
+    {
 
-  if(i1 < 0) i1 += l;
-  if(i2 < 0) i2 += l;
+      if(! m->sq_length || 0 > (l=m->sq_length(s))) return NULL;
+
+      if(i1 < 0) i1 += l;
+      if(i2 < 0) i2 += l;
+    }
       
   return m->sq_slice(s,i1,i2);
 }
@@ -802,16 +806,8 @@ PySequence_Tuple(s)
 
   for(i=0; i < l; i++)
     {
-      if((item=PySequence_GetItem(s,i)))
-       {
-         if(PyTuple_SetItem(t,i,item) == -1)
-           {
-             Py_DECREF(item);
-             Py_DECREF(t);
-             return NULL;
-           }
-       }
-      else
+      if(((item=PySequence_GetItem(s,i))) ||
+        PyTuple_SetItem(t,i,item) == -1)
        {
          Py_DECREF(t);
          return NULL;
@@ -826,25 +822,20 @@ PySequence_List(s)
 {
   int l, i;
   PyObject *t, *item;
+
   if(! s) return Py_ReturnNullError();
+
   Py_TRY((l=PySequence_Length(s)) != -1);
   Py_TRY(t=PyList_New(l));
+
   for(i=0; i < l; i++)
     {
-      if((item=PySequence_GetItem(s,i)))
-      {
-        if(PyList_SetItem(t,i,item) == -1)
-          {
-            Py_DECREF(item);
-            Py_DECREF(t);
-            return NULL;
-          }
-      }
-      else
-      {
-        Py_DECREF(t);
-        return NULL;
-      }
+      if((item=PySequence_GetItem(s,i)) ||
+        PyList_SetItem(t,i,item) == -1)
+       {
+         Py_DECREF(t);
+         return NULL;
+       }
     }
   return t;
 }
@@ -946,7 +937,10 @@ PyMapping_HasKeyString(o, key)
   PyObject *v;
 
   v=PyMapping_GetItemString(o,key);
-  if(v) return 1;
+  if(v) {
+    Py_DECREF(v);
+    return 1;
+  }
   PyErr_Clear();
   return 0;
 }
@@ -959,7 +953,10 @@ PyMapping_HasKey(o, key)
   PyObject *v;
 
   v=PyObject_GetItem(o,key);
-  if(v) return 1;
+  if(v) {
+    Py_DECREF(v);
+    return 1;
+  }
   PyErr_Clear();
   return 0;
 }