2 /* Support for dynamic loading of extension modules */
10 #if defined(__NetBSD__)
11 #include <sys/param.h>
15 #define dlerror() "error in dynamic linking"
23 #if (defined(__OpenBSD__) || defined(__NetBSD__)) && !defined(__ELF__)
24 #define LEAD_UNDERSCORE "_"
26 #define LEAD_UNDERSCORE ""
34 const struct filedescr _PyImport_DynLoadFiletab
[] = {
36 {".dll", "rb", C_EXTENSION
},
37 {"module.dll", "rb", C_EXTENSION
},
39 {".so", "rb", C_EXTENSION
},
40 {"module.so", "rb", C_EXTENSION
},
50 static int nhandles
= 0;
53 dl_funcptr
_PyImport_GetDynLoadFunc(const char *fqname
, const char *shortname
,
54 const char *pathname
, FILE *fp
)
61 if (strchr(pathname
, '/') == NULL
) {
62 /* Prefix bare filename with "./" */
63 sprintf(pathbuf
, "./%-.255s", pathname
);
67 sprintf(funcname
, LEAD_UNDERSCORE
"init%.200s", shortname
);
72 fstat(fileno(fp
), &statb
);
73 for (i
= 0; i
< nhandles
; i
++) {
74 if (statb
.st_dev
== handles
[i
].dev
&&
75 statb
.st_ino
== handles
[i
].ino
) {
76 p
= (dl_funcptr
) dlsym(handles
[i
].handle
,
82 handles
[nhandles
].dev
= statb
.st_dev
;
83 handles
[nhandles
].ino
= statb
.st_ino
;
88 /* RTLD_NOW: resolve externals now
89 (i.e. core dump now if some are missing) */
90 handle
= dlopen(pathname
, RTLD_NOW
);
93 printf("dlopen(\"%s\", %d);\n", pathname
,
95 handle
= dlopen(pathname
, RTLD_LAZY
);
98 PyErr_SetString(PyExc_ImportError
, dlerror());
101 if (fp
!= NULL
&& nhandles
< 128)
102 handles
[nhandles
++].handle
= handle
;
103 p
= (dl_funcptr
) dlsym(handle
, funcname
);