1 /********************************************************************
5 Win32 specific import code.
13 #include "malloc.h" // for alloca
15 extern const char *PyWin_DLLVersionString
; // a string loaded from the DLL at startup.
17 /* Return whether this is Win32s, i.e., Win32 API on Win 3.1(1).
18 This function is exported! */
22 static BOOL bIsWin32s
= -1; /* flag as "not yet looked" */
24 if (bIsWin32s
== -1) {
26 ver
.dwOSVersionInfoSize
= sizeof(ver
);
28 bIsWin32s
= ver
.dwPlatformId
== VER_PLATFORM_WIN32s
;
33 FILE *PyWin_FindRegisteredModule( const char *moduleName
, struct filedescr
**ppFileDesc
, char *pathBuf
, int pathLen
)
36 const char keyPrefix
[] = "Software\\Python\\PythonCore\\";
37 const char keySuffix
[] = "\\Modules\\";
39 // In debugging builds, we _must_ have the debug version registered.
40 const char debugString
[] = "\\Debug";
42 const char debugString
[] = "";
44 struct filedescr
*fdp
= NULL
;
46 HKEY keyBase
= PyWin_IsWin32s() ? HKEY_CLASSES_ROOT
: HKEY_LOCAL_MACHINE
;
50 // Calculate the size for the sprintf buffer.
51 // Get the size of the chars only, plus 1 NULL.
52 int bufSize
= sizeof(keyPrefix
)-1 + strlen(PyWin_DLLVersionString
) + sizeof(keySuffix
) + strlen(moduleName
) + sizeof(debugString
) - 1;
53 // alloca == no free required, but memory only local to fn, also no heap fragmentation!
54 moduleKey
= alloca(bufSize
);
55 sprintf(moduleKey
, "Software\\Python\\PythonCore\\%s\\Modules\\%s%s", PyWin_DLLVersionString
, moduleName
, debugString
);
57 modNameSize
= pathLen
;
58 regStat
= RegQueryValue(keyBase
, moduleKey
, pathBuf
, &modNameSize
);
59 if (regStat
!=ERROR_SUCCESS
)
61 // use the file extension to locate the type entry.
62 for (fdp
= _PyImport_Filetab
; fdp
->suffix
!= NULL
; fdp
++) {
63 int extLen
=strlen(fdp
->suffix
);
64 if (modNameSize
>extLen
&& strnicmp(pathBuf
+(modNameSize
-extLen
-1),fdp
->suffix
,extLen
)==0)
67 if (fdp
->suffix
==NULL
)
69 fp
= fopen(pathBuf
, fdp
->mode
);