Skip to content

Commit 6d0c7cb

Browse files
committed
Merge commit 'e9ab5c4df898fadaf976d7b014fa38a1b6d595a8' into release/graal-vm/1.0
2 parents d96e385 + e9ab5c4 commit 6d0c7cb

File tree

121 files changed

+4024
-1334
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+4024
-1334
lines changed

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33
This changelog summarizes major changes between GraalVM versions of the Python
44
language runtime. The main focus is on user-observable behavior of the engine.
55

6+
## Version 1.0.0 RC9
7+
8+
* Support `help` in the builtin Python shell
9+
* Add `readline` to enable history and autocompletion in the Python shell
10+
* Add support for the -q, -E, -s, and -S Python launcher flags
11+
* Improve display of foreign array-like objects
12+
* Improve support for string and bytes regular expressions using our TRegex engine
13+
* Support loading site-packages installed with easy_install
14+
* Initial support for the `binascii` module
15+
616
## Version 1.0.0 RC8
717

818
* Report allocations when the `--memtracer` option is used

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@
180180
dynamicImports:: "sulong,/compiler",
181181

182182
setup +: [
183-
["mx", "sforceimport"],
183+
["mx", "sforceimports"],
184184
["mx", "--dynamicimports", self.dynamicImports, "build"],
185185
]
186186
},

graalpython/benchmarks/src/harness.py

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,15 @@
4444

4545

4646
_HRULE = '-'.join(['' for i in range(80)])
47-
ATTR_BENCHMARK = '__benchmark__'
47+
48+
#: this function is used to pre-process the arguments as expected by the __benchmark__ and __setup__ entry points
4849
ATTR_PROCESS_ARGS = '__process_args__'
50+
#: gets called with the preprocessed arguments before __benchmark__
51+
ATTR_SETUP = '__setup__'
52+
#: gets called with the preprocessed arguments N times
53+
ATTR_BENCHMARK = '__benchmark__'
54+
#: performs any teardown needed in the benchmark
55+
ATTR_TEARDOWN = '__teardown__'
4956

5057

5158
def ccompile(name, code):
@@ -131,7 +138,6 @@ def _call_attr(self, attr_name, *args):
131138
return attr(*args)
132139

133140
def run(self):
134-
print(_HRULE)
135141
if self._run_once:
136142
print("### %s, exactly one iteration (no warmup curves)" % (self.bench_module.__name__))
137143
else:
@@ -143,10 +149,15 @@ def run(self):
143149
# default args processor considers all args as ints
144150
args = list(map(int, self.bench_args))
145151

146-
print("### args = %s" % args)
152+
print("### args = ", args)
147153
print(_HRULE)
148154

155+
print("### setup ... ")
156+
self._call_attr(ATTR_SETUP, *args)
157+
print("### start benchmark ... ")
158+
149159
bench_func = self._get_attr(ATTR_BENCHMARK)
160+
durations = []
150161
if bench_func and hasattr(bench_func, '__call__'):
151162
if self.warmup:
152163
print("### warming up for %s iterations ... " % self.warmup)
@@ -156,18 +167,31 @@ def run(self):
156167
for iteration in range(self.iterations):
157168
start = time()
158169
bench_func(*args)
159-
duration = "%.3f" % (time() - start)
170+
duration = time() - start
171+
durations.append(duration)
172+
duration_str = "%.3f" % duration
160173
if self._run_once:
161-
print("@@@ name=%s, duration=%s" % (self.bench_module.__name__, duration))
174+
print("@@@ name=%s, duration=%s" % (self.bench_module.__name__, duration_str))
162175
else:
163-
print("### iteration=%s, name=%s, duration=%s" % (iteration, self.bench_module.__name__, duration))
176+
print("### iteration=%s, name=%s, duration=%s" % (iteration, self.bench_module.__name__, duration_str))
177+
178+
print(_HRULE)
179+
print("### teardown ... ")
180+
self._call_attr(ATTR_TEARDOWN)
181+
print("### benchmark complete")
182+
print(_HRULE)
183+
print("### BEST duration: %.3f s" % min(durations))
184+
print("### WORST duration: %.3f s" % max(durations))
185+
print("### AVG duration: %.3f" % (sum(durations) / len(durations)))
186+
print(_HRULE)
164187

165188

166-
def run_benchmark(prog, args):
189+
def run_benchmark(args):
167190
warmup = 0
168191
iterations = 1
169192
bench_file = None
170193
bench_args = []
194+
paths = []
171195

172196
i = 0
173197
while i < len(args):
@@ -177,19 +201,36 @@ def run_benchmark(prog, args):
177201
iterations = _as_int(args[i])
178202
elif arg.startswith("--iterations"):
179203
iterations = _as_int(arg.split("=")[1])
204+
180205
elif arg == '-w':
181206
i += 1
182207
warmup = _as_int(args[i])
183208
elif arg.startswith("--warmup"):
184209
warmup = _as_int(arg.split("=")[1])
210+
211+
elif arg == '-p':
212+
i += 1
213+
paths = args[i].split(",")
214+
elif arg.startswith("--path"):
215+
paths = arg.split("=")[1].split(",")
216+
185217
elif bench_file is None:
186218
bench_file = arg
187219
else:
188220
bench_args.append(arg)
189221
i += 1
190222

223+
# set the paths if specified
224+
print(_HRULE)
225+
if paths:
226+
for pth in paths:
227+
print("### adding module path: %s" % pth)
228+
sys.path.append(pth)
229+
else:
230+
print("### no extra module search paths specified")
231+
191232
BenchRunner(bench_file, bench_args=bench_args, iterations=iterations, warmup=warmup).run()
192233

193234

194235
if __name__ == '__main__':
195-
run_benchmark(sys.argv[0], sys.argv[1:])
236+
run_benchmark(sys.argv[1:])

graalpython/benchmarks/src/micro/arith-binop.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,8 @@ def measure(num):
4343

4444
def __benchmark__(num=5):
4545
measure(num)
46+
47+
48+
def __teardown__():
49+
# teardown example
50+
print("arith-binop teardown")

graalpython/benchmarks/src/micro/c-magic-iter.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,25 @@
5757
int ci_init(PyObject* self, PyObject* args, PyObject* kwds);
5858
5959
PyObject* ci_iter(PyObject* self) {
60-
return ((NativeCustomIterableObject*)self)->it;
60+
PyObject* result = ((NativeCustomIterableObject*)self)->it;
61+
Py_INCREF(result);
62+
return result;
6163
}
6264
6365
PyObject* cit_iter(PyObject* self) {
66+
Py_INCREF(self);
6467
return self;
6568
}
6669
6770
PyObject* cit_next(PyObject* self) {
6871
NativeCustomIteratorObject* s = (NativeCustomIteratorObject*)self;
69-
return PyLong_FromLongLong(ci_item((PyObject*)(s->obj), (s->pos)++));
72+
return ci_item((PyObject*)(s->obj), (s->pos)++);
7073
}
7174
7275
PyObject* ci_item(PyObject* self, Py_ssize_t i) {
73-
return ((NativeCustomIterableObject*)self)->scale * i;
76+
PyObject* result = PyLong_FromSsize_t(((NativeCustomIterableObject*)self)->scale * i);
77+
Py_INCREF(result);
78+
return result;
7479
}
7580
7681
@@ -177,6 +182,8 @@
177182
};
178183
179184
int ci_init(PyObject* self, PyObject* args, PyObject* kwds) {
185+
Py_XINCREF(args);
186+
Py_XINCREF(kwds);
180187
static char *kwlist[] = {"scale", NULL};
181188
Py_ssize_t n = 0;
182189
@@ -187,7 +194,11 @@
187194
tself->scale = n + 1;
188195
189196
PyObject *argList = PyTuple_New(0);
197+
Py_INCREF(argList);
190198
PyObject *obj = PyObject_CallObject((PyObject *) &CustomIteratorType, argList);
199+
Py_DECREF(argList);
200+
Py_INCREF(obj);
201+
Py_INCREF(tself);
191202
((NativeCustomIteratorObject*)obj)->obj = tself;
192203
tself->it = obj;
193204
@@ -221,6 +232,7 @@
221232
Py_INCREF(&CustomIteratorType);
222233
PyModule_AddObject(m, "NativeCustomIterable", (PyObject *)&CustomIterableType);
223234
PyModule_AddObject(m, "NativeCustomIterator", (PyObject *)&CustomIteratorType);
235+
Py_INCREF(m);
224236
return m;
225237
}
226238

graalpython/com.oracle.graal.python.cext/src/abstract.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ PyObject * PyMapping_GetItemString(PyObject *o, const char *key) {
266266
return UPCALL_CEXT_O(_jls_PyObject_GetItem, native_to_java(o), polyglot_from_string(key, SRC_CS));
267267
}
268268

269+
UPCALL_ID(PyMapping_Keys);
270+
PyObject * PyMapping_Keys(PyObject *o) {
271+
return UPCALL_CEXT_O(_jls_PyMapping_Keys, native_to_java(o));
272+
}
273+
269274
// taken from CPython "Objects/abstract.c"
270275
int PyObject_GetBuffer(PyObject *obj, Py_buffer *view, int flags) {
271276
PyBufferProcs *pb = obj->ob_type->tp_as_buffer;

graalpython/com.oracle.graal.python.cext/src/capi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ uint64_t PyTruffle_Wchar_Size() {
247247
return SIZEOF_WCHAR_T;
248248
}
249249

250-
void* PyObjectHandle_ForJavaObject(void* cobj, unsigned long flags) {
250+
void* PyObjectHandle_ForJavaObject(void* cobj) {
251251
if (truffle_cannot_be_handle(cobj)) {
252252
return truffle_deref_handle_for_managed(cobj);
253253
}

graalpython/com.oracle.graal.python.cext/src/longobject.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,15 @@ PyTypeObject PyLong_Type = PY_TRUFFLE_TYPE("int", &PyType_Type, Py_TPFLAGS_DEFAU
4747

4848
UPCALL_ID(PyLong_AsPrimitive);
4949
long PyLong_AsLong(PyObject *obj) {
50-
return UPCALL_CEXT_L(_jls_PyLong_AsPrimitive, native_to_java(obj), 1, sizeof(long), polyglot_from_string("long", SRC_CS));
50+
return UPCALL_CEXT_L(_jls_PyLong_AsPrimitive, native_to_java(obj), 1, sizeof(long));
5151
}
5252

5353
long PyLong_AsLongAndOverflow(PyObject *obj, int *overflow) {
5454
if (obj == NULL) {
5555
PyErr_BadInternalCall();
5656
return -1;
5757
}
58-
long result = UPCALL_CEXT_L(_jls_PyLong_AsPrimitive, native_to_java(obj), 1, sizeof(long), polyglot_from_string("long", SRC_CS));
58+
long result = UPCALL_CEXT_L(_jls_PyLong_AsPrimitive, native_to_java(obj), 1, sizeof(long));
5959
*overflow = result == -1L && PyErr_Occurred() != NULL;
6060
return result;
6161
}
@@ -79,7 +79,7 @@ unsigned long PyLong_AsUnsignedLong(PyObject *obj) {
7979
PyErr_BadInternalCall();
8080
return (unsigned long)-1;
8181
}
82-
return (unsigned long) UPCALL_CEXT_L(_jls_PyLong_AsPrimitive, native_to_java(obj), 0, sizeof(unsigned long), polyglot_from_string("unsigned long", SRC_CS));
82+
return (unsigned long) UPCALL_CEXT_L(_jls_PyLong_AsPrimitive, native_to_java(obj), 0, sizeof(unsigned long));
8383
}
8484
PyObject * PyLong_FromSsize_t(Py_ssize_t n) {
8585
return PyLong_FromLongLong(n);
@@ -90,9 +90,8 @@ PyObject * PyLong_FromDouble(double n) {
9090
return UPCALL_CEXT_O(_jls_PyLong_FromDouble, n);
9191
}
9292

93-
UPCALL_ID(ssize_t);
9493
Py_ssize_t PyLong_AsSsize_t(PyObject *obj) {
95-
return UPCALL_CEXT_L(_jls_PyLong_AsPrimitive, native_to_java(obj), 1, sizeof(Py_ssize_t), _jls_ssize_t);
94+
return UPCALL_CEXT_L(_jls_PyLong_AsPrimitive, native_to_java(obj), 1, sizeof(Py_ssize_t));
9695
}
9796

9897
PyObject * PyLong_FromVoidPtr(void *p) {

graalpython/com.oracle.graal.python.shell/src/com/oracle/graal/python/shell/ConsoleHandler.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,14 @@
4343
import java.io.IOException;
4444
import java.io.InputStream;
4545
import java.nio.charset.StandardCharsets;
46+
import java.util.List;
47+
import java.util.function.BiConsumer;
48+
import java.util.function.BooleanSupplier;
49+
import java.util.function.Consumer;
50+
import java.util.function.Function;
51+
import java.util.function.IntConsumer;
52+
import java.util.function.IntFunction;
53+
import java.util.function.IntSupplier;
4654

4755
import org.graalvm.polyglot.Context;
4856

@@ -59,10 +67,20 @@ public abstract class ConsoleHandler {
5967

6068
public abstract void setPrompt(String prompt);
6169

70+
public void addCompleter(@SuppressWarnings("unused") Function<String, List<String>> completer) {
71+
// ignore by default
72+
}
73+
6274
public void setContext(@SuppressWarnings("unused") Context context) {
6375
// ignore by default
6476
}
6577

78+
@SuppressWarnings("unused")
79+
public void setHistory(BooleanSupplier shouldRecord, IntSupplier getSize, Consumer<String> addItem, IntFunction<String> getItem, BiConsumer<Integer, String> setItem, IntConsumer removeItem,
80+
Runnable clear) {
81+
// ignore by default
82+
}
83+
6684
public InputStream createInputStream() {
6785
return new InputStream() {
6886
byte[] buffer = null;

0 commit comments

Comments
 (0)