Skip to content

Commit b686bb2

Browse files
committed
Implement sys.exit and stdout/stderr/stdin
1 parent 5f03d50 commit b686bb2

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

sys/sys.go

+12-10
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,10 @@ If it is another kind of object, it will be printed and the system
124124
exit status will be one (i.e., failure).`
125125

126126
func sys_exit(self py.Object, args py.Tuple) py.Object {
127-
panic("Not implemented")
128-
return py.None
129-
// py.Object exit_code = 0;
130-
// if (!PyArg_UnpackTuple(args, "exit", 0, 1, &exit_code)) {
131-
// return nil;
132-
// }
133-
// /* Raise SystemExit so callers may catch it or clean up. */
134-
// PyErr_SetObject(PyExc_SystemExit, exit_code);
135-
// return nil;
127+
var exit_code py.Object
128+
py.UnpackTuple(args, nil, "exit", 0, 1, &exit_code)
129+
// Raise SystemExit so callers may catch it or clean up.
130+
panic(py.ExceptionNew(py.SystemExit, args, nil))
136131
}
137132

138133
const getdefaultencoding_doc = `getdefaultencoding() -> string
@@ -676,8 +671,15 @@ func init() {
676671
for i, v := range pyargs {
677672
argv.Items[i] = py.String(v)
678673
}
674+
stdin, stdout, stderr := (*py.File)(os.Stdin), (*py.File)(os.Stdout), (*py.File)(os.Stderr)
679675
globals := py.StringDict{
680-
"argv": argv,
676+
"argv": argv,
677+
"stdin": stdin,
678+
"stdout": stdout,
679+
"stderr": stderr,
680+
"__stdin__": stdin,
681+
"__stdout__": stdout,
682+
"__stderr__": stderr,
681683
//"version": py.Int(MARSHAL_VERSION),
682684
// /* stdin/stdout/stderr are now set by pythonrun.c */
683685

0 commit comments

Comments
 (0)