+27
-8
lines changedFilter options
+27
-8
lines changed Original file line number Diff line number Diff line change
@@ -24,6 +24,8 @@
24
24
import datetime
25
25
import unittest
26
26
import sqlite3 as sqlite
27
+
import weakref
28
+
from test import support
27
29
28
30
class RegressionTests(unittest.TestCase):
29
31
def setUp(self):
@@ -376,6 +378,22 @@ def CheckCommitCursorReset(self):
376
378
counter += 1
377
379
self.assertEqual(counter, 3, "should have returned exactly three rows")
378
380
381
+
def CheckBpo31770(self):
382
+
"""
383
+
The interpreter shouldn't crash in case Cursor.__init__() is called
384
+
more than once.
385
+
"""
386
+
def callback(*args):
387
+
pass
388
+
con = sqlite.connect(":memory:")
389
+
cur = sqlite.Cursor(con)
390
+
ref = weakref.ref(cur, callback)
391
+
cur.__init__(con)
392
+
del cur
393
+
# The interpreter shouldn't crash when ref is collected.
394
+
del ref
395
+
support.gc_collect()
396
+
379
397
380
398
def suite():
381
399
regression_suite = unittest.makeSuite(RegressionTests, "Check")
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
1
+
Prevent a crash when calling the ``__init__()`` method of a
2
+
``sqlite3.Cursor`` object more than once. Patch by Oren Milman.
Original file line number Diff line number Diff line change
@@ -39,21 +39,20 @@ static int pysqlite_cursor_init(pysqlite_Cursor* self, PyObject* args, PyObject*
39
39
}
40
40
41
41
Py_INCREF(connection);
42
-
self->connection = connection;
43
-
self->statement = NULL;
44
-
self->next_row = NULL;
45
-
self->in_weakreflist = NULL;
42
+
Py_XSETREF(self->connection, connection);
43
+
Py_CLEAR(self->statement);
44
+
Py_CLEAR(self->next_row);
46
45
47
-
self->row_cast_map = PyList_New(0);
46
+
Py_XSETREF(self->row_cast_map, PyList_New(0));
48
47
if (!self->row_cast_map) {
49
48
return -1;
50
49
}
51
50
52
51
Py_INCREF(Py_None);
53
-
self->description = Py_None;
52
+
Py_XSETREF(self->description, Py_None);
54
53
55
54
Py_INCREF(Py_None);
56
-
self->lastrowid= Py_None;
55
+
Py_XSETREF(self->lastrowid, Py_None);
57
56
58
57
self->arraysize = 1;
59
58
self->closed = 0;
@@ -62,7 +61,7 @@ static int pysqlite_cursor_init(pysqlite_Cursor* self, PyObject* args, PyObject*
62
61
self->rowcount = -1L;
63
62
64
63
Py_INCREF(Py_None);
65
-
self->row_factory = Py_None;
64
+
Py_XSETREF(self->row_factory, Py_None);
66
65
67
66
if (!pysqlite_check_thread(self->connection)) {
68
67
return -1;
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4