summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-11-25 20:58:13 (GMT)
committerGuido van Rossum <guido@python.org>1997-11-25 20:58:13 (GMT)
commitddc3fb573429a40ac7c80088edf25ee19f7a5265 (patch)
tree3dfb77939b312d2aca2677b91ae0a7c407a56836 /Python/pythonrun.c
parent84cca446f2829b114d472d5b41d0003115cd9382 (diff)
downloadcpython-ddc3fb573429a40ac7c80088edf25ee19f7a5265.zip
cpython-ddc3fb573429a40ac7c80088edf25ee19f7a5265.tar.gz
cpython-ddc3fb573429a40ac7c80088edf25ee19f7a5265.tar.bz2
Apply str() to sys.ps1 or sys.ps2 before using them as a prompt, so
you can assign an object whose str() evaluates to the current directory (or whatever).
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c30
1 files changed, 14 insertions, 16 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index bfed548..b8abe25 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -459,24 +459,22 @@ PyRun_InteractiveOne(fp, filename)
PyObject *m, *d, *v, *w;
node *n;
perrdetail err;
- char *ps1, *ps2;
+ char *ps1 = "", *ps2 = "";
v = PySys_GetObject("ps1");
- w = PySys_GetObject("ps2");
- if (v != NULL && PyString_Check(v)) {
- Py_INCREF(v);
- ps1 = PyString_AsString(v);
- }
- else {
- v = NULL;
- ps1 = "";
- }
- if (w != NULL && PyString_Check(w)) {
- Py_INCREF(w);
- ps2 = PyString_AsString(w);
+ if (v != NULL) {
+ v = PyObject_Str(v);
+ if (v == NULL)
+ PyErr_Clear();
+ else if (PyString_Check(v))
+ ps1 = PyString_AsString(v);
}
- else {
- w = NULL;
- ps2 = "";
+ w = PySys_GetObject("ps2");
+ if (w != NULL) {
+ w = PyObject_Str(w);
+ if (w == NULL)
+ PyErr_Clear();
+ else if (PyString_Check(w))
+ ps2 = PyString_AsString(w);
}
Py_BEGIN_ALLOW_THREADS
n = PyParser_ParseFile(fp, filename, &_PyParser_Grammar,