Skip to content

Commit 2dfee04

Browse files
committed
migrate hpy j.l.String usages to TruffleString
1 parent 2f0872e commit 2dfee04

File tree

8 files changed

+71
-82
lines changed

8 files changed

+71
-82
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/cext/PythonCextTypeBuiltins.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
import com.oracle.truffle.api.dsl.NodeFactory;
6868
import com.oracle.truffle.api.dsl.Specialization;
6969
import com.oracle.truffle.api.frame.VirtualFrame;
70+
import com.oracle.truffle.api.strings.TruffleString;
7071

7172
@CoreFunctions(extendsModule = PythonCextBuiltins.PYTHON_CEXT)
7273
@GenerateNodeFactory
@@ -147,7 +148,7 @@ static int doSlow(VirtualFrame frame, Object derived, Object cls) {
147148
@GenerateNodeFactory
148149
abstract static class PyTruffleCreateType extends PythonQuaternaryBuiltinNode {
149150
@Specialization
150-
static PythonClass createType(VirtualFrame frame, String name, PTuple bases, PDict namespaceOrig, Object metaclass,
151+
static PythonClass createType(VirtualFrame frame, TruffleString name, PTuple bases, PDict namespaceOrig, Object metaclass,
151152
@Cached CreateTypeNode createType) {
152153
return createType.execute(frame, namespaceOrig, name, bases, metaclass, PKeyword.EMPTY_KEYWORDS);
153154
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/capsule/PyCapsule.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,12 @@
4545
import com.oracle.truffle.api.interop.TruffleObject;
4646
import com.oracle.truffle.api.library.ExportLibrary;
4747
import com.oracle.truffle.api.library.ExportMessage;
48+
import com.oracle.truffle.api.strings.TruffleString;
4849

4950
@ExportLibrary(InteropLibrary.class)
5051
public final class PyCapsule implements TruffleObject {
5152
private Object pointer;
52-
private String name;
53+
private TruffleString name;
5354
private Object context;
5455
private Object destructor;
5556

@@ -61,11 +62,11 @@ public void setPointer(Object pointer) {
6162
this.pointer = pointer;
6263
}
6364

64-
public String getName() {
65+
public TruffleString getName() {
6566
return name;
6667
}
6768

68-
public void setName(String name) {
69+
public void setName(TruffleString name) {
6970
this.name = name;
7071
}
7172

@@ -91,7 +92,7 @@ public String toDisplayString(@SuppressWarnings("unused") boolean allowSideEffec
9192
String quote, n;
9293
if (name != null) {
9394
quote = "\"";
94-
n = name;
95+
n = name.toJavaStringUncached();
9596
} else {
9697
quote = "";
9798
n = "NULL";

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CApiContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ public static CApiContext ensureCapiWasLoaded(Node node, PythonContext context,
970970

971971
String libpython = System.getProperty("LibPythonNativeLibrary");
972972
if (libpython != null) {
973-
SourceBuilder nfiSrcBuilder = Source.newBuilder("nfi", "load(RTLD_GLOBAL) \"" + libpython + "\"", libPythonName);
973+
SourceBuilder nfiSrcBuilder = Source.newBuilder("nfi", "load(RTLD_GLOBAL) \"" + libpython + "\"", "<libpython-native>");
974974
nativeLibpython = context.getEnv().parseInternal(nfiSrcBuilder.build()).call();
975975
}
976976

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/capi/CExtNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3988,7 +3988,7 @@ static PBuiltinFunction doIt(CApiContext context, Object methodDef,
39883988

39893989
mlMethObj = interopLibrary.readMember(methodDef, J_ML_METH);
39903990
if (!resultLib.isExecutable(mlMethObj)) {
3991-
LOGGER.warning(() -> String.format(ErrorMessages.ML_METH_IS_NOT_CALLABLE, methodName));
3991+
LOGGER.warning(() -> String.format("ml_meth of %s is not callable", methodName));
39923992
}
39933993
} catch (UnknownIdentifierException e) {
39943994
CompilerDirectives.transferToInterpreterAndInvalidate();

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyContextFunctions.java

Lines changed: 47 additions & 67 deletions
Large diffs are not rendered by default.

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyDef.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___ADD__;
5858
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___AND__;
5959
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___BOOL__;
60+
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___CALL__;
6061
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___CONTAINS__;
6162
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___DELITEM__;
6263
import static com.oracle.graal.python.nodes.SpecialMethodNames.T___DIVMOD__;
@@ -366,9 +367,9 @@ enum HPySlot {
366367
HPY_SQ_ITEM(44, HPySlotWrapper.SQ_ITEM, T___GETITEM__),
367368
HPY_SQ_LENGTH(45, HPySlotWrapper.LENFUNC, T___LEN__),
368369
HPY_SQ_REPEAT(46, HPySlotWrapper.INDEXARGFUNC, T___MUL__, T___RMUL__),
369-
HPY_TP_CALL(50, HPySlotWrapper.NULL, __CALL__),
370+
HPY_TP_CALL(50, HPySlotWrapper.NULL, T___CALL__),
370371
HPY_TP_INIT(60, HPySlotWrapper.INIT, T___INIT__),
371-
HPY_TP_ITER(62, HPySlotWrapper.UNARYFUNC, __ITER__),
372+
HPY_TP_ITER(62, HPySlotWrapper.UNARYFUNC, T___ITER__),
372373
HPY_TP_NEW(65, HPySlotWrapper.NULL, T___NEW__),
373374
HPY_TP_REPR(66, HPySlotWrapper.UNARYFUNC, T___REPR__),
374375
HPY_TP_RICHCOMPARE(67, w(RICHCMP_LT, RICHCMP_LE, RICHCMP_EQ, RICHCMP_NE, RICHCMP_GT, RICHCMP_GE), k(T___LT__, T___LE__, T___EQ__, T___NE__, T___GT__, T___GE__)),

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/hpy/GraalHPyNodes.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,11 +430,11 @@ static GetSetDescriptor doGeneric(GraalHPyContext context, Object owner, Object
430430
try {
431431
getterFunPtr = interopLibrary.readMember(legacyGetSetDef, "get");
432432
if (!(resultLib.isNull(getterFunPtr) || resultLib.isExecutable(getterFunPtr))) {
433-
LOGGER.warning(() -> String.format(ErrorMessages.GET_OF_S_IS_NOT_CALLABLE, getSetDescrName));
433+
LOGGER.warning(() -> String.format("get of %s is not callable", getSetDescrName));
434434
}
435435
setterFunPtr = interopLibrary.readMember(legacyGetSetDef, "set");
436436
if (!(resultLib.isNull(setterFunPtr) || resultLib.isExecutable(setterFunPtr))) {
437-
LOGGER.warning(() -> String.format(ErrorMessages.SET_OF_S_IS_NOT_CALLABLE, getSetDescrName));
437+
LOGGER.warning(() -> String.format("set of %s is not callable", getSetDescrName));
438438
}
439439
readOnly = resultLib.isNull(setterFunPtr);
440440
closurePtr = interopLibrary.readMember(legacyGetSetDef, "closure");
@@ -2046,7 +2046,7 @@ Object doGeneric(GraalHPyContext context, Object typeSpec, Object typeSpecParamA
20462046

20472047
// create the type object
20482048
Object metatype = getMetatype(context, typeSpecParamArray, ptrLib, castToJavaIntNode, callHelperFunctionNode, hPyAsPythonObjectNode);
2049-
PythonModule pythonCextModule = PythonContext.get(this).lookupBuiltinModule(PythonCextBuiltins.PYTHON_CEXT);
2049+
PythonModule pythonCextModule = PythonContext.get(this).lookupBuiltinModule(PythonCextBuiltins.T_PYTHON_CEXT);
20502050
PythonClass newType = (PythonClass) callCreateTypeNode.execute(null, pythonCextModule, T_PYTRUFFLE_CREATETYPE,
20512051
names[1], bases, namespace, metatype != null ? metatype : PythonBuiltinClassType.PythonClass);
20522052
// allocate additional memory for the metatype and set it

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/ErrorMessages.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -983,8 +983,6 @@ public abstract class ErrorMessages {
983983
public static final TruffleString EXPECTING_COLON_DELIMITER = tsLiteral("Expecting ':' delimiter");
984984
public static final TruffleString EXPECTING_COMMA_DELIMITER = tsLiteral("Expecting ',' delimiter");
985985
public static final TruffleString EXPECTING_VALUE = tsLiteral("Expecting value");
986-
public static final TruffleString GET_OF_S_IS_NOT_CALLABLE = tsLiteral("get of %s is not callable");
987-
public static final TruffleString SET_OF_S_IS_NOT_CALLABLE = tsLiteral("set of %s is not callable");
988986

989987
// SSL errors
990988
public static final TruffleString SSL_SESSION_CLOSED = tsLiteral("SSL/TLS session closed cleanly.");
@@ -1381,7 +1379,6 @@ public abstract class ErrorMessages {
13811379
public static final TruffleString MODULE_HAS_MULTIPLE_CREATE_SLOTS = tsLiteral("module %s has multiple create slots");
13821380
public static final TruffleString MODULE_USES_UNKNOW_SLOT_ID = tsLiteral("module %s uses unknown slot ID %i");
13831381
public static final TruffleString ML_FLAGS_IS_NOT_INTEGER = tsLiteral("ml_flags of %s is not an integer");
1384-
public static final TruffleString ML_METH_IS_NOT_CALLABLE = tsLiteral("ml_meth of %s is not callable");
13851382
public static final TruffleString INVALID_STRUCT_MEMBER = tsLiteral("Invalid struct member '%s'");
13861383
public static final TruffleString CANNOT_ACCESS_STRUCT_MEMBER_FLAGS_OR_METH = tsLiteral("Cannot access struct member 'ml_flags' or 'ml_meth'.");
13871384
public static final TruffleString FIELD_DID_NOT_RETURN_ARRAY = tsLiteral("field '%s' did not return an array");
@@ -1434,4 +1431,13 @@ public abstract class ErrorMessages {
14341431

14351432
public static final TruffleString ATTEMPTING_GETTER_NO_NATIVE_SPACE = tsLiteral("Attempting to getter function but object has no associated native space.");
14361433
public static final TruffleString ATTEMPTING_SETTER_NO_NATIVE_SPACE = tsLiteral("Attempting to setter function but object has no associated native space.");
1434+
1435+
public static final TruffleString INSTANCE_OF_CONTEXTVAR_EXPECTED = tsLiteral("an instance of ContextVar was expected");
1436+
public static final TruffleString CAPSULE_SETPOINTER_CALLED_WITH_NULL_POINTER = tsLiteral("PyCapsule_SetPointer called with null pointer");
1437+
public static final TruffleString CAPSULE_GETPOINTER_WITH_INVALID_CAPSULE = tsLiteral("HPyCapsule_GetPointer called with invalid PyCapsule object");
1438+
public static final TruffleString CAPSULE_GETCONTEXT_WITH_INVALID_CAPSULE = tsLiteral("HPyCapsule_GetContext called with invalid PyCapsule object");
1439+
public static final TruffleString CAPSULE_GETNAME_WITH_INVALID_CAPSULE = tsLiteral("HPyCapsule_GetName called with invalid PyCapsule object");
1440+
public static final TruffleString CAPSULE_GETDESTRUCTOR_WITH_INVALID_CAPSULE = tsLiteral("HPyCapsule_GetDestructor called with invalid PyCapsule object");
1441+
public static final TruffleString MSG_NOT_SET = tsLiteral("<message not set>");
1442+
14371443
}

0 commit comments

Comments
 (0)