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

Add functions PySys_GetAttr(), PySys_GetAttrString(),
PySys_GetOptionalAttr() and PySys_GetOptionalAttrString().
This commit is contained in:
Serhiy Storchaka 2025-05-28 20:11:09 +03:00 committed by GitHub
parent b265a7ddeb
commit bac3fcba5b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 287 additions and 93 deletions

View file

@ -3647,7 +3647,7 @@ _Py_DumpPathConfig(PyThreadState *tstate)
#define DUMP_SYS(NAME) \
do { \
PySys_FormatStderr(" sys.%s = ", #NAME); \
if (_PySys_GetOptionalAttrString(#NAME, &obj) < 0) { \
if (PySys_GetOptionalAttrString(#NAME, &obj) < 0) { \
PyErr_Clear(); \
} \
if (obj != NULL) { \
@ -3671,7 +3671,7 @@ _Py_DumpPathConfig(PyThreadState *tstate)
#undef DUMP_SYS
PyObject *sys_path;
(void) _PySys_GetOptionalAttrString("path", &sys_path);
(void) PySys_GetOptionalAttrString("path", &sys_path);
if (sys_path != NULL && PyList_Check(sys_path)) {
PySys_WriteStderr(" sys.path = [\n");
Py_ssize_t len = PyList_GET_SIZE(sys_path);
@ -4294,7 +4294,7 @@ _PyConfig_CreateXOptionsDict(const PyConfig *config)
static int
config_get_sys_write_bytecode(const PyConfig *config, int *value)
{
PyObject *attr = _PySys_GetRequiredAttrString("dont_write_bytecode");
PyObject *attr = PySys_GetAttrString("dont_write_bytecode");
if (attr == NULL) {
return -1;
}
@ -4315,7 +4315,7 @@ config_get(const PyConfig *config, const PyConfigSpec *spec,
{
if (use_sys) {
if (spec->sys.attr != NULL) {
return _PySys_GetRequiredAttrString(spec->sys.attr);
return PySys_GetAttrString(spec->sys.attr);
}
if (strcmp(spec->name, "write_bytecode") == 0) {