Skip to content

Commit dab0a3f

Browse files
committed
Return default value 0 for basicsize, itemsize, and dictoffset.
1 parent 09f9204 commit dab0a3f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -503,32 +503,35 @@ Object doTpHash(ManagedPythonClass object, @SuppressWarnings("unused") String ke
503503

504504
@Specialization(guards = "eq(TP_BASICSIZE, key)")
505505
Object doTpBasicsize(ManagedPythonClass object, @SuppressWarnings("unused") String key,
506+
@Cached("create()") CastToIndexNode castToIntNode,
506507
@Cached("create(__BASICSIZE__)") GetFixedAttributeNode getAttrNode) {
507-
return getAttrNode.executeObject(object);
508+
Object val = getAttrNode.executeObject(object);
509+
return val != PNone.NO_VALUE ? castToIntNode.execute(val) : 0L;
508510
}
509511

510512
@Specialization(guards = "eq(TP_ITEMSIZE, key)")
511-
Object doTpItemsize(ManagedPythonClass object, @SuppressWarnings("unused") String key,
513+
long doTpItemsize(ManagedPythonClass object, @SuppressWarnings("unused") String key,
514+
@Cached("create()") CastToIndexNode castToIntNode,
512515
@Cached("create(__ITEMSIZE__)") GetFixedAttributeNode getAttrNode) {
513516
Object val = getAttrNode.executeObject(object);
514517
// If the attribute does not exist, this means that we take 'tp_itemsize' from the base
515518
// object which is by default 0 (see typeobject.c:PyBaseObject_Type).
516519
if (val == PNone.NO_VALUE) {
517520
return 0L;
518521
}
519-
return val;
522+
return val != PNone.NO_VALUE ? castToIntNode.execute(val) : 0L;
520523
}
521524

522525
@Specialization(guards = "eq(TP_DICTOFFSET, key)")
523-
Object doTpDictoffset(ManagedPythonClass object, @SuppressWarnings("unused") String key,
526+
long doTpDictoffset(ManagedPythonClass object, @SuppressWarnings("unused") String key,
524527
@Cached("create()") CastToIndexNode castToIntNode,
525528
@Cached("create(__DICTOFFSET__)") GetFixedAttributeNode getAttrNode) {
526529
// TODO properly implement 'tp_dictoffset' for builtin classes
527530
if (object instanceof PythonBuiltinClass) {
528531
return 0L;
529532
}
530533
Object dictoffset = getAttrNode.executeObject(object);
531-
return castToIntNode.execute(dictoffset);
534+
return dictoffset != PNone.NO_VALUE ? castToIntNode.execute(dictoffset) : 0L;
532535
}
533536

534537
@Specialization(guards = "eq(TP_WEAKLISTOFFSET, key)")

0 commit comments

Comments
 (0)