summaryrefslogtreecommitdiffstats
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c51
1 files changed, 13 insertions, 38 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 57bf04d..e23b879 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -706,7 +706,6 @@ sys_displayhook(PyObject *module, PyObject *o)
{
PyObject *outf;
PyObject *builtins;
- static PyObject *newline = NULL;
PyThreadState *tstate = _PyThreadState_GET();
builtins = PyImport_GetModule(&_Py_ID(builtins));
@@ -747,12 +746,8 @@ sys_displayhook(PyObject *module, PyObject *o)
return NULL;
}
}
- if (newline == NULL) {
- newline = PyUnicode_FromString("\n");
- if (newline == NULL)
- return NULL;
- }
- if (PyFile_WriteObject(newline, outf, Py_PRINT_RAW) != 0)
+ _Py_DECLARE_STR(newline, "\n");
+ if (PyFile_WriteObject(&_Py_STR(newline), outf, Py_PRINT_RAW) != 0)
return NULL;
if (PyObject_SetAttr(builtins, &_Py_ID(_), o) != 0)
return NULL;
@@ -946,30 +941,18 @@ sys_intern_impl(PyObject *module, PyObject *s)
/*
* Cached interned string objects used for calling the profile and
- * trace functions. Initialized by trace_init().
+ * trace functions.
*/
-static PyObject *whatstrings[8] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
-
-static int
-trace_init(void)
-{
- static const char * const whatnames[8] = {
- "call", "exception", "line", "return",
- "c_call", "c_exception", "c_return",
- "opcode"
- };
- PyObject *name;
- int i;
- for (i = 0; i < 8; ++i) {
- if (whatstrings[i] == NULL) {
- name = PyUnicode_InternFromString(whatnames[i]);
- if (name == NULL)
- return -1;
- whatstrings[i] = name;
- }
- }
- return 0;
-}
+static PyObject *whatstrings[8] = {
+ &_Py_ID(call),
+ &_Py_ID(exception),
+ &_Py_ID(line),
+ &_Py_ID(return),
+ &_Py_ID(c_call),
+ &_Py_ID(c_exception),
+ &_Py_ID(c_return),
+ &_Py_ID(opcode),
+};
static PyObject *
@@ -1050,10 +1033,6 @@ trace_trampoline(PyObject *self, PyFrameObject *frame,
static PyObject *
sys_settrace(PyObject *self, PyObject *args)
{
- if (trace_init() == -1) {
- return NULL;
- }
-
PyThreadState *tstate = _PyThreadState_GET();
if (args == Py_None) {
if (_PyEval_SetTrace(tstate, NULL, NULL) < 0) {
@@ -1099,10 +1078,6 @@ sys_gettrace_impl(PyObject *module)
static PyObject *
sys_setprofile(PyObject *self, PyObject *args)
{
- if (trace_init() == -1) {
- return NULL;
- }
-
PyThreadState *tstate = _PyThreadState_GET();
if (args == Py_None) {
if (_PyEval_SetProfile(tstate, NULL, NULL) < 0) {