PageRenderTime 14ms CodeModel.GetById 11ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

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