2 /* Support for dynamic loading of extension modules */
10 #if defined(__NetBSD__)
11 #include <sys/param.h>
15 #define dlerror() "error in dynamic linking"
22 #if defined(PYOS_OS2) && defined(PYCC_GCC)
27 #if (defined(__OpenBSD__) || defined(__NetBSD__)) && !defined(__ELF__)
28 #define LEAD_UNDERSCORE "_"
30 #define LEAD_UNDERSCORE ""
34 const struct filedescr _PyImport_DynLoadFiletab
[] = {
36 {".dll", "rb", C_EXTENSION
},
37 {"module.dll", "rb", C_EXTENSION
},
39 #if defined(PYOS_OS2) && defined(PYCC_GCC)
40 {".pyd", "rb", C_EXTENSION
},
41 {".dll", "rb", C_EXTENSION
},
44 {".exe", "rb", C_EXTENSION
},
45 {".EXE", "rb", C_EXTENSION
},
46 {"module.exe", "rb", C_EXTENSION
},
47 {"MODULE.EXE", "rb", C_EXTENSION
},
49 {".so", "rb", C_EXTENSION
},
50 {"module.so", "rb", C_EXTENSION
},
66 static int nhandles
= 0;
69 dl_funcptr
_PyImport_GetDynLoadFunc(const char *fqname
, const char *shortname
,
70 const char *pathname
, FILE *fp
)
78 if (strchr(pathname
, '/') == NULL
) {
79 /* Prefix bare filename with "./" */
80 PyOS_snprintf(pathbuf
, sizeof(pathbuf
), "./%-.255s", pathname
);
84 PyOS_snprintf(funcname
, sizeof(funcname
),
85 LEAD_UNDERSCORE
"init%.200s", shortname
);
90 fstat(fileno(fp
), &statb
);
91 for (i
= 0; i
< nhandles
; i
++) {
92 if (statb
.st_dev
== handles
[i
].dev
&&
93 statb
.st_ino
== handles
[i
].ino
) {
94 p
= (dl_funcptr
) dlsym(handles
[i
].handle
,
100 handles
[nhandles
].dev
= statb
.st_dev
;
102 handles
[nhandles
].ino
[0] = statb
.st_ino
[0];
103 handles
[nhandles
].ino
[1] = statb
.st_ino
[1];
104 handles
[nhandles
].ino
[2] = statb
.st_ino
[2];
106 handles
[nhandles
].ino
= statb
.st_ino
;
111 #if !(defined(PYOS_OS2) && defined(PYCC_GCC))
112 dlopenflags
= PyThreadState_GET()->interp
->dlopenflags
;
116 PySys_WriteStderr("dlopen(\"%s\", %x);\n", pathname
,
120 /* VMS currently don't allow a pathname, use a logical name instead */
121 /* Concatenate 'python_module_' and shortname */
122 /* so "import vms.bar" will use the logical python_module_bar */
123 /* As C module use only one name space this is probably not a */
124 /* important limitation */
125 PyOS_snprintf(pathbuf
, sizeof(pathbuf
), "python_module_%-.200s",
130 handle
= dlopen(pathname
, dlopenflags
);
132 if (handle
== NULL
) {
133 const char *error
= dlerror();
135 error
= "unknown dlopen() error";
136 PyErr_SetString(PyExc_ImportError
, error
);
139 if (fp
!= NULL
&& nhandles
< 128)
140 handles
[nhandles
++].handle
= handle
;
141 p
= (dl_funcptr
) dlsym(handle
, funcname
);