Skip to content

Commit ae6391b

Browse files
committed
Initialize slots of native types that didn't go through PyType_Ready
1 parent aedceab commit ae6391b

File tree

1 file changed

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

1 file changed

+14
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
import com.oracle.graal.python.runtime.sequence.storage.MroSequenceStorage;
104104
import com.oracle.graal.python.util.InlineWeakValueProfile;
105105
import com.oracle.truffle.api.CompilerAsserts;
106+
import com.oracle.truffle.api.CompilerDirectives;
106107
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
107108
import com.oracle.truffle.api.TruffleLogger;
108109
import com.oracle.truffle.api.dsl.Cached;
@@ -955,7 +956,19 @@ static TpSlots doManaged(PythonManagedClass klass) {
955956

956957
@Specialization
957958
static TpSlots doNative(PythonAbstractNativeObject nativeKlass) {
958-
return nativeKlass.getTpSlots();
959+
TpSlots tpSlots = nativeKlass.getTpSlots();
960+
if (tpSlots == null) {
961+
/*
962+
* This happens when we try to get slots of a type that didn't go through
963+
* PyType_Ready yet. Specifically, numpy has a "fortran" type (defined in
964+
* `fortranobject.c`) that they never ready and just expect it to work because it's
965+
* simple. So just do the minimum to make the slots available.
966+
*/
967+
CompilerDirectives.transferToInterpreterAndInvalidate();
968+
tpSlots = TpSlots.fromNative(nativeKlass, PythonContext.get(null));
969+
nativeKlass.setTpSlots(tpSlots);
970+
}
971+
return tpSlots;
959972
}
960973
}
961974

0 commit comments

Comments
 (0)