494 Commits
Author SHA1 Message Date
Miss Islington (bot)andJelle Zijlstra cd046264fc [3.14] gh-159739: Keep SQLite list parameters alive while binding (GH-160192) (#160362)
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-23 00:13:19 +00:00
Serhiy Storchaka 15045f45ce [3.14] gh-150449: Raise ValueError for sqlite3.Blob slices with a negative step (GH-155773) (GH-159110)
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 503560dcad)


(cherry picked from commit d9e8d226a3d05ea020256086aee24d21f9792206)
2026-10-10 11:42:41 +00:00
stevensandStan Ulbrych 31e1476cc3 [3.14] gh-155952: Fix <unrepresentable> Argument Clinic defaults in several signatures (#156172)
(cherry picked from commit 5a7fd42138)

Co-authored-by: Stan Ulbrych <stan@python.org>
2026-08-21 13:23:30 +01:00
Serhiy StorchakaandSteve Stagg 8288442bb6 [3.14] gh-152817: Prevent deletion of sqlite3 cursor.row_factory attr (GH-152818) (GH-156161)
(cherry picked from commit 8e96dd6f25)

Co-authored-by: Steve Stagg <stestagg@gmail.com>
2026-08-21 08:54:06 +00:00
Miss Islington (bot)andSerhiy Storchaka f3a0531688 [3.14] gh-156101: Fix sqlite3 Cursor.arraysize on a failed assignment (GH-156105) (GH-156157)
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-08-21 07:42:25 +00:00
Miss Islington (bot)andSerhiy Storchaka 31d0cf94ab [3.14] gh-156100: Fix crashes in the sqlite3 Connection.autocommit setter (GH-156104) (GH-156152)
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-08-21 07:32:43 +00:00
Serhiy Storchaka 90a1f02b7d [3.14] gh-113318: Fix @getter and @setter in Argument Clinic (GH-155778) (GH-156011)
(cherry picked from commit 915970ce9d)
2026-08-18 13:09:24 +00:00
Miss Islington (bot)andtonghuaroot a3d61936c2 [3.14] gh-153695: Fix sqlite3.Row.__hash__ with an unhashable value (GH-153696) (#153724)
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:49:09 +00:00
Miss Islington (bot)andJiseok CHOI 62f4782fc2 [3.14] gh-150913: Fix sqlite3.Blob validation for empty slice assignment (GH-150915) (GH-150924)
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:07:32 +00:00
Miss Islington (bot)andSepehr Rasouli 3207263d10 [3.14] gh-149738: Fix segmentation fault bug in sqllite3 (GH-149754) (#150769)
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 14:52:25 +02:00
Serhiy Storchaka 7168b02795 [3.14] gh-150285: Fix too long docstrings in the sqlite3 module (GH-150290) (GH-150461)
(cherry picked from commit 0466560b31)
2026-05-26 09:27:04 +00:00
Miss Islington (bot)andBénédikt Tran 1458ea0065 [3.14] gh-146090: fix memory management of internal sqlite3 callback contexts (GH-146569) (#146595)
gh-146090: fix memory management of internal `sqlite3` callback contexts (GH-146569)
(cherry picked from commit aa6680775d)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2026-03-29 15:15:05 +02:00
Miss Islington (bot)andA.Ibrahim bc6a7a2b0c [3.14] gh-142787: Handle empty sqlite3 blob slices (GH-142824) (#145297)
(cherry picked from commit 06b0920f12)

Co-authored-by: A.Ibrahim <abdulrasheedibrahim47@gmail.com>
2026-02-27 01:12:51 +01:00
Bénédikt Tran 048edac8be [3.14] gh-142830: prevent some crashes when mutating sqlite3 callbacks (GH-143245) (#143322)
(cherry picked from commit 7f6c16a956)
2026-01-01 11:24:21 +00:00
Miss Islington (bot)andPrithviraj Chaudhuri 212b096b2a [3.14] gh-140042: Removing unsafe call to sqlite3_shutdown (GH-141690) (#141793)
Co-authored-by: Prithviraj Chaudhuri <p.chaudhuri1993@gmail.com>
2025-11-30 14:32:11 +02:00
cde02ae782 [3.14] gh-139283: correctly handle size limit in cursor.fetchmany() (GH-139296) (GH-139441)
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.
(cherry picked from commit bc172ee830)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2025-10-07 21:23:08 +02:00
Erlend E. Aaslandandchiri ebbfd8f51a [3.14] gh-138736: Fix sqlite3.Connection.blobopen 'row' parameter type and naming (#138738) (GH-139062)
(cherry picked from commit 8eb106240f)

Co-authored-by: chiri <chirizxc@proton.me>
2025-10-07 20:38:26 +02:00
Miss Islington (bot)andBénédikt Tran 6d94af4b98 [3.14] gh-139327: fix some reference leaks in sqlite3 error branches (GH-139328) (GH-139471)
(cherry picked from commit d0a3eff9d6)

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-10-07 20:22:20 +02:00
3267847759 [3.14] gh-135607: remove null checking of weakref list in dealloc of extension modules and objects (#135614) (#136119)
gh-135607: remove null checking of weakref list in dealloc of extension modules and objects (#135614)

(cherry picked from commit b1056c2a44)

Co-authored-by: Xuanteng Huang <44627253+xuantengh@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
2025-06-30 15:59:22 +02: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
Brett Simmers c2627d6eea gh-116322: Add Py_mod_gil module slot (#116882)
This PR adds the ability to enable the GIL if it was disabled at
interpreter startup, and modifies the multi-phase module initialization
path to enable the GIL when loading a module, unless that module's spec
includes a slot indicating it can run safely without the GIL.

PEP 703 called the constant for the slot `Py_mod_gil_not_used`; I went
with `Py_MOD_GIL_NOT_USED` for consistency with gh-104148.

A warning will be issued up to once per interpreter for the first
GIL-using module that is loaded. If `-v` is given, a shorter message
will be printed to stderr every time a GIL-using module is loaded
(including the first one that issues a warning).
2024-05-03 11:30:55 -04:00
Erlend E. Aasland b568c2c1ff gh-118406: Add signature for sqlite3.Connection objects (#118428) 2024-04-30 19:58:22 +00:00
Erlend E. AaslandandAN Long 550483b7e6 gh-117995: Don't raise DeprecationWarnings for indexed nameless params (#118001)
Filter out '?NNN' placeholders when looking for named params.

Co-authored-by: AN Long <aisk@users.noreply.github.com>
2024-04-22 08:43:20 +02:00
neonene c520bf9bdf gh-117613: Argument Clinic: ensure that 'defining_class' params are positional-only (#117781) 2024-04-16 09:52:45 +00:00
mpage df73179048 gh-111926: Make weakrefs thread-safe in free-threaded builds (#117168)
Most mutable data is protected by a striped lock that is keyed on the
referenced object's address. The weakref's hash is protected using the
weakref's per-object lock.
 
Note that this only affects free-threaded builds. Apart from some minor
refactoring, the added code is all either gated by `ifdef`s or is a no-op
(e.g. `Py_BEGIN_CRITICAL_SECTION`).
2024-04-08 10:58:38 -04:00
Steve Dower 7861dfd26a gh-111140: Adds PyLong_AsNativeBytes and PyLong_FromNative[Unsigned]Bytes functions (GH-114886) 2024-02-12 20:13:13 +00:00
Mariusz FelisiakandErlend E. Aasland 1a10437a14 gh-91602: Add iterdump() support for filtering database objects (#114501)
Add optional 'filter' parameter to iterdump() that allows a "LIKE"
pattern for filtering database objects to dump.

Co-authored-by: Erlend E. Aasland <erlend@python.org>
2024-02-06 12:34:56 +01:00
Nikita Sobolev 87cd20a567 gh-115026: Argument Clinic: handle PyBuffer_FillInfo errors in generated code (#115027) 2024-02-05 11:45:09 +01:00
Serhiy Storchaka afac3c9b7e gh-111789: Simplify the sqlite code (GH-111829)
Use new C API functions PyDict_GetItemRef() and
PyMapping_GetOptionalItemString().
2023-11-10 20:49:24 +00:00
Serhiy Storchaka 771bd3c94a Add private _PyUnicode_AsUTF8NoNUL() function (GH-111957)
Like PyUnicode_AsUTF8(), but check for embedded null characters.
2023-11-10 21:31:36 +02:00
Victor Stinner 11e83488c5 gh-111089: Revert PyUnicode_AsUTF8() changes (#111833)
* Revert "gh-111089: Use PyUnicode_AsUTF8() in Argument Clinic (#111585)"

This reverts commit d9b606b3d0.

* Revert "gh-111089: Use PyUnicode_AsUTF8() in getargs.c (#111620)"

This reverts commit cde1071b2a.

* Revert "gh-111089: PyUnicode_AsUTF8() now raises on embedded NUL (#111091)"

This reverts commit d731579bfb.

* Revert "gh-111089: Add PyUnicode_AsUTF8() to the limited C API (#111121)"

This reverts commit d8f32be5b6.

* Revert "gh-111089: Use PyUnicode_AsUTF8() in sqlite3 (#111122)"

This reverts commit 37e4e20eaa.
2023-11-07 22:36:13 +00:00
Victor Stinner d9b606b3d0 gh-111089: Use PyUnicode_AsUTF8() in Argument Clinic (#111585)
Replace PyUnicode_AsUTF8AndSize() with PyUnicode_AsUTF8() to remove
the explicit check for embedded null characters.

The change avoids to have to include explicitly <string.h> to get the
strlen() function when using a recent version of the limited C API.
2023-11-01 16:34:42 +01:00
Furkan OnderandStefan Krah 32c37fe1ba gh-67565: Remove redundant C-contiguity checks (GH-105521)
Co-authored-by: Stefan Krah <skrah@bytereef.org>
2023-10-23 12:54:46 +03:00