Skip to content

Commit 92bc5d5

Browse files
committed
Read ht_name in type.__qualname__
1 parent e26fa1e commit 92bc5d5

File tree

1 file changed

+15
-8
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type

1 file changed

+15
-8
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/type/TypeBuiltins.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
package com.oracle.graal.python.builtins.objects.type;
2828

2929
import static com.oracle.graal.python.builtins.objects.PNone.NO_VALUE;
30+
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyHeapTypeObject__ht_qualname;
3031
import static com.oracle.graal.python.builtins.objects.cext.structs.CFields.PyTypeObject__tp_name;
3132
import static com.oracle.graal.python.nodes.BuiltinNames.T_BUILTINS;
3233
import static com.oracle.graal.python.nodes.HiddenAttr.ALLOC;
@@ -1255,19 +1256,25 @@ static Object setName(PythonClass cls, Object value,
12551256
}
12561257

12571258
@Specialization(guards = "isNoValue(value)")
1258-
static TruffleString getNative(PythonNativeClass cls, @SuppressWarnings("unused") PNone value,
1259+
static Object getNative(PythonNativeClass cls, @SuppressWarnings("unused") PNone value,
1260+
@Cached GetTypeFlagsNode getTypeFlagsNode,
1261+
@Cached CStructAccess.ReadObjectNode getHtName,
12591262
@Cached CStructAccess.ReadCharPtrNode getTpNameNode,
12601263
@Cached TruffleString.CodePointLengthNode codePointLengthNode,
12611264
@Cached TruffleString.IndexOfCodePointNode indexOfCodePointNode,
12621265
@Cached TruffleString.SubstringNode substringNode) {
1263-
// 'tp_name' contains the fully-qualified name, i.e., 'module.A.B...'
1264-
TruffleString tpName = getTpNameNode.readFromObj(cls, PyTypeObject__tp_name);
1265-
int nameLen = codePointLengthNode.execute(tpName, TS_ENCODING);
1266-
int firstDot = indexOfCodePointNode.execute(tpName, '.', 0, nameLen, TS_ENCODING);
1267-
if (firstDot < 0) {
1268-
return tpName;
1266+
if ((getTypeFlagsNode.execute(cls) & TypeFlags.HEAPTYPE) != 0) {
1267+
return getHtName.readFromObj(cls, PyHeapTypeObject__ht_qualname);
1268+
} else {
1269+
// 'tp_name' contains the fully-qualified name, i.e., 'module.A.B...'
1270+
TruffleString tpName = getTpNameNode.readFromObj(cls, PyTypeObject__tp_name);
1271+
int nameLen = codePointLengthNode.execute(tpName, TS_ENCODING);
1272+
int firstDot = indexOfCodePointNode.execute(tpName, '.', 0, nameLen, TS_ENCODING);
1273+
if (firstDot < 0) {
1274+
return tpName;
1275+
}
1276+
return substringNode.execute(tpName, firstDot + 1, nameLen - firstDot - 1, TS_ENCODING, true);
12691277
}
1270-
return substringNode.execute(tpName, firstDot + 1, nameLen - firstDot - 1, TS_ENCODING, true);
12711278
}
12721279

12731280
@Specialization(guards = "!isNoValue(value)")

0 commit comments

Comments
 (0)