Skip to content

Commit 572c79e

Browse files
committed
Warn on unexpected types in PyObject_SetDoc
1 parent 9b83dbd commit 572c79e

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
import com.oracle.graal.python.builtins.modules.cext.PythonCextBuiltins.CApiUnaryBuiltinNode;
8383
import com.oracle.graal.python.builtins.objects.PNone;
8484
import com.oracle.graal.python.builtins.objects.cext.PythonAbstractNativeObject;
85+
import com.oracle.graal.python.builtins.objects.cext.capi.CApiContext;
8586
import com.oracle.graal.python.builtins.objects.cext.capi.CExtNodes.AsCharPointerNode;
8687
import com.oracle.graal.python.builtins.objects.cext.capi.PrimitiveNativeWrapper;
8788
import com.oracle.graal.python.builtins.objects.cext.common.CArrayWrappers.CStringWrapper;
@@ -137,6 +138,7 @@
137138
import com.oracle.graal.python.runtime.PythonContext;
138139
import com.oracle.graal.python.runtime.exception.PException;
139140
import com.oracle.truffle.api.CompilerDirectives;
141+
import com.oracle.truffle.api.TruffleLogger;
140142
import com.oracle.truffle.api.dsl.Bind;
141143
import com.oracle.truffle.api.dsl.Cached;
142144
import com.oracle.truffle.api.dsl.Cached.Exclusive;
@@ -962,6 +964,8 @@ Object get(Object obj,
962964

963965
@CApiBuiltin(ret = Int, args = {PyObject, ConstCharPtrAsTruffleString}, call = Direct)
964966
abstract static class PyObject_SetDoc extends CApiBinaryBuiltinNode {
967+
private static final TruffleLogger LOGGER = CApiContext.getLogger(PyObject_SetDoc.class);
968+
965969
@Specialization
966970
static int set(PBuiltinFunction obj, Object value,
967971
@Shared("write") @Cached WriteAttributeToPythonObjectNode write) {
@@ -1001,7 +1005,9 @@ static int set(PythonAbstractNativeObject type, Object value,
10011005
@Fallback
10021006
@SuppressWarnings("unused")
10031007
static int set(Object obj, Object value) {
1004-
// The callers don't expect errors, so just do nothing
1008+
CompilerDirectives.transferToInterpreterAndInvalidate();
1009+
// The callers don't expect errors, so just warn
1010+
LOGGER.warning("Unexpected type in PyObject_SetDoc: " + obj.getClass());
10051011
return 1;
10061012
}
10071013
}

0 commit comments

Comments
 (0)