From 6f30a1dd4ee3309dbcf4fa3e041a5fd4cfb75fda Mon Sep 17 00:00:00 2001 From: Oren Milman Date: Thu, 12 Oct 2017 11:20:04 +0300 Subject: [PATCH 1/5] init commit --- Modules/_sqlite/cursor.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index cfe2627aacd5b7..f7a34c10c2ac92 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -39,21 +39,20 @@ static int pysqlite_cursor_init(pysqlite_Cursor* self, PyObject* args, PyObject* } Py_INCREF(connection); - self->connection = connection; - self->statement = NULL; - self->next_row = NULL; - self->in_weakreflist = NULL; + Py_XSETREF(self->connection, connection); + Py_CLEAR(self->statement); + Py_CLEAR(self->next_row); - self->row_cast_map = PyList_New(0); + Py_XSETREF(self->row_cast_map, PyList_New(0)); if (!self->row_cast_map) { return -1; } Py_INCREF(Py_None); - self->description = Py_None; + Py_XSETREF(self->description, Py_None); Py_INCREF(Py_None); - self->lastrowid= Py_None; + Py_XSETREF(self->lastrowid, Py_None); self->arraysize = 1; self->closed = 0; @@ -62,7 +61,7 @@ static int pysqlite_cursor_init(pysqlite_Cursor* self, PyObject* args, PyObject* self->rowcount = -1L; Py_INCREF(Py_None); - self->row_factory = Py_None; + Py_XSETREF(self->row_factory, Py_None); if (!pysqlite_check_thread(self->connection)) { return -1; From 15f071aff1f468e7760d850a3a56d88929d6ee69 Mon Sep 17 00:00:00 2001 From: Oren Milman Date: Thu, 12 Oct 2017 18:48:40 +0300 Subject: [PATCH 2/5] added a NEWS.d item and a test. --- Lib/sqlite3/test/regression.py | 15 +++++++++++++++ .../2017-10-12-18-45-38.bpo-31770.GV3MPx.rst | 2 ++ 2 files changed, 17 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2017-10-12-18-45-38.bpo-31770.GV3MPx.rst diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py index 7dd0050528f8fa..8b754989daed89 100644 --- a/Lib/sqlite3/test/regression.py +++ b/Lib/sqlite3/test/regression.py @@ -24,6 +24,7 @@ import datetime import unittest import sqlite3 as sqlite +import weakref class RegressionTests(unittest.TestCase): def setUp(self): @@ -376,6 +377,20 @@ def CheckCommitCursorReset(self): counter += 1 self.assertEqual(counter, 3, "should have returned exactly three rows") + def CheckBpo31770(self): + """ + The interpreter shouldn't crash in case __init__() is called more than + once. + """ + def callback(*args): + pass + con = sqlite.connect(":memory:") + cur = sqlite.Cursor(con) + ref = weakref.ref(cur, callback) + cur.__init__(con) + del cur + del ref # shouldn't crash + def suite(): regression_suite = unittest.makeSuite(RegressionTests, "Check") diff --git a/Misc/NEWS.d/next/Library/2017-10-12-18-45-38.bpo-31770.GV3MPx.rst b/Misc/NEWS.d/next/Library/2017-10-12-18-45-38.bpo-31770.GV3MPx.rst new file mode 100644 index 00000000000000..86c7b804bdaca3 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2017-10-12-18-45-38.bpo-31770.GV3MPx.rst @@ -0,0 +1,2 @@ +Prevent a crash when calling the ``__init__()`` method of a +``sqlite3.Cursor`` object more than once. Patch by Oren Milman. From 497ced81c66d05275ae587c646f94b0826877387 Mon Sep 17 00:00:00 2001 From: Oren Milman Date: Thu, 12 Oct 2017 18:56:37 +0300 Subject: [PATCH 3/5] improve the test's comment --- Lib/sqlite3/test/regression.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py index 8b754989daed89..cdc1b0fbf16e97 100644 --- a/Lib/sqlite3/test/regression.py +++ b/Lib/sqlite3/test/regression.py @@ -379,8 +379,8 @@ def CheckCommitCursorReset(self): def CheckBpo31770(self): """ - The interpreter shouldn't crash in case __init__() is called more than - once. + The interpreter shouldn't crash in case Cursor.__init__() is called + more than once. """ def callback(*args): pass From 82dfbf86d770ee814924a5f8557cf4921a8eb275 Mon Sep 17 00:00:00 2001 From: Oren Milman Date: Sat, 14 Oct 2017 17:01:32 +0300 Subject: [PATCH 4/5] improve the test. --- Lib/sqlite3/test/regression.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py index cdc1b0fbf16e97..3e82d83c0cd3f9 100644 --- a/Lib/sqlite3/test/regression.py +++ b/Lib/sqlite3/test/regression.py @@ -25,6 +25,7 @@ import unittest import sqlite3 as sqlite import weakref +from test import support class RegressionTests(unittest.TestCase): def setUp(self): @@ -389,7 +390,7 @@ def callback(*args): ref = weakref.ref(cur, callback) cur.__init__(con) del cur - del ref # shouldn't crash + support.gc_collect() # shouldn't crash def suite(): From 51bb3411c85a2b3020a951a093644eb2da7f9da6 Mon Sep 17 00:00:00 2001 From: Oren Milman Date: Fri, 20 Oct 2017 10:32:10 +0300 Subject: [PATCH 5/5] changed the test to include both 'del ref' and the call to gc_collect() --- Lib/sqlite3/test/regression.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Lib/sqlite3/test/regression.py b/Lib/sqlite3/test/regression.py index 3e82d83c0cd3f9..3ff9abd98993f7 100644 --- a/Lib/sqlite3/test/regression.py +++ b/Lib/sqlite3/test/regression.py @@ -390,7 +390,9 @@ def callback(*args): ref = weakref.ref(cur, callback) cur.__init__(con) del cur - support.gc_collect() # shouldn't crash + # The interpreter shouldn't crash when ref is collected. + del ref + support.gc_collect() def suite(): pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy