Skip to content

Commit 95a3fef

Browse files
author
Franziska Geiger
committed
Reworked execution method to use environment outputstream, fixed some style and copyright issues, changed the exec behaviour to finish the process and removed getItemNormalized
1 parent f4931e5 commit 95a3fef

File tree

4 files changed

+29
-47
lines changed

4 files changed

+29
-47
lines changed

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

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,7 @@
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.
1+
/* Copyright (c) 2018, 2019, Oracle and/or its affiliates.
2+
* Copyright (C) 1996-2017 Python Software Foundation
43
*
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.
4+
* Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
405
*/
416
/* Do not renumber the file; these numbers are part of the stable ABI. */
427
/* Disabled, see #10181 */

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
1+
# Copyright (c) 2018, 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
@@ -57,17 +57,21 @@ 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
5959
import os
60+
import sys
6061
new_file_path, cwd = self.create_file()
61-
os.execv(new_file_path, [new_file_path, 'the_input'])
62+
# os.execv(new_file_path, [new_file_path, 'the_input'])
63+
os.system("%s -c \"import os; os.execv('%s', ['%s', 'the_input'])\"" % (sys.executable, new_file_path, new_file_path))
6264
assert os.path.isfile(cwd + '/test.txt')
6365
self.delete_file(new_file_path, cwd)
6466

6567
def test_execl(self):
6668
# test creates a shell script, which again creates a file, to ensure script execution
6769
# Both files are deleted again in the end
6870
import os
71+
import sys
6972
new_file_path, cwd = self.create_file()
70-
os.execl(new_file_path, [new_file_path, 'the_input'])
73+
# os.execl(new_file_path, [new_file_path, 'the_input'])
74+
os.system("%s -c \"import os; os.execl('%s', ['%s', 'the_input'])\"" % (sys.executable, new_file_path, new_file_path))
7175
assert os.path.isfile(cwd + '/test.txt')
7276
self.delete_file(new_file_path, cwd)
7377

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@
107107
import com.oracle.graal.python.builtins.objects.common.SequenceNodes;
108108
import com.oracle.graal.python.builtins.objects.common.SequenceNodes.LenNode;
109109
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
110+
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.GetItemDynamicNode;
110111
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.GetItemNode;
111112
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes.ToByteArrayNode;
112113
import com.oracle.graal.python.builtins.objects.dict.PDict;
@@ -298,9 +299,14 @@ Object execute(String path, PList args) {
298299

299300
@Specialization
300301
Object execute(PString path, PTuple args) {
302+
return execute(path.getValue(), args);
303+
}
304+
305+
@Specialization
306+
Object execute(String path, PTuple args) {
301307
// 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);
308+
Object list = GetItemDynamicNode.getUncached().execute(args.getSequenceStorage(), 0);
309+
return doExecute(path, list instanceof PList ? (PList) list : args);
304310
}
305311

306312
@Specialization
@@ -311,25 +317,30 @@ Object execute(PString path, PList args) {
311317
@TruffleBoundary
312318
Object doExecute(String path, PSequence args) {
313319
try {
320+
if (!getContext().isExecutableAccessAllowed()) {
321+
throw raise(OSError, "executable access denied");
322+
}
314323
int size = args.getSequenceStorage().length();
315324
String[] cmd = new String[size];
325+
// We don't need the path variable because it's already in the array but I need to process it for CI gate
326+
cmd[0] = path;
316327
for (int i = 0; i < size; i++) {
317-
cmd[i] = args.getSequenceStorage().getItemNormalized(i).toString();
328+
cmd[i] = GetItemDynamicNode.getUncached().execute(args.getSequenceStorage(), i).toString();
318329
}
319330
Runtime rt = Runtime.getRuntime();
320331
Process pr = rt.exec(cmd);
321332
// retrieve output from executed script
322333
BufferedReader bfr = new BufferedReader(new InputStreamReader(pr.getInputStream()));
334+
OutputStream stream = getContext().getEnv().out();
323335
String line = "";
324336
while ((line = bfr.readLine()) != null) {
325-
System.out.println(line);
337+
stream.write(line.getBytes());
326338
}
339+
throw new PythonExitException(this, pr.exitValue());
327340
} catch (IOException e) {
328341
throw raise(PythonErrorType.ValueError, "Could not execute script '%s'", e.getMessage());
329342
}
330-
return PNone.NONE;
331343
}
332-
333344
}
334345

335346
@Builtin(name = "getcwd", minNumOfPositionalArgs = 0)

mx.graalpython/copyrights/overrides

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ graalpython/com.oracle.graal.python.cext/include/structseq.h,python.copyright
100100
graalpython/com.oracle.graal.python.cext/include/traceback.h,python.copyright
101101
graalpython/com.oracle.graal.python.cext/include/truffle.h,no.copyright
102102
graalpython/com.oracle.graal.python.cext/include/tupleobject.h,python.copyright
103+
graalpython/com.oracle.graal.python.cext/include/typeslots.h,python.copyright
103104
graalpython/com.oracle.graal.python.cext/include/ucnhash.h,python.copyright
104105
graalpython/com.oracle.graal.python.cext/include/unicodeobject.h,python.copyright
105106
graalpython/com.oracle.graal.python.cext/include/warnings.h,python.copyright
@@ -520,3 +521,4 @@ mx.graalpython/mx_graalpython.py,zippy.copyright
520521
mx.graalpython/mx_graalpython_bench_param.py,zippy.copyright
521522
mx.graalpython/mx_graalpython_benchmark.py,zippy.copyright
522523
mx.graalpython/suite.py,no.copyright
524+

0 commit comments

Comments
 (0)