/[libtool]/libtool/libltdl/ltdl.c
ViewVC logotype

Diff of /libtool/libltdl/ltdl.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.137 by gary, Tue Jun 26 01:06:00 2001 UTC revision 1.138 by gary, Tue Jun 26 01:37:48 2001 UTC
# Line 203  static const char      sys_search_path[]       = LT Line 203  static const char      sys_search_path[]       = LT
203     ensure that the stored error message from the last error is not     ensure that the stored error message from the last error is not
204     accidentally erased if the current function doesn't generate an     accidentally erased if the current function doesn't generate an
205     error of its own.  */     error of its own.  */
206  #define MUTEX_LOCK()                            LT_STMT_START { \  #define LT_DLMUTEX_LOCK()                       LT_STMT_START { \
207          if (mutex_lock) (*mutex_lock)();        } LT_STMT_END          if (lt_dlmutex_lock_func) (*lt_dlmutex_lock_func)();    \
208  #define MUTEX_UNLOCK()                          LT_STMT_START { \                                                  } LT_STMT_END
209          if (mutex_unlock) (*mutex_unlock)();    } LT_STMT_END  #define LT_DLMUTEX_UNLOCK()                     LT_STMT_START { \
210  #define MUTEX_SETERROR(errormsg)                LT_STMT_START { \          if (lt_dlmutex_unlock_func) (*lt_dlmutex_unlock_func)();\
211          if (mutex_seterror) (*mutex_seterror) (errormsg);       \                                                  } LT_STMT_END
212          else last_error = (errormsg);           } LT_STMT_END  #define LT_DLMUTEX_SETERROR(errormsg)           LT_STMT_START { \
213  #define MUTEX_GETERROR(errormsg)                LT_STMT_START { \          if (lt_dlmutex_seterror_func)                           \
214          if (mutex_seterror) errormsg = (*mutex_geterror)();     \                  (*lt_dlmutex_seterror_func) (errormsg);         \
215          else (errormsg) = last_error;           } LT_STMT_END          else    lt_dllast_error = (errormsg);   } LT_STMT_END
216    #define LT_DLMUTEX_GETERROR(errormsg)           LT_STMT_START { \
217            if (lt_dlmutex_seterror_func)                           \
218                    (errormsg) = (*lt_dlmutex_geterror_func) ();    \
219            else    (errormsg) = lt_dllast_error;   } LT_STMT_END
220    
221  /* The mutex functions stored here are global, and are necessarily the  /* The mutex functions stored here are global, and are necessarily the
222     same for all threads that wish to share access to libltdl.  */     same for all threads that wish to share access to libltdl.  */
223  static  lt_dlmutex_lock     *mutex_lock     = 0;  static  lt_dlmutex_lock     *lt_dlmutex_lock_func     = 0;
224  static  lt_dlmutex_unlock   *mutex_unlock   = 0;  static  lt_dlmutex_unlock   *lt_dlmutex_unlock_func   = 0;
225  static  lt_dlmutex_seterror *mutex_seterror = 0;  static  lt_dlmutex_seterror *lt_dlmutex_seterror_func = 0;
226  static  lt_dlmutex_geterror *mutex_geterror = 0;  static  lt_dlmutex_geterror *lt_dlmutex_geterror_func = 0;
227  static  const char          *last_error     = 0;  static  const char          *lt_dllast_error          = 0;
228    
229    
230  /* Either set or reset the mutex functions.  Either all the arguments must  /* Either set or reset the mutex functions.  Either all the arguments must
# Line 238  lt_dlmutex_register (lock, unlock, seter Line 242  lt_dlmutex_register (lock, unlock, seter
242    int                errors     = 0;    int                errors     = 0;
243    
244    /* Lock using the old lock() callback, if any.  */    /* Lock using the old lock() callback, if any.  */
245    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
246    
247    if ((lock && unlock && seterror && geterror)    if ((lock && unlock && seterror && geterror)
248        || !(lock || unlock || seterror || geterror))        || !(lock || unlock || seterror || geterror))
249      {      {
250        mutex_lock     = lock;        lt_dlmutex_lock_func     = lock;
251        mutex_unlock   = unlock;        lt_dlmutex_unlock_func   = unlock;
252        mutex_geterror = geterror;        lt_dlmutex_geterror_func = geterror;
253      }      }
254    else    else
255      {      {
256        MUTEX_SETERROR (LT_DLSTRERROR (INVALID_MUTEX_ARGS));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_MUTEX_ARGS));
257        ++errors;        ++errors;
258      }      }
259    
# Line 302  lt_dladderror (diagnostic) Line 306  lt_dladderror (diagnostic)
306    int           result   = -1;    int           result   = -1;
307    const char  **temp     = (const char **) 0;    const char  **temp     = (const char **) 0;
308    
309    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
310    
311    index  = errorcount - LT_ERROR_MAX;    index  = errorcount - LT_ERROR_MAX;
312    temp = LT_DLREALLOC (const char *, user_error_strings, 1 + index);    temp = LT_DLREALLOC (const char *, user_error_strings, 1 + index);
313    if (temp == 0)    if (temp == 0)
314      {      {
315        MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
316      }      }
317    else    else
318      {      {
# Line 317  lt_dladderror (diagnostic) Line 321  lt_dladderror (diagnostic)
321        result                    = errorcount++;        result                    = errorcount++;
322      }      }
323    
324    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
325    
326    return result;    return result;
327  }  }
# Line 328  lt_dlseterror (index) Line 332  lt_dlseterror (index)
332  {  {
333    int           errors   = 0;    int           errors   = 0;
334    
335    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
336    
337    if (index >= errorcount || index < 0)    if (index >= errorcount || index < 0)
338      {      {
339        /* Ack!  Error setting the error message! */        /* Ack!  Error setting the error message! */
340        MUTEX_SETERROR (LT_DLSTRERROR (INVALID_ERRORCODE));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_ERRORCODE));
341        ++errors;        ++errors;
342      }      }
343    else if (index < LT_ERROR_MAX)    else if (index < LT_ERROR_MAX)
344      {      {
345        /* No error setting the error message! */        /* No error setting the error message! */
346        MUTEX_SETERROR (lt_dlerror_strings[errorcount]);        LT_DLMUTEX_SETERROR (lt_dlerror_strings[errorcount]);
347      }      }
348    else    else
349      {      {
350        /* No error setting the error message! */        /* No error setting the error message! */
351        MUTEX_SETERROR (user_error_strings[errorcount - LT_ERROR_MAX]);        LT_DLMUTEX_SETERROR (user_error_strings[errorcount - LT_ERROR_MAX]);
352      }      }
353    
354    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
355    
356    return errors;    return errors;
357  }  }
# Line 603  sys_dl_open (loader_data, filename) Line 607  sys_dl_open (loader_data, filename)
607    
608    if (!module)    if (!module)
609      {      {
610        MUTEX_SETERROR (DLERROR (CANNOT_OPEN));        LT_DLMUTEX_SETERROR (DLERROR (CANNOT_OPEN));
611      }      }
612    
613    return module;    return module;
# Line 618  sys_dl_close (loader_data, module) Line 622  sys_dl_close (loader_data, module)
622    
623    if (dlclose (module) != 0)    if (dlclose (module) != 0)
624      {      {
625        MUTEX_SETERROR (DLERROR (CANNOT_CLOSE));        LT_DLMUTEX_SETERROR (DLERROR (CANNOT_CLOSE));
626        ++errors;        ++errors;
627      }      }
628    
# Line 635  sys_dl_sym (loader_data, module, symbol) Line 639  sys_dl_sym (loader_data, module, symbol)
639    
640    if (!address)    if (!address)
641      {      {
642        MUTEX_SETERROR (DLERROR (SYMBOL_NOT_FOUND));        LT_DLMUTEX_SETERROR (DLERROR (SYMBOL_NOT_FOUND));
643      }      }
644    
645    return address;    return address;
# Line 733  sys_shl_open (loader_data, filename) Line 737  sys_shl_open (loader_data, filename)
737    
738        if (!module)        if (!module)
739          {          {
740            MUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN));            LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN));
741          }          }
742      }      }
743        
# Line 749  sys_shl_close (loader_data, module) Line 753  sys_shl_close (loader_data, module)
753    
754    if (module && (shl_unload ((shl_t) (module)) != 0))    if (module && (shl_unload ((shl_t) (module)) != 0))
755      {      {
756        MUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE));
757        ++errors;        ++errors;
758      }      }
759    
# Line 767  sys_shl_sym (loader_data, module, symbol Line 771  sys_shl_sym (loader_data, module, symbol
771    /* sys_shl_open should never return a NULL module handle */    /* sys_shl_open should never return a NULL module handle */
772    if (module == (lt_module) 0)    if (module == (lt_module) 0)
773    {    {
774      MUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE));      LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE));
775    }    }
776    else if (!shl_findsym((shl_t*) &module, symbol, TYPE_UNDEFINED, &address))    else if (!shl_findsym((shl_t*) &module, symbol, TYPE_UNDEFINED, &address))
777      {      {
778        if (!address)        if (!address)
779          {          {
780            MUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND));            LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND));
781          }          }
782      }      }
783        
# Line 836  sys_wll_open (loader_data, filename) Line 840  sys_wll_open (loader_data, filename)
840        searchname = LT_DLMALLOC (char, 2+ LT_DLSTRLEN (filename));        searchname = LT_DLMALLOC (char, 2+ LT_DLSTRLEN (filename));
841        if (!searchname)        if (!searchname)
842          {          {
843            MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));            LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
844            return 0;            return 0;
845          }          }
846        strcpy (searchname, filename);        strcpy (searchname, filename);
# Line 862  sys_wll_open (loader_data, filename) Line 866  sys_wll_open (loader_data, filename)
866       We check whether LoadLibrary is returning a handle to       We check whether LoadLibrary is returning a handle to
867       an already loaded module, and simulate failure if we       an already loaded module, and simulate failure if we
868       find one. */       find one. */
869    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
870    cur = handles;    cur = handles;
871    while (cur)    while (cur)
872      {      {
# Line 879  sys_wll_open (loader_data, filename) Line 883  sys_wll_open (loader_data, filename)
883    
884        cur = cur->next;        cur = cur->next;
885    }    }
886    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
887    
888    if (cur || !module)    if (cur || !module)
889      {      {
890        MUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN));
891        module = 0;        module = 0;
892      }      }
893    
# Line 899  sys_wll_close (loader_data, module) Line 903  sys_wll_close (loader_data, module)
903    
904    if (FreeLibrary(module) == 0)    if (FreeLibrary(module) == 0)
905      {      {
906        MUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE));
907        ++errors;        ++errors;
908      }      }
909    
# Line 916  sys_wll_sym (loader_data, module, symbol Line 920  sys_wll_sym (loader_data, module, symbol
920    
921    if (!address)    if (!address)
922      {      {
923        MUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND));
924      }      }
925    
926    return address;    return address;
# Line 961  sys_bedl_open (loader_data, filename) Line 965  sys_bedl_open (loader_data, filename)
965    
966    if (image <= 0)    if (image <= 0)
967      {      {
968        MUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN));
969        image = 0;        image = 0;
970      }      }
971    
# Line 977  sys_bedl_close (loader_data, module) Line 981  sys_bedl_close (loader_data, module)
981    
982    if (unload_add_on ((image_id) module) != B_OK)    if (unload_add_on ((image_id) module) != B_OK)
983      {      {
984        MUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE));
985        ++errors;        ++errors;
986      }      }
987    
# Line 995  sys_bedl_sym (loader_data, module, symbo Line 999  sys_bedl_sym (loader_data, module, symbo
999    
1000    if (get_image_symbol (image, symbol, B_SYMBOL_TYPE_ANY, address) != B_OK)    if (get_image_symbol (image, symbol, B_SYMBOL_TYPE_ANY, address) != B_OK)
1001      {      {
1002        MUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND));
1003        address = 0;        address = 0;
1004      }      }
1005    
# Line 1031  sys_dld_open (loader_data, filename) Line 1035  sys_dld_open (loader_data, filename)
1035    
1036    if (!module)    if (!module)
1037      {      {
1038        MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
1039        module = 0;        module = 0;
1040      }      }
1041    else if (dld_link (filename) != 0)    else if (dld_link (filename) != 0)
1042      {      {
1043        MUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_OPEN));
1044        LT_DLFREE (module);        LT_DLFREE (module);
1045        module = 0;        module = 0;
1046      }      }
# Line 1053  sys_dld_close (loader_data, module) Line 1057  sys_dld_close (loader_data, module)
1057    
1058    if (dld_unlink_by_file ((char*)(module), 1) != 0)    if (dld_unlink_by_file ((char*)(module), 1) != 0)
1059      {      {
1060        MUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CANNOT_CLOSE));
1061        ++errors;        ++errors;
1062      }      }
1063    else    else
# Line 1074  sys_dld_sym (loader_data, module, symbol Line 1078  sys_dld_sym (loader_data, module, symbol
1078    
1079    if (!address)    if (!address)
1080      {      {
1081        MUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND));
1082      }      }
1083    
1084    return address;    return address;
# Line 1109  presym_init (loader_data) Line 1113  presym_init (loader_data)
1113  {  {
1114    int errors = 0;    int errors = 0;
1115    
1116    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
1117    
1118    preloaded_symbols = 0;    preloaded_symbols = 0;
1119    if (default_preloaded_symbols)    if (default_preloaded_symbols)
# Line 1117  presym_init (loader_data) Line 1121  presym_init (loader_data)
1121        errors = lt_dlpreload (default_preloaded_symbols);        errors = lt_dlpreload (default_preloaded_symbols);
1122      }      }
1123    
1124    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
1125    
1126    return errors;    return errors;
1127  }  }
# Line 1127  presym_free_symlists () Line 1131  presym_free_symlists ()
1131  {  {
1132    lt_dlsymlists_t *lists;    lt_dlsymlists_t *lists;
1133    
1134    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
1135    
1136    lists = preloaded_symbols;    lists = preloaded_symbols;
1137    while (lists)    while (lists)
# Line 1139  presym_free_symlists () Line 1143  presym_free_symlists ()
1143      }      }
1144    preloaded_symbols = 0;    preloaded_symbols = 0;
1145    
1146    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
1147    
1148    return 0;    return 0;
1149  }  }
# Line 1160  presym_add_symlist (preloaded) Line 1164  presym_add_symlist (preloaded)
1164    lt_dlsymlists_t *lists;    lt_dlsymlists_t *lists;
1165    int              errors   = 0;    int              errors   = 0;
1166    
1167    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
1168    
1169    lists = preloaded_symbols;    lists = preloaded_symbols;
1170    while (lists)    while (lists)
# Line 1181  presym_add_symlist (preloaded) Line 1185  presym_add_symlist (preloaded)
1185      }      }
1186    else    else
1187      {      {
1188        MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
1189        ++errors;        ++errors;
1190      }      }
1191    
1192   done:   done:
1193    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
1194    return errors;    return errors;
1195  }  }
1196    
# Line 1198  presym_open (loader_data, filename) Line 1202  presym_open (loader_data, filename)
1202    lt_dlsymlists_t *lists;    lt_dlsymlists_t *lists;
1203    lt_module        module = (lt_module) 0;    lt_module        module = (lt_module) 0;
1204    
1205    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
1206    lists = preloaded_symbols;    lists = preloaded_symbols;
1207    
1208    if (!lists)    if (!lists)
1209      {      {
1210        MUTEX_SETERROR (LT_DLSTRERROR (NO_SYMBOLS));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_SYMBOLS));
1211        goto done;        goto done;
1212      }      }
1213    
# Line 1229  presym_open (loader_data, filename) Line 1233  presym_open (loader_data, filename)
1233        lists = lists->next;        lists = lists->next;
1234      }      }
1235    
1236    MUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));    LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));
1237    
1238   done:   done:
1239    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
1240    return module;    return module;
1241  }  }
1242    
# Line 1265  presym_sym (loader_data, module, symbol) Line 1269  presym_sym (loader_data, module, symbol)
1269      ++syms;      ++syms;
1270    }    }
1271    
1272    MUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND));    LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND));
1273    
1274    return 0;    return 0;
1275  }  }
# Line 1333  lt_dlinit () Line 1337  lt_dlinit ()
1337  {  {
1338    int         errors   = 0;    int         errors   = 0;
1339    
1340    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
1341    
1342    /* Initialize only at first call. */    /* Initialize only at first call. */
1343    if (++initialized == 1)    if (++initialized == 1)
# Line 1360  lt_dlinit () Line 1364  lt_dlinit ()
1364    
1365        if (presym_init (presym.dlloader_data))        if (presym_init (presym.dlloader_data))
1366          {          {
1367            MUTEX_SETERROR (LT_DLSTRERROR (INIT_LOADER));            LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INIT_LOADER));
1368            ++errors;            ++errors;
1369          }          }
1370        else if (errors != 0)        else if (errors != 0)
1371          {          {
1372            MUTEX_SETERROR (LT_DLSTRERROR (DLOPEN_NOT_SUPPORTED));            LT_DLMUTEX_SETERROR (LT_DLSTRERROR (DLOPEN_NOT_SUPPORTED));
1373            ++errors;            ++errors;
1374          }          }
1375      }      }
1376    
1377    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
1378    
1379    return errors;    return errors;
1380  }  }
# Line 1391  lt_dlpreload (preloaded) Line 1395  lt_dlpreload (preloaded)
1395    
1396        presym_free_symlists();        presym_free_symlists();
1397        
1398        MUTEX_LOCK ();        LT_DLMUTEX_LOCK ();
1399        if (default_preloaded_symbols)        if (default_preloaded_symbols)
1400          {          {
1401            errors = lt_dlpreload (default_preloaded_symbols);            errors = lt_dlpreload (default_preloaded_symbols);
1402          }          }
1403        MUTEX_UNLOCK ();        LT_DLMUTEX_UNLOCK ();
1404      }      }
1405    
1406    return errors;    return errors;
# Line 1406  int Line 1410  int
1410  lt_dlpreload_default (preloaded)  lt_dlpreload_default (preloaded)
1411       const lt_dlsymlist *preloaded;       const lt_dlsymlist *preloaded;
1412  {  {
1413    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
1414    default_preloaded_symbols = preloaded;    default_preloaded_symbols = preloaded;
1415    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
1416    return 0;    return 0;
1417  }  }
1418    
# Line 1420  lt_dlexit () Line 1424  lt_dlexit ()
1424    const char  *errormsg;    const char  *errormsg;
1425    int          errors   = 0;    int          errors   = 0;
1426    
1427    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
1428    loader = loaders;    loader = loaders;
1429    
1430    if (!initialized)    if (!initialized)
1431      {      {
1432        MUTEX_SETERROR (LT_DLSTRERROR (SHUTDOWN));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SHUTDOWN));
1433        ++errors;        ++errors;
1434        goto done;        goto done;
1435      }      }
# Line 1481  lt_dlexit () Line 1485  lt_dlexit ()
1485      }      }
1486    
1487   done:   done:
1488    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
1489    return errors;    return errors;
1490  }  }
1491    
# Line 1495  tryall_dlopen (handle, filename) Line 1499  tryall_dlopen (handle, filename)
1499    const char    *saved_error;    const char    *saved_error;
1500    int            errors         = 0;    int            errors         = 0;
1501    
1502    MUTEX_GETERROR (saved_error);    LT_DLMUTEX_GETERROR (saved_error);
1503    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
1504    
1505    cur    = handles;    cur    = handles;
1506    loader = loaders;    loader = loaders;
# Line 1532  tryall_dlopen (handle, filename) Line 1536  tryall_dlopen (handle, filename)
1536        cur->info.filename = strdup (filename);        cur->info.filename = strdup (filename);
1537        if (!cur->info.filename)        if (!cur->info.filename)
1538          {          {
1539            MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));            LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
1540            ++errors;            ++errors;
1541            goto done;            goto done;
1542          }          }
# Line 1563  tryall_dlopen (handle, filename) Line 1567  tryall_dlopen (handle, filename)
1567      }      }
1568    
1569    cur->loader   = loader;    cur->loader   = loader;
1570    last_error    = saved_error;    lt_dllast_error       = saved_error;
1571        
1572   done:   done:
1573    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
1574    
1575    return errors;    return errors;
1576  }  }
# Line 1604  find_module (handle, dir, libdir, dlname Line 1608  find_module (handle, dir, libdir, dlname
1608    
1609            if (!filename)            if (!filename)
1610              {              {
1611                MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));                LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
1612                return 1;                return 1;
1613              }              }
1614    
# Line 1626  find_module (handle, dir, libdir, dlname Line 1630  find_module (handle, dir, libdir, dlname
1630    
1631            if (!filename)            if (!filename)
1632              {              {
1633                MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));                LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
1634                return 1;                return 1;
1635              }              }
1636    
# Line 1717  foreach_dirinpath (search_path, base_nam Line 1721  foreach_dirinpath (search_path, base_nam
1721    int   lenbase         = LT_DLSTRLEN (base_name);    int   lenbase         = LT_DLSTRLEN (base_name);
1722    char *filename, *canonical, *next;    char *filename, *canonical, *next;
1723    
1724    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
1725    
1726    if (!search_path || !*search_path)    if (!search_path || !*search_path)
1727      {      {
1728        MUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));
1729        goto cleanup;        goto cleanup;
1730      }      }
1731    
1732    canonical = canonicalize_path (search_path);    canonical = canonicalize_path (search_path);
1733    if (!canonical)    if (!canonical)
1734      {      {
1735        MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
1736        goto cleanup;        goto cleanup;
1737      }      }
1738    
# Line 1759  foreach_dirinpath (search_path, base_nam Line 1763  foreach_dirinpath (search_path, base_nam
1763    
1764            if (!filename)            if (!filename)
1765              {              {
1766                MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));                LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
1767                goto cleanup;                goto cleanup;
1768              }              }
1769          }          }
# Line 1780  foreach_dirinpath (search_path, base_nam Line 1784  foreach_dirinpath (search_path, base_nam
1784    LT_DLFREE (canonical);    LT_DLFREE (canonical);
1785    LT_DLFREE (filename);    LT_DLFREE (filename);
1786    
1787    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
1788        
1789    return result;    return result;
1790  }  }
# Line 1818  find_file_callback (filename, data1, dat Line 1822  find_file_callback (filename, data1, dat
1822      }      }
1823    else    else
1824      {      {
1825        MUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));
1826      }      }
1827    
1828    return is_done;    return is_done;
# Line 1886  load_deplibs (handle, deplibs) Line 1890  load_deplibs (handle, deplibs)
1890      }      }
1891    ++errors;    ++errors;
1892    
1893    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
1894    save_search_path = strdup (user_search_path);    save_search_path = strdup (user_search_path);
1895    if (user_search_path && !save_search_path)    if (user_search_path && !save_search_path)
1896      {      {
1897        MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
1898        goto cleanup;        goto cleanup;
1899      }      }
1900    
# Line 1933  load_deplibs (handle, deplibs) Line 1937  load_deplibs (handle, deplibs)
1937    LT_DLFREE (user_search_path);    LT_DLFREE (user_search_path);
1938    user_search_path = save_search_path;    user_search_path = save_search_path;
1939    
1940    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
1941    
1942    if (!depcount)    if (!depcount)
1943      {      {
# Line 2076  trim (dest, str) Line 2080  trim (dest, str)
2080        tmp = LT_DLMALLOC (char, end - str);        tmp = LT_DLMALLOC (char, end - str);
2081        if (!tmp)        if (!tmp)
2082          {          {
2083            last_error = LT_DLSTRERROR (NO_MEMORY);            lt_dllast_error = LT_DLSTRERROR (NO_MEMORY);
2084            return 1;            return 1;
2085          }          }
2086    
# Line 2116  lt_dlopen (filename) Line 2120  lt_dlopen (filename)
2120    const char *saved_error;    const char *saved_error;
2121    char  *canonical = 0, *base_name = 0, *dir = 0, *name = 0;    char  *canonical = 0, *base_name = 0, *dir = 0, *name = 0;
2122    
2123    MUTEX_GETERROR (saved_error);    LT_DLMUTEX_GETERROR (saved_error);
2124    
2125    /* dlopen self? */    /* dlopen self? */
2126    if (!filename)    if (!filename)
# Line 2124  lt_dlopen (filename) Line 2128  lt_dlopen (filename)
2128        handle = (lt_dlhandle) LT_DLMALLOC (struct lt_dlhandle_struct, 1);        handle = (lt_dlhandle) LT_DLMALLOC (struct lt_dlhandle_struct, 1);
2129        if (!handle)        if (!handle)
2130          {          {
2131            MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));            LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
2132            return 0;            return 0;
2133          }          }
2134    
# Line 2148  lt_dlopen (filename) Line 2152  lt_dlopen (filename)
2152    canonical = canonicalize_path (filename);    canonical = canonicalize_path (filename);
2153    if (!canonical)    if (!canonical)
2154      {      {
2155        MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
2156        LT_DLFREE (handle);        LT_DLFREE (handle);
2157        return 0;        return 0;
2158      }      }
# Line 2162  lt_dlopen (filename) Line 2166  lt_dlopen (filename)
2166        dir = LT_DLMALLOC (char, base_name - canonical + 1);        dir = LT_DLMALLOC (char, base_name - canonical + 1);
2167        if (!dir)        if (!dir)
2168          {          {
2169            MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));            LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
2170            handle = 0;            handle = 0;
2171            goto cleanup;            goto cleanup;
2172          }          }
# Line 2197  lt_dlopen (filename) Line 2201  lt_dlopen (filename)
2201        name = LT_DLMALLOC (char, ext - base_name + 1);        name = LT_DLMALLOC (char, ext - base_name + 1);
2202        if (!name)        if (!name)
2203          {          {
2204            MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));            LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
2205            handle = 0;            handle = 0;
2206            goto cleanup;            goto cleanup;
2207          }          }
# Line 2248  lt_dlopen (filename) Line 2252  lt_dlopen (filename)
2252          }          }
2253        if (!file)        if (!file)
2254          {          {
2255            MUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));            LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));
2256          }          }
2257    
2258        if (!file)        if (!file)
# Line 2262  lt_dlopen (filename) Line 2266  lt_dlopen (filename)
2266        if (!line)        if (!line)
2267          {          {
2268            fclose (file);            fclose (file);
2269            MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));            LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
2270            handle = 0;            handle = 0;
2271            goto cleanup;            goto cleanup;
2272          }          }
# Line 2361  lt_dlopen (filename) Line 2365  lt_dlopen (filename)
2365            LT_DLFREE (handle);            LT_DLFREE (handle);
2366            if (!error)            if (!error)
2367              {              {
2368                MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));                LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
2369              }              }
2370    
2371            free_vars (dlname, old_name, libdir, deplibs);            free_vars (dlname, old_name, libdir, deplibs);
# Line 2403  lt_dlopen (filename) Line 2407  lt_dlopen (filename)
2407        handle = (lt_dlhandle) LT_DLMALLOC (struct lt_dlhandle_struct, 1);        handle = (lt_dlhandle) LT_DLMALLOC (struct lt_dlhandle_struct, 1);
2408        if (!handle)        if (!handle)
2409          {          {
2410            MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));            LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
2411            /* handle is already set to 0 */            /* handle is already set to 0 */
2412            goto cleanup;            goto cleanup;
2413          }          }
# Line 2443  lt_dlopen (filename) Line 2447  lt_dlopen (filename)
2447        handle->info.name         = name;        handle->info.name         = name;
2448        handle->next              = handles;        handle->next              = handles;
2449    
2450        MUTEX_LOCK ();        LT_DLMUTEX_LOCK ();
2451        handles                   = handle;        handles                   = handle;
2452        MUTEX_UNLOCK ();        LT_DLMUTEX_UNLOCK ();
2453    
2454        name = 0; /* don't free this during `cleanup' */        name = 0; /* don't free this during `cleanup' */
2455      }      }
2456    
2457    MUTEX_SETERROR (saved_error);    LT_DLMUTEX_SETERROR (saved_error);
2458    
2459   cleanup:   cleanup:
2460    LT_DLFREE (dir);    LT_DLFREE (dir);
# Line 2469  lt_dlopenext (filename) Line 2473  lt_dlopenext (filename)
2473    int   len;    int   len;
2474    const char *saved_error;    const char *saved_error;
2475    
2476    MUTEX_GETERROR (saved_error);    LT_DLMUTEX_GETERROR (saved_error);
2477    
2478    if (!filename)    if (!filename)
2479      {      {
# Line 2479  lt_dlopenext (filename) Line 2483  lt_dlopenext (filename)
2483    len = strlen (filename);    len = strlen (filename);
2484    if (!len)    if (!len)
2485      {      {
2486        MUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));
2487        return 0;        return 0;
2488      }      }
2489    
# Line 2487  lt_dlopenext (filename) Line 2491  lt_dlopenext (filename)
2491    tmp = LT_DLMALLOC (char, len+4);    tmp = LT_DLMALLOC (char, len+4);
2492    if (!tmp)    if (!tmp)
2493      {      {
2494        MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
2495        return 0;        return 0;
2496      }      }
2497    strcpy (tmp, filename);    strcpy (tmp, filename);
# Line 2495  lt_dlopenext (filename) Line 2499  lt_dlopenext (filename)
2499    handle = lt_dlopen (tmp);    handle = lt_dlopen (tmp);
2500    if (handle)    if (handle)
2501      {      {
2502        MUTEX_SETERROR (saved_error);        LT_DLMUTEX_SETERROR (saved_error);
2503        LT_DLFREE (tmp);        LT_DLFREE (tmp);
2504        return handle;        return handle;
2505      }      }
# Line 2508  lt_dlopenext (filename) Line 2512  lt_dlopenext (filename)
2512        tmp = LT_DLMALLOC (char, len + strlen (shlib_ext) + 1);        tmp = LT_DLMALLOC (char, len + strlen (shlib_ext) + 1);
2513        if (!tmp)        if (!tmp)
2514          {          {
2515            MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));            LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
2516            return 0;            return 0;
2517          }          }
2518        strcpy (tmp, filename);        strcpy (tmp, filename);
# Line 2522  lt_dlopenext (filename) Line 2526  lt_dlopenext (filename)
2526    handle = lt_dlopen (tmp);    handle = lt_dlopen (tmp);
2527    if (handle)    if (handle)
2528      {      {
2529        MUTEX_SETERROR (saved_error);        LT_DLMUTEX_SETERROR (saved_error);
2530        LT_DLFREE (tmp);        LT_DLFREE (tmp);
2531        return handle;        return handle;
2532      }      }
# Line 2535  lt_dlopenext (filename) Line 2539  lt_dlopenext (filename)
2539        return handle;        return handle;
2540      }      }
2541    
2542    MUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));    LT_DLMUTEX_SETERROR (LT_DLSTRERROR (FILE_NOT_FOUND));
2543    LT_DLFREE (tmp);    LT_DLFREE (tmp);
2544    return 0;    return 0;
2545  }  }
# Line 2562  foreachfile_callback (dirname, data1, da Line 2566  foreachfile_callback (dirname, data1, da
2566    if (!dirp)    if (!dirp)
2567      return 0;      return 0;
2568    
2569    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
2570    
2571    rewinddir (dirp);    rewinddir (dirp);
2572    while ((direntp = readdir (dirp)))    while ((direntp = readdir (dirp)))
# Line 2583  foreachfile_callback (dirname, data1, da Line 2587  foreachfile_callback (dirname, data1, da
2587    
2588            if (!filename)            if (!filename)
2589              {              {
2590                MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));                LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
2591                goto cleanup;                goto cleanup;
2592              }              }
2593          }          }
# Line 2604  foreachfile_callback (dirname, data1, da Line 2608  foreachfile_callback (dirname, data1, da
2608    LT_DLFREE (filename);    LT_DLFREE (filename);
2609    closedir (dirp);    closedir (dirp);
2610        
2611    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
2612    
2613    return 0;    return 0;
2614  }  }
# Line 2661  lt_dlclose (handle) Line 2665  lt_dlclose (handle)
2665    lt_dlhandle cur, last;    lt_dlhandle cur, last;
2666    int errors = 0;    int errors = 0;
2667    
2668    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
2669    
2670    /* check whether the handle is valid */    /* check whether the handle is valid */
2671    last = cur = handles;    last = cur = handles;
# Line 2673  lt_dlclose (handle) Line 2677  lt_dlclose (handle)
2677    
2678    if (!cur)    if (!cur)
2679      {      {
2680        MUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE));
2681        ++errors;        ++errors;
2682        goto done;        goto done;
2683      }      }
# Line 2709  lt_dlclose (handle) Line 2713  lt_dlclose (handle)
2713    
2714    if (LT_DLIS_RESIDENT (handle))    if (LT_DLIS_RESIDENT (handle))
2715      {      {
2716        MUTEX_SETERROR (LT_DLSTRERROR (CLOSE_RESIDENT_MODULE));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (CLOSE_RESIDENT_MODULE));
2717        ++errors;        ++errors;
2718      }      }
2719    
2720   done:   done:
2721    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
2722    
2723    return errors;    return errors;
2724  }  }
# Line 2732  lt_dlsym (handle, symbol) Line 2736  lt_dlsym (handle, symbol)
2736    
2737    if (!handle)    if (!handle)
2738      {      {
2739        MUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE));
2740        return 0;        return 0;
2741      }      }
2742    
2743    if (!symbol)    if (!symbol)
2744      {      {
2745        MUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (SYMBOL_NOT_FOUND));
2746        return 0;        return 0;
2747      }      }
2748    
# Line 2756  lt_dlsym (handle, symbol) Line 2760  lt_dlsym (handle, symbol)
2760    
2761    if (!sym)    if (!sym)
2762      {      {
2763        MUTEX_SETERROR (LT_DLSTRERROR (BUFFER_OVERFLOW));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (BUFFER_OVERFLOW));
2764        return 0;        return 0;
2765      }      }
2766    
# Line 2765  lt_dlsym (handle, symbol) Line 2769  lt_dlsym (handle, symbol)
2769      {      {
2770        const char *saved_error;        const char *saved_error;
2771    
2772        MUTEX_GETERROR (saved_error);        LT_DLMUTEX_GETERROR (saved_error);
2773    
2774        /* this is a libtool module */        /* this is a libtool module */
2775        if (handle->loader->sym_prefix)        if (handle->loader->sym_prefix)
# Line 2791  lt_dlsym (handle, symbol) Line 2795  lt_dlsym (handle, symbol)
2795              }              }
2796            return address;            return address;
2797          }          }
2798        MUTEX_SETERROR (saved_error);        LT_DLMUTEX_SETERROR (saved_error);
2799      }      }
2800    
2801    /* otherwise try "symbol" */    /* otherwise try "symbol" */
# Line 2819  lt_dlerror () Line 2823  lt_dlerror ()
2823  {  {
2824    const char *error;    const char *error;
2825    
2826    MUTEX_GETERROR (error);    LT_DLMUTEX_GETERROR (error);
2827    MUTEX_SETERROR (0);    LT_DLMUTEX_SETERROR (0);
2828    
2829    return error;    return error;
2830  }  }
# Line 2836  lt_dladdsearchdir (search_dir) Line 2840  lt_dladdsearchdir (search_dir)
2840        return errors;        return errors;
2841      }      }
2842    
2843    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
2844    if (!user_search_path)    if (!user_search_path)
2845      {      {
2846        user_search_path = strdup (search_dir);        user_search_path = strdup (search_dir);
2847        if (!user_search_path)        if (!user_search_path)
2848          {          {
2849            last_error = LT_DLSTRERROR (NO_MEMORY);            lt_dllast_error = LT_DLSTRERROR (NO_MEMORY);
2850            ++errors;            ++errors;
2851          }          }
2852      }      }
# Line 2853  lt_dladdsearchdir (search_dir) Line 2857  lt_dladdsearchdir (search_dir)
2857    
2858        if (!new_search_path)        if (!new_search_path)
2859          {          {
2860            MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));            LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
2861            ++errors;            ++errors;
2862          }          }
2863        else        else
# Line 2864  lt_dladdsearchdir (search_dir) Line 2868  lt_dladdsearchdir (search_dir)
2868            LT_DLMEM_REASSIGN (user_search_path, new_search_path);            LT_DLMEM_REASSIGN (user_search_path, new_search_path);
2869          }          }
2870      }      }
2871    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
2872    
2873    return errors;    return errors;
2874  }  }
# Line 2875  lt_dlsetsearchpath (search_path) Line 2879  lt_dlsetsearchpath (search_path)
2879  {  {
2880    int errors = 0;    int errors = 0;
2881    
2882    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
2883    LT_DLFREE (user_search_path);    LT_DLFREE (user_search_path);
2884    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
2885    
2886    if (!search_path || !strlen (search_path))    if (!search_path || !strlen (search_path))
2887      {      {
2888        return errors;        return errors;
2889      }      }
2890    
2891    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
2892    user_search_path = strdup (search_path);    user_search_path = strdup (search_path);
2893    if (!user_search_path)    if (!user_search_path)
2894      {      {
2895        ++errors;        ++errors;
2896      }      }
2897    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
2898    
2899    return errors;    return errors;
2900  }  }
# Line 2900  lt_dlgetsearchpath () Line 2904  lt_dlgetsearchpath ()
2904  {  {
2905    const char *saved_path;    const char *saved_path;
2906    
2907    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
2908    saved_path = user_search_path;    saved_path = user_search_path;
2909    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
2910    
2911    return saved_path;    return saved_path;
2912  }  }
# Line 2915  lt_dlmakeresident (handle) Line 2919  lt_dlmakeresident (handle)
2919    
2920    if (!handle)    if (!handle)
2921      {      {
2922        MUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE));
2923        ++errors;        ++errors;
2924      }      }
2925    else    else
# Line 2932  lt_dlisresident        (handle) Line 2936  lt_dlisresident        (handle)
2936  {  {
2937    if (!handle)    if (!handle)
2938      {      {
2939        MUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE));
2940        return -1;        return -1;
2941      }      }
2942    
# Line 2950  lt_dlgetinfo (handle) Line 2954  lt_dlgetinfo (handle)
2954  {  {
2955    if (!handle)    if (!handle)
2956      {      {
2957        MUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_HANDLE));
2958        return 0;        return 0;
2959      }      }
2960    
# Line 2972  lt_dlforeach (func, data) Line 2976  lt_dlforeach (func, data)
2976    int errors = 0;    int errors = 0;
2977    lt_dlhandle cur;    lt_dlhandle cur;
2978    
2979    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
2980    
2981    cur = handles;    cur = handles;
2982    while (cur)    while (cur)
# Line 2987  lt_dlforeach (func, data) Line 2991  lt_dlforeach (func, data)
2991          }          }
2992      }      }
2993    
2994    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
2995    
2996    return errors;    return errors;
2997  }  }
# Line 2998  lt_dlcaller_register () Line 3002  lt_dlcaller_register ()
3002    static int last_caller_id = -1;    static int last_caller_id = -1;
3003    int result;    int result;
3004    
3005    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
3006    result = ++last_caller_id;    result = ++last_caller_id;
3007    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
3008    
3009    return result;    return result;
3010  }  }
# Line 3019  lt_dlcaller_set_data (key, handle, data) Line 3023  lt_dlcaller_set_data (key, handle, data)
3023    
3024    /* This needs to be locked so that the caller data can be updated    /* This needs to be locked so that the caller data can be updated
3025       simultaneously by different threads.  */       simultaneously by different threads.  */
3026    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
3027    
3028    if (handle->caller_data)    if (handle->caller_data)
3029      n_elements = N_ELEMENTS (handle->caller_data);      n_elements = N_ELEMENTS (handle->caller_data);
# Line 3042  lt_dlcaller_set_data (key, handle, data) Line 3046  lt_dlcaller_set_data (key, handle, data)
3046    
3047        if (temp == 0)        if (temp == 0)
3048          {          {
3049            MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));            LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
3050            stale =  (lt_ptr) 0;            stale =  (lt_ptr) 0;
3051            goto done;            goto done;
3052          }          }
# Line 3058  lt_dlcaller_set_data (key, handle, data) Line 3062  lt_dlcaller_set_data (key, handle, data)
3062    handle->caller_data[i].data = data;    handle->caller_data[i].data = data;
3063    
3064   done:   done:
3065    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
3066    
3067    return stale;    return stale;
3068  }  }
# Line 3073  lt_dlcaller_get_data  (key, handle) Line 3077  lt_dlcaller_get_data  (key, handle)
3077    
3078    /* This needs to be locked so that the caller data isn't updated by    /* This needs to be locked so that the caller data isn't updated by
3079       another thread part way through this function.  */       another thread part way through this function.  */
3080    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
3081    
3082    if (handle->caller_data)    if (handle->caller_data)
3083      n_elements = N_ELEMENTS (handle->caller_data);      n_elements = N_ELEMENTS (handle->caller_data);
# Line 3091  lt_dlcaller_get_data  (key, handle) Line 3095  lt_dlcaller_get_data  (key, handle)
3095        }        }
3096    }    }
3097    
3098    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
3099    
3100    return result;    return result;
3101  }  }
# Line 3115  lt_dlloader_add (place, dlloader, loader Line 3119  lt_dlloader_add (place, dlloader, loader
3119        || (dlloader->module_close == 0)        || (dlloader->module_close == 0)
3120        || (dlloader->find_sym == 0))        || (dlloader->find_sym == 0))
3121      {      {
3122        MUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER));
3123        return 1;        return 1;
3124      }      }
3125    
# Line 3123  lt_dlloader_add (place, dlloader, loader Line 3127  lt_dlloader_add (place, dlloader, loader
3127    node = LT_DLMALLOC (lt_dlloader, 1);    node = LT_DLMALLOC (lt_dlloader, 1);
3128    if (node == 0)    if (node == 0)
3129      {      {
3130        MUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (NO_MEMORY));
3131        return 1;        return 1;
3132      }      }
3133    
# Line 3136  lt_dlloader_add (place, dlloader, loader Line 3140  lt_dlloader_add (place, dlloader, loader
3140    node->find_sym        = dlloader->find_sym;    node->find_sym        = dlloader->find_sym;
3141    node->dlloader_data   = dlloader->dlloader_data;    node->dlloader_data   = dlloader->dlloader_data;
3142    
3143    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
3144    if (!loaders)    if (!loaders)
3145      {      {
3146        /* If there are no loaders, NODE becomes the list! */        /* If there are no loaders, NODE becomes the list! */
# Line 3169  lt_dlloader_add (place, dlloader, loader Line 3173  lt_dlloader_add (place, dlloader, loader
3173    
3174        if (ptr->next != place)        if (ptr->next != place)
3175          {          {
3176            last_error = LT_DLSTRERROR (INVALID_LOADER);            lt_dllast_error = LT_DLSTRERROR (INVALID_LOADER);
3177            ++errors;            ++errors;
3178          }          }
3179        else        else
# Line 3180  lt_dlloader_add (place, dlloader, loader Line 3184  lt_dlloader_add (place, dlloader, loader
3184          }          }
3185      }      }
3186    
3187    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
3188    
3189    return errors;    return errors;
3190  }  }
# Line 3195  lt_dlloader_remove (loader_name) Line 3199  lt_dlloader_remove (loader_name)
3199    
3200    if (!place)    if (!place)
3201      {      {
3202        MUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER));
3203        return 1;        return 1;
3204      }      }
3205    
3206    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
3207    
3208    /* Fail if there are any open modules which use this loader. */    /* Fail if there are any open modules which use this loader. */
3209    for  (handle = handles; handle; handle = handle->next)    for  (handle = handles; handle; handle = handle->next)
3210      {      {
3211        if (handle->loader == place)        if (handle->loader == place)
3212          {          {
3213            MUTEX_SETERROR (LT_DLSTRERROR (REMOVE_LOADER));            LT_DLMUTEX_SETERROR (LT_DLSTRERROR (REMOVE_LOADER));
3214            ++errors;            ++errors;
3215            goto done;            goto done;
3216          }          }
# Line 3241  lt_dlloader_remove (loader_name) Line 3245  lt_dlloader_remove (loader_name)
3245    LT_DLFREE (place);    LT_DLFREE (place);
3246    
3247   done:   done:
3248    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
3249    
3250    return errors;    return errors;
3251  }  }
# Line 3252  lt_dlloader_next (place) Line 3256  lt_dlloader_next (place)
3256  {  {
3257    lt_dlloader *next;    lt_dlloader *next;
3258    
3259    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
3260    next = place ? place->next : loaders;    next = place ? place->next : loaders;
3261    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
3262    
3263    return next;    return next;
3264  }  }
# Line 3267  lt_dlloader_name (place) Line 3271  lt_dlloader_name (place)
3271    
3272    if (place)    if (place)
3273      {      {
3274        MUTEX_LOCK ();        LT_DLMUTEX_LOCK ();
3275        name = place ? place->loader_name : 0;        name = place ? place->loader_name : 0;
3276        MUTEX_UNLOCK ();        LT_DLMUTEX_UNLOCK ();
3277      }      }
3278    else    else
3279      {      {
3280        MUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER));
3281      }      }
3282    
3283    return name;    return name;
# Line 3287  lt_dlloader_data (place) Line 3291  lt_dlloader_data (place)
3291    
3292    if (place)    if (place)
3293      {      {
3294        MUTEX_LOCK ();        LT_DLMUTEX_LOCK ();
3295        data = place ? &(place->dlloader_data) : 0;        data = place ? &(place->dlloader_data) : 0;
3296        MUTEX_UNLOCK ();        LT_DLMUTEX_UNLOCK ();
3297      }      }
3298    else    else
3299      {      {
3300        MUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER));        LT_DLMUTEX_SETERROR (LT_DLSTRERROR (INVALID_LOADER));
3301      }      }
3302    
3303    return data;    return data;
# Line 3305  lt_dlloader_find (loader_name) Line 3309  lt_dlloader_find (loader_name)
3309  {  {
3310    lt_dlloader *place = 0;    lt_dlloader *place = 0;
3311    
3312    MUTEX_LOCK ();    LT_DLMUTEX_LOCK ();
3313    for (place = loaders; place; place = place->next)    for (place = loaders; place; place = place->next)
3314      {      {
3315        if (strcmp (place->loader_name, loader_name) == 0)        if (strcmp (place->loader_name, loader_name) == 0)
# Line 3313  lt_dlloader_find (loader_name) Line 3317  lt_dlloader_find (loader_name)
3317            break;            break;
3318          }          }
3319      }      }
3320    MUTEX_UNLOCK ();    LT_DLMUTEX_UNLOCK ();
3321    
3322    return place;    return place;
3323  }  }

Legend:
Removed from v.1.137  
changed lines
  Added in v.1.138

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26