2 /* Support for dynamic loading of extension modules */
9 #if defined(__NetBSD__) && (NetBSD < 199712)
12 #define dlerror() "error in dynamic linking"
20 #define LEAD_UNDERSCORE "_"
22 #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
)
57 if (strchr(pathname
, '/') == NULL
) {
58 /* Prefix bare filename with "./" */
59 sprintf(pathbuf
, "./%-.255s", pathname
);
63 sprintf(funcname
, LEAD_UNDERSCORE
"init%.200s", shortname
);
68 fstat(fileno(fp
), &statb
);
69 for (i
= 0; i
< nhandles
; i
++) {
70 if (statb
.st_dev
== handles
[i
].dev
&&
71 statb
.st_ino
== handles
[i
].ino
) {
72 p
= (dl_funcptr
) dlsym(handles
[i
].handle
,
78 handles
[nhandles
].dev
= statb
.st_dev
;
79 handles
[nhandles
].ino
= statb
.st_ino
;
84 /* RTLD_NOW: resolve externals now
85 (i.e. core dump now if some are missing) */
86 handle
= dlopen(pathname
, RTLD_NOW
);
89 printf("dlopen(\"%s\", %d);\n", pathname
,
91 handle
= dlopen(pathname
, RTLD_LAZY
);
94 PyErr_SetString(PyExc_ImportError
, dlerror());
97 if (fp
!= NULL
&& nhandles
< 128)
98 handles
[nhandles
++].handle
= handle
;
99 p
= (dl_funcptr
) dlsym(handle
, funcname
);