Skip to content

Commit 6766feb

Browse files
author
Franziska Geiger
committed
Implement os.execv + added a .h file for third party library
1 parent 5ea13c9 commit 6766feb

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/* Do not renumber the file; these numbers are part of the stable ABI. */
2+
/* Disabled, see #10181 */
3+
#undef Py_bf_getbuffer
4+
#undef Py_bf_releasebuffer
5+
#define Py_mp_ass_subscript 3
6+
#define Py_mp_length 4
7+
#define Py_mp_subscript 5
8+
#define Py_nb_absolute 6
9+
#define Py_nb_add 7
10+
#define Py_nb_and 8
11+
#define Py_nb_bool 9
12+
#define Py_nb_divmod 10
13+
#define Py_nb_float 11
14+
#define Py_nb_floor_divide 12
15+
#define Py_nb_index 13
16+
#define Py_nb_inplace_add 14
17+
#define Py_nb_inplace_and 15
18+
#define Py_nb_inplace_floor_divide 16
19+
#define Py_nb_inplace_lshift 17
20+
#define Py_nb_inplace_multiply 18
21+
#define Py_nb_inplace_or 19
22+
#define Py_nb_inplace_power 20
23+
#define Py_nb_inplace_remainder 21
24+
#define Py_nb_inplace_rshift 22
25+
#define Py_nb_inplace_subtract 23
26+
#define Py_nb_inplace_true_divide 24
27+
#define Py_nb_inplace_xor 25
28+
#define Py_nb_int 26
29+
#define Py_nb_invert 27
30+
#define Py_nb_lshift 28
31+
#define Py_nb_multiply 29
32+
#define Py_nb_negative 30
33+
#define Py_nb_or 31
34+
#define Py_nb_positive 32
35+
#define Py_nb_power 33
36+
#define Py_nb_remainder 34
37+
#define Py_nb_rshift 35
38+
#define Py_nb_subtract 36
39+
#define Py_nb_true_divide 37
40+
#define Py_nb_xor 38
41+
#define Py_sq_ass_item 39
42+
#define Py_sq_concat 40
43+
#define Py_sq_contains 41
44+
#define Py_sq_inplace_concat 42
45+
#define Py_sq_inplace_repeat 43
46+
#define Py_sq_item 44
47+
#define Py_sq_length 45
48+
#define Py_sq_repeat 46
49+
#define Py_tp_alloc 47
50+
#define Py_tp_base 48
51+
#define Py_tp_bases 49
52+
#define Py_tp_call 50
53+
#define Py_tp_clear 51
54+
#define Py_tp_dealloc 52
55+
#define Py_tp_del 53
56+
#define Py_tp_descr_get 54
57+
#define Py_tp_descr_set 55
58+
#define Py_tp_doc 56
59+
#define Py_tp_getattr 57
60+
#define Py_tp_getattro 58
61+
#define Py_tp_hash 59
62+
#define Py_tp_init 60
63+
#define Py_tp_is_gc 61
64+
#define Py_tp_iter 62
65+
#define Py_tp_iternext 63
66+
#define Py_tp_methods 64
67+
#define Py_tp_new 65
68+
#define Py_tp_repr 66
69+
#define Py_tp_richcompare 67
70+
#define Py_tp_setattr 68
71+
#define Py_tp_setattro 69
72+
#define Py_tp_str 70
73+
#define Py_tp_traverse 71
74+
#define Py_tp_members 72
75+
#define Py_tp_getset 73
76+
#define Py_tp_free 74
77+
#define Py_nb_matrix_multiply 75
78+
#define Py_nb_inplace_matrix_multiply 76
79+
#define Py_am_await 77
80+
#define Py_am_aiter 78
81+
#define Py_am_anext 79
82+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03050000
83+
/* New in 3.5 */
84+
#define Py_tp_finalize 80
85+
#endif

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
import com.oracle.graal.python.builtins.objects.floats.PFloat;
113113
import com.oracle.graal.python.builtins.objects.function.PKeyword;
114114
import com.oracle.graal.python.builtins.objects.ints.PInt;
115+
import com.oracle.graal.python.builtins.objects.list.PList;
115116
import com.oracle.graal.python.builtins.objects.module.PythonModule;
116117
import com.oracle.graal.python.builtins.objects.str.PString;
117118
import com.oracle.graal.python.builtins.objects.tuple.PTuple;
@@ -283,6 +284,33 @@ public void postInitialize(PythonCore core) {
283284
((PDict) environAttr).setDictStorage(environ.getDictStorage());
284285
}
285286

287+
@Builtin(name = "execv", minNumOfPositionalArgs = 2)
288+
@GenerateNodeFactory
289+
public abstract static class ExecvNode extends PythonBuiltinNode {
290+
291+
@Specialization
292+
Object execute(String path, PList args) {
293+
return doExecute(path, args);
294+
}
295+
296+
@TruffleBoundary
297+
Object doExecute(String path, PList args) {
298+
try {
299+
int size = args.getSequenceStorage().length();
300+
String[] cmd = new String[1 + size];
301+
cmd[0] = path;
302+
for (int i = 1; i < size; i++) {
303+
cmd[i + 3] = args.getSequenceStorage().getItemNormalized(i).toString();
304+
}
305+
new ProcessBuilder(cmd).start();
306+
} catch (IOException e) {
307+
throw raise(PythonErrorType.ValueError, "Could not execute script '%s'", e.getMessage());
308+
}
309+
return PNone.NONE;
310+
}
311+
312+
}
313+
286314
@Builtin(name = "getcwd", minNumOfPositionalArgs = 0)
287315
@GenerateNodeFactory
288316
public abstract static class CwdNode extends PythonBuiltinNode {

0 commit comments

Comments
 (0)