8000 3.12 backport gh 105236 by erlend-aasland · Pull Request #105358 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

3.12 backport gh 105236 #105358

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
c2b127e
Post 3.12.0b1
Yhg1s May 22, 2023
97f8547
[3.12] Add the 3.12 branch to the github workflows. (GH-104768) (#104…
miss-islington May 22, 2023
b44beac
[3.12] gh-87891: Add ABI check to CI (#104793)
encukou May 23, 2023
25b5ce7
[3.12] howto/urllib2: remove link to an outdated french translation (…
miss-islington May 23, 2023
905d419
[3.12] GH-104668: Don't call PyOS_* hooks in subinterpreters (GH-104760)
miss-islington May 23, 2023
e43fbbd
[3.12] GH-101291: Avoid using macros with casts in low-level long API…
miss-islington May 23, 2023
9aea1f2
[3.12] gh-99108: Release the GIL around hashlib built-in computation …
miss-islington May 23, 2023
f4e2049
[3.12] gh-104271: Fix auto() fallback in case of mixed type Enum (GH-…
itamaro May 23, 2023
5c8418c
[3.12] Remove gh-103207 changelog item as it was never part of any re…
miss-islington May 23, 2023
22c45c4
[3.12] gh-103295: fix stack overwrite on 32-bit in perf map test harn…
miss-islington May 23, 2023
b719dd8
[3.12] gh-104372: use == -1 before PyErr_Occurred (GH-104831) (#104833)
miss-islington May 24, 2023
d10d1e3
[3.12] gh-104797: Allow Protocols to inherit from collections.abc.Buf…
miss-islington May 24, 2023
a5c0ef8
[3.12] gh-102856: Add changes related to PEP 701 in 3.12 What's New d…
miss-islington May 24, 2023
2d685ec
[3.12] gh-102856: Add missing quote to fix doctest (GH-104852) (#104854)
miss-islington May 24, 2023
3d2ed89
[3.12] gh-104825: Remove implicit newline in the line attribute in to…
pablogsal May 24, 2023
b151660
[3.12] gh-101282: Enclose BOLT_APPLY_FLAGS value in double quotes (gh…
corona10 May 24, 2023
5e1799e
[3.12] gh-104719: IDLE - test existence of all tokenize references. (…
miss-islington May 24, 2023
25890eb
[3.12] gh-102856: Update "Formatted string literals" docs section aft…
miss-islington May 24, 2023
2b54ea5
[3.12] gh-104825: add omitted idlelib text fix (#104880)
terryjreedy May 24, 2023
45b88e0
gh-103207: The macOS 13 Ventura Installer.app permission problem is f…
ned-deily May 24, 2023
ddc29c8
[3.12] gh-104866: Tokenize should emit NEWLINE after exiting block wi…
miss-islington May 24, 2023
3d91d03
[3.12] Improve test coverage for is_typeddict (GH-104884) (#104889)
miss-islington May 24, 2023
b670214
[3.12] gh-104879: Fix TypeAliasType.__module__ in exec() (GH-104881) …
miss-islington May 24, 2023
c4bc97a
[3.12] gh-99108: Refresh HACL* (GH-104808) (#104893)
miss-islington May 24, 2023
a064233
[3.12] gh-104874: Document NewType.__supertype__ (GH-104875) (#104906)
miss-islington May 24, 2023
51eb009
[3.12] Fix test_importlib.test_side_effect_import() (GH-104840) (#104…
miss-islington May 25, 2023
4833f62
[3.12] Misc updates to Whatsnew 3.12 (GH-104912) (GH-104915)
miss-islington May 25, 2023
1a47d11
[3.12] Misc improvements to the itertools docs (GH-104916) (GH-104917)
miss-islington May 25, 2023
b328ba1
[3.12] Fix indentation in `json.AttrDict` REPL example (GH-104930) (#…
miss-islington May 25, 2023
d176f78
Improves the Windows MSI test run on PR (GH-104929)
miss-islington May 25, 2023
930efde
[3.12] gh-104935: typing: Fix interactions between `@runtime_checkabl…
miss-islington May 25, 2023
5c2971b
[3.12] gh-104372: Drop the GIL around the vfork() call. (GH-104782) (…
miss-islington May 25, 2023
8010cef
[3.12] gh-102024: Reduced _idle_semaphore.release calls (GH-102025) (…
miss-islington May 26, 2023
bd2cc41
[3.12] gh-104479: Update outdated tutorial floating-point reference (…
miss-islington May 26, 2023
6324458
[3.12] gh-104943: Remove mentions of old Python versions (GH-104945) …
miss-islington May 26, 2023
b31cfd2
[3.12] Fix typo in the tokenizer (GH-104950) (#104953)
miss-islington May 26, 2023
83bdfa4
[3.12] gh-104924: Fix `read()able` in `http.client` log messages (gh-…
miss-islington May 26, 2023
3158b4d
[3.12] gh-104955: Fix __release_buffer__ signature (GH-104956) (#104973)
miss-islington May 26, 2023
01af2b0
[3.12] Remove raw asserts in test_typing.py (GH-104951) (#104978)
miss-islington May 26, 2023
8ca2957
[3.12] gh-104972: Ensure that line attributes in tokens in the tokeni…
miss-islington May 26, 2023
97509ca
[3.12] CI: Cache config.cache across runs to speed up build (GH-10480…
hugovk May 26, 2023
bb1e57e
[3.12] gh-104984: remove kwargs and starargs from Call & ClassDef (GH…
miss-islington May 26, 2023
dcee0aa
[3.12] gh-103921: Document PEP 695 (GH-104642) (#104989)
miss-islington May 26, 2023
eca102d
[3.12] GH-104947: Make pathlib.PureWindowsPath comparisons consistent…
miss-islington May 26, 2023
305d78b
[3.12] GH-103631: Fix `PurePosixPath(PureWindowsPath(...))` separator…
miss-islington May 26, 2023
05189f3
[3.12] GH-101588: Deprecate pickle/copy/deepcopy support in itertools…
miss-islington May 26, 2023
2c02c68
[3.12] gh-104976: Ensure trailing dedent tokens are emitted as the pr…
miss-islington May 26, 2023
f625ec3
[3.12] gh-104839: Prevent test_venv AddressSanitizer spam (GH-105005)…
miss-islington May 27, 2023
368d177
[3.12] gh-104992: [What's New in 3.11] Document unittest.TestProgram.…
miss-islington May 27, 2023
edd0cb8
[3.12] CI: Precompute hash for config cache key in check_source job (…
miss-islington May 27, 2023
2b176bc
[3.12] gh-105017: Fix including additional NL token when using CRLF (…
miss-islington May 27, 2023
5426ff1
[3.12] gh-104497: Make tkinter test pass with tk 8.7 (GH-104789) (#10…
miss-islington May 27, 2023
36a4227
[3.12] gh-104992: [What's New in 3.12] Document unittest.TestProgram.…
miss-islington May 28, 2023
41b622b
[3.12] gh-105013: Fix inspect.getsource with parenthesized multiline …
miss-islington May 28, 2023
3f8d5d9
[3.12] gh-105017: Include CRLF lines in strings and column numbers (G…
miss-islington May 28, 2023
74bbc60
[3.12] Document PEP 698 and other new typing features in What's New (…
miss-islington May 28, 2023
5dc6b18
Fix compiler warning in unicodeobject.c (GH-105050)
miss-islington May 29, 2023
635ce29
gh-104803: Implement ntpath.isdevdrive for checking whether a path is…
miss-islington May 29, 2023
68bf3fe
gh-104820: Fixes os.stat on Windows to better handle file systems tha…
miss-islington May 29, 2023
56722ef
gh-103646: Remove --include-pip-user from default APPX package build …
miss-islington May 29, 2023
6794526
[3.12] GH-89455: Add missing attributes (added in 3.11) to traceback …
miss-islington May 29, 2023
7f04a15
[3.12] gh-105077: Fix test_tkinter refleak checking (GH-105078) (GH-1…
miss-islington May 30, 2023
fd6b913
[3.12] gh-102251: Fix reference leak in _testsinglephase initializati…
miss-islington May 30, 2023
7899fac
[3.12] gh-104799: Move location of type_params AST fields (GH-104828)…
miss-islington May 30, 2023
b45df73
[3.12] gh-105071: add PyUnstable_Exc_PrepReraiseStar to expose except…
iritkatriel May 30, 2023
4e7d41f
[3.12] Enable the ABI check job to publish the updated ABI data file …
zooba May 30, 2023
9fb7abb
[3.12] gh-103921: Minor PEP-695 fixes to the `ast` module docs (GH-10…
miss-islington May 30, 2023
aeee5a5
[3.12] gh-105071: add missing versionadded directive (GH-105097) (#10…
miss-islington May 30, 2023
9ae49e3
gh-88745: Add _winapi.CopyFile2 and update shutil.copy2 to use it (GH…
miss-islington May 30, 2023
5fff491
[3.12] gh-105035: fix super() calls on unusual types (e.g. meta-types…
miss-islington May 30, 2023
af7b55d
[3.12] gh-89886: Properly quote Autoconf macro arguments (#105062) (#…
erlend-aasland May 30, 2023
e3fcd9e
[3.12] gh-103142: Update macOS installer to use OpenSSL 1.1.1u. (GH-1…
miss-islington May 31, 2023
4729100
[3.12] gh-105091: stable_abi.py: Remove "Unixy" check from --all on o…
miss-islington May 31, 2023
2f8c22f
[3.12] gh-105042: Disable unmatched parens syntax error in python tok…
miss-islington May 31, 2023
c687946
[3.12] gh-105069: Add a readline-like callable to the tokenizer to co…
miss-islington May 31, 2023
01b42f9
[3.12] gh-105096: Reformat wave documentation (#105136) (#105138)
vstinner May 31, 2023
d3c21a9
[3.12] gh-97933: add LOAD_FAST_AND_CLEAR to 3.12 What's New bytecode …
miss-islington May 31, 2023
4f477c7
[3.12] gh-87729: add LOAD_SUPER_ATTR to 3.12 What's New (GH-105125) (…
miss-islington May 31, 2023
076f3cd
[3.12] gh-105144: Runtime-checkable protocols: move all 'sanity check…
miss-islington May 31, 2023
e7cb216
[3.12] GH-105113: Improve performance of `pathlib.PurePath.match()` (…
barneygale May 31, 2023
f87c6d1
[3.12] gh-102304: Fix 2 New Stable ABI Functions (gh-104762) (gh-105123)
ericsnowcurrently May 31, 2023
8b51666
[3.12] gh-102251: Explicitly free state for test modules with state i…
miss-islington May 31, 2023
dbd7d7c
gh-105146: Update links at end of Windows installer (uninstall/repair…
8000 miss-islington May 31, 2023
6375287
[3.12] gh-89886: Rely on HAVE_SYS_TIME_H (GH-105058) (#105192)
miss-islington Jun 1, 2023
25543ae
[3.12] gh-103142: Upgrade binary builds and CI to OpenSSL 1.1.1u (GH-…
miss-islington Jun 1, 2023
83c7386
[3.12] GH-89886: Bump to GNU Autoconf v2.71 (#104925) (#105207)
erlend-aasland Jun 1, 2023
c38ceb0
[3.12] gh-105020: Share tp_bases and tp_mro Between Interpreters For …
miss-islington Jun 1, 2023
d2be5c7
[3.12] gh-104341: Call _PyEval_ReleaseLock() with NULL When Finalizin…
miss-islington Jun 1, 2023
d57ee81
[3.12] gh-104614: Make Sure ob_type is Always Set Correctly by PyType…
miss-islington Jun 1, 2023
e6d5e63
[3.12] gh-104799: Default missing lists in AST to the empty list (GH-…
miss-islington Jun 2, 2023
46cc4f0
[3.12] gh-105184: document that marshal functions can fail and need t…
miss-islington Jun 2, 2023
103ae4e
[3.12] gh-105194: Fix format specifier escaped characters in f-string…
miss-islington Jun 2, 2023
00fe618
[3.12] gh-102778: update documentation of PyErr_PrintEx and traceback…
miss-islington Jun 2, 2023
72d5dfa
[3.12] gh-104614: Fix potential ref. leak in _testcapimodule/get_basi…
miss-islington Jun 2, 2023
d3922c4
[3.12] gh-105080: Fixed inconsistent signature on derived classes (GH…
miss-islington Jun 2, 2023
f629d5f
[3.12] gh-89415: Mention new `IP_*` constants in `socket` module in t…
miss-islington Jun 3, 2023
c7a9d96
[3.12] gh-104690 Disallow thread creation and fork at interpreter fin…
miss-islington Jun 4, 2023
6b61fe9
[3.12] Fix typo in Python 3.12 What's New (GH-105278) (#105282)
miss-islington Jun 4, 2023
9ce3312
[3.12] gh-104882: Docs: fix description of relationship between `sock…
miss-islington Jun 4, 2023
3e7ddc2
[3.12] gh-98963: Restore the ability to have a dict-less property. (G…
miss-islington Jun 5, 2023
6d03541
[3.12] gh-105164: Detect annotations inside match blocks (GH-105177) …
miss-islington Jun 5, 2023
5175026
[3.12] gh-105237: Allow calling `issubclass(X, typing.Protocol)` agai…
miss-islington Jun 5, 2023
2031238
[3.12] gh-105280: Ensure `isinstance([], collections.abc.Mapping)` al…
miss-islington Jun 5, 2023
83fc562
[3.12] gh-105286: Improve `typing.py` docstrings (#105287) (#105319)
AlexWaygood Jun 5, 2023
dbc179e
[3.12] Clarify that error messages are better with PEP 701 (GH-105150…
miss-islington Jun 5, 2023
0c51318
[3.12] What's New in 3.12: List 'Improved Modules' alphabetically (GH…
hugovk Jun 5, 2023
05b6153
[3.12] gh-97908: CAPI docs: Remove repeated struct names from member …
miss-islington Jun 5, 2023
ab660e9
[3.12] gh-89412: Add missing attributes (added in 3.10) to traceback …
miss-islington Jun 5, 2023
3aa3be4
[3.12] gh-105324: Fix tokenize module main function for stdin (GH-105…
miss-islington Jun 5, 2023
bdd2b89
[3.12] gh-90005: Don't link with libbsd if not needed (#105236)
erlend-aasland Jun 6, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[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
  • Loading branch information
miss-islington authored Jun 1, 2023
commit d57ee813ebd496a3fd8118d7dc057d54c4af847e
38 changes: 37 additions & 1 deletion Lib/test/test_capi/test_misc.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Run the _testcapi module tests (tests for the Python/C API): by defn,
# these are all functions _testcapi exports whose name begins with 'test_'.

from collections import OrderedDict
import _thread
from collections import OrderedDict
import contextlib
import importlib.machinery
import importlib.util
import os
Expand Down Expand Up @@ -1626,6 +1627,41 @@ def test_tp_mro_is_set(self):
self.assertIsNot(mro, None)


class TestStaticTypes(unittest.TestCase):

_has_run = False

@classmethod
def setUpClass(cls):
# The tests here don't play nice with our approach to refleak
# detection, so we bail out in that case.
if cls._has_run:
raise unittest.SkipTest('these tests do not support re-running')
cls._has_run = True

@contextlib.contextmanager
def basic_static_type(self, *args):
cls = _testcapi.get_basic_static_type(*args)
yield cls

def test_pytype_ready_always_sets_tp_type(self):
# The point of this test is to prevent something like
# https://github.com/python/cpython/issues/104614
# from happening again.

# First check when tp_base/tp_bases is *not* set before PyType_Ready().
with self.basic_static_type() as cls:
self.assertIs(cls.__base__, object);
self.assertEqual(cls.__bases__, (object,));
self.assertIs(type(cls), type(object));

# Then check when we *do* set tp_base/tp_bases first.
with self.basic_static_type(object) as cls:
self.assertIs(cls.__base__, object);
self.assertEqual(cls.__bases__, (object,));
self.assertIs(type(cls), type(object));


class TestThreadState(unittest.TestCase):

@threading_helper.reap_threads
Expand Down
8000
45 changes: 45 additions & 0 deletions Modules/_testcapimodule.c
6D40
Original file line number Diff line number Diff line change
Expand Up @@ -2627,6 +2627,50 @@ type_get_tp_mro(PyObject *self, PyObject *type)
}


/* We only use 2 in test_capi/test_misc.py. */
#define NUM_BASIC_STATIC_TYPES 2
static PyTypeObject BasicStaticTypes[NUM_BASIC_STATIC_TYPES] = {
#define INIT_BASIC_STATIC_TYPE \
{ \
PyVarObject_HEAD_INIT(NULL, 0) \
.tp_name = "BasicStaticType", \
.tp_basicsize = sizeof(PyObject), \
}
INIT_BASIC_STATIC_TYPE,
INIT_BASIC_STATIC_TYPE,
#undef INIT_BASIC_STATIC_TYPE
};
static int num_basic_static_types_used = 0;

static PyObject *
get_basic_static_type(PyObject *self, PyObject *args)
{
PyObject *base = NULL;
if (!PyArg_ParseTuple(args, "|O", &base)) {
return NULL;
}
assert(base == NULL || PyType_Check(base));

if(num_basic_static_types_used >= NUM_BASIC_STATIC_TYPES) {
PyErr_SetString(PyExc_RuntimeError, "no more available basic static types");
return NULL;
}
PyTypeObject *cls = &BasicStaticTypes[num_basic_static_types_used++];

if (base != NULL) {
cls->tp_base = (PyTypeObject *)Py_NewRef(base);
cls->tp_bases = Py_BuildValue("(O)", base);
if (cls->tp_bases == NULL) {
return NULL;
}
}
if (PyType_Ready(cls) < 0) {
return NULL;
}
return (PyObject *)cls;
}


// Test PyThreadState C API
static PyObject *
test_tstate_capi(PyObject *self, PyObject *Py_UNUSED(args))
Expand Down Expand Up @@ -3384,6 +3428,7 @@ static PyMethodDef TestMethods[] = {
{"type_assign_version", type_assign_version, METH_O, PyDoc_STR("PyUnstable_Type_AssignVersionTag")},
{"type_get_tp_bases", type_get_tp_bases, METH_O},
{"type_get_tp_mro", type_get_tp_mro, METH_O},
{"get_basic_static_type", get_basic_static_type, METH_VARARGS, NULL},
{"test_tstate_capi", test_tstate_capi, METH_NOARGS, NULL},
{"frame_getlocals", frame_getlocals, METH_O, NULL},
{"frame_getglobals", frame_getglobals, METH_O, NULL},
Expand Down
60 changes: 44 additions & 16 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,11 +306,14 @@ clear_tp_bases(PyTypeObject *self)
{
if (self->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
if (_Py_IsMainInterpreter(_PyInterpreterState_GET())) {
if (self->tp_bases != NULL
&& PyTuple_GET_SIZE(self->tp_bases) > 0)
{
assert(_Py_IsImmortal(self->tp_bases));
_Py_ClearImmortal(self->tp_bases);
if (self->tp_bases != NULL) {
if (PyTuple_GET_SIZE(self->tp_bases) == 0) {
Py_CLEAR(self->tp_bases);
}
else {
assert(_Py_IsImmortal(self->tp_bases));
_Py_ClearImmortal(self->tp_bases);
}
}
}
return;
Expand Down Expand Up @@ -352,11 +355,14 @@ clear_tp_mro(PyTypeObject *self)
{
if (self->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
if (_Py_IsMainInterpreter(_PyInterpreterState_GET())) {
if (self->tp_mro != NULL
&& PyTuple_GET_SIZE(self->tp_mro) > 0)
{
assert(_Py_IsImmortal(self->tp_mro));
_Py_ClearImmortal(self->tp_mro);
if (self->tp_mro != NULL) {
if (PyTuple_GET_SIZE(self->tp_mro) == 0) {
Py_CLEAR(self->tp_mro);
}
else {
assert(_Py_IsImmortal(self->tp_mro));
_Py_ClearImmortal(self->tp_mro);
}
}
}
return;
Expand Down Expand Up @@ -6996,12 +7002,8 @@ type_ready_pre_checks(PyTypeObject *type)


static int
type_ready_set_bases(PyTypeObject *type)
type_ready_set_base(PyTypeObject *type)
{
if (lookup_tp_bases(type) != NULL) {
return 0;
}

/* Initialize tp_base (defaults to BaseObject unless that's us) */
PyTypeObject *base = type->tp_base;
if (base == NULL && type != &PyBaseObject_Type) {
Expand All @@ -7025,18 +7027,38 @@ type_ready_set_bases(PyTypeObject *type)
}
}

return 0;
}

static int
type_ready_set_type(PyTypeObject *type)
{
/* Initialize ob_type if NULL. This means extensions that want to be
compilable separately on Windows can call PyType_Ready() instead of
initializing the ob_type field of their type objects. */
/* The test for base != NULL is really unnecessary, since base is only
NULL when type is &PyBaseObject_Type, and we know its ob_type is
not NULL (it's initialized to &PyType_Type). But coverity doesn't
know that. */
PyTypeObject *base = type->tp_base;
if (Py_IS_TYPE(type, NULL) && base != NULL) {
Py_SET_TYPE(type, Py_TYPE(base));
}

/* Initialize tp_bases */
return 0;
}

static int
type_ready_set_bases(PyTypeObject *type)
{
if (type->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
if (!_Py_IsMainInterpreter(_PyInterpreterState_GET())) {
assert(lookup_tp_bases(type) != NULL);
return 0;
}
assert(lookup_tp_bases(type) == NULL);
}

PyObject *bases = lookup_tp_bases(type);
if (bases == NULL) {
PyTypeObject *base = type->tp_base;
Expand Down Expand Up @@ -7446,6 +7468,12 @@ type_ready(PyTypeObject *type, int rerunbuiltin)
if (type_ready_set_dict(type) < 0) {
goto error;
}
if (type_ready_set_base(type) < 0) {
goto error;
}
if (type_ready_set_type(type) < 0) {
goto error;
}
if (type_ready_set_bases(type) < 0) {
goto error;
}
Expand Down
2 changes: 2 additions & 0 deletions Tools/c-analyzer/cpython/ignored.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,8 @@ Modules/_testcapi/watchers.c - num_code_object_destroyed_events -
Module 525A s/_testcapi/watchers.c - pyfunc_watchers -
Modules/_testcapi/watchers.c - func_watcher_ids -
Modules/_testcapi/watchers.c - func_watcher_callbacks -
Modules/_testcapimodule.c - BasicStaticTypes -
Modules/_testcapimodule.c - num_basic_static_types_used -
Modules/_testcapimodule.c - ContainerNoGC_members -
Modules/_testcapimodule.c - ContainerNoGC_type -
Modules/_testcapimodule.c - FmData -
Expand Down
0