Commit graph

71 commits

Author SHA1 Message Date
Serhiy Storchaka
fc4d2c3dc6
[3.12] gh-81682: Fix test failures when CPython is built without docstrings (GH-113410) (GH-113429)
(cherry picked from commit 4e5b27e6a3)
2023-12-23 11:50:01 +00:00
Miss Islington (bot)
8f43250c91
[3.12] Add more C API tests (GH-112522) (GH-112525)
Add tests for PyObject_Str(), PyObject_Repr(), PyObject_ASCII() and
PyObject_Bytes().
(cherry picked from commit e0449b9a7f)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-11-29 22:02:57 +02:00
Miss Islington (bot)
e28722e772
[3.12] gh-109802: Increase test coverage for complexobject.c (GH-112452) (GH-112489)
(cherry picked from commit f14d741daa)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2023-11-28 08:33:44 +00:00
Miss Islington (bot)
46047bb12b
[3.12] gh-112438: Fix support of format units with the "e" prefix in nested tuples in PyArg_Parse (gh-112439) (GH-112460)
(cherry picked from commit 4eea1e8236)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-11-27 17:57:30 +00:00
Miss Islington (bot)
759168a2a9
[3.12] gh-111495: Add tests for PyList C API (GH-111562) (GH-111861)
(cherry picked from commit a3903c8ec8)

Signed-off-by: kalyanr <kalyan.ben10@live.com>
Co-authored-by: Kalyan <kalyan.ben10@live.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2023-11-08 18:10:13 +00:00
Miss Islington (bot)
f70ae99cb4
[3.12] gh-111765: Move old PyFloat_* tests to Lib/test/test_capi/test_float.py (GH-111766) (GH-111818)
(cherry picked from commit a077b2fbb8)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2023-11-07 12:06:21 +00:00
Miss Islington (bot)
e0c2bf4672
[3.12] gh-111495: Add tests for PyComplex C API (GH-111591) (GH-111753)
(cherry picked from commit 24b5cbd3dc)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2023-11-05 08:12:57 +00:00
Miss Islington (bot)
fef32a1d08
[3.12] gh-111495: Add tests for PyFloat C API (GH-111624) (GH-111752)
(cherry picked from commit b452202a11)

Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
2023-11-05 10:01:31 +02:00
Serhiy Storchaka
cd778b4917
[3.12] gh-111495: Test C API functions with extreme sizes and indices (GH-111631) (GH-111731)
(cherry picked from commit a8e1f474c2)
2023-11-04 12:28:34 +02:00
Miss Islington (bot)
f1087855e2
[3.12] gh-111495: Add tests for PyBytes and PyByteArray C API (GH-111496) (GH-111607)
(cherry picked from commit 97b3cd38d1)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-11-01 18:23:39 +00:00
Miss Islington (bot)
748bc48648
[3.12] gh-108082: C API: Add tests for PyErr_WriteUnraisable() (GH-111455) (GH-111507)
Also document the behavior when called with NULL.
(cherry picked from commit bca3305429)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-10-30 17:36:00 +00:00
Serhiy Storchaka
54e93d36d0
[3.12] gh-111065: Add more tests for the C API with the PySys_ prefix (GH-111067) (GH-111305)
* Move existing tests for PySys_GetObject() and PySys_SetObject() into
  specialized files.
* Add test for PySys_GetXOptions() using _testcapi.
* Add tests for PySys_FormatStdout(), PySys_FormatStderr(),
  PySys_WriteStdout() and PySys_WriteStderr() using ctypes.

(cherry picked from commit b2ba298527)
2023-10-25 09:10:03 +00:00
Furkan Onder
d4d947dd71
[3.12] gh-67565: Add tests for C-contiguity checks (GH-110951) (GH-111198)
(cherry picked from commit 9376728ce4)
2023-10-23 12:50:07 +03:00
Miss Islington (bot)
6b38ddba97
[3.12] Add tests for failing PyUnicode_AsUTF8AndSize() with psize=NULL (GH-111100) (GH-111105)
(cherry picked from commit b60f058708)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-10-20 10:22:09 +00:00
Serhiy Storchaka
7c3e8e5af0
[3.12] gh-110628: Add tests for PyLong C API (GH-110629) (GH-110854)
(cherry picked from commit 9d40ebf190)
2023-10-14 10:20:24 +03:00
Miss Islington (bot)
1c44f881c7
[3.12] gh-110815: Improve tests for PyArg_ParseTupleAndKeywords() (GH-110817) (GH-110825)
(cherry picked from commit 548ce0923b)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-10-13 13:41:43 +00:00
Miss Islington (bot)
ca971d12ed
[3.12] gh-84489: C API: Add tests for Py_BuildValue() (GH-110596) (GH-110680)
(cherry picked from commit 5c6e85480a)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-10-11 11:12:39 +03:00
Nikita Sobolev
3ed5cb0de3
[3.12] gh-110525: Add CAPI tests for set and frozenset objects (GH-110526). (GH-110547)
(cherry picked from commit c49edd7d9c)
2023-10-09 10:04:09 +00:00
Miss Islington (bot)
62d9ae414f
[3.12] gh-109496: Skip test_capi.test_decref_freed_object() on ASAN (GH-109573) (#109578)
Co-authored-by: Victor Stinner <vstinner@python.org>
2023-10-02 15:09:35 +01:00
Miss Islington (bot)
74a7f5d2da
[3.12] gh-109496: Detect Py_DECREF() after dealloc in debug mode (GH-109539) (#109545)
gh-109496: Detect Py_DECREF() after dealloc in debug mode (GH-109539)

On a Python built in debug mode, Py_DECREF() now calls
_Py_NegativeRefcount() if the object is a dangling pointer to
deallocated memory: memory filled with 0xDD "dead byte" by the debug
hook on memory allocators. The fix is to check the reference count
*before* checking for _Py_IsImmortal().

Add test_decref_freed_object() to test_capi.test_misc.
(cherry picked from commit 0bb0d88e2d)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-09-18 17:39:27 +00:00
Miss Islington (bot)
0eb6d87304
[3.12] gh-80527: Change support.requires_legacy_unicode_capi() (GH-108438) (#108446)
gh-80527: Change support.requires_legacy_unicode_capi() (GH-108438)

The decorator now requires to be called with parenthesis:

    @support.requires_legacy_unicode_capi()

instead of:

    @support.requires_legacy_unicode_capi

The implementation now only imports _testcapi when the decorator is
called, so "import test.support" no longer imports the _testcapi
extension.
(cherry picked from commit 995f4c48e1)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-08-25 18:18:24 +02:00
Miss Islington (bot)
97d67e9dab
[3.12] gh-107915: Handle errors in C API functions PyErr_Set*() and PyErr_Format() (GH-107918) (#108134)
* gh-107915: Handle errors in C API functions PyErr_Set*() and PyErr_Format() (GH-107918)

Such C API functions as PyErr_SetString(), PyErr_Format(),
PyErr_SetFromErrnoWithFilename() and many others no longer crash or
ignore errors if it failed to format the error message or decode the
filename. Instead, they keep a corresponding error.
(cherry picked from commit 633ea217a8)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>

* Define PY_SSIZE_T_CLEAN.

---------

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2023-08-20 23:07:24 +02:00
Miss Islington (bot)
84a4370e31
[3.12] gh-91051: fix type watcher test to be robust to existing watcher (GH-107989) (#108053)
gh-91051: fix type watcher test to be robust to existing watcher (GH-107989)
(cherry picked from commit fce93c80ae)

Co-authored-by: Carl Meyer <carl@oddbird.net>
2023-08-17 01:18:24 +02:00
Serhiy Storchaka
9c8dfcec64
[3.12] gh-107178: Add the C API tests for the Abstract Objects Layer (GH-107179) (#107728)
Cover all the Mapping Protocol, almost all the Sequence Protocol
(except PySequence_Fast) and a part of the Object Protocol.

Move existing tests to Lib/test/test_capi/test_abstract.py and
Modules/_testcapi/abstract.c.

Add also tests for PyDict C API..
(cherry picked from commit 16c9415fba)
2023-08-16 14:29:08 +02:00
Serhiy Storchaka
72534ca85c
[3.12] gh-107735: Add C API tests for PySys_GetObject() and PySys_SetObject() (GH-107736) (#107740)
[3.12] gh-107735: Add C API tests for PySys_GetObject() and PySys_SetObject() (GH-107736).
(cherry picked from commit bea5f93196)
2023-08-16 14:28:14 +02:00
Miss Islington (bot)
00bfed7cba
[3.12] gh-91051: fix segfault when using all 8 type watchers (GH-107853) (#107876)
* gh-91051: fix segfault when using all 8 type watchers (GH-107853)
(cherry picked from commit 66e4edd734)

Co-authored-by: Carl Meyer <carl@oddbird.net>
2023-08-16 11:58:54 +02:00
Miss Islington (bot)
431ce239d2
[3.12] gh-107810: Improve DeprecationWarning for metaclasses with custom tp_new (GH-107834) (#107864)
gh-107810: Improve DeprecationWarning for metaclasses with custom tp_new (GH-107834)

(cherry picked from commit 16dcce2176)

Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2023-08-11 16:12:50 +02:00
Miss Islington (bot)
abaf89d908
[3.12] gh-104621: Check for Incompatible Extensions in import_find_extension() (gh-107184) (gh-107360)
gh-104621: Check for Incompatible Extensions in import_find_extension() (gh-107184)

This fixes a bug where incompatible modules could still be imported if attempted multiple times.
(cherry picked from commit 75c974f535)

Co-authored-by: Eric Snow <ericsnowcurrently@gmail.com>
2023-07-27 21:51:34 +00:00
Miss Islington (bot)
713590f9b2
[3.12] gh-106714: Fix test_capi to not write a coredump (GH-107007) (#107009)
gh-106714: Fix test_capi to not write a coredump (GH-107007)

test_capi: Fix test_no_FatalError_infinite_loop() to no longer write
a coredump, by using test.support.SuppressCrashReport.
(cherry picked from commit 4a1026d764)

Co-authored-by: Victor Stinner <vstinner@python.org>
2023-07-22 12:48:41 +00:00
Serhiy Storchaka
2da967ea14
[3.12] gh-99593: Add tests for Unicode C API (part 3) (GH-104728) (GH-106595)
Add tests for codecs.
(cherry picked from commit 51ea664d18)
2023-07-10 20:58:58 +03:00
Eric Snow
33d3069c45
[3.12] gh-104812: Run Pending Calls in any Thread (gh-104813) (gh-105752)
For a while now, pending calls only run in the main thread (in the main interpreter).  This PR changes things to allow any thread run a pending call, unless the pending call was explicitly added for the main thread to run.
(cherry picked from commit 757b402)
2023-06-14 00:50:08 +00:00
Miss Islington (bot)
2eed1f5868
[3.12] gh-103968: PyType_FromMetaclass: Allow metaclasses with tp_new=NULL (GH-105386) (GH-105697)
gh-103968: PyType_FromMetaclass: Allow metaclasses with tp_new=NULL (GH-105386)
(cherry picked from commit 2b90796be6)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
2023-06-12 16:24:21 +00:00
Miss Islington (bot)
d57ee813eb
[3.12] gh-104614: Make Sure ob_type is Always Set Correctly by PyType_Ready() (gh-105122) (gh-105211)
When I added the relevant condition to type_ready_set_bases() in gh-103912, I had missed that the function also sets tp_base and ob_type (if necessary).  That led to problems for third-party static types.

We fix that here, by making those extra operations distinct and by adjusting the condition to be more specific.
(cherry picked from commit 1469393)

Co-authored-by: Eric Snow ericsnowcurrently@gmail.com
2023-06-01 23:06:38 +00:00
Miss Islington (bot)
c38ceb032d
[3.12] gh-105020: Share tp_bases and tp_mro Between Interpreters For All Static Builtin Types (gh-105115) (gh-105124)
In gh-103912 we added tp_bases and tp_mro to each PyInterpreterState.types.builtins entry.  However, doing so ignored the fact that both PyTypeObject fields are public API, and not documented as internal (as opposed to tp_subclasses).  We address that here by reverting back to shared objects, making them immortal in the process.
(cherry picked from commit 7be667d)

Co-authored-by: Eric Snow ericsnowcurrently@gmail.com
2023-06-01 22:24:55 +00:00
Irit Katriel
b45df737d4
[3.12] gh-105071: add PyUnstable_Exc_PrepReraiseStar to expose except* implementation in the unstable API (GH-105072) (#105095)
(cherry picked from commit b7aadb4583)
2023-05-30 16:50:23 +01:00
Serhiy Storchaka
f3466bc040
gh-98836: Extend PyUnicode_FromFormat() (GH-98838)
* Support for conversion specifiers o (octal) and X (uppercase hexadecimal).
* Support for length modifiers j (intmax_t) and t (ptrdiff_t).
* Length modifiers are now applied to all integer conversions.
* Support for wchar_t C strings (%ls and %lV).
* Support for variable width and precision (*).
* Support for flag - (left alignment).
2023-05-22 00:32:39 +03:00
Mark Shannon
93923793f6
GH-101291: Add low level, unstable API for pylong (GH-101685)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
2023-05-21 14:45:48 +01:00
Dong-hee Na
2e91c7e626
gh-104469: Convert _testcapi/exceptions to use AC (gh-104502) 2023-05-21 18:39:45 +09:00
Mark Shannon
cfa517d5a6
GH-96803: Document and test new unstable internal frame API functions (GH-104211)
Weaken contract of PyUnstable_InterpreterFrame_GetCode to return PyObject*.
2023-05-18 10:10:15 +01:00
Brandt Bucher
1eb950ca55
GH-104405: Add missing PEP 523 checks (GH-104406) 2023-05-12 22:23:13 +00:00
Eric Snow
f3e7eb48f8
gh-99113: Add PyInterpreterConfig.own_gil (gh-104204)
We also add PyInterpreterState.ceval.own_gil to record if the interpreter actually has its own GIL.

Note that for now we don't actually respect own_gil; all interpreters still share the one GIL.  However, PyInterpreterState.ceval.own_gil does reflect PyInterpreterConfig.own_gil.  That lie is a temporary one that we will fix when the GIL really becomes per-interpreter.
2023-05-05 15:59:20 -06:00
Serhiy Storchaka
2ba931ff72
gh-99593: Add tests for Unicode C API (part 2) (#99868)
Add tests for lower-level functions.

Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
2023-05-04 15:25:09 +00:00
Petr Viktorin
cd9a56c2b0
gh-103509: PEP 697 -- Limited C API for Extending Opaque Types (GH-103511)
Co-authored-by: Oleg Iarygin <oleg@arhadthedev.net>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-05-04 09:56:53 +02:00
Petr Viktorin
524a7f77fd
gh-103968: Deprecate creating heap types whose metaclass has custom tp_new. (GH-103972)
(That's a mouthful of an edge case!)

Co-authored-by: Barney Gale <barney.gale@gmail.com>
2023-05-03 15:17:14 +02:00
Dong-hee Na
d81ca7ec02
gh-84436: Add integration C API tests for immortal objects (gh-103962) 2023-05-03 00:05:30 +09:00
Jurica Bradarić
87223f32ab
gh-103743: Add PyUnstable_Object_GC_NewWithExtraData (GH-103744)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
2023-05-02 13:38:46 +02:00
Rodolfo M. Pereira
8291ae31dd
GH-103805: Lib test f541 linting issue fix (#103812)
This PR makes some minor linting adjustments to the Lib/test module
caught by [ruff](https://github.com/charliermarsh/ruff). The adjustments
are all related to the `F541 f-string without any placeholders` issue.

Issue: https://github.com/python/cpython/issues/103805

<!-- gh-issue-number: gh-103805 -->
* Issue: gh-103805
<!-- /gh-issue-number -->

---------

Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Gregory P. Smith <greg@krypto.org>
2023-04-24 23:24:49 +00:00
Eric Snow
df3173d28e
gh-101659: Isolate "obmalloc" State to Each Interpreter (gh-101660)
This is strictly about moving the "obmalloc" runtime state from
`_PyRuntimeState` to `PyInterpreterState`.  Doing so improves isolation
between interpreters, specifically most of the memory (incl. objects)
allocated for each interpreter's use.  This is important for a
per-interpreter GIL, but such isolation is valuable even without it.

FWIW, a per-interpreter obmalloc is the proverbial
canary-in-the-coalmine when it comes to the isolation of objects between
interpreters.  Any object that leaks (unintentionally) to another
interpreter is highly likely to cause a crash (on debug builds at
least).  That's a useful thing to know, relative to interpreter
isolation.
2023-04-24 17:23:57 -06:00
Furkan Onder
8317d51996
Gh-68586: use run_python_until_end in test_capi (GH-102729)
Co-authored-by: Aidin Gharibnavaz

Automerge-Triggered-By: GH:kumaraditya303
2023-04-09 01:44:49 -07:00
Irit Katriel
51d693c584
gh-102594: PyErr_SetObject adds note to exception raised on normalization error (#102675) 2023-03-16 10:16:01 +00:00