Skip to content

Commit 5bc6902

Browse files
committed
Merge commit '485066a3465766afa7d1cfa0a7f4c16332c13ca3' into release/graal-vm/1.0
2 parents c6aa379 + 485066a commit 5bc6902

File tree

196 files changed

+4403
-2357
lines changed

Some content is hidden

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

196 files changed

+4403
-2357
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
overlay: "934f7a99e60cbc8d0affd873805c057b576f3709",
2+
overlay: "2b63e24614bc48b008ea15460ab22129f4a2c442",
33

44
// ======================================================================================================
55
//

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ declare_type(PyByteArray_Type, bytearray, PyByteArrayObject);
131131
declare_type(PyCFunction_Type, builtin_function_or_method, PyCFunctionObject);
132132
declare_type(PyMethodDescr_Type, method_descriptor, PyMethodDescrObject);
133133
declare_type(PyGetSetDescr_Type, getset_descriptor, PyGetSetDescrObject);
134-
declare_type(PyWrapperDescr_Type, wrapper_descriptor, PyWrapperDescrObject);
135-
declare_type(PyMemberDescr_Type, member_descriptor, PyMemberDescrObject);
134+
declare_type(PyWrapperDescr_Type, method_descriptor, PyWrapperDescrObject); // LS: previously wrapper_descriptor
135+
declare_type(PyMemberDescr_Type, property, PyMemberDescrObject); // LS: previously member_descriptor
136136
declare_type(_PyExc_BaseException, BaseException, PyBaseExceptionObject);
137137
declare_type(PyBuffer_Type, buffer, PyBufferDecorator);
138138
declare_type(PyFunction_Type, function, PyFunctionObject);

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ PyObject * PyLong_FromSsize_t(Py_ssize_t n) {
8585
return PyLong_FromLongLong(n);
8686
}
8787

88-
UPCALL_ID(PyLong_FromLongLong);
88+
UPCALL_ID(PyLong_FromDouble);
8989
PyObject * PyLong_FromDouble(double n) {
90-
return UPCALL_CEXT_O(_jls_PyLong_FromLongLong, n, 1);
90+
return UPCALL_CEXT_O(_jls_PyLong_FromDouble, n);
9191
}
9292

9393
UPCALL_ID(ssize_t);
@@ -106,10 +106,13 @@ PyObject * PyLong_FromVoidPtr(void *p) {
106106
return PyLong_FromUnsignedLongLong((unsigned long long)(uintptr_t)p);
107107
#endif /* SIZEOF_VOID_P <= SIZEOF_LONG */
108108
}
109+
110+
UPCALL_ID(PyLong_AsVoidPtr);
109111
void * PyLong_AsVoidPtr(PyObject *obj){
110-
return (void *)PyLong_AsSsize_t(obj);
112+
return (void *)UPCALL_CEXT_PTR(_jls_PyLong_AsVoidPtr, native_to_java(obj));
111113
}
112114

115+
UPCALL_ID(PyLong_FromLongLong);
113116
PyObject * PyLong_FromLong(long n) {
114117
return UPCALL_CEXT_O(_jls_PyLong_FromLongLong, n, 1);
115118
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,12 @@ PyObject* PyObject_CallMethod(PyObject* object, const char* method, const char*
243243
return UPCALL_CEXT_O(_jls_PyObject_CallMethod, native_to_java(object), polyglot_from_string(method, SRC_CS), native_to_java(args));
244244
}
245245

246+
PyObject* _PyObject_CallMethod_SizeT(PyObject* object, const char* method, const char* fmt, ...) {
247+
PyObject* args;
248+
CALL_WITH_VARARGS(args, Py_BuildValue, 3, fmt);
249+
return UPCALL_CEXT_O(_jls_PyObject_CallMethod, native_to_java(object), polyglot_from_string(method, SRC_CS), native_to_java(args));
250+
}
251+
246252
UPCALL_ID(type);
247253
PyObject* PyObject_Type(PyObject* obj) {
248254
return UPCALL_O(PY_BUILTIN, _jls_type, native_to_java(obj));

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,7 @@ int PyType_Ready(PyTypeObject* cls) {
232232
PyDict_SetItemString(native_members, "tp_name", polyglot_from_string(cls->tp_name, SRC_CS));
233233
PyDict_SetItemString(native_members, "tp_doc", polyglot_from_string(cls->tp_doc ? cls->tp_doc : "", SRC_CS));
234234
PyDict_SetItemString(native_members, "tp_basicsize", PyLong_FromSsize_t(cls->tp_basicsize));
235-
const char* lastDot = strrchr(cls->tp_name, '.');
236-
if (lastDot) {
237-
PyDict_SetItemString(native_members, "__module__", polyglot_from_string(lastDot + 1, SRC_CS));
238-
}
235+
const char* class_name = cls->tp_name;
239236
PyTypeObject* javacls = polyglot_invoke(PY_TRUFFLE_CEXT,
240237
"PyType_Ready",
241238
// no conversion of cls here, because we

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/PythonTests.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,15 @@ public static void assertPrints(String expected, Path scriptName) {
192192
public static void assertPrints(String expected, String code) {
193193
final ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
194194
final PrintStream printStream = new PrintStream(byteArray);
195-
String source = code;
196-
PythonTests.runScript(new String[0], source, printStream, System.err);
195+
PythonTests.runScript(new String[0], code, printStream, System.err);
196+
String result = byteArray.toString().replaceAll("\r\n", "\n");
197+
assertEquals(expected.replaceAll(" at 0x[0-9a-f]*>", " at 0xabcd>"), result.replaceAll(" at 0x[0-9a-f]*>", " at 0xabcd>"));
198+
}
199+
200+
public static void assertPrints(String expected, org.graalvm.polyglot.Source code) {
201+
final ByteArrayOutputStream byteArray = new ByteArrayOutputStream();
202+
final PrintStream printStream = new PrintStream(byteArray);
203+
PythonTests.runScript(new String[0], code, printStream, System.err);
197204
String result = byteArray.toString().replaceAll("\r\n", "\n");
198205
assertEquals(expected.replaceAll(" at 0x[0-9a-f]*>", " at 0xabcd>"), result.replaceAll(" at 0x[0-9a-f]*>", " at 0xabcd>"));
199206
}
@@ -311,6 +318,15 @@ public static void runScript(String[] args, String source, OutputStream out, Out
311318
}
312319
}
313320

321+
public static void runScript(String[] args, org.graalvm.polyglot.Source source, OutputStream out, OutputStream err) {
322+
try {
323+
enterContext(args);
324+
context.eval(source);
325+
} finally {
326+
flush(out, err);
327+
}
328+
}
329+
314330
public static void runScript(String[] args, String source, OutputStream out, OutputStream err, Runnable cb) {
315331
try {
316332
enterContext(args);

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/basic/HelloWorldTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,11 @@ public class HelloWorldTests {
3434
public void helloworld() {
3535
assertPrints("hello world\n", "print(\"hello world\")");
3636
}
37+
38+
@Test
39+
public void helloworldAgain() {
40+
org.graalvm.polyglot.Source source = org.graalvm.polyglot.Source.create("python", "try: print(value)\nexcept:print('hello')\nvalue='world'");
41+
assertPrints("hello\n", source);
42+
assertPrints("hello\n", source);
43+
}
3744
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/datatype/PRangeTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@
3535
import com.oracle.graal.python.builtins.objects.range.PRange;
3636
import com.oracle.graal.python.nodes.control.GetIteratorNode;
3737
import com.oracle.graal.python.nodes.control.GetNextNode;
38+
import com.oracle.graal.python.nodes.object.IsBuiltinClassProfile;
3839
import com.oracle.graal.python.runtime.exception.PException;
3940
import com.oracle.graal.python.runtime.object.PythonObjectFactory;
4041
import com.oracle.graal.python.test.PythonTests;
4142
import com.oracle.truffle.api.frame.VirtualFrame;
4243
import com.oracle.truffle.api.nodes.Node;
4344
import com.oracle.truffle.api.nodes.RootNode;
4445
import com.oracle.truffle.api.nodes.UnexpectedResultException;
45-
import com.oracle.truffle.api.profiles.ConditionProfile;
4646

4747
public class PRangeTests {
4848
@Before
@@ -75,14 +75,14 @@ public void loopWithOnlyStop() throws UnexpectedResultException {
7575
Object iter = getIter.executeWith(range);
7676
GetNextNode next = GetNextNode.create();
7777
testRoot.doInsert(next);
78-
ConditionProfile errorProfile = ConditionProfile.createBinaryProfile();
78+
IsBuiltinClassProfile errorProfile = IsBuiltinClassProfile.create();
7979

8080
while (true) {
8181
try {
8282
int item = next.executeInt(iter);
8383
assertEquals(index, item);
8484
} catch (PException e) {
85-
e.expectStopIteration(PythonLanguage.getCore(), errorProfile);
85+
e.expectStopIteration(errorProfile);
8686
break;
8787
}
8888
index++;
@@ -99,14 +99,14 @@ public void loopWithStep() throws UnexpectedResultException {
9999
Object iter = getIter.executeWith(range);
100100
GetNextNode next = GetNextNode.create();
101101
testRoot.doInsert(next);
102-
ConditionProfile errorProfile = ConditionProfile.createBinaryProfile();
102+
IsBuiltinClassProfile errorProfile = IsBuiltinClassProfile.create();
103103

104104
while (true) {
105105
try {
106106
int item = next.executeInt(iter);
107107
assertEquals(index, item);
108108
} catch (PException e) {
109-
e.expectStopIteration(PythonLanguage.getCore(), errorProfile);
109+
e.expectStopIteration(errorProfile);
110110
break;
111111
}
112112
index += 2;

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/interop/JavaInteropTest.java

Lines changed: 109 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,17 +66,17 @@
6666
import com.oracle.truffle.api.nodes.Node;
6767

6868
public class JavaInteropTest extends PythonTests {
69-
private ByteArrayOutputStream os;
69+
private ByteArrayOutputStream out;
7070
private Context context;
7171
private ByteArrayOutputStream err;
7272

7373
@Before
7474
public void setUpTest() {
75-
os = new ByteArrayOutputStream();
75+
out = new ByteArrayOutputStream();
7676
err = new ByteArrayOutputStream();
7777
Builder builder = Context.newBuilder();
7878
builder.allowAllAccess(true);
79-
builder.out(os);
79+
builder.out(out);
8080
builder.err(err);
8181
context = builder.build();
8282
}
@@ -128,7 +128,7 @@ public void testPassingFloats() throws Exception {
128128
context.eval(script);
129129
Value main = context.getPolyglotBindings().getMember("foo");
130130
main.execute((float) 1.0, (float) 2.0);
131-
assertEquals("2.0\n", os.toString("UTF-8"));
131+
assertEquals("2.0\n", out.toString("UTF-8"));
132132
}
133133

134134
@Test
@@ -141,7 +141,7 @@ public void testAsFunction() throws Exception {
141141
context.eval(script);
142142
Value main = context.getPolyglotBindings().getMember("foo");
143143
main.execute();
144-
assertEquals("Called\n", os.toString("UTF-8"));
144+
assertEquals("Called\n", out.toString("UTF-8"));
145145
}
146146

147147
@Test
@@ -154,7 +154,7 @@ public void testAsFunctionVarArgs() throws Exception {
154154
context.eval(script);
155155
Value main = context.getPolyglotBindings().getMember("foo");
156156
main.execute("Hello", "World");
157-
assertEquals("Hello World\n", os.toString("UTF-8"));
157+
assertEquals("Hello World\n", out.toString("UTF-8"));
158158
}
159159

160160
@Test
@@ -165,7 +165,7 @@ public void mainFunctionsAreImplicitlyImporteable() throws Exception {
165165
context.eval(script);
166166
Value main = context.getBindings("python").getMember("foo");
167167
main.execute("Hello", "World");
168-
assertEquals("Hello World\n", os.toString("UTF-8"));
168+
assertEquals("Hello World\n", out.toString("UTF-8"));
169169
}
170170

171171
@Test
@@ -175,7 +175,7 @@ public void builtinFunctionsAreImporteable() throws Exception {
175175
context.eval(script);
176176
Value main = context.getBindings("python").getMember("__builtins__").getMember("print");
177177
main.execute("Hello", "World");
178-
assertEquals("Hello World\n", os.toString("UTF-8"));
178+
assertEquals("Hello World\n", out.toString("UTF-8"));
179179
}
180180

181181
@Test
@@ -186,15 +186,15 @@ public void testMultipleInvocationsAreInSameScope() throws Exception {
186186
Source script = Source.create("python", source);
187187
Value foo = context.eval(script);
188188
foo.execute("Hello", "World");
189-
assertEquals("Hello World\n", os.toString("UTF-8"));
189+
assertEquals("Hello World\n", out.toString("UTF-8"));
190190

191191
source = "def bar(a, b):\n" +
192192
" foo(a, b)\n" +
193193
"bar";
194194
script = Source.create("python", source);
195195
Value bar = context.eval(script);
196196
bar.execute("Hello", "World");
197-
assertEquals("Hello World\nHello World\n", os.toString("UTF-8"));
197+
assertEquals("Hello World\nHello World\n", out.toString("UTF-8"));
198198

199199
source = "invalid syntax";
200200
script = Source.create("python", source);
@@ -203,9 +203,9 @@ public void testMultipleInvocationsAreInSameScope() throws Exception {
203203
} catch (Throwable t) {
204204
}
205205
bar.execute("Hello", "World");
206-
assertEquals("Hello World\nHello World\nHello World\n", os.toString("UTF-8"));
206+
assertEquals("Hello World\nHello World\nHello World\n", out.toString("UTF-8"));
207207
foo.execute("Hello", "World");
208-
assertEquals("Hello World\nHello World\nHello World\nHello World\n", os.toString("UTF-8"));
208+
assertEquals("Hello World\nHello World\nHello World\nHello World\n", out.toString("UTF-8"));
209209
}
210210

211211
@Test
@@ -335,4 +335,101 @@ public void tryInvokeThenReadExecute() {
335335
assert result[0].equals(ForeignObjectWithOOInvoke.class.getName());
336336
assert result[1].equals(ForeignObjectWithoutOOInvoke.class.getName());
337337
}
338+
339+
public class JavaObject {
340+
public byte byteValue = 1;
341+
public short shortValue = 2;
342+
public int intValue = 3;
343+
public long longValue = 4;
344+
public float floatValue = 5;
345+
public double doubleValue = 6;
346+
public boolean booleanValue = true;
347+
public char charValue = 'c';
348+
349+
public byte getByteValue() {
350+
return byteValue;
351+
}
352+
353+
public short getShortValue() {
354+
return shortValue;
355+
}
356+
357+
public int getIntValue() {
358+
return intValue;
359+
}
360+
361+
public long getLongValue() {
362+
return longValue;
363+
}
364+
365+
public float getFloatValue() {
366+
return floatValue;
367+
}
368+
369+
public double getDoubleValue() {
370+
return doubleValue;
371+
}
372+
373+
public boolean getBooleanValue() {
374+
return booleanValue;
375+
}
376+
377+
public char getCharValue() {
378+
return charValue;
379+
}
380+
}
381+
382+
@Test
383+
public void accessJavaObjectFields() throws IOException {
384+
Source suitePy = Source.newBuilder("python", "" +
385+
"def foo(obj):\n" +
386+
" print(obj.byteValue, type(obj.byteValue))\n" +
387+
" print(obj.shortValue, type(obj.shortValue))\n" +
388+
" print(obj.intValue, type(obj.intValue))\n" +
389+
" print(obj.longValue, type(obj.longValue))\n" +
390+
" print(obj.floatValue, type(obj.floatValue))\n" +
391+
" print(obj.doubleValue, type(obj.doubleValue))\n" +
392+
" print(obj.booleanValue, type(obj.booleanValue))\n" +
393+
" print(obj.charValue, type(obj.charValue))\n" +
394+
"foo",
395+
"suite.py").build();
396+
Value foo = context.eval(suitePy);
397+
foo.execute(new JavaObject());
398+
assertEquals("" +
399+
"1 <class 'int'>\n" +
400+
"2 <class 'int'>\n" +
401+
"3 <class 'int'>\n" +
402+
"4 <class 'int'>\n" +
403+
"5.0 <class 'float'>\n" +
404+
"6.0 <class 'float'>\n" +
405+
"True <class 'bool'>\n" +
406+
"c <class 'str'>\n", out.toString("UTF-8"));
407+
}
408+
409+
@Test
410+
public void accessJavaObjectGetters() throws IOException {
411+
Source suitePy = Source.newBuilder("python", "" +
412+
"def foo(obj):\n" +
413+
" print(obj.getByteValue(), type(obj.getByteValue()))\n" +
414+
" print(obj.getShortValue(), type(obj.getShortValue()))\n" +
415+
" print(obj.getIntValue(), type(obj.getIntValue()))\n" +
416+
" print(obj.getLongValue(), type(obj.getLongValue()))\n" +
417+
" print(obj.getFloatValue(), type(obj.getFloatValue()))\n" +
418+
" print(obj.getDoubleValue(), type(obj.getDoubleValue()))\n" +
419+
" print(obj.getBooleanValue(), type(obj.getBooleanValue()))\n" +
420+
" print(obj.getCharValue(), type(obj.getCharValue()))\n" +
421+
"foo",
422+
"suite.py").build();
423+
Value foo = context.eval(suitePy);
424+
foo.execute(new JavaObject());
425+
assertEquals("" +
426+
"1 <class 'int'>\n" +
427+
"2 <class 'int'>\n" +
428+
"3 <class 'int'>\n" +
429+
"4 <class 'int'>\n" +
430+
"5.0 <class 'float'>\n" +
431+
"6.0 <class 'float'>\n" +
432+
"True <class 'bool'>\n" +
433+
"c <class 'str'>\n", out.toString("UTF-8"));
434+
}
338435
}

0 commit comments

Comments
 (0)