Skip to content

Commit f4f181b

Browse files
[GR-74429] Avoid native image analysis problems when embedding GraalPy into certain Micronaut configurations.
PullRequest: graalpython/4340
2 parents ce1d381 + b31aaa3 commit f4f181b

File tree

8 files changed

+35
-21
lines changed

8 files changed

+35
-21
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -44,6 +44,7 @@
4444
import static com.oracle.graal.python.nodes.BuiltinNames.J_FORMATTER_PARSER;
4545
import static com.oracle.graal.python.nodes.BuiltinNames.J__STRING;
4646

47+
import java.util.ArrayList;
4748
import java.util.List;
4849

4950
import com.oracle.graal.python.PythonLanguage;
@@ -87,7 +88,7 @@ protected ArgumentClinicProvider getArgumentClinic() {
8788
PSequenceIterator formatterParser(VirtualFrame frame, TruffleString self,
8889
@Cached("createFor($node)") BoundaryCallData boundaryCallData) {
8990
TemplateFormatter formatter = new TemplateFormatter(self);
90-
List<Object[]> parserList;
91+
ArrayList<Object[]> parserList;
9192
PythonContext context = PythonContext.get(this);
9293
PythonLanguage language = context.getLanguage(this);
9394
Object state = ExecutionContext.BoundaryCallContext.enter(frame, language, context, boundaryCallData);
@@ -100,7 +101,7 @@ PSequenceIterator formatterParser(VirtualFrame frame, TruffleString self,
100101
}
101102
}
102103

103-
private static PSequenceIterator parserListToIterator(List<Object[]> parserList, PythonLanguage language) {
104+
private static PSequenceIterator parserListToIterator(ArrayList<Object[]> parserList, PythonLanguage language) {
104105
Object[] tuples = new Object[parserList.size()];
105106
for (int i = 0; i < tuples.length; i++) {
106107
tuples[i] = PFactory.createTuple(language, parserList.get(i));

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/re/MatchBuiltins.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,18 @@ static Object lastGroup(PMatch self,
595595
return PNone.NONE;
596596
}
597597

598-
for (Map.Entry<String, Object> entry : self.pattern.groupToIndexMap.entrySet()) {
598+
String name = getLastGroupName(self.pattern.groupToIndexMap, groupIndex);
599+
if (name != null) {
600+
return fromJavaStringNode.execute(name, TS_ENCODING);
601+
}
602+
603+
// the last matched group does not have a name
604+
return PNone.NONE;
605+
}
606+
607+
@TruffleBoundary
608+
private static String getLastGroupName(LinkedHashMap<String, Object> groupToIndexMap, int groupIndex) {
609+
for (Map.Entry<String, Object> entry : groupToIndexMap.entrySet()) {
599610
Object value = entry.getValue();
600611

601612
if (!(value instanceof Integer valueInteger)) {
@@ -606,13 +617,10 @@ static Object lastGroup(PMatch self,
606617

607618
if (valueInteger == groupIndex) {
608619
// a named group found
609-
String name = entry.getKey();
610-
return fromJavaStringNode.execute(name, TS_ENCODING);
620+
return entry.getKey();
611621
}
612622
}
613-
614-
// the last matched group does not have a name
615-
return PNone.NONE;
623+
return null;
616624
}
617625
}
618626

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/namespace/SimpleNamespaceBuiltins.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2021, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -204,7 +204,7 @@ abstract static class SimpleNamespaceReprNode extends PythonUnaryBuiltinNode {
204204
@CompilerDirectives.ValueType
205205
protected static final class NSReprState {
206206
private final HashingStorage dictStorage;
207-
private final List<Pair<TruffleString, TruffleString>> items;
207+
private final ArrayList<Pair<TruffleString, TruffleString>> items;
208208

209209
@CompilerDirectives.TruffleBoundary
210210
NSReprState(HashingStorage dictStorage) {

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/str/TemplateFormatter.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363

6464
import java.math.BigInteger;
6565
import java.util.ArrayList;
66-
import java.util.List;
6766

6867
import com.oracle.graal.python.builtins.modules.BuiltinFunctions.FormatNode;
6968
import com.oracle.graal.python.builtins.modules.SysModuleBuiltins;
@@ -91,7 +90,7 @@ public final class TemplateFormatter {
9190
private String empty;
9291
private Object[] args;
9392
private Object keywords;
94-
private List<Object[]> parserList = null;
93+
private ArrayList<Object[]> parserList = null;
9594
private int autoNumbering;
9695
private int autoNumberingState;
9796

@@ -411,9 +410,9 @@ private Object renderField(Node node, int start, int end, boolean recursive, int
411410

412411
public static class FieldNameSplitResult {
413412
public Object first;
414-
public List<Object[]> parserList;
413+
public ArrayList<Object[]> parserList;
415414

416-
public FieldNameSplitResult(Object first, List<Object[]> parserList) {
415+
public FieldNameSplitResult(Object first, ArrayList<Object[]> parserList) {
417416
this.first = first;
418417
this.parserList = parserList;
419418
}
@@ -467,7 +466,7 @@ private static Object convert(Node node, Object obj, char conversion) {
467466
}
468467

469468
@TruffleBoundary
470-
public List<Object[]> formatterParser(Node node) {
469+
public ArrayList<Object[]> formatterParser(Node node) {
471470
this.parserList = new ArrayList<>();
472471
this.lastEnd = 0;
473472
buildString(node, 0, this.template.length(), 2, null);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PosixSupportLibrary.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -912,7 +912,7 @@ public static AddrInfoCursorLibrary getUncached() {
912912
* Exception that indicates and error while executing
913913
* {@link #getaddrinfo(Object, Object, Object, int, int, int, int)}.
914914
*/
915-
public static class GetAddrInfoException extends Exception {
915+
public static final class GetAddrInfoException extends Exception {
916916

917917
private static final long serialVersionUID = 3013253817849329391L;
918918

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PythonContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ public Thread getOwner() {
769769
@CompilationFinal private long perfCounterStart = System.nanoTime();
770770

771771
public static final String CHILD_CONTEXT_DATA = "childContextData";
772-
@CompilationFinal private List<Integer> childContextFDs;
772+
@CompilationFinal private ArrayList<Integer> childContextFDs;
773773
private final ChildContextData childContextData;
774774
private final SharedMultiprocessingData sharedMultiprocessingData;
775775

@@ -1241,7 +1241,7 @@ private static void start(Thread thread) {
12411241
thread.start();
12421242
}
12431243

1244-
public synchronized List<Integer> getChildContextFDs() {
1244+
public synchronized ArrayList<Integer> getChildContextFDs() {
12451245
if (childContextFDs == null) {
12461246
childContextFDs = new ArrayList<>();
12471247
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/PException.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,11 +191,16 @@ public static PException fromExceptionInfo(Object pythonException, boolean withJ
191191
@Override
192192
public String getMessage() {
193193
if (message == null) {
194-
return pythonException.toString();
194+
return getPythonExceptionString();
195195
}
196196
return message;
197197
}
198198

199+
@TruffleBoundary
200+
private String getPythonExceptionString() {
201+
return pythonException.toString();
202+
}
203+
199204
public void materializeMessage() {
200205
if (message == null) {
201206
message = ExceptionUtils.getExceptionMessage(pythonException);

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/exception/PIncompleteSourceException.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2022, 2023, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2022, 2026, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -103,6 +103,7 @@ boolean hasExceptionMessage() {
103103
}
104104

105105
@ExportMessage
106+
@TruffleBoundary
106107
String getExceptionMessage() {
107108
return getMessage();
108109
}

0 commit comments

Comments
 (0)