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