Skip to content

Commit 1f67a54

Browse files
committed
Fix ups from code reviews
1 parent b628adf commit 1f67a54

File tree

10 files changed

+23
-80
lines changed

10 files changed

+23
-80
lines changed

Include/internal/pycore_dict.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ extern int _PyDict_DelItem_KnownHash_LockHeld(PyObject *mp, PyObject *key,
3636

3737
extern int _PyDict_Contains_KnownHash(PyObject *, PyObject *, Py_hash_t);
3838

39-
extern void _PyDict_ClearKeysVersion(PyObject *mp);
39+
extern void _PyDict_ClearKeysVersionLockHeld(PyObject *mp);
4040

4141
extern int _PyDict_Next(
4242
PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash);

Include/internal/pycore_magic_number.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ Known values:
290290
Python 3.15a4 3657 (Add BINARY_OP_SUBSCR_USTR_INT)
291291
Python 3.15a4 3658 (Optimize bytecode for list/set called on genexp)
292292
Python 3.15a4 3659 (Add CALL_FUNCTION_EX specialization)
293-
Python 3.15a4 3658 (Lazy imports IMPORT_NAME opcode changes)
293+
Python 3.15a4 3660 (Lazy imports IMPORT_NAME opcode changes)
294294
295295
296296
Python 3.16 will start with 3700

Objects/dictobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4678,7 +4678,7 @@ _PyDict_SizeOf_LockHeld(PyDictObject *mp)
46784678
}
46794679

46804680
void
4681-
_PyDict_ClearKeysVersion(PyObject *mp)
4681+
_PyDict_ClearKeysVersionLockHeld(PyObject *mp)
46824682
{
46834683
ASSERT_DICT_LOCKED(mp);
46844684

Objects/lazyimportobject.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,6 @@ lazy_import_repr(PyObject *op)
109109
return res;
110110
}
111111

112-
static PyObject *
113-
lazy_import_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
114-
{
115-
if (!_PyArg_NoKeywords("lazy_import", kwds)) {
116-
return NULL;
117-
}
118-
119-
Py_ssize_t nargs = PyTuple_GET_SIZE(args);
120-
if (!_PyArg_CheckPositional("lazy_import", nargs, 2, 3)) {
121-
return NULL;
122-
}
123-
124-
PyObject *builtins = PyTuple_GET_ITEM(args, 0);
125-
PyObject *name = PyTuple_GET_ITEM(args, 1);
126-
PyObject *fromlist = nargs == 3 ? PyTuple_GET_ITEM(args, 2) : NULL;
127-
return _PyLazyImport_New(builtins, name, fromlist);
128-
}
129-
130112
PyObject *
131113
_PyLazyImport_GetName(PyObject *op)
132114
{
@@ -172,6 +154,5 @@ PyTypeObject PyLazyImport_Type = {
172154
.tp_clear = lazy_import_clear,
173155
.tp_methods = lazy_import_methods,
174156
.tp_alloc = PyType_GenericAlloc,
175-
.tp_new = lazy_import_new,
176157
.tp_free = PyObject_GC_Del,
177158
};

Objects/moduleobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,14 +1269,14 @@ _PyModule_IsPossiblyShadowing(PyObject *origin)
12691269
int
12701270
_PyModule_ReplaceLazyValue(PyObject *dict, PyObject *name, PyObject *value)
12711271
{
1272-
// The adaptive interpreter uses the dictionary version to return the
1272+
// The adaptive interpreter uses the dictionary keys version to return the
12731273
// slot at a given index from the module. When replacing a value the
12741274
// version number doesn't change, so we need to atomically clear the
12751275
// version before replacing so that it doesn't return a lazy value.
12761276
int err;
12771277
Py_BEGIN_CRITICAL_SECTION(dict);
12781278

1279-
_PyDict_ClearKeysVersion(dict);
1279+
_PyDict_ClearKeysVersionLockHeld(dict);
12801280
err = _PyDict_SetItem_LockHeld((PyDictObject *)dict, name, value);
12811281

12821282
Py_END_CRITICAL_SECTION();

Python/bytecodes.c

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,19 +1865,6 @@ dummy_func(
18651865
_PyEval_LoadGlobalStackRef(GLOBALS(), BUILTINS(), name, res);
18661866

18671867
ERROR_IF(PyStackRef_IsNull(*res));
1868-
1869-
PyObject *res_o = PyStackRef_AsPyObjectBorrow(*res);
1870-
if (PyLazyImport_CheckExact(res_o)) {
1871-
PyObject *l_v = _PyImport_LoadLazyImportTstate(tstate, res_o);
1872-
PyStackRef_CLOSE(res[0]);
1873-
ERROR_IF(l_v == NULL);
1874-
int err = _PyModule_ReplaceLazyValue(GLOBALS(), name, l_v);
1875-
if (err < 0) {
1876-
Py_DECREF(l_v);
1877-
ERROR_IF(true);
1878-
}
1879-
*res = PyStackRef_FromPyObjectSteal(l_v);
1880-
}
18811868
}
18821869

18831870
op(_PUSH_NULL_CONDITIONAL, ( -- null[oparg & 1])) {

Python/ceval.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4176,6 +4176,24 @@ _PyEval_LoadGlobalStackRef(PyObject *globals, PyObject *builtins, PyObject *name
41764176
}
41774177
*writeto = PyStackRef_FromPyObjectSteal(res);
41784178
}
4179+
4180+
PyObject *res_o = PyStackRef_AsPyObjectBorrow(*writeto);
4181+
if (PyLazyImport_CheckExact(res_o)) {
4182+
PyObject *l_v = _PyImport_LoadLazyImportTstate(PyThreadState_GET(), res_o);
4183+
PyStackRef_CLOSE(writeto[0]);
4184+
if (l_v == NULL) {
4185+
assert(PyErr_Occurred());
4186+
*writeto = PyStackRef_NULL;
4187+
return;
4188+
}
4189+
int err = _PyModule_ReplaceLazyValue(globals, name, l_v);
4190+
if (err < 0) {
4191+
Py_DECREF(l_v);
4192+
*writeto = PyStackRef_NULL;
4193+
return;
4194+
}
4195+
*writeto = PyStackRef_FromPyObjectSteal(l_v);
4196+
}
41794197
}
41804198

41814199
PyObject *

Python/executor_cases.c.h

Lines changed: 0 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

Lines changed: 0 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/jit.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "pycore_floatobject.h"
1212
#include "pycore_frame.h"
1313
#include "pycore_function.h"
14-
#include "pycore_import.h"
1514
#include "pycore_interpframe.h"
1615
#include "pycore_interpolation.h"
1716
#include "pycore_intrinsics.h"

0 commit comments

Comments
 (0)