Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1839bac

Browse files
committed
Forward port r64930.
Fix one more case in cursor.c.
1 parent dff1834 commit 1839bac

2 files changed

Lines changed: 14 additions & 25 deletions

File tree

Modules/_sqlite/connection.c

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -944,19 +944,16 @@ PyObject* pysqlite_connection_call(pysqlite_Connection* self, PyObject* args, Py
944944
_pysqlite_seterror(self->db, NULL);
945945
}
946946

947-
Py_DECREF(statement);
948-
statement = 0;
947+
Py_CLEAR(statement);
949948
} else {
950949
weakref = PyWeakref_NewRef((PyObject*)statement, NULL);
951950
if (!weakref) {
952-
Py_DECREF(statement);
953-
statement = 0;
951+
Py_CLEAR(statement);
954952
goto error;
955953
}
956954

957955
if (PyList_Append(self->statements, weakref) != 0) {
958-
Py_DECREF(weakref);
959-
statement = 0;
956+
Py_CLEAR(weakref);
960957
goto error;
961958
}
962959

@@ -980,15 +977,13 @@ PyObject* pysqlite_connection_execute(pysqlite_Connection* self, PyObject* args,
980977

981978
method = PyObject_GetAttrString(cursor, "execute");
982979
if (!method) {
983-
Py_DECREF(cursor);
984-
cursor = 0;
980+
Py_CLEAR(cursor);
985981
goto error;
986982
}
987983

988984
result = PyObject_CallObject(method, args);
989985
if (!result) {
990-
Py_DECREF(cursor);
991-
cursor = 0;
986+
Py_CLEAR(cursor);
992987
}
993988

994989
error:
@@ -1011,15 +1006,13 @@ PyObject* pysqlite_connection_executemany(pysqlite_Connection* self, PyObject* a
10111006

10121007
method = PyObject_GetAttrString(cursor, "executemany");
10131008
if (!method) {
1014-
Py_DECREF(cursor);
1015-
cursor = 0;
1009+
Py_CLEAR(cursor);
10161010
goto error;
10171011
}
10181012

10191013
result = PyObject_CallObject(method, args);
10201014
if (!result) {
1021-
Py_DECREF(cursor);
1022-
cursor = 0;
1015+
Py_CLEAR(cursor);
10231016
}
10241017

10251018
error:
@@ -1042,15 +1035,13 @@ PyObject* pysqlite_connection_executescript(pysqlite_Connection* self, PyObject*
10421035

10431036
method = PyObject_GetAttrString(cursor, "executescript");
10441037
if (!method) {
1045-
Py_DECREF(cursor);
1046-
cursor = 0;
1038+
Py_CLEAR(cursor);
10471039
goto error;
10481040
}
10491041

10501042
result = PyObject_CallObject(method, args);
10511043
if (!result) {
1052-
Py_DECREF(cursor);
1053-
cursor = 0;
1044+
Py_CLEAR(cursor);
10541045
}
10551046

10561047
error:

Modules/_sqlite/cursor.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* cursor.c - the cursor type
22
*
3-
* Copyright (C) 2004-2007 Gerhard Häring <[email protected]>
3+
* Copyright (C) 2004-2007 Gerhard Häring <[email protected]>
44
*
55
* This file is part of pysqlite.
66
*
@@ -529,7 +529,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
529529
}
530530
rc = pysqlite_statement_create(self->statement, self->connection, operation);
531531
if (rc != SQLITE_OK) {
532-
self->statement = 0;
532+
Py_CLEAR(self->statement);
533533
goto error;
534534
}
535535
}
@@ -602,7 +602,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
602602
}
603603
rc = pysqlite_statement_create(self->statement, self->connection, operation);
604604
if (rc != SQLITE_OK) {
605-
self->statement = 0;
605+
Py_CLEAR(self->statement);
606606
goto error;
607607
}
608608
}
@@ -711,8 +711,7 @@ PyObject* _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject*
711711
self->next_row = _pysqlite_fetch_one_row(self);
712712
} else if (rc == SQLITE_DONE && !multiple) {
713713
pysqlite_statement_reset(self->statement);
714-
Py_DECREF(self->statement);
715-
self->statement = 0;
714+
Py_CLEAR(self->statement);
716715
}
717716

718717
switch (statement_type) {
@@ -1013,8 +1012,7 @@ PyObject* pysqlite_cursor_close(pysqlite_Cursor* self, PyObject* args)
10131012

10141013
if (self->statement) {
10151014
(void)pysqlite_statement_reset(self->statement);
1016-
Py_DECREF(self->statement);
1017-
self->statement = 0;
1015+
Py_CLEAR(self->statement);
10181016
}
10191017

10201018
Py_INCREF(Py_None);

0 commit comments

Comments
 (0)