507 Commits
Author SHA1 Message Date
Miss Islington (bot)andJelle Zijlstra 7291b843d8 [3.15] gh-159739: Keep SQLite list parameters alive while binding (GH-160192) (#160361)
When a SQL parameter sequence is an exact list, sqlite3 retrieved an element as a borrowed reference before taking ownership. On free-threaded builds another thread can replace it in between, so binding can use a freed object and crash. Fetch a strong reference atomically. Backport to 3.15 and 3.14.
(cherry picked from commit 4df47d8e60)

Co-authored-by: Jelle Zijlstra <jelle@openai.com>
2026-10-22 23:59:01 +00:00
Miss Islington (bot)andSerhiy Storchaka b508fa800b [3.15] gh-156100: Fix crashes in the sqlite3 Connection.autocommit setter (GH-156104) (GH-156151)
Deleting the attribute crashed, and setting it to an integer which does not
fit in C long reported success with OverflowError set.
(cherry picked from commit daebcac92d)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-10-10 12:31:48 +03:00
Miss Islington (bot)andSerhiy Storchaka cb34920e00 [3.15] gh-156101: Fix sqlite3 Cursor.arraysize on a failed assignment (GH-156105) (GH-156156)
PyLong_AsUInt32() stores 0 in the target on error, so the attribute was
clobbered when the assigned value was too large.
(cherry picked from commit 53760b3f8d)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-10-10 09:26:17 +00:00
Serhiy Storchaka 503560dcad [3.15] gh-150449: Raise ValueError for sqlite3.Blob slices with a negative step (GH-155773)
Reading or writing such a slice computed a negative length and failed with
SystemError.  Empty slices, which select nothing, are still allowed.

(cherry picked from commit d9e8d226a3d05ea020256086aee24d21f9792206)
2026-10-09 18:35:20 +00:00
Serhiy StorchakaandSteve Stagg a412ffda43 [3.15] gh-152817: Prevent deletion of sqlite3 cursor.row_factory attr (GH-152818) (GH-156160)
(cherry picked from commit 8e96dd6f25)

Co-authored-by: Steve Stagg <stestagg@gmail.com>
2026-10-09 20:55:48 +03:00
Serhiy Storchaka fbbe36329b [3.15] gh-113318: Fix @getter and @setter in Argument Clinic (GH-155778) (GH-156010)
(cherry picked from commit 915970ce9d)
2026-10-09 20:54:35 +03:00
Miss Islington (bot)andcui fliter bd519fc7f5 [3.15] gh-155781: Hold strong references to sqlite3 converters (GH-155784) (#156192)
Co-authored-by: cui fliter <imcusg@gmail.com>
2026-08-29 13:20:23 +03:00
Miss Islington (bot)andStan Ulbrych 32beeab7dd [3.15] gh-155952: Fix <unrepresentable> Argument Clinic defaults in several signatures (GH-155954) (#156165)
gh-155952: Fix `<unrepresentable>` Argument Clinic defaults in several signatures (GH-155954)
(cherry picked from commit 033dc43bcf)

Co-authored-by: Stan Ulbrych <stan@python.org>
2026-08-29 10:08:27 +03:00
Miss Islington (bot)andSerhiy Storchaka ef8d25bae8 [3.15] gh-155702: Fix sqlite3.Blob slice assignment with a step (GH-155703) (#155765)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-08-19 05:37:30 +03:00
Miss Islington (bot)andtonghuaroot f58e582479 [3.15] gh-153695: Fix sqlite3.Row.__hash__ with an unhashable value (GH-153696) (#153723)
gh-153695: Fix sqlite3.Row.__hash__ with an unhashable value (GH-153696)
(cherry picked from commit b704b647b2)

Co-authored-by: tonghuaroot (童话) <tonghuaroot@gmail.com>
2026-07-14 22:55:51 +00:00
Miss Islington (bot)andJiseok CHOI c6d64cc60d [3.15] gh-150913: Fix sqlite3.Blob validation for empty slice assignment (GH-150915) (GH-150923)
ass_subscript_slice() returned early when the computed slice length
was zero, bypassing validation performed for non-empty slices.
(cherry picked from commit fc9c4db130)

Co-authored-by: Jiseok CHOI <jiseok.dev@gmail.com>
2026-06-04 14:10:30 +00:00
Miss Islington (bot)andSepehr Rasouli 1835400ff5 [3.15] gh-149738: Fix segmentation fault bug in sqllite3 (GH-149754) (#150768)
gh-149738: Fix segmentation fault bug in sqllite3 (GH-149754)

Deleting the `row_factory` or `text_factory` attribute is no longer allowed.
(cherry picked from commit 60fdb3192b)

Co-authored-by: Sepehr Rasouli <sepehrrasouli06@gmail.com>
2026-06-02 09:36:03 +00:00
Miss Islington (bot)andSerhiy Storchaka 79937e3cf1 [3.15] gh-150285: Fix too long docstrings in the sqlite3 module (GH-150290) (GH-150340)
(cherry picked from commit 0466560b31)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2026-05-24 13:43:38 +00:00
Bénédikt Tran aa6680775d gh-146090: fix memory management of internal sqlite3 callback contexts (#146569) 2026-03-29 14:21:37 +02:00
Karolina SurmaandVictor Stinner 1887a95f51 gh-128341: Use _Py_ABI_SLOT in stdlib modules (#145770)
Rename from _Py_INTERNAL_ABI_SLOT to _Py_ABI_SLOT
and define the macro using _PyABIInfo_DEFAULT.

Use the ABI slot in stdlib extension modules to enable running
a check of ABI version compatibility.

_tkinter, _tracemalloc and readline don't use the slots, hence they need
explicit handling.

Co-authored-by: Victor Stinner <vstinner@python.org>
2026-03-24 17:47:55 +00:00
A.Ibrahim 06b0920f12 gh-142787: Handle empty sqlite3 blob slices (#142824) 2026-02-26 23:40:25 +00:00
Thomas Kluyver 74c1f4145e gh-144377: Clean up sqlite3 Connection's list of weakrefs to Cursor objects (#144378) 2026-02-03 13:36:12 +01:00
Bénédikt Tran 7f6c16a956 gh-142830: prevent some crashes when mutating sqlite3 callbacks (#143245) 2026-01-01 11:55:05 +01:00
Prithviraj Chaudhuri b1558b6d3e gh-140042: Removing unsafe call to sqlite3_shutdown (GH-141690) 2025-11-20 15:35:22 +01:00
Bénédikt Tran 27acaf1cb7 gh-139327: consolidate sqlite3_finalize and sqlite3_reset usages (GH-139329) 2025-10-15 15:18:07 +02:00
Victor Stinner c4e7d245d6 gh-138342: Move _PyObject_VisitType() to the internal C API (#139734) 2025-10-08 12:10:58 +02:00
Bénédikt Tran d0a3eff9d6 gh-139327: fix some reference leaks in sqlite3 error branches (#139328) 2025-10-01 11:10:12 +02:00
Bénédikt Tran bc172ee830 gh-139283: correctly handle size limit in cursor.fetchmany() (#139296)
Passing a negative or zero size to `cursor.fetchmany()` made it fetch all rows
instead of none.

While this could be considered a security vulnerability, it was decided to treat
this issue as a regular bug as passing a non-sanitized *size* value in the first
place is not recommended.
2025-09-30 11:18:55 +02:00
Victor Stinner 243d599a05 gh-129813, PEP 782: Use PyBytesWriter in _sqlite (#138956)
Replace PyBytes_FromStringAndSize(NULL, size) with the new public
PyBytesWriter API.
2025-09-18 14:58:35 +02:00
chiri 8eb106240f gh-138736: Fix sqlite3.Connection.blobopen 'row' parameter type and naming (#138738)
The 'row' parameter represents a ROWID. Clarify this in docs and docstrings.
2025-09-17 15:51:14 +00:00
Peter Bierma 4f6ecd10c2 gh-138342: Use a common utility for visiting an object's type (GH-138343)
Add `_PyObject_VisitType` in place of `tp_traverse` functions that only visit the object's type.
2025-09-01 16:20:33 +00:00
Adam Turner 918e3ba6c0 GH-137623: Use an AC decorator for docstring line length enforcement (#137690) 2025-08-18 18:29:00 +01:00
b1056c2a44 gh-135607: remove null checking of weakref list in dealloc of extension modules and objects (#135614)
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-06-30 11:14:31 +00:00
Petr ViktorinandTan Long e7a3c20b92 gh-133390: Support SQL keyword completion for sqlite3 CLI (GH-133393) (GH-135292)
Co-authored-by: Tan Long <tanloong@foxmail.com>
2025-06-12 16:28:30 +02:00
Petr Viktorin 24069fbca8 Revert "gh-133390: Support SQL keyword completion for sqlite3 CLI (#133393)" temporarily (GH-135232)
This reverts commit 62b3d2d443,
which broke buildbots
2025-06-07 08:56:43 +00:00
Tan Long 62b3d2d443 gh-133390: Support SQL keyword completion for sqlite3 CLI (#133393) 2025-06-06 16:52:41 +02:00
Serhiy Storchaka dcf93c4c93 gh-133595: Clean up sqlite3.Connection APIs (GH-133605)
* All parameters of sqlite3.connect() except "database" are now keyword-only.
* The first three parameters of methods create_function() and
  create_aggregate() are now positional-only.
* The first parameter of methods set_authorizer(), set_progress_handler()
  and set_trace_callback() is now positional-only.
2025-05-08 15:42:00 +03:00
8614f86b71 gh-131525: Cache the result of tuple_hash (#131529)
* gh-131525: Cache the result of tuple_hash

* Fix debug builds

* Add blurb

* Fix formatting

* Pre-compute empty tuple singleton

* Mostly set the cache within tuple_alloc

* Fixes for TSAN

* Pre-compute empty tuple singleton

* Fix for 32-bit platforms

* Assert that op != NULL in _PyTuple_RESET_HASH_CACHE

* Use FT_ATOMIC_STORE_SSIZE_RELAXED macro

* Update Include/internal/pycore_tuple.h

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>

* Fix alignment

* atomic load

* Update Objects/tupleobject.c

Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>

---------

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
2025-03-27 09:57:06 -04:00
Mark Shannon a45f25361d GH-131238: More refactoring of core header files (GH-131351)
Adds new pycore_stats.h header file to help break dependencies involving the pycore_code.h header.
2025-03-17 14:41:05 +00:00
Victor Stinner 9d759b63d8 gh-111178: Change Argument Clinic signature for METH_O (#130682)
Use "PyObject*" for METH_O functions to fix an undefined behavior.
2025-03-11 16:33:36 +01:00
Erlend E. Aasland 3b366a4a4b gh-129928: Rework sqlite3 error helpers (#129929)
Add a helper for raising DB-API compatible exceptions based on the
result code of SQLite C APIs. Some APIs do not store the error indicator
on the database pointer, so we need to be able to deduce the DB-API
compatible exception directly from the error code.

- rename _pysqlite_seterror() as set_error_from_db()
- introduce set_error_from_code()
2025-02-11 07:49:25 +00:00
Erlend E. Aasland 3a2e7aacf6 gh-129928: Raise more accurate exception for incorrect sqlite3 UDF creation (#129941)
Consistently raise ProgrammingError if the user tries to create an UDF
with an invalid number of parameters.
2025-02-11 08:26:01 +01:00
Erlend E. Aasland 7e6ee50b6b gh-129603: Don't segfault if sqlite3.Row description is None (#129604) 2025-02-10 00:27:28 +01:00
Victor StinnerandErlend E. Aasland 218f205f20 gh-129354: Use PyErr_FormatUnraisable() function (#129524)
Replace PyErr_WriteUnraisable() with PyErr_FormatUnraisable().

Update test_sqlite3 tests.

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2025-02-03 12:10:18 +00:00
Bénédikt Tran 881984b41a gh-111178: fix UBSan failures in Modules/_sqlite (GH-129087)
* fix UBSan failures for `pysqlite_Blob`
* fix UBSan failures for `pysqlite_Connection`
* fix UBSan failures for `pysqlite_Cursor`
* fix UBSan failures for `pysqlite_PrepareProtocol`
* fix UBSan failures for `pysqlite_Row`
* fix UBSan failures for `pysqlite_Statement`

* suppress unused return values
2025-01-31 14:33:30 +01:00
Victor Stinner 3bebe46d34 gh-128911: Add PyImport_ImportModuleAttr() function (#128912)
Add PyImport_ImportModuleAttr() and
PyImport_ImportModuleAttrString() functions.

* Add unit tests.
* Replace _PyImport_GetModuleAttr()
  with PyImport_ImportModuleAttr().
* Replace _PyImport_GetModuleAttrString()
  with PyImport_ImportModuleAttrString().
* Remove "pycore_import.h" includes, no longer needed.
2025-01-30 11:17:29 +00:00
Erlend E. Aasland 379ab856f5 gh-129346: Handle allocation errors for SQLite aggregate context (#129347) 2025-01-27 18:16:19 +01:00
Erlend E. Aasland 537296cdcd gh-111178: Generate correct signature for most self converters (#128447) 2025-01-20 12:40:18 +01:00
Bénédikt TranandVictor Stinner 7303f06846 gh-126742: Add _PyErr_SetLocaleString, use it for gdbm & dlerror messages (GH-126746)
- Add a helper to set an error from locale-encoded `char*`
- Use the helper for gdbm & dlerror messages

Co-authored-by: Victor Stinner <vstinner@python.org>
2024-12-17 12:12:45 +01:00
Serhiy Storchaka 061e50f196 gh-122943: Add the varpos parameter in _PyArg_UnpackKeywords (GH-126564)
Remove _PyArg_UnpackKeywordsWithVararg.
Add comments for integer arguments of _PyArg_UnpackKeywords.
2024-11-08 14:23:50 +02:00
Steve Dower e731554337 Fixes loop variables to be the same types as their limit (GH-120958) 2024-06-24 17:11:47 +01:00
Petr ViktorinandEric Snow 6f1d448bc1 gh-113993: Allow interned strings to be mortal, and fix related issues (GH-120520)
* Add an InternalDocs file describing how interning should work and how to use it.

* Add internal functions to *explicitly* request what kind of interning is done:
  - `_PyUnicode_InternMortal`
  - `_PyUnicode_InternImmortal`
  - `_PyUnicode_InternStatic`

* Switch uses of `PyUnicode_InternInPlace` to those.

* Disallow using `_Py_SetImmortal` on strings directly.
  You should use `_PyUnicode_InternImmortal` instead:
  - Strings should be interned before immortalization, otherwise you're possibly
    interning a immortalizing copy.
  - `_Py_SetImmortal` doesn't handle the `SSTATE_INTERNED_MORTAL` to
    `SSTATE_INTERNED_IMMORTAL` update, and those flags can't be changed in
    backports, as they are now part of public API and version-specific ABI.

* Add private `_only_immortal` argument for `sys.getunicodeinternedsize`, used in refleak test machinery.

* Make sure the statically allocated string singletons are unique. This means these sets are now disjoint:
  - `_Py_ID`
  - `_Py_STR` (including the empty string)
  - one-character latin-1 singletons

  Now, when you intern a singleton, that exact singleton will be interned.

* Add a `_Py_LATIN1_CHR` macro, use it instead of `_Py_ID`/`_Py_STR` for one-character latin-1 singletons everywhere (including Clinic).

* Intern `_Py_STR` singletons at startup.

* For free-threaded builds, intern `_Py_LATIN1_CHR` singletons at startup.

* Beef up the tests. Cover internal details (marked with `@cpython_only`).

* Add lots of assertions

Co-Authored-By: Eric Snow <ericsnowcurrently@gmail.com>
2024-06-21 17:19:31 +02:00
Erlend E. Aasland af359cee75 gh-118928: sqlite3: correctly bail if sequences of params are used with named placeholders (#119197) 2024-05-20 09:44:42 -04:00
Erlend E. AaslandandHugo van Kemenade d8e0e00919 gh-118928: sqlite3: disallow sequences of params with named placeholders (#118929)
Follow-up of gh-101693. The previous DeprecationWarning is replaced with 
raising sqlite3.ProgrammingError.

Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2024-05-14 16:10:55 +00:00
Hugo van Kemenade a019347947 gh-118924: Remove sqlite3.version and sqlite3.version_info (#118925) 2024-05-10 20:42:34 +00:00