@@ -121,32 +121,40 @@ abstract static class PyImport_GetModule extends CApiUnaryBuiltinNode {
121
121
private static final TruffleString T__LOCK_UNLOCK_MODULE = tsLiteral ("_lock_unlock_module" );
122
122
123
123
@ Specialization
124
- @ TruffleBoundary
125
- Object getModule (Object name ) {
126
- PythonContext context = PythonContext .get (null );
124
+ Object getModule (Object name ,
125
+ @ Bind ("this" ) Node inliningTarget ,
126
+ @ Cached PyObjectGetItem getItem ,
127
+ @ Cached PyObjectGetAttr getAttr ,
128
+ @ Cached PyObjectIsTrueNode isTrueNode ) {
129
+ PythonContext context = PythonContext .get (inliningTarget );
127
130
PDict modules = context .getSysModules ();
128
131
Object m ;
129
132
try {
130
- m = PyObjectGetItem . executeUncached ( modules , name );
133
+ m = getItem . execute ( null , inliningTarget , modules , name );
131
134
} catch (PException e ) {
132
135
return context .getNativeNull ();
133
136
}
134
137
if (m != PNone .NONE ) {
135
138
boolean initializing = false ;
136
139
try {
137
- Object spec = PyObjectGetAttr . executeUncached ( m , T___SPEC__ );
138
- Object initializingObj = PyObjectGetAttr . executeUncached ( spec , T___INITIALIZING__ );
139
- if (PyObjectIsTrueNode . executeUncached ( initializingObj )) {
140
+ Object spec = getAttr . execute ( null , inliningTarget , m , T___SPEC__ );
141
+ Object initializingObj = getAttr . execute ( null , inliningTarget , spec , T___INITIALIZING__ );
142
+ if (isTrueNode . execute ( null , inliningTarget , initializingObj )) {
140
143
initializing = true ;
141
144
}
142
145
} catch (PException e ) {
143
146
// ignore
144
147
}
145
148
if (initializing ) {
146
- PyObjectCallMethodObjArgs . executeUncached ( context . getImportlib (), T__LOCK_UNLOCK_MODULE , name );
149
+ waitForInitialization ( name , context );
147
150
}
148
151
}
149
152
return m ;
150
153
}
154
+
155
+ @ TruffleBoundary
156
+ private static void waitForInitialization (Object name , PythonContext context ) {
157
+ PyObjectCallMethodObjArgs .executeUncached (context .getImportlib (), T__LOCK_UNLOCK_MODULE , name );
158
+ }
151
159
}
152
160
}
0 commit comments