1996-08-21 12:03:37 -03:00
|
|
|
/********************************************************************
|
|
|
|
|
1996-08-21 21:06:59 -03:00
|
|
|
import_nt.c
|
1996-08-21 12:03:37 -03:00
|
|
|
|
|
|
|
Win32 specific import code.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
1997-05-05 18:45:44 -03:00
|
|
|
#include "Python.h"
|
1996-08-21 12:03:37 -03:00
|
|
|
#include "osdefs.h"
|
|
|
|
#include <windows.h>
|
|
|
|
#include "importdl.h"
|
1997-09-29 20:39:31 -03:00
|
|
|
#include "malloc.h" // for alloca
|
|
|
|
|
|
|
|
extern const char *PyWin_DLLVersionString; // a string loaded from the DLL at startup.
|
1996-08-21 12:03:37 -03:00
|
|
|
|
|
|
|
FILE *PyWin_FindRegisteredModule( const char *moduleName, struct filedescr **ppFileDesc, char *pathBuf, int pathLen)
|
|
|
|
{
|
1997-09-29 20:39:31 -03:00
|
|
|
char *moduleKey;
|
|
|
|
const char keyPrefix[] = "Software\\Python\\PythonCore\\";
|
|
|
|
const char keySuffix[] = "\\Modules\\";
|
1998-05-26 10:53:23 -03:00
|
|
|
#ifdef _DEBUG
|
|
|
|
// In debugging builds, we _must_ have the debug version registered.
|
|
|
|
const char debugString[] = "\\Debug";
|
|
|
|
#else
|
|
|
|
const char debugString[] = "";
|
|
|
|
#endif
|
1996-08-21 12:03:37 -03:00
|
|
|
struct filedescr *fdp = NULL;
|
|
|
|
FILE *fp;
|
2000-04-04 19:48:55 -03:00
|
|
|
HKEY keyBase = HKEY_LOCAL_MACHINE;
|
1998-05-26 10:53:23 -03:00
|
|
|
int modNameSize;
|
1998-06-15 15:01:34 -03:00
|
|
|
long regStat;
|
1997-09-29 20:39:31 -03:00
|
|
|
|
1998-05-26 10:53:23 -03:00
|
|
|
// Calculate the size for the sprintf buffer.
|
|
|
|
// Get the size of the chars only, plus 1 NULL.
|
2000-06-28 19:20:06 -03:00
|
|
|
size_t bufSize = sizeof(keyPrefix)-1 + strlen(PyWin_DLLVersionString) + sizeof(keySuffix) + strlen(moduleName) + sizeof(debugString) - 1;
|
1997-09-29 20:39:31 -03:00
|
|
|
// alloca == no free required, but memory only local to fn, also no heap fragmentation!
|
1998-05-26 10:53:23 -03:00
|
|
|
moduleKey = alloca(bufSize);
|
|
|
|
sprintf(moduleKey, "Software\\Python\\PythonCore\\%s\\Modules\\%s%s", PyWin_DLLVersionString, moduleName, debugString);
|
1997-09-29 20:39:31 -03:00
|
|
|
|
1999-01-14 18:40:30 -04:00
|
|
|
modNameSize = pathLen;
|
1998-06-15 15:01:34 -03:00
|
|
|
regStat = RegQueryValue(keyBase, moduleKey, pathBuf, &modNameSize);
|
|
|
|
if (regStat!=ERROR_SUCCESS)
|
1996-08-21 12:03:37 -03:00
|
|
|
return NULL;
|
|
|
|
// use the file extension to locate the type entry.
|
1997-05-08 20:43:52 -03:00
|
|
|
for (fdp = _PyImport_Filetab; fdp->suffix != NULL; fdp++) {
|
2000-06-28 19:20:06 -03:00
|
|
|
size_t extLen = strlen(fdp->suffix);
|
1996-08-21 12:03:37 -03:00
|
|
|
if (modNameSize>extLen && strnicmp(pathBuf+(modNameSize-extLen-1),fdp->suffix,extLen)==0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (fdp->suffix==NULL)
|
|
|
|
return NULL;
|
|
|
|
fp = fopen(pathBuf, fdp->mode);
|
|
|
|
if (fp != NULL)
|
|
|
|
*ppFileDesc = fdp;
|
|
|
|
return fp;
|
|
|
|
}
|
1998-05-26 10:53:23 -03:00
|
|
|
|