From edf846f58e7c24516d1450460ae91623563c6c62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Tue, 29 Mar 2022 20:28:40 -0600 Subject: [PATCH 1/2] CI: Enable failing on error This was introduced when we split the CI script into two, the second one does not fail on error. --- ci/test.xsh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ci/test.xsh b/ci/test.xsh index 79f5dbf356..790318a3f7 100644 --- a/ci/test.xsh +++ b/ci/test.xsh @@ -1,3 +1,8 @@ +#!/usr/bin/env xonsh +# +$RAISE_SUBPROC_ERROR = True +trace on + # Run some simple compilation tests, works everywhere: src/bin/lpython --version # Compile and link separately From d427bc4a7303db072604761c40c6fec2c0cea0af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20=C4=8Cert=C3=ADk?= Date: Tue, 29 Mar 2022 21:06:13 -0600 Subject: [PATCH 2/2] Make os.open API exactly as in CPython --- integration_tests/test_os.py | 4 ++-- src/runtime/os.py | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/integration_tests/test_os.py b/integration_tests/test_os.py index fea7230893..664d5fea0a 100644 --- a/integration_tests/test_os.py +++ b/integration_tests/test_os.py @@ -1,12 +1,12 @@ from ltypes import i64 -from os import (open, read, close) +from os import (open, read, close, O_RDONLY) def test(): path: str path = "integration_tests/test_os.py" fd: i64 n: i64 - fd = open(path, "r") + fd = open(path, O_RDONLY) n = 100 print(read(fd, n)) close(fd) diff --git a/src/runtime/os.py b/src/runtime/os.py index 8d1050e3f9..9b4e2eb8b4 100644 --- a/src/runtime/os.py +++ b/src/runtime/os.py @@ -1,10 +1,22 @@ from ltypes import i32, i64, ccall -def open(path: str, flag: str) -> i64: +O_RDONLY: i32 # = 0 FIXME: Assign the value 0 to O_RDONLY +# O_WRONLY: i32 = 1 +# O_RDWR : i32 = 2 +# O_CREAT : i32 = 64 +# O_APPEND: i32 = 1024 + + +def open(path: str, flag: i32) -> i64: """ Returns the file descriptor for the newly opened file """ - return _lpython_open(path, flag) + sflag: str + if flag == O_RDONLY: + sflag = "r" + else: + quit(1) # not implemented yet + return _lpython_open(path, sflag) @ccall def _lpython_open(path: str, flag: str) -> i64: