Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Merge branch 'main' into capi-PySys_GetAttr2
  • Loading branch information
serhiy-storchaka committed Feb 25, 2025
commit 982eeac59aa9a6cf1ec00dfdf16acae4f84329f4
9 changes: 4 additions & 5 deletions Modules/_cursesmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static const char PyCursesVersion[] = "2.2";
#include "pycore_capsule.h" // _PyCapsule_SetTraverse()
#include "pycore_long.h" // _PyLong_GetZero()
#include "pycore_structseq.h" // _PyStructSequence_NewType()
#include "pycore_sysmodule.h" // _PySys_GetRequiredAttrString()
#include "pycore_sysmodule.h" // PySys_GetAttrString()

#ifdef __hpux
#define STRICT_SYSV_CURSES
Expand Down Expand Up @@ -3543,15 +3543,14 @@ _curses_setupterm_impl(PyObject *module, const char *term, int fd)
if (fd == -1) {
PyObject* sys_stdout;

sys_stdout = _PySys_GetRequiredAttrString("stdout");
if (sys_stdout == NULL) {
if (PySys_GetAttrString("stdout", &sys_stdout) < 0) {
return NULL;
}

if (sys_stdout == Py_None) {
if (sys_stdout == NULL || sys_stdout == Py_None) {
cursesmodule_state *state = get_cursesmodule_state(module);
PyErr_SetString(state->error, "lost sys.stdout");
Py_DECREF(sys_stdout);
Py_XDECREF(sys_stdout);
return NULL;
}

Expand Down
5 changes: 2 additions & 3 deletions Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Copyright (C) 1994 Steen Lumholt.
#endif

#include "pycore_long.h" // _PyLong_IsNegative()
#include "pycore_sysmodule.h" // _PySys_GetRequiredAttrString()

#ifdef MS_WINDOWS
# include <windows.h>
Expand Down Expand Up @@ -145,7 +144,7 @@ _get_tcl_lib_path(void)
int stat_return_value;
PyObject *prefix;

PyObject *prefix = _PySys_GetRequiredAttrString("base_prefix");
(void) PySys_GetAttrString("base_prefix", &prefix);
if (prefix == NULL) {
return NULL;
}
Expand Down Expand Up @@ -3520,7 +3519,7 @@ PyInit__tkinter(void)

/* This helps the dynamic loader; in Unicode aware Tcl versions
it also helps Tcl find its encodings. */
uexe = _PySys_GetRequiredAttrString("executable");
(void) PySys_GetAttrString("executable", &uexe);
if (uexe && PyUnicode_Check(uexe)) { // sys.executable can be None
cexe = PyUnicode_EncodeFSDefault(uexe);
Py_DECREF(uexe);
Expand Down
6 changes: 2 additions & 4 deletions Modules/syslogmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ Revision history:

#include "Python.h"
#include "osdefs.h" // SEP
#include "pycore_sysmodule.h" // _PySys_GetRequiredAttrString()

#include <syslog.h>

Expand Down Expand Up @@ -90,10 +89,9 @@ syslog_get_argv(void)
Py_ssize_t argv_len, scriptlen;
PyObject *scriptobj;
Py_ssize_t slash;
PyObject *argv = _PySys_GetRequiredAttrString("argv");
PyObject *argv;

if (argv == NULL) {
PyErr_Clear();
if (PySys_GetAttrString("argv", &argv) <= 0) {
return NULL;
}

Expand Down
2 changes: 1 addition & 1 deletion Objects/moduleobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "pycore_object.h" // _PyType_AllocNoTrack
#include "pycore_pyerrors.h" // _PyErr_FormatFromCause()
#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "pycore_sysmodule.h" // _PySys_GetOptionalAttrString()
#include "pycore_sysmodule.h" // PySys_GetAttrString()

#include "osdefs.h" // MAXPATHLEN

Expand Down
5 changes: 2 additions & 3 deletions Python/_warnings.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "pycore_pyerrors.h" // _PyErr_Occurred()
#include "pycore_pylifecycle.h" // _Py_IsInterpreterFinalizing()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_sysmodule.h" // _PySys_GetRequiredAttr()
#include "pycore_traceback.h" // _Py_DisplaySourceLine()

#include <stdbool.h>
Expand Down Expand Up @@ -563,8 +562,8 @@ show_warning(PyThreadState *tstate, PyObject *filename, int lineno,
goto error;
}

f_stderr = _PySys_GetRequiredAttr(&_Py_ID(stderr));
if (f_stderr == NULL) {
if (PySys_GetAttr(&_Py_ID(stderr), &f_stderr) <= 0) {
fprintf(stderr, "lost sys.stderr\n");
goto error;
}

Expand Down
2 changes: 1 addition & 1 deletion Python/bltinmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include "pycore_pyerrors.h" // _PyErr_NoMemory()
#include "pycore_pystate.h" // _PyThreadState_GET()
#include "pycore_pythonrun.h" // _Py_SourceAsString()
#include "pycore_sysmodule.h" // _PySys_GetRequiredAttr()
#include "pycore_tuple.h" // _PyTuple_FromArray()
#include "pycore_cell.h" // PyCell_GetRef()
#include "pycore_sysmodule.h" // _PySys_GetRequiredAttr()

#include "clinic/bltinmodule.c.h"

Expand Down
2 changes: 1 addition & 1 deletion Python/ceval.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "pycore_tuple.h" // _PyTuple_ITEMS()
#include "pycore_uop_ids.h" // Uops
#include "pycore_pyerrors.h"
#include "pycore_sysmodule.h" // _PySys_GetOptionalAttrString()
#include "pycore_sysmodule.h" // PySys_GetAttrString()

#include "pycore_dict.h"
#include "dictobject.h"
Expand Down
2 changes: 1 addition & 1 deletion Python/sysmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ _PySys_GetRequiredAttr(PyObject *name)
}
PyObject *value;
if (PyDict_GetItemRef(sysdict, name, &value) == 0) {
PyErr_Format(PyExc_RuntimeError, "lost sys.%S", name);
PyErr_Format(PyExc_RuntimeError, "lost sys.%U", name);
}
return value;
}
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.