]> granicus.if.org Git - python/commitdiff
Forward port r64930.
authorAlexandre Vassalotti <alexandre@peadrop.com>
Sun, 13 Jul 2008 21:57:48 +0000 (21:57 +0000)
committerAlexandre Vassalotti <alexandre@peadrop.com>
Sun, 13 Jul 2008 21:57:48 +0000 (21:57 +0000)
Fix one more case in cursor.c.

Modules/_sqlite/connection.c
Modules/_sqlite/cursor.c

index 2d1b8220d0c502b50bc54775557ba72df8b04b0a..b2cca807ebd908c2a5b551c3ee18b536307d1293 100644 (file)
@@ -944,19 +944,16 @@ PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, Py
             _pysqlite_seterror(self->db, NULL);
         }
 
-        Py_DECREF(statement);
-        statement = 0;
+        Py_CLEAR(statement);
     } else {
         weakref = PyWeakref_NewRef((PyObject*)statement, NULL);
         if (!weakref) {
-            Py_DECREF(statement);
-            statement = 0;
+            Py_CLEAR(statement);
             goto error;
         }
 
         if (PyList_Append(self->statements, weakref) != 0) {
-            Py_DECREF(weakref);
-            statement = 0;
+            Py_CLEAR(weakref);
             goto error;
         }
 
@@ -980,15 +977,13 @@ PyObject* pysqlite_connection_execute(pysqlite_Connection* self, PyObject* args,
 
     method = PyObject_GetAttrString(cursor, "execute");
     if (!method) {
-        Py_DECREF(cursor);
-        cursor = 0;
+        Py_CLEAR(cursor);
         goto error;
     }
 
     result = PyObject_CallObject(method, args);
     if (!result) {
-        Py_DECREF(cursor);
-        cursor = 0;
+        Py_CLEAR(cursor);
     }
 
 error:
@@ -1011,15 +1006,13 @@ PyObject* pysqlite_connection_executemany(pysqlite_Connection* self, PyObject* a
 
     method = PyObject_GetAttrString(cursor, "executemany");
     if (!method) {
-        Py_DECREF(cursor);
-        cursor = 0;
+        Py_CLEAR(cursor);
         goto error;
     }
 
     result = PyObject_CallObject(method, args);
     if (!result) {
-        Py_DECREF(cursor);
-        cursor = 0;
+        Py_CLEAR(cursor);
     }
 
 error:
@@ -1042,15 +1035,13 @@ PyObject* pysqlite_connection_executescript(pysqlite_Connection* self, PyObject*
 
     method = PyObject_GetAttrString(cursor, "executescript");
     if (!method) {
-        Py_DECREF(cursor);
-        cursor = 0;
+        Py_CLEAR(cursor);
         goto error;
     }
 
     result = PyObject_CallObject(method, args);
     if (!result) {
-        Py_DECREF(cursor);
-        cursor = 0;
+        Py_CLEAR(cursor);
     }
 
 error:
index 29d3ff4ee273dc1cf8c24f2a73acd91352c627a3..14dd002165d0aabbe402439faca705b5b4aee4eb 100644 (file)
@@ -1,6 +1,6 @@
 /* cursor.c - the cursor type
  *
- * Copyright (C) 2004-2007 Gerhard Häring <gh@ghaering.de>
+ * Copyright (C) 2004-2007 Gerhard Häring <gh@ghaering.de>
  *
  * This file is part of pysqlite.
  *
@@ -529,7 +529,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
         }
         rc = pysqlite_statement_create(self->statement, self->connection, operation);
         if (rc != SQLITE_OK) {
-            self->statement = 0;
+            Py_CLEAR(self->statement);
             goto error;
         }
     }
@@ -602,7 +602,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
         }
         rc = pysqlite_statement_create(self->statement, self->connection, operation);
         if (rc != SQLITE_OK) {
-            self->statement = 0;
+            Py_CLEAR(self->statement);
             goto error;
         }
     }
@@ -711,8 +711,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
             self->next_row = _pysqlite_fetch_one_row(self);
         } else if (rc == SQLITE_DONE && !multiple) {
             pysqlite_statement_reset(self->statement);
-            Py_DECREF(self->statement);
-            self->statement = 0;
+            Py_CLEAR(self->statement);
         }
 
         switch (statement_type) {
@@ -1013,8 +1012,7 @@ PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args)
 
     if (self->statement) {
         (void)pysqlite_statement_reset(self->statement);
-        Py_DECREF(self->statement);
-        self->statement = 0;
+        Py_CLEAR(self->statement);
     }
 
     Py_INCREF(Py_None);