9494import com .oracle .graal .python .builtins .modules .MsvcrtModuleBuiltins ;
9595import com .oracle .graal .python .builtins .modules .NtModuleBuiltins ;
9696import com .oracle .graal .python .builtins .modules .OperatorModuleBuiltins ;
97+ import com .oracle .graal .python .builtins .modules .OverlappedModuleBuiltins ;
9798import com .oracle .graal .python .builtins .modules .PolyglotModuleBuiltins ;
9899import com .oracle .graal .python .builtins .modules .PosixModuleBuiltins ;
99100import com .oracle .graal .python .builtins .modules .PosixShMemModuleBuiltins ;
122123import com .oracle .graal .python .builtins .modules .WarningsModuleBuiltins ;
123124import com .oracle .graal .python .builtins .modules .WeakRefModuleBuiltins ;
124125import com .oracle .graal .python .builtins .modules .WinapiModuleBuiltins ;
126+ import com .oracle .graal .python .builtins .modules .WinregLegacyModuleBuiltins ;
125127import com .oracle .graal .python .builtins .modules .WinregModuleBuiltins ;
126128import com .oracle .graal .python .builtins .modules .ast .AstBuiltins ;
127129import com .oracle .graal .python .builtins .modules .ast .AstModuleBuiltins ;
418420import com .oracle .truffle .api .object .Shape ;
419421import com .oracle .truffle .api .source .Source ;
420422import com .oracle .truffle .api .strings .TruffleString ;
423+ import org .graalvm .nativeimage .ImageInfo ;
421424
422425/**
423426 * The core is a historical artifact and PythonContext and Python3Core should be merged.
@@ -435,18 +438,13 @@ public abstract class Python3Core {
435438
436439 private static TruffleString [] getCoreFiles () {
437440 // Order matters!
438- List < TruffleString > coreFiles = List . of (
441+ return new TruffleString []{
439442 T___GRAALPYTHON__ ,
440443 T__SRE ,
441444 T__SYSCONFIG ,
442445 T_JAVA ,
443- toTruffleStringUncached ("pip_hook" ));
444- if (PythonLanguage .getPythonOS () == PythonOS .PLATFORM_WIN32 ) {
445- coreFiles = new ArrayList <>(coreFiles );
446- coreFiles .add (toTruffleStringUncached ("_nt" ));
447- }
448-
449- return coreFiles .toArray (new TruffleString [0 ]);
446+ toTruffleStringUncached ("pip_hook" )
447+ };
450448 }
451449
452450 private PythonBuiltins [] builtins ;
@@ -561,6 +559,8 @@ private static PythonBuiltins[] initializeBuiltins(TruffleLanguage.Env env) {
561559 new WinregModuleBuiltins (),
562560 new MsvcrtModuleBuiltins (),
563561 new WinapiModuleBuiltins (),
562+ new OverlappedModuleBuiltins (),
563+ new WinregLegacyModuleBuiltins (),
564564 new CryptModuleBuiltins (),
565565 new ScandirIteratorBuiltins (),
566566 new DirEntryBuiltins (),
@@ -1051,6 +1051,17 @@ private void initializePython3Core(TruffleString coreHome) {
10511051 initialized = true ;
10521052 }
10531053
1054+ private void initializeWindowsCoreFiles (TruffleString coreHome ) {
1055+ if (PythonLanguage .getPythonOS () == PythonOS .PLATFORM_WIN32 ) {
1056+ assert !ImageInfo .inImageBuildtimeCode ();
1057+ loadFile (toTruffleStringUncached ("_nt" ), coreHome );
1058+ loadFile (toTruffleStringUncached ("_winapi" ), toTruffleStringUncached ("modules/_winapi" ), coreHome );
1059+ loadFile (toTruffleStringUncached ("_overlapped" ), toTruffleStringUncached ("modules/_overlapped" ), coreHome );
1060+ loadFile (toTruffleStringUncached ("winreg" ), toTruffleStringUncached ("modules/winreg" ), coreHome );
1061+ loadFile (toTruffleStringUncached ("_winreg" ), toTruffleStringUncached ("modules/_winreg" ), coreHome );
1062+ }
1063+ }
1064+
10541065 /**
10551066 * Run post-initialization code that needs a fully working Python environment. This will be run
10561067 * eagerly when the context is initialized on the JVM or a new context is created on SVM, but is
@@ -1059,6 +1070,7 @@ private void initializePython3Core(TruffleString coreHome) {
10591070 public final void postInitialize (Env env ) {
10601071 if (!env .isPreInitialization ()) {
10611072 initialized = false ;
1073+ initializeWindowsCoreFiles (getContext ().getCoreHomeOrFail ());
10621074
10631075 for (PythonBuiltins builtin : builtins ) {
10641076 if (builtin .needsPostInitialize ()) {
@@ -1319,26 +1331,34 @@ private Source getInternalSource(TruffleString basename, TruffleString prefix) {
13191331 }
13201332
13211333 private void loadFile (TruffleString s , TruffleString prefix ) {
1334+ loadFile (s , s , prefix );
1335+ }
1336+
1337+ private void loadFile (TruffleString s , TruffleString sourceName , TruffleString prefix ) {
13221338 PythonModule mod = lookupBuiltinModule (s );
13231339 if (mod == null ) {
13241340 // use an anonymous module for the side-effects
13251341 mod = PFactory .createPythonModule (T___ANONYMOUS__ );
13261342 }
1327- loadFile (s , prefix , mod );
1343+ loadFile (s , sourceName , prefix , mod );
13281344 }
13291345
13301346 private void loadFile (TruffleString s , TruffleString prefix , PythonModule mod ) {
1347+ loadFile (s , s , prefix , mod );
1348+ }
1349+
1350+ private void loadFile (TruffleString s , TruffleString sourceName , TruffleString prefix , PythonModule mod ) {
13311351 if (ImpModuleBuiltins .importFrozenModuleObjectNoRaise (this , cat (T_GRAALPYTHON , T_DOT , s ), mod ) != null ) {
13321352 LOGGER .log (Level .FINE , () -> "import '" + s + "' # <frozen>" );
13331353 return ;
13341354 }
13351355
13361356 LOGGER .log (Level .FINE , () -> "import '" + s + "'" );
13371357 Supplier <CallTarget > getCode = () -> {
1338- Source source = getInternalSource (s , prefix );
1358+ Source source = getInternalSource (sourceName , prefix );
13391359 return getLanguage ().parse (getContext (), source , InputType .FILE , false , 0 , false , null , EnumSet .noneOf (FutureFeature .class ));
13401360 };
1341- RootCallTarget callTarget = (RootCallTarget ) getLanguage ().cacheCode (s , getCode );
1361+ RootCallTarget callTarget = (RootCallTarget ) getLanguage ().cacheCode (sourceName , getCode );
13421362 PCode code = PFactory .createCode (language , callTarget );
13431363 CallDispatchers .SimpleIndirectInvokeNode .executeUncached (callTarget , PArguments .withGlobals (code , mod ));
13441364 }
0 commit comments