Skip to content

Commit f4931e5

Browse files
author
Franziska Geiger
committed
- Added execution output stream to java system out
- Added argument testing to unit test - added execl support plus another unit test - Added typeslot file as external dependency
1 parent 464da1f commit f4931e5

File tree

4 files changed

+78
-7
lines changed

4 files changed

+78
-7
lines changed

graalpython/com.oracle.graal.python.cext/include/typeslots.h

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,43 @@
1+
/*
2+
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
141
/* Do not renumber the file; these numbers are part of the stable ABI. */
242
/* Disabled, see #10181 */
343
#undef Py_bf_getbuffer

graalpython/com.oracle.graal.python.test/src/tests/test_posix.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
22
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
33
#
44
# The Universal Permissive License (UPL), Version 1.0
@@ -56,6 +56,22 @@ def test_uname(self):
5656
def test_execv(self):
5757
# test creates a shell script, which again creates a file, to ensure script execution
5858
# Both files are deleted again in the end
59+
import os
60+
new_file_path, cwd = self.create_file()
61+
os.execv(new_file_path, [new_file_path, 'the_input'])
62+
assert os.path.isfile(cwd + '/test.txt')
63+
self.delete_file(new_file_path, cwd)
64+
65+
def test_execl(self):
66+
# test creates a shell script, which again creates a file, to ensure script execution
67+
# Both files are deleted again in the end
68+
import os
69+
new_file_path, cwd = self.create_file()
70+
os.execl(new_file_path, [new_file_path, 'the_input'])
71+
assert os.path.isfile(cwd + '/test.txt')
72+
self.delete_file(new_file_path, cwd)
73+
74+
def create_file(self):
5975
import os
6076
import stat
6177
cwd = os.getcwd()
@@ -64,11 +80,12 @@ def test_execv(self):
6480
script.write('#!/bin/sh\n')
6581
script.write("echo \"something echo with\" $1 > {}/test.txt\n".format(cwd))
6682
script.write('echo this is an output\n')
67-
assert os.path.isfile(cwd + '/myscript.sh')
83+
assert os.path.isfile(new_file_path)
6884
st = os.stat(new_file_path)
6985
os.chmod(new_file_path, st.st_mode | stat.S_IEXEC)
70-
os.execv(new_file_path, [new_file_path, 'the_input'])
71-
assert os.path.isfile(cwd + '/test.txt')
86+
return new_file_path, cwd
87+
88+
def delete_file(self, new_file_path, cwd):
89+
import os
7290
os.remove(new_file_path)
7391
os.remove(cwd + '/test.txt')
74-

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
import com.oracle.graal.python.runtime.exception.PException;
140140
import com.oracle.graal.python.runtime.exception.PythonErrorType;
141141
import com.oracle.graal.python.runtime.exception.PythonExitException;
142+
import com.oracle.graal.python.runtime.sequence.PSequence;
142143
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
143144
import com.oracle.truffle.api.CompilerDirectives;
144145
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
@@ -295,13 +296,20 @@ Object execute(String path, PList args) {
295296
return doExecute(path, args);
296297
}
297298

299+
@Specialization
300+
Object execute(PString path, PTuple args) {
301+
// in case of execl the PList happens to be in the tuples first entry
302+
Object list = args.getSequenceStorage().getItemNormalized(0);
303+
return doExecute(path.getValue(), list instanceof PList ? (PList) list : args);
304+
}
305+
298306
@Specialization
299307
Object execute(PString path, PList args) {
300308
return doExecute(path.getValue(), args);
301309
}
302310

303311
@TruffleBoundary
304-
Object doExecute(String path, PList args) {
312+
Object doExecute(String path, PSequence args) {
305313
try {
306314
int size = args.getSequenceStorage().length();
307315
String[] cmd = new String[size];
@@ -310,7 +318,7 @@ Object doExecute(String path, PList args) {
310318
}
311319
Runtime rt = Runtime.getRuntime();
312320
Process pr = rt.exec(cmd);
313-
// retrieve output from executed script and print it
321+
// retrieve output from executed script
314322
BufferedReader bfr = new BufferedReader(new InputStreamReader(pr.getInputStream()));
315323
String line = "";
316324
while ((line = bfr.readLine()) != null) {

graalpython/lib-graalpython/posix.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,9 @@ def uname():
143143
@__builtin__
144144
def get_terminal_size(fd = None):
145145
return terminal_size(old_get_terminal_size(fd))
146+
147+
def execl(file, *args):
148+
"""execl(file, *args)
149+
Execute the executable file with argument list args, replacing the
150+
current process. """
151+
execv(file, args)

0 commit comments

Comments
 (0)