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 ""
30 const struct filedescr _PyImport_DynLoadFiletab
[] = {
32 {".dll", "rb", C_EXTENSION
},
33 {"module.dll", "rb", C_EXTENSION
},
35 {".so", "rb", C_EXTENSION
},
36 {"module.so", "rb", C_EXTENSION
},
46 static int nhandles
= 0;
49 dl_funcptr
_PyImport_GetDynLoadFunc(const char *fqname
, const char *shortname
,
50 const char *pathname
, FILE *fp
)
58 if (strchr(pathname
, '/') == NULL
) {
59 /* Prefix bare filename with "./" */
60 PyOS_snprintf(pathbuf
, sizeof(pathbuf
), "./%-.255s", pathname
);
64 PyOS_snprintf(funcname
, sizeof(funcname
),
65 LEAD_UNDERSCORE
"init%.200s", shortname
);
70 fstat(fileno(fp
), &statb
);
71 for (i
= 0; i
< nhandles
; i
++) {
72 if (statb
.st_dev
== handles
[i
].dev
&&
73 statb
.st_ino
== handles
[i
].ino
) {
74 p
= (dl_funcptr
) dlsym(handles
[i
].handle
,
80 handles
[nhandles
].dev
= statb
.st_dev
;
81 handles
[nhandles
].ino
= statb
.st_ino
;
85 dlopenflags
= PyThreadState_Get()->interp
->dlopenflags
;
88 printf("dlopen(\"%s\", %x);\n", pathname
, dlopenflags
);
90 handle
= dlopen(pathname
, dlopenflags
);
93 PyErr_SetString(PyExc_ImportError
, dlerror());
96 if (fp
!= NULL
&& nhandles
< 128)
97 handles
[nhandles
++].handle
= handle
;
98 p
= (dl_funcptr
) dlsym(handle
, funcname
);