10000 gh-108512: Add and use new replacements for PySys_GetObject() by serhiy-storchaka · Pull Request #111035 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-108512: Add and use new replacements for PySys_GetObject() #111035

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

Merged
merged 24 commits into from
May 28, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4d0f508
gh-108512: Add and use new replacements for PySys_GetObject()
serhiy-storchaka Sep 20, 2023
eb42b39
Update Misc/stable_abi.toml
serhiy-storchaka Oct 18, 2023
2d4588d
Merge branch 'main' into capi-PySys_GetAttr
serhiy-storchaka Oct 18, 2023
2eb9533
Add tests.
serhiy-storchaka Oct 19, 2023
9fc2f3d
Apply suggestions from code review
serhiy-storchaka Oct 19, 2023
65713ce
Address review comments.
serhiy-storchaka Oct 19, 2023
e6ecf11
Check that the name is a string.
serhiy-storchaka Oct 19, 2023
8a0f5f2
Merge remote-tracking branch 'refs/remotes/origin/capi-PySys_GetAttr'…
serhiy-storchaka Oct 19, 2023
516829e
Make the new C API not public.
serhiy-storchaka Oct 19, 2023
9503aaf
Remove from Misc/stable_abi.toml.
serhiy-storchaka Oct 19, 2023
e2857ef
Merge branch 'main' into capi-PySys_GetAttr
serhiy-storchaka Jan 28, 2025
dc26ec2
Add to the limited C API.
serhiy-storchaka Jan 28, 2025
104dcc2
Replace few new occurrences of PySys_GetObject().
serhiy-storchaka Jan 28, 2025
cf75fc3
Update the documentation.
serhiy-storchaka Jan 28, 2025
9434659
Clean up.
serhiy-storchaka Jan 28, 2025
56639d8
Fix a typo.
serhiy-storchaka Jan 28, 2025
b40a665
Merge branch 'main' into capi-PySys_GetAttr
serhiy-storchaka Feb 6, 2025
03b9c0a
Merge branch 'main' into capi-PySys_GetAttr
serhiy-storchaka Feb 6, 2025
5d793c5
Merge remote-tracking branch 'refs/remotes/origin/capi-PySys_GetAttr'…
serhiy-storchaka Feb 6, 2025
09869ed
Merge branch 'main' into capi-PySys_GetAttr
serhiy-storchaka Feb 25, 2025
439bc3c
Merge branch 'main' into capi-PySys_GetAttr
serhiy-storchaka May 21, 2025
93ab31b
Move to 3.15.
serhiy-storchaka May 21, 2025
154a82a
Address review comments.
serhiy-storchaka May 22, 2025
81c7605
Improve tests.
serhiy-storchaka May 22, 2025
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
Replace few new occurrences of PySys_GetObject().
  • Loading branch information
serhiy-storchaka committed Jan 28, 2025
commit 104dcc215631763331ff4c005d8469afebe08eb0
7 changes: 6 additions & 1 deletion Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1001,13 +1001,18 @@ _Py_module_getattro_impl(PyModuleObject *m, PyObject *name, int suppress)
}
int is_possibly_shadowing_stdlib = 0;
if (is_possibly_shadowing) {
PyObject *stdlib_modules = PySys_GetObject("stdlib_module_names");
PyObject *stdlib_modules;
if (PySys_GetOptionalAttrString("stdlib_module_names", &stdlib_modules) < 0) {
goto done;
}
if (stdlib_modules && PyAnySet_Check(stdlib_modules)) {
is_possibly_shadowing_stdlib = PySet_Contains(stdlib_modules, mod_name);
if (is_possibly_shadowing_stdlib < 0) {
Py_DECREF(stdlib_modules);
goto done;
}
}
Py_XDECREF(stdlib_modules);
}

if (is_possibly_shadowing_stdlib) {
Expand Down
7 changes: 6 additions & 1 deletion Python/ceval.c
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -2765,13 +2765,18 @@ _PyEval_ImportFrom(PyThreadState *tstate, PyObject *v, PyObject *name)
}
int is_possibly_shadowing_stdlib = 0;
if (is_possibly_shadowing) {
PyObject *stdlib_modules = PySys_GetObject("stdlib_module_names");
PyObject *stdlib_modules;
if (PySys_GetOptionalAttrString("stdlib_module_names", &stdlib_modules) < 0) {
goto done;
}
if (stdlib_modules && PyAnySet_Check(stdlib_modules)) {
is_possibly_shadowing_stdlib = PySet_Contains(stdlib_modules, mod_name_or_unknown);
if (is_possibly_shadowing_stdlib < 0) {
Py_DECREF(stdlib_modules);
goto done;
}
}
Py_XDECREF(stdlib_modules);
}

if (origin == NULL && PyModule_Check(v)) {
Expand Down
16 changes: 2 additions & 14 deletions Python/initconfig.c
Original file line number Diff line number Diff line change
Expand Up @@ -4091,22 +4091,10 @@ _PyConfig_CreateXOptionsDict(const PyConfig *config)
}


static PyObject*
config_get_sys(const char *name)
{
PyObject *value = PySys_GetObject(name);
if (value == NULL) {
PyErr_Format(PyExc_RuntimeError, "lost sys.%s", name);
return NULL;
}
return Py_NewRef(value);
}


static int
config_get_sys_write_bytecode(const PyConfig *config, int *value)
{
PyObject *attr = config_get_sys("dont_write_bytecode");
PyObject *attr = PySys_GetAttrString("dont_write_bytecode");
if (attr == NULL) {
return -1;
}
Expand All @@ -4127,7 +4115,7 @@ config_get(const PyConfig *config, const PyConfigSpec *spec,
{
if (use_sys) {
if (spec->sys.attr != NULL) {
return config_get_sys(spec->sys.attr);
return PySys_GetAttrString(spec->sys.attr);
}

if (strcmp(spec->name, "write_bytecode") == 0) {
Expand Down
5 changes: 1 addition & 4 deletions Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -3230,11 +3230,8 @@ sys_set_flag(PyObject *flags, Py_ssize_t pos, PyObject *value)
int
_PySys_SetFlagObj(Py_ssize_t pos, PyObject *value)
{
PyObject *flags = Py_XNewRef(PySys_GetObject("flags"));
PyObject *flags = PySys_GetAttrString("flags");
if (flags == NULL) {
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_RuntimeError, "lost sys.flags");
}
return -1;
}

Expand Down
0