Skip to content

Commit 393265c

Browse files
committed
Fix PyObject_SetDoc with NULL value
1 parent d29ab35 commit 393265c

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
135135
import com.oracle.graal.python.nodes.object.GetClassNode;
136136
import com.oracle.graal.python.nodes.truffle.PythonTypes;
137+
import com.oracle.graal.python.runtime.PythonContext;
137138
import com.oracle.graal.python.runtime.exception.PException;
138139
import com.oracle.truffle.api.CompilerDirectives;
139140
import com.oracle.truffle.api.dsl.Bind;
@@ -962,40 +963,46 @@ Object get(Object obj,
962963
@CApiBuiltin(ret = Int, args = {PyObject, ConstCharPtrAsTruffleString}, call = Direct)
963964
abstract static class PyObject_SetDoc extends CApiBinaryBuiltinNode {
964965
@Specialization
965-
static int set(PBuiltinFunction obj, TruffleString value,
966+
static int set(PBuiltinFunction obj, Object value,
966967
@Shared("write") @Cached WriteAttributeToPythonObjectNode write) {
967968
write.execute(obj, T___DOC__, value);
968969
return 1;
969970
}
970971

971972
@Specialization
972-
static int set(PBuiltinMethod obj, TruffleString value,
973+
static int set(PBuiltinMethod obj, Object value,
973974
@Shared("write") @Cached WriteAttributeToPythonObjectNode write) {
974975
set(obj.getBuiltinFunction(), value, write);
975976
return 1;
976977
}
977978

978979
@Specialization
979-
static int set(GetSetDescriptor obj, TruffleString value,
980+
static int set(GetSetDescriptor obj, Object value,
980981
@Shared("write") @Cached WriteAttributeToPythonObjectNode write) {
981982
write.execute(obj, T___DOC__, value);
982983
return 1;
983984
}
984985

985986
@Specialization(guards = "isType.execute(inliningTarget, type)", limit = "1")
986-
static int set(PythonAbstractNativeObject type, TruffleString value,
987-
@SuppressWarnings("unused") @Bind("this") Node inliningTarget,
987+
static int set(PythonAbstractNativeObject type, Object value,
988+
@Bind("this") Node inliningTarget,
988989
@SuppressWarnings("unused") @Cached IsTypeNode isType,
989990
@Cached CStructAccess.WritePointerNode writePointerNode) {
990-
writePointerNode.write(type.getPtr(), PyTypeObject__tp_doc, new CStringWrapper(value));
991+
Object cValue;
992+
if (value instanceof TruffleString stringValue) {
993+
cValue = new CStringWrapper(stringValue);
994+
} else {
995+
cValue = PythonContext.get(inliningTarget).getNativeNull();
996+
}
997+
writePointerNode.write(type.getPtr(), PyTypeObject__tp_doc, cValue);
991998
return 1;
992999
}
9931000

9941001
@Fallback
9951002
@SuppressWarnings("unused")
9961003
static int set(Object obj, Object value) {
997-
CompilerDirectives.transferToInterpreterAndInvalidate();
998-
throw CompilerDirectives.shouldNotReachHere("Don't know how to set doc for " + obj.getClass());
1004+
// The callers don't expect errors, so just do nothing
1005+
return 1;
9991006
}
10001007
}
10011008
}

0 commit comments

Comments
 (0)