/src/lib/foreign_interface/foreign_dll_loader.e

http://github.com/tybor/Liberty · Specman e · 60 lines · 32 code · 4 blank · 24 comment · 2 complexity · 7e02bc7e8bc92b5ead2a6852ff715258 MD5 · raw file

  1. -- This file is part of a Liberty Eiffel library.
  2. -- See the full copyright at the end.
  3. --
  4. expanded class FOREIGN_DLL_LOADER
  5. insert
  6. DYNAMIC_LINKING_LOADER
  7. feature {ANY}
  8. library (filename: ABSTRACT_STRING): FOREIGN_DLL
  9. -- The Result may be Void if the library is not found.
  10. require
  11. filename /= Void
  12. local
  13. dllname: FIXED_STRING
  14. dso: DYNAMIC_SHARED_OBJECT
  15. do
  16. dllname := filename.intern
  17. Result := loaded_dll.fast_reference_at(dllname)
  18. if Result = Void then
  19. dso := new_dynamic_shared_object(dllname, rtld_lazy | rtld_global | rtld_deepbind)
  20. if dso /= Void then
  21. check
  22. dso.name = dllname
  23. end
  24. create Result.make(dso)
  25. loaded_dll.put(Result, dllname)
  26. end
  27. end
  28. ensure
  29. Result /= Void implies Result.filename.is_equal(filename)
  30. end
  31. feature {FOREIGN_DLL_HANDLER}
  32. loaded_dll: DICTIONARY[FOREIGN_DLL, FIXED_STRING]
  33. once
  34. create {HASHED_DICTIONARY[FOREIGN_DLL, FIXED_STRING]} Result.with_capacity(2)
  35. end
  36. end -- class FOREIGN_DLL_LOADER
  37. --
  38. -- Copyright (C) 2009-2017: by all the people cited in the AUTHORS file.
  39. --
  40. -- Permission is hereby granted, free of charge, to any person obtaining a copy
  41. -- of this software and associated documentation files (the "Software"), to deal
  42. -- in the Software without restriction, including without limitation the rights
  43. -- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  44. -- copies of the Software, and to permit persons to whom the Software is
  45. -- furnished to do so, subject to the following conditions:
  46. --
  47. -- The above copyright notice and this permission notice shall be included in
  48. -- all copies or substantial portions of the Software.
  49. --
  50. -- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  51. -- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  52. -- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  53. -- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  54. -- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  55. -- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  56. -- THE SOFTWARE.