Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
630924f1
Commit
630924f1
authored
Jul 25, 1997
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use Py_NewInterpreter() and friends. Remove saving/restoring of std files.
parent
275558cb
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
22 deletions
+16
-22
Demo/pysvr/pysvr.c
Demo/pysvr/pysvr.c
+16
-22
No files found.
Demo/pysvr/pysvr.c
View file @
630924f1
...
...
@@ -192,13 +192,8 @@ static PyObject *the_builtins;
static
void
init_python
()
{
if
(
the_interp
)
return
;
Py_Initialize
();
/* Initialize the interpreter */
the_builtins
=
PyEval_GetBuiltins
();
/* Get __builtins__ */
PyEval_InitThreads
();
/* Create and acquire the interpreter lock */
the_tstate
=
PyEval_SaveThread
();
/* Release lock & get thread state */
the_interp
=
the_tstate
->
interpreter_state
;
/* Get interp state */
PyEval_ReleaseLock
();
/* Release the lock */
}
static
void
*
...
...
@@ -250,25 +245,25 @@ run_interpreter(FILE *input, FILE *output)
{
PyThreadState
*
tstate
;
PyObject
*
new_stdin
,
*
new_stdout
;
PyObject
*
old_stdin
,
*
old_stdout
,
*
old_stderr
;
PyObject
*
globals
;
PyObject
*
mainmod
,
*
globals
;
char
buffer
[
1000
];
char
*
p
,
*
q
;
int
n
,
end
;
tstate
=
PyThreadState_New
(
the_interp
);
PyEval_AcquireThread
(
tstate
);
PyEval_AcquireLock
();
tstate
=
Py_NewInterpreter
();
if
(
tstate
==
NULL
)
{
fprintf
(
output
,
"Sorry -- can't create an interpreter
\n
"
);
return
;
}
globals
=
PyDict_New
();
PyDict_SetItemString
(
globals
,
"__builtins__"
,
the_builtins
);
mainmod
=
PyImport_AddModule
(
"__main__"
);
globals
=
PyModule_GetDict
(
mainmod
);
Py_INCREF
(
globals
);
new_stdin
=
PyFile_FromFile
(
input
,
"<socket-in>"
,
"r"
,
NULL
);
new_stdout
=
PyFile_FromFile
(
output
,
"<socket-out>"
,
"w"
,
NULL
);
old_stdin
=
PySys_GetObject
(
"stdin"
);
old_stdout
=
PySys_GetObject
(
"stdout"
);
old_stderr
=
PySys_GetObject
(
"stderr"
);
for
(
n
=
1
;
!
PyErr_Occurred
();
n
++
)
{
Py_BEGIN_ALLOW_THREADS
fprintf
(
output
,
"%d> "
,
n
);
...
...
@@ -299,10 +294,6 @@ run_interpreter(FILE *input, FILE *output)
if
(
end
<
0
)
PyErr_Print
();
PySys_SetObject
(
"stdin"
,
old_stdin
);
PySys_SetObject
(
"stdout"
,
old_stdout
);
PySys_SetObject
(
"stderr"
,
old_stderr
);
if
(
end
)
break
;
}
...
...
@@ -311,8 +302,8 @@ run_interpreter(FILE *input, FILE *output)
Py_XDECREF
(
new_stdin
);
Py_XDECREF
(
new_stdout
);
Py
Eval_ReleaseThread
(
tstate
);
Py
ThreadState_Delete
(
tstate
);
Py
_EndInterpreter
(
tstate
);
Py
Eval_ReleaseLock
(
);
fprintf
(
output
,
"Goodbye!
\n
"
);
}
...
...
@@ -321,6 +312,9 @@ static int
run_command
(
char
*
buffer
,
PyObject
*
globals
)
{
PyObject
*
m
,
*
d
,
*
v
;
fprintf
(
stderr
,
"run_command: %s"
,
buffer
);
if
(
strchr
(
buffer
,
'\n'
)
==
NULL
)
fprintf
(
stderr
,
"
\n
"
);
v
=
PyRun_String
(
buffer
,
Py_single_input
,
globals
,
globals
);
if
(
v
==
NULL
)
{
if
(
PyErr_Occurred
()
==
PyExc_SystemExit
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment