Skip to content

Commit 3efa357

Browse files
author
Franziska Geiger
committed
[GR-17472][GR-17471][GR-17470] Multiple little fixes to run Cython
PullRequest: graalpython/602
2 parents ed39066 + bba205e commit 3efa357

File tree

7 files changed

+70
-26
lines changed

7 files changed

+70
-26
lines changed

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -486,10 +486,23 @@ def as_utf8_string(self):
486486
return bytes_literal(self.utf8encode(), 'utf8')
487487

488488

489-
def test_wrapped_string_contains():
490-
testString = EncodedString('something')
489+
def test_wrapped_string_contains1():
490+
test_string = EncodedString('something')
491491
dict = {'something': (1, 0), 'nothing': (2, 0)}
492492
reached = False
493-
if testString in dict:
493+
if test_string in dict:
494494
reached = True
495495
assert reached
496+
497+
def test_wrapped_string_contains2():
498+
test_string = EncodedString('something')
499+
dict = {'something', 'nothing'}
500+
reached = False
501+
if test_string in dict:
502+
reached = True
503+
assert reached
504+
505+
def test_wrapped_string_get():
506+
a = 'test'
507+
dict = locals()
508+
assert dict['a']

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesBuiltins.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
import com.oracle.graal.python.nodes.function.builtins.PythonBinaryBuiltinNode;
6666
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
6767
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
68+
import com.oracle.graal.python.nodes.util.CastToIndexNode;
6869
import com.oracle.graal.python.runtime.exception.PythonErrorType;
6970
import com.oracle.graal.python.runtime.sequence.storage.ByteSequenceStorage;
7071
import com.oracle.graal.python.runtime.sequence.storage.SequenceStorage;
@@ -291,6 +292,14 @@ public Object mul(PBytes self, int times,
291292
return factory().createBytes(res);
292293
}
293294

295+
@Specialization
296+
public Object mul(PBytes self, Object times,
297+
@Cached("create()") SequenceStorageNodes.RepeatNode repeatNode,
298+
@Cached("create()") CastToIndexNode castToInt) {
299+
SequenceStorage res = repeatNode.execute(self.getSequenceStorage(), castToInt.execute(times));
300+
return factory().createBytes(res);
301+
}
302+
294303
@SuppressWarnings("unused")
295304
@Fallback
296305
public Object mul(Object self, Object other) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/common/HashingStorageNodes.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -516,12 +516,19 @@ protected boolean contains(EmptyStorage storage, Object key) {
516516

517517
@Specialization(guards = "isHashable(frame, key)")
518518
protected boolean contains(@SuppressWarnings("unused") VirtualFrame frame, KeywordsStorage storage, Object key,
519-
@Cached("createClassProfile()") ValueProfile keyTypeProfile) {
519+
@Cached("createClassProfile()") ValueProfile keyTypeProfile,
520+
@Cached LookupInheritedAttributeNode.Dynamic lookupHash,
521+
@Cached LookupAttributeInMRONode.Dynamic lookupStringHash) {
520522
Object profileKey = keyTypeProfile.profile(key);
521523
if (profileKey instanceof String) {
522524
return storage.hasKey(profileKey, DEFAULT_EQIVALENCE);
523-
} else if (profileKey instanceof PString && wrappedString((PString) profileKey)) {
524-
return storage.hasKey(((PString) profileKey).getValue(), DEFAULT_EQIVALENCE);
525+
} else if (profileKey instanceof PString) {
526+
if (wrappedString((PString) profileKey) || lookupHash.execute(key, __HASH__) == lookupStringHash.execute(PythonBuiltinClassType.PString, __HASH__)) {
527+
return storage.hasKey(((PString) profileKey).getValue(), DEFAULT_EQIVALENCE);
528+
}
529+
CompilerDirectives.transferToInterpreter();
530+
// see GR-17389
531+
throw new RuntimeException("String subclasses with custom hash in dict not implemented.");
525532
}
526533
return false;
527534
}
@@ -626,6 +633,11 @@ protected boolean contains(VirtualFrame frame, HashMapStorage storage, Object ke
626633
}
627634
}
628635

636+
@Specialization(guards = "isHashable(frame, key)")
637+
protected boolean contains(@SuppressWarnings("unused") VirtualFrame frame, LocalsStorage storage, PString key) {
638+
return storage.hasKey(key.getValue(), HashingStorage.DEFAULT_EQIVALENCE);
639+
}
640+
629641
@Specialization(guards = "isHashable(frame, key)")
630642
protected boolean contains(@SuppressWarnings("unused") VirtualFrame frame, LocalsStorage storage, Object key) {
631643
return storage.hasKey(key, HashingStorage.DEFAULT_EQIVALENCE);
@@ -870,7 +882,7 @@ protected HashingStorage doKeywordsGeneralize(VirtualFrame frame, KeywordsStorag
870882
newStorage.addAll(storage, getEquivalence());
871883
newStorage.setItem(key, value, getEquivalence());
872884
}
873-
return storage;
885+
return newStorage;
874886
}
875887

876888
@Specialization(guards = "isHashable(frame, key)")
@@ -1185,6 +1197,19 @@ Object doLocalsString(LocalsStorage storage, PString key) {
11851197
return storage.getItem(key.getValue(), DEFAULT_EQIVALENCE);
11861198
}
11871199

1200+
@Specialization(guards = {"!isJavaString(key)", "isHashable(frame, key)"})
1201+
Object doLocalsObject(VirtualFrame frame, LocalsStorage storage, PString key,
1202+
@Cached LookupInheritedAttributeNode.Dynamic lookupHash,
1203+
@Cached LookupAttributeInMRONode.Dynamic lookupStringHash,
1204+
@Cached GetItemNode recursiveNode) {
1205+
if (lookupHash.execute(key, __HASH__) == lookupStringHash.execute(PythonBuiltinClassType.PString, __HASH__)) {
1206+
return recursiveNode.execute(frame, storage, key.getValue());
1207+
}
1208+
CompilerDirectives.transferToInterpreter();
1209+
// see GR-17389
1210+
throw new RuntimeException("String subclasses with custom hash in dict not implemented.");
1211+
}
1212+
11881213
@Specialization(guards = {"!isJavaString(key)", "isHashable(frame, key)"})
11891214
@SuppressWarnings("unused")
11901215
Object doLocalsObject(VirtualFrame frame, LocalsStorage storage, Object key) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/formatting/StringFormatter.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,8 @@ private static Object asNumber(Object arg, CallNode callNode, BiFunction<Object,
123123
} else if (arg instanceof Double) {
124124
// A common case where it is safe to return arg.__int__()
125125
return ((Double) arg).intValue();
126+
} else if (arg instanceof Boolean) {
127+
return (Boolean) arg ? 1 : 0;
126128
} else if (arg instanceof PFloat) {
127129
return (int) ((PFloat) arg).getValue();
128130
} else if (arg instanceof PythonAbstractObject) {

mx.graalpython/mx_graalpython.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
import shutil
3232
import sys
3333
import tempfile
34-
import time
3534
from argparse import ArgumentParser
3635

3736
import mx
@@ -1041,13 +1040,13 @@ def python_build_watch(args):
10411040
if sum([args.full, args.graalvm, args.no_java]) > 1:
10421041
mx.abort("Only one of --full, --graalvm, --no-java can be specified")
10431042
if args.full:
1044-
suffixes = [".c", ".h", ".class", ".jar", ".java"]
1043+
# suffixes = [".c", ".h", ".class", ".jar", ".java"]
10451044
excludes = [".*\\.py$"]
10461045
elif args.graalvm:
1047-
suffixes = [".c", ".h", ".class", ".jar", ".java", ".py"]
1046+
# suffixes = [".c", ".h", ".class", ".jar", ".java", ".py"]
10481047
excludes = ["mx_.*\\.py$"]
10491048
else:
1050-
suffixes = [".c", ".h", ".class", ".jar"]
1049+
# suffixes = [".c", ".h", ".class", ".jar"]
10511050
excludes = [".*\\.py$", ".*\\.java$"]
10521051

10531052
cmd = ["inotifywait", "-q", "-e", "close_write,moved_to", "-r", "--format=%f"]

mx.graalpython/mx_graalpython_benchmark.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
# OF THE POSSIBILITY OF SUCH DAMAGE.
2424
from __future__ import print_function
2525

26-
import argparse
2726
import os
2827
import re
2928
from abc import ABCMeta, abstractproperty, abstractmethod

mx.graalpython/suite.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,14 @@
9191
],
9292
"sha1": "7a5960b8062ddbf0c0e79f806e23785d55fec3c8",
9393
},
94-
"XZ-1.8" : {
95-
"sha1" : "c4f7d054303948eb6a4066194253886c8af07128",
96-
"maven" : {
97-
"groupId" : "org.tukaani",
98-
"artifactId" : "xz",
99-
"version" : "1.8",
100-
},
101-
},
102-
94+
"XZ-1.8": {
95+
"sha1": "c4f7d054303948eb6a4066194253886c8af07128",
96+
"maven": {
97+
"groupId": "org.tukaani",
98+
"artifactId": "xz",
99+
"version": "1.8",
100+
},
101+
},
103102

104103
},
105104

@@ -160,7 +159,6 @@
160159
},
161160
},
162161

163-
164162
"projects": {
165163
# GRAALPYTHON ANTLR
166164
"com.oracle.graal.python.parser.antlr": {
@@ -204,11 +202,11 @@
204202
],
205203
"buildDependencies": ["com.oracle.graal.python.parser.antlr"],
206204
"jacoco": "include",
207-
"javaCompliance" : "8+",
208-
"checkstyleVersion" : "8.8",
205+
"javaCompliance": "8+",
206+
"checkstyleVersion": "8.8",
209207
"annotationProcessors": ["truffle:TRUFFLE_DSL_PROCESSOR"],
210208
"workingSets": "Truffle,Python",
211-
"spotbugsIgnoresGenerated" : True,
209+
"spotbugsIgnoresGenerated": True,
212210
},
213211

214212
# GRAALPYTHON TEST
@@ -242,7 +240,6 @@
242240
"testProject": True,
243241
},
244242

245-
246243
"com.oracle.graal.python.cext": {
247244
"subDir": "graalpython",
248245
"native": True,

0 commit comments

Comments
 (0)