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
},
43 {".so", "rb", C_EXTENSION
},
44 {"module.so", "rb", C_EXTENSION
},
55 static int nhandles
= 0;
58 dl_funcptr
_PyImport_GetDynLoadFunc(const char *fqname
, const char *shortname
,
59 const char *pathname
, FILE *fp
)
67 if (strchr(pathname
, '/') == NULL
) {
68 /* Prefix bare filename with "./" */
69 PyOS_snprintf(pathbuf
, sizeof(pathbuf
), "./%-.255s", pathname
);
73 PyOS_snprintf(funcname
, sizeof(funcname
),
74 LEAD_UNDERSCORE
"init%.200s", shortname
);
79 fstat(fileno(fp
), &statb
);
80 for (i
= 0; i
< nhandles
; i
++) {
81 if (statb
.st_dev
== handles
[i
].dev
&&
82 statb
.st_ino
== handles
[i
].ino
) {
83 p
= (dl_funcptr
) dlsym(handles
[i
].handle
,
89 handles
[nhandles
].dev
= statb
.st_dev
;
90 handles
[nhandles
].ino
= statb
.st_ino
;
94 #if !(defined(PYOS_OS2) && defined(PYCC_GCC))
95 dlopenflags
= PyThreadState_Get()->interp
->dlopenflags
;
99 printf("dlopen(\"%s\", %x);\n", pathname
, dlopenflags
);
101 handle
= dlopen(pathname
, dlopenflags
);
103 if (handle
== NULL
) {
104 PyErr_SetString(PyExc_ImportError
, dlerror());
107 if (fp
!= NULL
&& nhandles
< 128)
108 handles
[nhandles
++].handle
= handle
;
109 p
= (dl_funcptr
) dlsym(handle
, funcname
);