Skip to content

Commit e5eb12b

Browse files
committed
Pass pattern to error as str/bytes, not as Pattern
1 parent 5f92d33 commit e5eb12b

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ public String getTRegexOption() {
161161

162162
public static final class TRegexCache {
163163

164+
private final Object originalPattern;
164165
private final String pattern;
165166
private final String flags;
166167
private final boolean binary;
@@ -193,6 +194,7 @@ public static final class TRegexCache {
193194

194195
@TruffleBoundary
195196
public TRegexCache(Object pattern, int flags) {
197+
this.originalPattern = pattern;
196198
String patternStr;
197199
boolean binary = true;
198200
try {
@@ -379,7 +381,7 @@ private String getTRegexOptions(String encoding, PythonMethod pythonMethod, bool
379381
}
380382

381383
@TruffleBoundary
382-
public Object compile(PythonContext context, Object patternObject, PythonMethod method, boolean mustAdvance, TruffleString locale) {
384+
public Object compile(PythonContext context, PythonMethod method, boolean mustAdvance, TruffleString locale) {
383385
String encoding = isBinary() ? ENCODING_LATIN_1 : ENCODING_UTF_32;
384386
String options = getTRegexOptions(encoding, method, mustAdvance, locale);
385387
InteropLibrary lib = InteropLibrary.getUncached();
@@ -393,7 +395,7 @@ public Object compile(PythonContext context, Object patternObject, PythonMethod
393395
regexp = compiledRegex;
394396
}
395397
} catch (RuntimeException e) {
396-
throw handleCompilationError(e, patternObject, lib, context);
398+
throw handleCompilationError(e, lib, context);
397399
}
398400
if (isLocaleSensitive()) {
399401
setLocaleSensitiveRegexp(method, mustAdvance, locale, regexp);
@@ -403,7 +405,7 @@ public Object compile(PythonContext context, Object patternObject, PythonMethod
403405
return regexp;
404406
}
405407

406-
private static RuntimeException handleCompilationError(RuntimeException e, Object patternObject, InteropLibrary lib, PythonContext context) {
408+
private RuntimeException handleCompilationError(RuntimeException e, InteropLibrary lib, PythonContext context) {
407409
try {
408410
if (lib.isException(e)) {
409411
if (lib.getExceptionType(e) == ExceptionType.PARSE_ERROR) {
@@ -418,7 +420,7 @@ private static RuntimeException handleCompilationError(RuntimeException e, Objec
418420
int position = sourceSection.getCharIndex();
419421
PythonModule module = context.lookupBuiltinModule(BuiltinNames.T__SRE);
420422
Object errorConstructor = PyObjectLookupAttr.getUncached().execute(null, module, T_ERROR);
421-
PBaseException exception = (PBaseException) CallNode.getUncached().execute(errorConstructor, reason, patternObject, position);
423+
PBaseException exception = (PBaseException) CallNode.getUncached().execute(errorConstructor, reason, originalPattern, position);
422424
return PRaiseNode.getUncached().raiseExceptionObject(exception);
423425
}
424426
}
@@ -508,7 +510,7 @@ Object localeNonSensitive(Object pattern, PythonMethod method, boolean mustAdvan
508510
if (tRegex != null) {
509511
return tRegex;
510512
} else {
511-
return tRegexCache.compile(getContext(), pattern, method, mustAdvance, null);
513+
return tRegexCache.compile(getContext(), method, mustAdvance, null);
512514
}
513515
}
514516

@@ -525,7 +527,7 @@ Object localeSensitive(Object pattern, PythonMethod method, boolean mustAdvance,
525527
if (tRegex != null) {
526528
return tRegex;
527529
} else {
528-
return tRegexCache.compile(getContext(), pattern, method, mustAdvance, locale);
530+
return tRegexCache.compile(getContext(), method, mustAdvance, locale);
529531
}
530532
}
531533

0 commit comments

Comments
 (0)