blob: 5ccfd8152d72de919f492f3262f4cd60a6fe92ea [file] [log] [blame]
Guido van Rossum22a1d361999-12-20 21:18:49 +00001/***********************************************************
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00002Copyright (c) 2000, BeOpen.com.
3Copyright (c) 1995-2000, Corporation for National Research Initiatives.
4Copyright (c) 1990-1995, Stichting Mathematisch Centrum.
5All rights reserved.
Guido van Rossum22a1d361999-12-20 21:18:49 +00006
Guido van Rossumfd71b9e2000-06-30 23:50:40 +00007See the file "Misc/COPYRIGHT" for information on usage and
8redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
Guido van Rossum22a1d361999-12-20 21:18:49 +00009******************************************************************/
10
11/* Support for dynamic loading of extension modules */
12
13#define INCL_DOSERRORS
14#define INCL_DOSMODULEMGR
15#include <os2.h>
16
17#include "Python.h"
18#include "importdl.h"
19
20
21const struct filedescr _PyImport_DynLoadFiletab[] = {
22 {".pyd", "rb", C_EXTENSION},
23 {".dll", "rb", C_EXTENSION},
24 {0, 0}
25};
26
Guido van Rossum96a8fb71999-12-22 14:09:35 +000027dl_funcptr _PyImport_GetDynLoadFunc(const char *fqname, const char *shortname,
Guido van Rossum22a1d361999-12-20 21:18:49 +000028 const char *pathname, FILE *fp)
29{
30 dl_funcptr p;
31 APIRET rc;
32 HMODULE hDLL;
33 char failreason[256];
Guido van Rossum96a8fb71999-12-22 14:09:35 +000034 char funcname[258];
Guido van Rossum22a1d361999-12-20 21:18:49 +000035
36 rc = DosLoadModule(failreason,
37 sizeof(failreason),
38 pathname,
39 &hDLL);
40
41 if (rc != NO_ERROR) {
42 char errBuf[256];
43 sprintf(errBuf,
44 "DLL load failed, rc = %d: %s",
45 rc, failreason);
46 PyErr_SetString(PyExc_ImportError, errBuf);
47 return NULL;
48 }
49
Guido van Rossum96a8fb71999-12-22 14:09:35 +000050 sprintf(funcname, "init%.200s", shortname);
Guido van Rossum22a1d361999-12-20 21:18:49 +000051 rc = DosQueryProcAddr(hDLL, 0L, funcname, &p);
52 if (rc != NO_ERROR)
53 p = NULL; /* Signify Failure to Acquire Entrypoint */
54 return p;
55}