@@ -127,6 +127,8 @@ static void aix_loaderror(char *name);
127127#ifdef DYNAMIC_LINK
128128
129129#ifdef USE_SHLIB
130+ #include <sys/types.h>
131+ #include <sys/stat.h>
130132#ifdef __NetBSD__
131133#include <nlist.h>
132134#include <link.h>
@@ -204,9 +206,10 @@ struct filedescr import_filetab[] = {
204206};
205207
206208object *
207- load_dynamic_module (name , pathname )
209+ load_dynamic_module (name , pathname , fp )
208210 char * name ;
209211 char * pathname ;
212+ FILE * fp ;
210213{
211214#ifndef DYNAMIC_LINK
212215 err_setstr (ImportError , "dynamically linked modules not supported" );
@@ -215,7 +218,34 @@ load_dynamic_module(name, pathname)
215218 object * m ;
216219 char funcname [258 ];
217220 dl_funcptr p = NULL ;
221+ #ifdef USE_SHLIB
222+ static struct {
223+ dev_t dev ;
224+ ino_t ino ;
225+ void * handle ;
226+ } handles [128 ];
227+ static int nhandles = 0 ;
228+ #endif
218229 sprintf (funcname , FUNCNAME_PATTERN , name );
230+ #ifdef USE_SHLIB
231+ if (fp != NULL ) {
232+ int i ;
233+ struct stat statb ;
234+ fstat (fileno (fp ), & statb );
235+ for (i = 0 ; i < nhandles ; i ++ ) {
236+ if (statb .st_dev == handles [i ].dev &&
237+ statb .st_ino == handles [i ].ino ) {
238+ p = (dl_funcptr ) dlsym (handles [i ].handle ,
239+ funcname );
240+ goto got_it ;
241+ }
242+ }
243+ if (nhandles < 128 ) {
244+ handles [nhandles ].dev = statb .st_dev ;
245+ handles [nhandles ].ino = statb .st_ino ;
246+ }
247+ }
248+ #endif /* USE_SHLIB */
219249#ifdef USE_MAC_SHARED_LIBRARY
220250 /* Dynamic loading of CFM shared libraries on the Mac */
221251 {
@@ -255,6 +285,8 @@ load_dynamic_module(name, pathname)
255285 err_setstr (ImportError , dlerror ());
256286 return NULL ;
257287 }
288+ if (fp != NULL && nhandles < 128 )
289+ handles [nhandles ++ ].handle = handle ;
258290 p = (dl_funcptr ) dlsym (handle , funcname );
259291 }
260292#endif /* USE_SHLIB */
@@ -345,6 +377,7 @@ load_dynamic_module(name, pathname)
345377 perror (funcname );
346378 }
347379#endif /* hpux */
380+ got_it :
348381 if (p == NULL ) {
349382 err_setstr (ImportError ,
350383 "dynamic module does not define init function" );
@@ -385,7 +418,7 @@ void aix_loaderror(char *pathname)
385418 int errno ;
386419 char * errstr ;
387420 } load_errtab [] = {
388- {L_ERROR_TOOMANY , "to many errors, rest skipped." },
421+ {L_ERROR_TOOMANY , "too many errors, rest skipped." },
389422 {L_ERROR_NOLIB , "can't load library:" },
390423 {L_ERROR_UNDEF , "can't find symbol in library:" },
391424 {L_ERROR_RLDBAD ,
0 commit comments