Skip to content

Commit dc150c2

Browse files
committed
[GR-28410] Fixes for test_re
PullRequest: graalpython/1604
2 parents fb2a310 + e1928f1 commit dc150c2

File tree

4 files changed

+132
-205
lines changed

4 files changed

+132
-205
lines changed

graalpython/com.oracle.graal.python.test/src/graalpytest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
# test_compileall tries to recompile the whole PYTHONPATH, which makes it interfere with any test that
5555
# creates temporary py files
5656
'test_compileall',
57+
# test_import tests various behaviors related to __pycache__ directory,
58+
# it can interfere with other tests that generate code
59+
'test_import',
5760
]
5861

5962

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_re.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*graalpython.lib-python.3.test.test_re.PatternReprTests.test_multiple_flags
77
*graalpython.lib-python.3.test.test_re.PatternReprTests.test_quotes
88
*graalpython.lib-python.3.test.test_re.PatternReprTests.test_single_flag
9+
*graalpython.lib-python.3.test.test_re.PatternReprTests.test_unicode_flag
910
*graalpython.lib-python.3.test.test_re.PatternReprTests.test_unknown_flags
1011
*graalpython.lib-python.3.test.test_re.PatternReprTests.test_without_flags
1112
*graalpython.lib-python.3.test.test_re.ReTests.test_anyall
@@ -54,10 +55,13 @@
5455
*graalpython.lib-python.3.test.test_re.ReTests.test_large_subn
5556
*graalpython.lib-python.3.test.test_re.ReTests.test_lookahead
5657
*graalpython.lib-python.3.test.test_re.ReTests.test_lookbehind
58+
*graalpython.lib-python.3.test.test_re.ReTests.test_match_getitem
5759
*graalpython.lib-python.3.test.test_re.ReTests.test_multiple_repeat
5860
*graalpython.lib-python.3.test.test_re.ReTests.test_not_literal
5961
*graalpython.lib-python.3.test.test_re.ReTests.test_nothing_to_repeat
6062
*graalpython.lib-python.3.test.test_re.ReTests.test_other_escapes
63+
*graalpython.lib-python.3.test.test_re.ReTests.test_pattern_compare
64+
*graalpython.lib-python.3.test.test_re.ReTests.test_pattern_compare_bytes
6165
*graalpython.lib-python.3.test.test_re.ReTests.test_pickling
6266
*graalpython.lib-python.3.test.test_re.ReTests.test_qualified_re_split
6367
*graalpython.lib-python.3.test.test_re.ReTests.test_qualified_re_sub
@@ -67,6 +71,8 @@
6771
*graalpython.lib-python.3.test.test_re.ReTests.test_re_escape_non_ascii_bytes
6872
*graalpython.lib-python.3.test.test_re.ReTests.test_re_findall
6973
*graalpython.lib-python.3.test.test_re.ReTests.test_re_groupref_exists
74+
*graalpython.lib-python.3.test.test_re.ReTests.test_re_groupref_overflow
75+
*graalpython.lib-python.3.test.test_re.ReTests.test_re_match
7076
*graalpython.lib-python.3.test.test_re.ReTests.test_re_split
7177
*graalpython.lib-python.3.test.test_re.ReTests.test_re_subn
7278
*graalpython.lib-python.3.test.test_re.ReTests.test_repeat_minmax_overflow_maxrepeat
@@ -76,6 +82,8 @@
7682
*graalpython.lib-python.3.test.test_re.ReTests.test_search_star_plus
7783
*graalpython.lib-python.3.test.test_re.ReTests.test_special_escapes
7884
*graalpython.lib-python.3.test.test_re.ReTests.test_stack_overflow
85+
*graalpython.lib-python.3.test.test_re.ReTests.test_sub_template_numeric_escape
7986
*graalpython.lib-python.3.test.test_re.ReTests.test_symbolic_groups
87+
*graalpython.lib-python.3.test.test_re.ReTests.test_symbolic_refs
8088
*graalpython.lib-python.3.test.test_re.ReTests.test_unlimited_zero_width_repeat
8189
*graalpython.lib-python.3.test.test_re.ReTests.test_weakref

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

Lines changed: 0 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -44,38 +44,27 @@
4444
import static com.oracle.graal.python.runtime.exception.PythonErrorType.ValueError;
4545

4646
import java.io.UnsupportedEncodingException;
47-
import java.nio.charset.StandardCharsets;
4847
import java.util.List;
4948

5049
import com.oracle.graal.python.PythonLanguage;
5150
import com.oracle.graal.python.builtins.Builtin;
5251
import com.oracle.graal.python.builtins.CoreFunctions;
5352
import com.oracle.graal.python.builtins.PythonBuiltins;
54-
import com.oracle.graal.python.builtins.objects.bytes.BytesUtils;
55-
import com.oracle.graal.python.builtins.objects.bytes.PBytesLike;
56-
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodes;
57-
import com.oracle.graal.python.builtins.objects.common.SequenceStorageNodesFactory.ToByteArrayNodeGen;
5853
import com.oracle.graal.python.builtins.objects.function.PFunction;
5954
import com.oracle.graal.python.builtins.objects.object.PythonObjectLibrary;
60-
import com.oracle.graal.python.builtins.objects.str.PString;
61-
import com.oracle.graal.python.nodes.ErrorMessages;
6255
import com.oracle.graal.python.nodes.call.CallNode;
6356
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
6457
import com.oracle.graal.python.nodes.function.builtins.PythonTernaryBuiltinNode;
65-
import com.oracle.graal.python.nodes.function.builtins.PythonUnaryBuiltinNode;
6658
import com.oracle.graal.python.nodes.truffle.PythonArithmeticTypes;
6759
import com.oracle.graal.python.nodes.util.CastToJavaStringNode;
6860
import com.oracle.graal.python.runtime.ExecutionContext.IndirectCallContext;
6961
import com.oracle.graal.python.runtime.PythonContext;
7062
import com.oracle.graal.python.runtime.PythonCore;
7163
import com.oracle.graal.python.runtime.PythonOptions;
72-
import com.oracle.graal.python.runtime.exception.PythonErrorType;
73-
import com.oracle.truffle.api.CompilerAsserts;
7464
import com.oracle.truffle.api.CompilerDirectives;
7565
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
7666
import com.oracle.truffle.api.dsl.Cached;
7767
import com.oracle.truffle.api.dsl.CachedContext;
78-
import com.oracle.truffle.api.dsl.Fallback;
7968
import com.oracle.truffle.api.dsl.GenerateNodeFactory;
8069
import com.oracle.truffle.api.dsl.NodeFactory;
8170
import com.oracle.truffle.api.dsl.Specialization;
@@ -105,79 +94,6 @@ public void initialize(PythonCore core) {
10594
super.initialize(core);
10695
}
10796

108-
/**
109-
* Replaces any <it>quoted</it> escape sequence like {@code "\\n"} (two characters; backslash +
110-
* 'n') by its single character like {@code "\n"} (one character; newline).
111-
*/
112-
@Builtin(name = "_process_escape_sequences", minNumOfPositionalArgs = 1)
113-
@GenerateNodeFactory
114-
abstract static class ProcessEscapeSequences extends PythonUnaryBuiltinNode {
115-
116-
@Child private SequenceStorageNodes.ToByteArrayNode toByteArrayNode;
117-
118-
@Specialization
119-
Object run(PString str) {
120-
return run(str.getValue());
121-
}
122-
123-
@Specialization
124-
@TruffleBoundary(transferToInterpreterOnException = false, allowInlining = true)
125-
Object run(String str) {
126-
if (containsBackslash(str)) {
127-
StringBuilder sb = BytesUtils.decodeEscapes(getCore(), str, true);
128-
return sb.toString();
129-
}
130-
return str;
131-
}
132-
133-
@Specialization
134-
Object run(PBytesLike str) {
135-
byte[] bytes = doBytes(getToByteArrayNode().execute(str.getSequenceStorage()));
136-
return factory().createByteArray(bytes);
137-
}
138-
139-
@Specialization(guards = "bufferLib.isBuffer(buffer)", limit = "3")
140-
Object run(Object buffer,
141-
@CachedLibrary("buffer") PythonObjectLibrary bufferLib) {
142-
byte[] bytes;
143-
try {
144-
bytes = bufferLib.getBufferBytes(buffer);
145-
} catch (UnsupportedMessageException e) {
146-
throw CompilerDirectives.shouldNotReachHere();
147-
}
148-
return factory().createByteArray(bytes);
149-
}
150-
151-
@TruffleBoundary(transferToInterpreterOnException = false, allowInlining = true)
152-
private byte[] doBytes(byte[] str) {
153-
StringBuilder sb = BytesUtils.decodeEscapes(getCore(), new String(str, StandardCharsets.US_ASCII), true);
154-
return sb.toString().getBytes(StandardCharsets.US_ASCII);
155-
}
156-
157-
private static boolean containsBackslash(String str) {
158-
CompilerAsserts.neverPartOfCompilation();
159-
for (int i = 0; i < str.length(); i++) {
160-
if (str.charAt(i) == '\\') {
161-
return true;
162-
}
163-
}
164-
return false;
165-
}
166-
167-
@Fallback
168-
Object run(Object o) {
169-
throw raise(PythonErrorType.TypeError, ErrorMessages.EXPECTED_S_NOT_P, "string", o);
170-
}
171-
172-
private SequenceStorageNodes.ToByteArrayNode getToByteArrayNode() {
173-
if (toByteArrayNode == null) {
174-
CompilerDirectives.transferToInterpreterAndInvalidate();
175-
toByteArrayNode = insert(ToByteArrayNodeGen.create());
176-
}
177-
return toByteArrayNode;
178-
}
179-
}
180-
18197
abstract static class ToRegexSourceNode extends Node {
18298

18399
public abstract Source execute(Object pattern, String flags);

0 commit comments

Comments
 (0)