|
134 | 134 | import com.oracle.graal.python.nodes.object.BuiltinClassProfiles.IsBuiltinObjectProfile;
|
135 | 135 | import com.oracle.graal.python.nodes.object.GetClassNode;
|
136 | 136 | import com.oracle.graal.python.nodes.truffle.PythonTypes;
|
| 137 | +import com.oracle.graal.python.runtime.PythonContext; |
137 | 138 | import com.oracle.graal.python.runtime.exception.PException;
|
138 | 139 | import com.oracle.truffle.api.CompilerDirectives;
|
139 | 140 | import com.oracle.truffle.api.dsl.Bind;
|
@@ -962,40 +963,46 @@ Object get(Object obj,
|
962 | 963 | @CApiBuiltin(ret = Int, args = {PyObject, ConstCharPtrAsTruffleString}, call = Direct)
|
963 | 964 | abstract static class PyObject_SetDoc extends CApiBinaryBuiltinNode {
|
964 | 965 | @Specialization
|
965 |
| - static int set(PBuiltinFunction obj, TruffleString value, |
| 966 | + static int set(PBuiltinFunction obj, Object value, |
966 | 967 | @Shared("write") @Cached WriteAttributeToPythonObjectNode write) {
|
967 | 968 | write.execute(obj, T___DOC__, value);
|
968 | 969 | return 1;
|
969 | 970 | }
|
970 | 971 |
|
971 | 972 | @Specialization
|
972 |
| - static int set(PBuiltinMethod obj, TruffleString value, |
| 973 | + static int set(PBuiltinMethod obj, Object value, |
973 | 974 | @Shared("write") @Cached WriteAttributeToPythonObjectNode write) {
|
974 | 975 | set(obj.getBuiltinFunction(), value, write);
|
975 | 976 | return 1;
|
976 | 977 | }
|
977 | 978 |
|
978 | 979 | @Specialization
|
979 |
| - static int set(GetSetDescriptor obj, TruffleString value, |
| 980 | + static int set(GetSetDescriptor obj, Object value, |
980 | 981 | @Shared("write") @Cached WriteAttributeToPythonObjectNode write) {
|
981 | 982 | write.execute(obj, T___DOC__, value);
|
982 | 983 | return 1;
|
983 | 984 | }
|
984 | 985 |
|
985 | 986 | @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, |
988 | 989 | @SuppressWarnings("unused") @Cached IsTypeNode isType,
|
989 | 990 | @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); |
991 | 998 | return 1;
|
992 | 999 | }
|
993 | 1000 |
|
994 | 1001 | @Fallback
|
995 | 1002 | @SuppressWarnings("unused")
|
996 | 1003 | 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; |
999 | 1006 | }
|
1000 | 1007 | }
|
1001 | 1008 | }
|
0 commit comments