Skip to content

Commit 0cedba0

Browse files
committed
Merge branch 'master'
2 parents 216747c + 66c2d7b commit 0cedba0

File tree

213 files changed

+3717
-1825
lines changed

Some content is hidden

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

213 files changed

+3717
-1825
lines changed

ci.jsonnet

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{ "overlay": "6d065be2f57c39d4637e1091d7c89d3afde6827c" }
1+
{ "overlay": "3c6f644a6a6c7d27bae5b0d82445818549a83175" }

graalpython/com.oracle.graal.python.benchmarks/java/com/oracle/graal/python/benchmarks/parser/ParserBenchRunner.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import com.oracle.graal.python.parser.PythonParserImpl;
4747
import com.oracle.graal.python.parser.PythonSSTNodeFactory;
4848
import com.oracle.graal.python.runtime.PythonContext;
49-
import com.oracle.graal.python.runtime.PythonCore;
49+
import com.oracle.graal.python.builtins.Python3Core;
5050
import com.oracle.graal.python.runtime.PythonParser;
5151
import com.oracle.truffle.api.TruffleFile;
5252
import com.oracle.truffle.api.source.Source;
@@ -98,7 +98,7 @@ public class ParserBenchRunner {
9898

9999
protected final PythonContext pyContext;
100100
protected final PythonParserImpl parser;
101-
protected final PythonCore core;
101+
protected final Python3Core core;
102102
private List<Source> sources;
103103

104104
public ParserBenchRunner() {

graalpython/com.oracle.graal.python.cext/include/cpython/abstract.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ _PyObject_FastCall(PyObject *func, PyObject *const *args, Py_ssize_t nargs)
155155
/* Call a callable without any arguments */
156156
static inline PyObject *
157157
_PyObject_CallNoArg(PyObject *func) {
158-
return _PyObject_Vectorcall(func, NULL, 0, NULL);
158+
return PyObject_CallObject(func, NULL); /* Truffle change: redirect to PyObject_CallObject until _PyObject_Vectorcall is implemented */
159159
}
160160

161161
PyAPI_FUNC(PyObject *) _PyObject_Call_Prepend(

graalpython/com.oracle.graal.python.cext/setup.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@
5858
libhpy_name = "libhpy"
5959
libposix_name = "libposix"
6060

61+
MACOS = sys.platform == "darwin"
6162
verbosity = '--verbose' if sys.flags.verbose else '--quiet'
62-
darwin_native = sys.platform == "darwin" and __graalpython__.platform_id == "native"
63+
darwin_native = MACOS and __graalpython__.platform_id == "native"
6364
relative_rpath = "@loader_path" if darwin_native else r"$ORIGIN"
6465
so_ext = get_config_var("EXT_SUFFIX")
6566
SOABI = get_config_var("SOABI")
6667
is_managed = 'managed' in SOABI
67-
lib_ext = 'dylib' if sys.platform == "darwin" else 'so'
68+
lib_ext = 'dylib' if MACOS else 'so'
6869

6970
# configure logger
7071
logger = logging.getLogger(__name__)
@@ -361,6 +362,8 @@ def __init__(self, name, subdir="modules", files=None, deps=[], **kwargs):
361362
# common case: just a single file which is the module's name plus the file extension
362363
if not files:
363364
self.files = [name + ".c"]
365+
else:
366+
self.files = files
364367
self.kwargs = kwargs
365368

366369
def __call__(self):

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ PyObject* PyDict_GetItemWithError(PyObject* d, PyObject* k) {
6767
return UPCALL_CEXT_BORROWED(_jls_PyDict_GetItemWithError, native_to_java(d), native_to_java(k));
6868
}
6969

70+
PyObject *
71+
_PyDict_GetItemIdWithError(PyObject *dp, struct _Py_Identifier *key)
72+
{
73+
PyObject *kv;
74+
kv = _PyUnicode_FromId(key); /* borrowed */
75+
if (kv == NULL)
76+
return NULL;
77+
return PyDict_GetItemWithError(dp, kv);
78+
}
79+
7080
PyObject* _PyDict_GetItemId(PyObject* d, _Py_Identifier* id) {
7181
return PyDict_GetItemString(d, id->string);
7282
}

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

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,68 @@ PyObject * PyObject_GetAttr(PyObject *v, PyObject *name) {
433433
return NULL;
434434
}
435435

436+
// taken from CPython "Objects/object.c"
437+
int _PyObject_LookupAttr(PyObject *v, PyObject *name, PyObject **result)
438+
{
439+
PyTypeObject *tp = Py_TYPE(v);
440+
441+
if (!PyUnicode_Check(name)) {
442+
PyErr_Format(PyExc_TypeError,
443+
"attribute name must be string, not '%.200s'",
444+
name->ob_type->tp_name);
445+
*result = NULL;
446+
return -1;
447+
}
448+
449+
/* Truffle change: this fast path is only applicable to cpython
450+
if (tp->tp_getattro == PyObject_GenericGetAttr) {
451+
*result = _PyObject_GenericGetAttrWithDict(v, name, NULL, 1);
452+
if (*result != NULL) {
453+
return 1;
454+
}
455+
if (PyErr_Occurred()) {
456+
return -1;
457+
}
458+
return 0;
459+
}
460+
*/
461+
if (tp->tp_getattro != NULL) {
462+
*result = (*tp->tp_getattro)(v, name);
463+
}
464+
else if (tp->tp_getattr != NULL) {
465+
const char *name_str = PyUnicode_AsUTF8(name);
466+
if (name_str == NULL) {
467+
*result = NULL;
468+
return -1;
469+
}
470+
*result = (*tp->tp_getattr)(v, (char *)name_str);
471+
}
472+
else {
473+
*result = NULL;
474+
return 0;
475+
}
476+
477+
if (*result != NULL) {
478+
return 1;
479+
}
480+
if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
481+
return -1;
482+
}
483+
PyErr_Clear();
484+
return 0;
485+
}
486+
487+
// taken from CPython "Objects/object.c"
488+
int _PyObject_LookupAttrId(PyObject *v, _Py_Identifier *name, PyObject **result)
489+
{
490+
PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
491+
if (!oname) {
492+
*result = NULL;
493+
return -1;
494+
}
495+
return _PyObject_LookupAttr(v, oname, result);
496+
}
497+
436498
UPCALL_ID(PyObject_GenericGetAttr);
437499
PyObject* PyObject_GenericGetAttr(PyObject* obj, PyObject* attr) {
438500
PyTypeObject *tp = Py_TYPE(obj);
@@ -486,6 +548,17 @@ int PyObject_SetAttr(PyObject *v, PyObject *name, PyObject *value) {
486548
return -1;
487549
}
488550

551+
// taken from CPython "Objects/object.c"
552+
int _PyObject_SetAttrId(PyObject *v, _Py_Identifier *name, PyObject *w)
553+
{
554+
int result;
555+
PyObject *oname = _PyUnicode_FromId(name); /* borrowed */
556+
if (!oname)
557+
return -1;
558+
result = PyObject_SetAttr(v, oname, w);
559+
return result;
560+
}
561+
489562
UPCALL_ID(PyObject_GenericSetAttr);
490563
int PyObject_GenericSetAttr(PyObject* obj, PyObject* attr, PyObject* value) {
491564
PyTypeObject *tp = Py_TYPE(obj);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,8 +486,8 @@ int PyType_Ready(PyTypeObject* cls) {
486486
} else {
487487
bases = PyTuple_Pack(1, base);
488488
}
489+
cls->tp_bases = bases;
489490
}
490-
cls->tp_bases = bases;
491491

492492
/* Initialize tp_dict */
493493
PyObject* dict = cls->tp_dict;

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,10 @@ protected List<String> preprocessArguments(List<String> givenArgs, Map<String, S
143143
inspectFlag = true;
144144
break;
145145
case "-m":
146-
if (i + 1 < arguments.size()) {
147-
// don't increment i here so that we capture the correct args
148-
String module = arguments.get(i + 1);
146+
programArgs.add(arg);
147+
i++;
148+
if (i < arguments.size()) {
149+
String module = arguments.get(i);
149150
commandString = "import runpy; runpy._run_module_as_main('" + module + "')";
150151
} else {
151152
print("Argument expected for the -m option");

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/advance/CustomModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import com.oracle.graal.python.builtins.CoreFunctions;
4747
import com.oracle.graal.python.builtins.PythonBuiltins;
4848
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
49-
import com.oracle.graal.python.runtime.PythonCore;
49+
import com.oracle.graal.python.builtins.Python3Core;
5050
import com.oracle.truffle.api.dsl.NodeFactory;
5151

5252
@CoreFunctions(defineModule = "CustomModule")
@@ -58,7 +58,7 @@ protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFa
5858
}
5959

6060
@Override
61-
public void initialize(PythonCore core) {
61+
public void initialize(Python3Core core) {
6262
super.initialize(core);
6363
this.builtinConstants.put("success", "success");
6464
}

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/parser/GeneratorAndCompForTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,29 @@ public void dictCompr() throws Exception {
349349
public void genExpr() throws Exception {
350350
checkScopeAndTree("(i for i in range(3))");
351351
}
352+
353+
@Test
354+
public void genExpr01() throws Exception {
355+
checkScopeAndTree("[ (c,s) for c in ('a','b') for s in (1,2,3,4,5)]");
356+
}
357+
358+
@Test
359+
public void genExpr02() throws Exception {
360+
checkScopeAndTree("[ (s,c) for c in ('a','b') for s in (1,2,3,4,5)]");
361+
}
362+
363+
@Test
364+
public void genExpr03() throws Exception {
365+
checkScopeAndTree("(e+1 for e in (i*2 for i in (1,2,3)))");
366+
}
367+
368+
@Test
369+
public void issueGitHub_42_v1() throws Exception {
370+
checkScopeAndTree("[e for e in (s for s in (1, 2, 3))]");
371+
}
372+
373+
@Test
374+
public void issueGitHub_42_v2() throws Exception {
375+
checkScopeAndTree("[e for e in [s for s in (1, 2, 3)]]");
376+
}
352377
}

0 commit comments

Comments
 (0)