mirror of
https://github.com/python/cpython.git
synced 2025-09-27 02:39:58 +00:00
Issue #19512: add some common identifiers to only create common strings once,
instead of creating temporary Unicode string objects Add also more identifiers in pythonrun.c to avoid temporary Unicode string objets for the interactive interpreter.
This commit is contained in:
parent
bb52020d44
commit
090543736f
13 changed files with 72 additions and 49 deletions
|
@ -143,9 +143,17 @@ typedef struct _Py_Identifier {
|
||||||
PyObject *object;
|
PyObject *object;
|
||||||
} _Py_Identifier;
|
} _Py_Identifier;
|
||||||
|
|
||||||
#define _Py_static_string(varname, value) static _Py_Identifier varname = { 0, value, 0 }
|
#define _Py_static_string_init(value) { 0, value, 0 }
|
||||||
|
#define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value)
|
||||||
#define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname)
|
#define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname)
|
||||||
|
|
||||||
|
/* Common identifiers */
|
||||||
|
PyAPI_DATA(_Py_Identifier) _PyId_path;
|
||||||
|
PyAPI_DATA(_Py_Identifier) _PyId_argv;
|
||||||
|
PyAPI_DATA(_Py_Identifier) _PyId_stdin;
|
||||||
|
PyAPI_DATA(_Py_Identifier) _PyId_stdout;
|
||||||
|
PyAPI_DATA(_Py_Identifier) _PyId_stderr;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Type objects contain a string containing the type name (to help somewhat
|
Type objects contain a string containing the type name (to help somewhat
|
||||||
in debugging), the allocation parameters (see PyObject_New() and
|
in debugging), the allocation parameters (see PyObject_New() and
|
||||||
|
|
|
@ -80,7 +80,7 @@ static void
|
||||||
PrintError(char *msg, ...)
|
PrintError(char *msg, ...)
|
||||||
{
|
{
|
||||||
char buf[512];
|
char buf[512];
|
||||||
PyObject *f = PySys_GetObject("stderr");
|
PyObject *f = _PySys_GetObjectId(&_PyId_stderr);
|
||||||
va_list marker;
|
va_list marker;
|
||||||
|
|
||||||
va_start(marker, msg);
|
va_start(marker, msg);
|
||||||
|
|
|
@ -2578,7 +2578,7 @@ PyCurses_setupterm(PyObject* self, PyObject *args, PyObject* keywds)
|
||||||
if (fd == -1) {
|
if (fd == -1) {
|
||||||
PyObject* sys_stdout;
|
PyObject* sys_stdout;
|
||||||
|
|
||||||
sys_stdout = PySys_GetObject("stdout");
|
sys_stdout = _PySys_GetObjectId(&_PyId_stdout);
|
||||||
|
|
||||||
if (sys_stdout == NULL || sys_stdout == Py_None) {
|
if (sys_stdout == NULL || sys_stdout == Py_None) {
|
||||||
PyErr_SetString(
|
PyErr_SetString(
|
||||||
|
|
|
@ -1005,7 +1005,7 @@ t_bootstrap(void *boot_raw)
|
||||||
PySys_WriteStderr(
|
PySys_WriteStderr(
|
||||||
"Unhandled exception in thread started by ");
|
"Unhandled exception in thread started by ");
|
||||||
PyErr_Fetch(&exc, &value, &tb);
|
PyErr_Fetch(&exc, &value, &tb);
|
||||||
file = PySys_GetObject("stderr");
|
file = _PySys_GetObjectId(&_PyId_stderr);
|
||||||
if (file != NULL && file != Py_None)
|
if (file != NULL && file != Py_None)
|
||||||
PyFile_WriteObject(boot->func, file, 0);
|
PyFile_WriteObject(boot->func, file, 0);
|
||||||
else
|
else
|
||||||
|
|
|
@ -136,7 +136,7 @@ faulthandler_get_fileno(PyObject *file, int *p_fd)
|
||||||
int fd;
|
int fd;
|
||||||
|
|
||||||
if (file == NULL || file == Py_None) {
|
if (file == NULL || file == Py_None) {
|
||||||
file = PySys_GetObject("stderr");
|
file = _PySys_GetObjectId(&_PyId_stderr);
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "unable to get sys.stderr");
|
PyErr_SetString(PyExc_RuntimeError, "unable to get sys.stderr");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -261,7 +261,7 @@ RunMainFromImporter(wchar_t *filename)
|
||||||
|
|
||||||
/* argv0 is usable as an import source, so put it in sys.path[0]
|
/* argv0 is usable as an import source, so put it in sys.path[0]
|
||||||
and import __main__ */
|
and import __main__ */
|
||||||
sys_path = PySys_GetObject("path");
|
sys_path = _PySys_GetObjectId(&_PyId_path);
|
||||||
if (sys_path == NULL) {
|
if (sys_path == NULL) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "unable to get sys.path");
|
PyErr_SetString(PyExc_RuntimeError, "unable to get sys.path");
|
||||||
goto error;
|
goto error;
|
||||||
|
|
|
@ -71,7 +71,7 @@ syslog_get_argv(void)
|
||||||
Py_ssize_t argv_len, scriptlen;
|
Py_ssize_t argv_len, scriptlen;
|
||||||
PyObject *scriptobj;
|
PyObject *scriptobj;
|
||||||
Py_ssize_t slash;
|
Py_ssize_t slash;
|
||||||
PyObject *argv = PySys_GetObject("argv");
|
PyObject *argv = _PySys_GetObjectId(&_PyId_argv);
|
||||||
|
|
||||||
if (argv == NULL) {
|
if (argv == NULL) {
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
|
|
@ -265,7 +265,7 @@ show_warning(PyObject *filename, int lineno, PyObject *text, PyObject
|
||||||
if (name == NULL) /* XXX Can an object lack a '__name__' attribute? */
|
if (name == NULL) /* XXX Can an object lack a '__name__' attribute? */
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
f_stderr = PySys_GetObject("stderr");
|
f_stderr = _PySys_GetObjectId(&_PyId_stderr);
|
||||||
if (f_stderr == NULL) {
|
if (f_stderr == NULL) {
|
||||||
fprintf(stderr, "lost sys.stderr\n");
|
fprintf(stderr, "lost sys.stderr\n");
|
||||||
goto error;
|
goto error;
|
||||||
|
@ -562,7 +562,7 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
|
||||||
else {
|
else {
|
||||||
*filename = NULL;
|
*filename = NULL;
|
||||||
if (*module != Py_None && PyUnicode_CompareWithASCIIString(*module, "__main__") == 0) {
|
if (*module != Py_None && PyUnicode_CompareWithASCIIString(*module, "__main__") == 0) {
|
||||||
PyObject *argv = PySys_GetObject("argv");
|
PyObject *argv = _PySys_GetObjectId(&_PyId_argv);
|
||||||
/* PyList_Check() is needed because sys.argv is set to None during
|
/* PyList_Check() is needed because sys.argv is set to None during
|
||||||
Python finalization */
|
Python finalization */
|
||||||
if (argv != NULL && PyList_Check(argv) && PyList_Size(argv) > 0) {
|
if (argv != NULL && PyList_Check(argv) && PyList_Size(argv) > 0) {
|
||||||
|
|
|
@ -1553,7 +1553,7 @@ builtin_print(PyObject *self, PyObject *args, PyObject *kwds)
|
||||||
kwlist, &sep, &end, &file, &flush))
|
kwlist, &sep, &end, &file, &flush))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (file == NULL || file == Py_None) {
|
if (file == NULL || file == Py_None) {
|
||||||
file = PySys_GetObject("stdout");
|
file = _PySys_GetObjectId(&_PyId_stdout);
|
||||||
if (file == NULL) {
|
if (file == NULL) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
|
PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1638,9 +1638,9 @@ static PyObject *
|
||||||
builtin_input(PyObject *self, PyObject *args)
|
builtin_input(PyObject *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PyObject *promptarg = NULL;
|
PyObject *promptarg = NULL;
|
||||||
PyObject *fin = PySys_GetObject("stdin");
|
PyObject *fin = _PySys_GetObjectId(&_PyId_stdin);
|
||||||
PyObject *fout = PySys_GetObject("stdout");
|
PyObject *fout = _PySys_GetObjectId(&_PyId_stdout);
|
||||||
PyObject *ferr = PySys_GetObject("stderr");
|
PyObject *ferr = _PySys_GetObjectId(&_PyId_stderr);
|
||||||
PyObject *tmp;
|
PyObject *tmp;
|
||||||
long fd;
|
long fd;
|
||||||
int tty;
|
int tty;
|
||||||
|
|
|
@ -844,7 +844,7 @@ PyErr_WriteUnraisable(PyObject *obj)
|
||||||
|
|
||||||
PyErr_Fetch(&t, &v, &tb);
|
PyErr_Fetch(&t, &v, &tb);
|
||||||
|
|
||||||
f = PySys_GetObject("stderr");
|
f = _PySys_GetObjectId(&_PyId_stderr);
|
||||||
if (f == NULL || f == Py_None)
|
if (f == NULL || f == Py_None)
|
||||||
goto done;
|
goto done;
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,21 @@
|
||||||
#define PATH_MAX MAXPATHLEN
|
#define PATH_MAX MAXPATHLEN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Common identifiers */
|
||||||
|
_Py_Identifier _PyId_argv = _Py_static_string_init("argv");
|
||||||
|
_Py_Identifier _PyId_path = _Py_static_string_init("path");
|
||||||
|
_Py_Identifier _PyId_stdin = _Py_static_string_init("stdin");
|
||||||
|
_Py_Identifier _PyId_stdout = _Py_static_string_init("stdout");
|
||||||
|
_Py_Identifier _PyId_stderr = _Py_static_string_init("stderr");
|
||||||
|
|
||||||
|
/* local identifiers */
|
||||||
|
_Py_IDENTIFIER(excepthook);
|
||||||
|
_Py_IDENTIFIER(ps1);
|
||||||
|
_Py_IDENTIFIER(ps2);
|
||||||
|
_Py_IDENTIFIER(last_type);
|
||||||
|
_Py_IDENTIFIER(last_value);
|
||||||
|
_Py_IDENTIFIER(last_traceback);
|
||||||
|
|
||||||
#ifdef Py_REF_DEBUG
|
#ifdef Py_REF_DEBUG
|
||||||
static
|
static
|
||||||
void _print_total_refs(void) {
|
void _print_total_refs(void) {
|
||||||
|
@ -412,7 +427,7 @@ _Py_InitializeEx_Private(int install_sigs, int install_importlib)
|
||||||
pstderr = PyFile_NewStdPrinter(fileno(stderr));
|
pstderr = PyFile_NewStdPrinter(fileno(stderr));
|
||||||
if (pstderr == NULL)
|
if (pstderr == NULL)
|
||||||
Py_FatalError("Py_Initialize: can't set preliminary stderr");
|
Py_FatalError("Py_Initialize: can't set preliminary stderr");
|
||||||
PySys_SetObject("stderr", pstderr);
|
_PySys_SetObjectId(&_PyId_stderr, pstderr);
|
||||||
PySys_SetObject("__stderr__", pstderr);
|
PySys_SetObject("__stderr__", pstderr);
|
||||||
Py_DECREF(pstderr);
|
Py_DECREF(pstderr);
|
||||||
|
|
||||||
|
@ -497,8 +512,8 @@ file_is_closed(PyObject *fobj)
|
||||||
static void
|
static void
|
||||||
flush_std_files(void)
|
flush_std_files(void)
|
||||||
{
|
{
|
||||||
PyObject *fout = PySys_GetObject("stdout");
|
PyObject *fout = _PySys_GetObjectId(&_PyId_stdout);
|
||||||
PyObject *ferr = PySys_GetObject("stderr");
|
PyObject *ferr = _PySys_GetObjectId(&_PyId_stderr);
|
||||||
PyObject *tmp;
|
PyObject *tmp;
|
||||||
_Py_IDENTIFIER(flush);
|
_Py_IDENTIFIER(flush);
|
||||||
|
|
||||||
|
@ -776,7 +791,7 @@ Py_NewInterpreter(void)
|
||||||
pstderr = PyFile_NewStdPrinter(fileno(stderr));
|
pstderr = PyFile_NewStdPrinter(fileno(stderr));
|
||||||
if (pstderr == NULL)
|
if (pstderr == NULL)
|
||||||
Py_FatalError("Py_Initialize: can't set preliminary stderr");
|
Py_FatalError("Py_Initialize: can't set preliminary stderr");
|
||||||
PySys_SetObject("stderr", pstderr);
|
_PySys_SetObjectId(&_PyId_stderr, pstderr);
|
||||||
PySys_SetObject("__stderr__", pstderr);
|
PySys_SetObject("__stderr__", pstderr);
|
||||||
Py_DECREF(pstderr);
|
Py_DECREF(pstderr);
|
||||||
|
|
||||||
|
@ -1170,7 +1185,7 @@ initstdio(void)
|
||||||
goto error;
|
goto error;
|
||||||
} /* if (fd < 0) */
|
} /* if (fd < 0) */
|
||||||
PySys_SetObject("__stdin__", std);
|
PySys_SetObject("__stdin__", std);
|
||||||
PySys_SetObject("stdin", std);
|
_PySys_SetObjectId(&_PyId_stdin, std);
|
||||||
Py_DECREF(std);
|
Py_DECREF(std);
|
||||||
|
|
||||||
/* Set sys.stdout */
|
/* Set sys.stdout */
|
||||||
|
@ -1185,7 +1200,7 @@ initstdio(void)
|
||||||
goto error;
|
goto error;
|
||||||
} /* if (fd < 0) */
|
} /* if (fd < 0) */
|
||||||
PySys_SetObject("__stdout__", std);
|
PySys_SetObject("__stdout__", std);
|
||||||
PySys_SetObject("stdout", std);
|
_PySys_SetObjectId(&_PyId_stdout, std);
|
||||||
Py_DECREF(std);
|
Py_DECREF(std);
|
||||||
|
|
||||||
#if 1 /* Disable this if you have trouble debugging bootstrap stuff */
|
#if 1 /* Disable this if you have trouble debugging bootstrap stuff */
|
||||||
|
@ -1219,7 +1234,7 @@ initstdio(void)
|
||||||
Py_DECREF(std);
|
Py_DECREF(std);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
if (PySys_SetObject("stderr", std) < 0) {
|
if (_PySys_SetObjectId(&_PyId_stderr, std) < 0) {
|
||||||
Py_DECREF(std);
|
Py_DECREF(std);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -1281,14 +1296,14 @@ PyRun_InteractiveLoopFlags(FILE *fp, const char *filename_str, PyCompilerFlags *
|
||||||
flags = &local_flags;
|
flags = &local_flags;
|
||||||
local_flags.cf_flags = 0;
|
local_flags.cf_flags = 0;
|
||||||
}
|
}
|
||||||
v = PySys_GetObject("ps1");
|
v = _PySys_GetObjectId(&PyId_ps1);
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
PySys_SetObject("ps1", v = PyUnicode_FromString(">>> "));
|
_PySys_SetObjectId(&PyId_ps1, v = PyUnicode_FromString(">>> "));
|
||||||
Py_XDECREF(v);
|
Py_XDECREF(v);
|
||||||
}
|
}
|
||||||
v = PySys_GetObject("ps2");
|
v = _PySys_GetObjectId(&PyId_ps2);
|
||||||
if (v == NULL) {
|
if (v == NULL) {
|
||||||
PySys_SetObject("ps2", v = PyUnicode_FromString("... "));
|
_PySys_SetObjectId(&PyId_ps2, v = PyUnicode_FromString("... "));
|
||||||
Py_XDECREF(v);
|
Py_XDECREF(v);
|
||||||
}
|
}
|
||||||
err = -1;
|
err = -1;
|
||||||
|
@ -1351,7 +1366,7 @@ PyRun_InteractiveOneObject(FILE *fp, PyObject *filename, PyCompilerFlags *flags)
|
||||||
|
|
||||||
if (fp == stdin) {
|
if (fp == stdin) {
|
||||||
/* Fetch encoding from sys.stdin if possible. */
|
/* Fetch encoding from sys.stdin if possible. */
|
||||||
v = PySys_GetObject("stdin");
|
v = _PySys_GetObjectId(&_PyId_stdin);
|
||||||
if (v && v != Py_None) {
|
if (v && v != Py_None) {
|
||||||
oenc = _PyObject_GetAttrId(v, &PyId_encoding);
|
oenc = _PyObject_GetAttrId(v, &PyId_encoding);
|
||||||
if (oenc)
|
if (oenc)
|
||||||
|
@ -1360,7 +1375,7 @@ PyRun_InteractiveOneObject(FILE *fp, PyObject *filename, PyCompilerFlags *flags)
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v = PySys_GetObject("ps1");
|
v = _PySys_GetObjectId(&PyId_ps1);
|
||||||
if (v != NULL) {
|
if (v != NULL) {
|
||||||
v = PyObject_Str(v);
|
v = PyObject_Str(v);
|
||||||
if (v == NULL)
|
if (v == NULL)
|
||||||
|
@ -1373,7 +1388,7 @@ PyRun_InteractiveOneObject(FILE *fp, PyObject *filename, PyCompilerFlags *flags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w = PySys_GetObject("ps2");
|
w = _PySys_GetObjectId(&PyId_ps2);
|
||||||
if (w != NULL) {
|
if (w != NULL) {
|
||||||
w = PyObject_Str(w);
|
w = PyObject_Str(w);
|
||||||
if (w == NULL)
|
if (w == NULL)
|
||||||
|
@ -1752,7 +1767,7 @@ handle_system_exit(void)
|
||||||
if (PyLong_Check(value))
|
if (PyLong_Check(value))
|
||||||
exitcode = (int)PyLong_AsLong(value);
|
exitcode = (int)PyLong_AsLong(value);
|
||||||
else {
|
else {
|
||||||
PyObject *sys_stderr = PySys_GetObject("stderr");
|
PyObject *sys_stderr = _PySys_GetObjectId(&_PyId_stderr);
|
||||||
if (sys_stderr != NULL && sys_stderr != Py_None) {
|
if (sys_stderr != NULL && sys_stderr != Py_None) {
|
||||||
PyFile_WriteObject(value, sys_stderr, Py_PRINT_RAW);
|
PyFile_WriteObject(value, sys_stderr, Py_PRINT_RAW);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1795,11 +1810,11 @@ PyErr_PrintEx(int set_sys_last_vars)
|
||||||
return;
|
return;
|
||||||
/* Now we know v != NULL too */
|
/* Now we know v != NULL too */
|
||||||
if (set_sys_last_vars) {
|
if (set_sys_last_vars) {
|
||||||
PySys_SetObject("last_type", exception);
|
_PySys_SetObjectId(&PyId_last_type, exception);
|
||||||
PySys_SetObject("last_value", v);
|
_PySys_SetObjectId(&PyId_last_value, v);
|
||||||
PySys_SetObject("last_traceback", tb);
|
_PySys_SetObjectId(&PyId_last_traceback, tb);
|
||||||
}
|
}
|
||||||
hook = PySys_GetObject("excepthook");
|
hook = _PySys_GetObjectId(&PyId_excepthook);
|
||||||
if (hook) {
|
if (hook) {
|
||||||
PyObject *args = PyTuple_Pack(3, exception, v, tb);
|
PyObject *args = PyTuple_Pack(3, exception, v, tb);
|
||||||
PyObject *result = PyEval_CallObject(hook, args);
|
PyObject *result = PyEval_CallObject(hook, args);
|
||||||
|
@ -2009,7 +2024,7 @@ void
|
||||||
PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
|
PyErr_Display(PyObject *exception, PyObject *value, PyObject *tb)
|
||||||
{
|
{
|
||||||
PyObject *seen;
|
PyObject *seen;
|
||||||
PyObject *f = PySys_GetObject("stderr");
|
PyObject *f = _PySys_GetObjectId(&_PyId_stderr);
|
||||||
if (PyExceptionInstance_Check(value)
|
if (PyExceptionInstance_Check(value)
|
||||||
&& tb != NULL && PyTraceBack_Check(tb)) {
|
&& tb != NULL && PyTraceBack_Check(tb)) {
|
||||||
/* Put the traceback on the exception, otherwise it won't get
|
/* Put the traceback on the exception, otherwise it won't get
|
||||||
|
@ -2107,7 +2122,7 @@ flush_io(void)
|
||||||
/* Save the current exception */
|
/* Save the current exception */
|
||||||
PyErr_Fetch(&type, &value, &traceback);
|
PyErr_Fetch(&type, &value, &traceback);
|
||||||
|
|
||||||
f = PySys_GetObject("stderr");
|
f = _PySys_GetObjectId(&_PyId_stderr);
|
||||||
if (f != NULL) {
|
if (f != NULL) {
|
||||||
r = _PyObject_CallMethodId(f, &PyId_flush, "");
|
r = _PyObject_CallMethodId(f, &PyId_flush, "");
|
||||||
if (r)
|
if (r)
|
||||||
|
@ -2115,7 +2130,7 @@ flush_io(void)
|
||||||
else
|
else
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
}
|
}
|
||||||
f = PySys_GetObject("stdout");
|
f = _PySys_GetObjectId(&_PyId_stdout);
|
||||||
if (f != NULL) {
|
if (f != NULL) {
|
||||||
r = _PyObject_CallMethodId(f, &PyId_flush, "");
|
r = _PyObject_CallMethodId(f, &PyId_flush, "");
|
||||||
if (r)
|
if (r)
|
||||||
|
|
|
@ -183,7 +183,7 @@ sys_displayhook(PyObject *self, PyObject *o)
|
||||||
}
|
}
|
||||||
if (_PyObject_SetAttrId(builtins, &PyId__, Py_None) != 0)
|
if (_PyObject_SetAttrId(builtins, &PyId__, Py_None) != 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
outf = PySys_GetObject("stdout");
|
outf = _PySys_GetObjectId(&_PyId_stdout);
|
||||||
if (outf == NULL || outf == Py_None) {
|
if (outf == NULL || outf == Py_None) {
|
||||||
PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
|
PyErr_SetString(PyExc_RuntimeError, "lost sys.stdout");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -1825,7 +1825,7 @@ PySys_SetPath(const wchar_t *path)
|
||||||
PyObject *v;
|
PyObject *v;
|
||||||
if ((v = makepathobject(path, DELIM)) == NULL)
|
if ((v = makepathobject(path, DELIM)) == NULL)
|
||||||
Py_FatalError("can't create sys.path");
|
Py_FatalError("can't create sys.path");
|
||||||
if (PySys_SetObject("path", v) != 0)
|
if (_PySys_SetObjectId(&_PyId_path, v) != 0)
|
||||||
Py_FatalError("can't assign sys.path");
|
Py_FatalError("can't assign sys.path");
|
||||||
Py_DECREF(v);
|
Py_DECREF(v);
|
||||||
}
|
}
|
||||||
|
@ -1894,7 +1894,7 @@ sys_update_path(int argc, wchar_t **argv)
|
||||||
wchar_t fullpath[MAX_PATH];
|
wchar_t fullpath[MAX_PATH];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
path = PySys_GetObject("path");
|
path = _PySys_GetObjectId(&_PyId_path);
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
@ -2081,7 +2081,7 @@ sys_pyfile_write(const char *text, PyObject *file)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sys_write(char *name, FILE *fp, const char *format, va_list va)
|
sys_write(_Py_Identifier *key, FILE *fp, const char *format, va_list va)
|
||||||
{
|
{
|
||||||
PyObject *file;
|
PyObject *file;
|
||||||
PyObject *error_type, *error_value, *error_traceback;
|
PyObject *error_type, *error_value, *error_traceback;
|
||||||
|
@ -2089,7 +2089,7 @@ sys_write(char *name, FILE *fp, const char *format, va_list va)
|
||||||
int written;
|
int written;
|
||||||
|
|
||||||
PyErr_Fetch(&error_type, &error_value, &error_traceback);
|
PyErr_Fetch(&error_type, &error_value, &error_traceback);
|
||||||
file = PySys_GetObject(name);
|
file = _PySys_GetObjectId(key);
|
||||||
written = PyOS_vsnprintf(buffer, sizeof(buffer), format, va);
|
written = PyOS_vsnprintf(buffer, sizeof(buffer), format, va);
|
||||||
if (sys_pyfile_write(buffer, file) != 0) {
|
if (sys_pyfile_write(buffer, file) != 0) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
|
@ -2109,7 +2109,7 @@ PySys_WriteStdout(const char *format, ...)
|
||||||
va_list va;
|
va_list va;
|
||||||
|
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
sys_write("stdout", stdout, format, va);
|
sys_write(&_PyId_stdout, stdout, format, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2119,19 +2119,19 @@ PySys_WriteStderr(const char *format, ...)
|
||||||
va_list va;
|
va_list va;
|
||||||
|
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
sys_write("stderr", stderr, format, va);
|
sys_write(&_PyId_stderr, stderr, format, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
sys_format(char *name, FILE *fp, const char *format, va_list va)
|
sys_format(_Py_Identifier *key, FILE *fp, const char *format, va_list va)
|
||||||
{
|
{
|
||||||
PyObject *file, *message;
|
PyObject *file, *message;
|
||||||
PyObject *error_type, *error_value, *error_traceback;
|
PyObject *error_type, *error_value, *error_traceback;
|
||||||
char *utf8;
|
char *utf8;
|
||||||
|
|
||||||
PyErr_Fetch(&error_type, &error_value, &error_traceback);
|
PyErr_Fetch(&error_type, &error_value, &error_traceback);
|
||||||
file = PySys_GetObject(name);
|
file = _PySys_GetObjectId(key);
|
||||||
message = PyUnicode_FromFormatV(format, va);
|
message = PyUnicode_FromFormatV(format, va);
|
||||||
if (message != NULL) {
|
if (message != NULL) {
|
||||||
if (sys_pyfile_write_unicode(message, file) != 0) {
|
if (sys_pyfile_write_unicode(message, file) != 0) {
|
||||||
|
@ -2151,7 +2151,7 @@ PySys_FormatStdout(const char *format, ...)
|
||||||
va_list va;
|
va_list va;
|
||||||
|
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
sys_format("stdout", stdout, format, va);
|
sys_format(&_PyId_stdout, stdout, format, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2161,6 +2161,6 @@ PySys_FormatStderr(const char *format, ...)
|
||||||
va_list va;
|
va_list va;
|
||||||
|
|
||||||
va_start(va, format);
|
va_start(va, format);
|
||||||
sys_format("stderr", stderr, format, va);
|
sys_format(&_PyId_stderr, stderr, format, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,7 +169,7 @@ _Py_FindSourceFile(PyObject *filename, char* namebuf, size_t namelen, PyObject *
|
||||||
tail++;
|
tail++;
|
||||||
taillen = strlen(tail);
|
taillen = strlen(tail);
|
||||||
|
|
||||||
syspath = PySys_GetObject("path");
|
syspath = _PySys_GetObjectId(&_PyId_path);
|
||||||
if (syspath == NULL || !PyList_Check(syspath))
|
if (syspath == NULL || !PyList_Check(syspath))
|
||||||
goto error;
|
goto error;
|
||||||
npath = PyList_Size(syspath);
|
npath = PyList_Size(syspath);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue