Debian Codegraph @

tests/functions.rs

raw symbols SCIP
1 #[cfg(windows)]
2 extern crate windows_sys;
3
4 extern crate libloadingrust-analyzer cargo libloading 0.8.9 libloading/;
5 use libloadingrust-analyzer cargo libloading 0.8.9 crate/::{Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#, Symbolrust-analyzer cargo libloading 0.8.9 safe/Symbol#};
6 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/::rawrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/::c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void#;
7
8 const TARGET_DIRrust-analyzer cargo libloading 0.8.9 TARGET_DIR.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'static str> = option_envrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/option_env!!("CARGO_TARGET_DIR");
9 const TARGET_TMPDIRrust-analyzer cargo libloading 0.8.9 TARGET_TMPDIR.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'static str> = option_envrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/option_env!!("CARGO_TARGET_TMPDIR");
10
11 fn lib_pathrust-analyzer cargo libloading 0.8.9 lib_path().() -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf# {
12 [
13 TARGET_TMPDIRrust-analyzer cargo libloading 0.8.9 TARGET_TMPDIR..unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(TARGET_DIRrust-analyzer cargo libloading 0.8.9 TARGET_DIR..unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().("target")),
14 "libtest_helpers.module",
15 ]
16 .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
17 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().()
18 }
19
20 fn make_helpersrust-analyzer cargo libloading 0.8.9 make_helpers().() {
21 static ONCErust-analyzer cargo libloading 0.8.9 ONCE.: ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Oncerust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once/Once# = ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::Oncerust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once/Once#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once/impl#[Once]new().();
22 ONCErust-analyzer cargo libloading 0.8.9 ONCE..call_oncerust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once/impl#[Once]call_once().(|| {
23 let rustc = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::var_osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var_os().("RUSTC").unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| "rustc".intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().());
24 let mut cmd = ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::processrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/::Commandrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/Command#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]new().(rustc);
25 cmd.argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("src/test_helpers.rs").argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("-o").argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().(lib_pathrust-analyzer cargo libloading 0.8.9 lib_path().());
26 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(target) = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::var_osrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var_os().("TARGET") {
27 cmd.argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().("--target").argrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]arg().(target);
28 } else {
29 eprintlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/eprintln!!("WARNING: $TARGET NOT SPECIFIED! BUILDING HELPER MODULE FOR NATIVE TARGET.");
30 }
31 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(cmd
32 .statusrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[Command]status().()
33 .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("could not compile the test helpers!")
34 .successrust-analyzer cargo std https://github.com/rust-lang/rust/library/std process/impl#[ExitStatus]success().());
35 });
36 }
37
38 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
39 fn test_id_u32rust-analyzer cargo libloading 0.8.9 test_id_u32().() {
40 make_helpersrust-analyzer cargo libloading 0.8.9 make_helpers().();
41 unsafe {
42 let lib = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::newrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]new().(lib_pathrust-analyzer cargo libloading 0.8.9 lib_path().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
43 let f: Symbolrust-analyzer cargo libloading 0.8.9 safe/Symbol#<unsafe extern "C" fn(u32) -> u32> = lib.getrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]get().(b"test_identity_u32\0").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
44 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(42, f(42));
45 }
46 }
47
48 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
49 fn test_try_into_ptrrust-analyzer cargo libloading 0.8.9 test_try_into_ptr().() {
50 make_helpersrust-analyzer cargo libloading 0.8.9 make_helpers().();
51 unsafe {
52 let lib = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::newrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]new().(lib_pathrust-analyzer cargo libloading 0.8.9 lib_path().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
53 let f: Symbolrust-analyzer cargo libloading 0.8.9 safe/Symbol#<unsafe extern "C" fn(u32) -> u32> = lib.getrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]get().(b"test_identity_u32\0").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
54 let ptr: *mut c_voidrust-analyzer cargo std https://github.com/rust-lang/rust/library/std os/raw/c_void# = f.try_as_raw_ptrrust-analyzer cargo libloading 0.8.9 safe/impl#[`Symbol<'lib, T>`]try_as_raw_ptr().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
55 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().ptr.is_nullrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]is_null().());
56 let ptr_casted: extern "C" fn(u32) -> u32 = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::transmuterust-analyzer cargo core https://github.com/rust-lang/rust/library/core intrinsics/transmute().(ptr);
57 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(42, ptr_casted(42));
58 }
59 }
60
61 #[repr(C)]
62 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
63 struct Srust-analyzer cargo libloading 0.8.9 S# {
64 arust-analyzer cargo libloading 0.8.9 S#a.: u64,
65 brust-analyzer cargo libloading 0.8.9 S#b.: u32,
66 crust-analyzer cargo libloading 0.8.9 S#c.: u16,
67 drust-analyzer cargo libloading 0.8.9 S#d.: u8,
68 }
69
70 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
71 fn test_id_structrust-analyzer cargo libloading 0.8.9 test_id_struct().() {
72 make_helpersrust-analyzer cargo libloading 0.8.9 make_helpers().();
73 unsafe {
74 let lib = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::newrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]new().(lib_pathrust-analyzer cargo libloading 0.8.9 lib_path().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
75 let f: Symbolrust-analyzer cargo libloading 0.8.9 safe/Symbol#<unsafe extern "C" fn(Srust-analyzer cargo libloading 0.8.9 S#) -> Srust-analyzer cargo libloading 0.8.9 S#> = lib.getrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]get().(b"test_identity_struct\0").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
76 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
77 Srust-analyzer cargo libloading 0.8.9 S# {
78 arust-analyzer cargo libloading 0.8.9 S#a.: 1,
79 brust-analyzer cargo libloading 0.8.9 S#b.: 2,
80 crust-analyzer cargo libloading 0.8.9 S#c.: 3,
81 drust-analyzer cargo libloading 0.8.9 S#d.: 4
82 },
83 f(Srust-analyzer cargo libloading 0.8.9 S# {
84 arust-analyzer cargo libloading 0.8.9 S#a.: 1,
85 brust-analyzer cargo libloading 0.8.9 S#b.: 2,
86 crust-analyzer cargo libloading 0.8.9 S#c.: 3,
87 drust-analyzer cargo libloading 0.8.9 S#d.: 4
88 })
89 );
90 }
91 }
92
93 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
94 fn test_0_no_0rust-analyzer cargo libloading 0.8.9 test_0_no_0().() {
95 make_helpersrust-analyzer cargo libloading 0.8.9 make_helpers().();
96 unsafe {
97 let lib = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::newrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]new().(lib_pathrust-analyzer cargo libloading 0.8.9 lib_path().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
98 let f: Symbolrust-analyzer cargo libloading 0.8.9 safe/Symbol#<unsafe extern "C" fn(Srust-analyzer cargo libloading 0.8.9 S#) -> Srust-analyzer cargo libloading 0.8.9 S#> = lib.getrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]get().(b"test_identity_struct\0").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
99 let f2: Symbolrust-analyzer cargo libloading 0.8.9 safe/Symbol#<unsafe extern "C" fn(Srust-analyzer cargo libloading 0.8.9 S#) -> Srust-analyzer cargo libloading 0.8.9 S#> = lib.getrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]get().(b"test_identity_struct").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
100 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(*rust-analyzer cargo libloading 0.8.9 safe/impl#[`Symbol<'_, T>`][Deref]deref().f, *rust-analyzer cargo libloading 0.8.9 safe/impl#[`Symbol<'_, T>`][Deref]deref().f2);
101 }
102 }
103
104 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
105 fn wrong_name_failsrust-analyzer cargo libloading 0.8.9 wrong_name_fails().() {
106 unsafe {
107 Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::newrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]new().("target/this_location_is_definitely_non existent:^~")
108 .errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]err().()
109 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
110 }
111 }
112
113 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
114 fn missing_symbol_failsrust-analyzer cargo libloading 0.8.9 missing_symbol_fails().() {
115 make_helpersrust-analyzer cargo libloading 0.8.9 make_helpers().();
116 unsafe {
117 let lib = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::newrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]new().(lib_pathrust-analyzer cargo libloading 0.8.9 lib_path().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
118 lib.getrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]get().::<*mut ()>(b"test_does_not_exist").errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]err().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
119 lib.getrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]get().::<*mut ()>(b"test_does_not_exist\0").errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]err().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
120 }
121 }
122
123 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
124 fn interior_null_failsrust-analyzer cargo libloading 0.8.9 interior_null_fails().() {
125 make_helpersrust-analyzer cargo libloading 0.8.9 make_helpers().();
126 unsafe {
127 let lib = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::newrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]new().(lib_pathrust-analyzer cargo libloading 0.8.9 lib_path().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
128 lib.getrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]get().::<*mut ()>(b"test_does\0_not_exist").errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]err().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
129 lib.getrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]get().::<*mut ()>(b"test\0_does_not_exist\0")
130 .errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]err().()
131 .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().();
132 }
133 }
134
135 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
136 fn test_incompatible_typerust-analyzer cargo libloading 0.8.9 test_incompatible_type().() {
137 make_helpersrust-analyzer cargo libloading 0.8.9 make_helpers().();
138 unsafe {
139 let lib = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::newrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]new().(lib_pathrust-analyzer cargo libloading 0.8.9 lib_path().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
140 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(match lib.getrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]get().::<()>(b"test_identity_u32\0") {
141 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(libloadingrust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#::IncompatibleSizerust-analyzer cargo libloading 0.8.9 error/Error#IncompatibleSize#) => true,
142 _ => false,
143 })
144 }
145 }
146
147 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
148 fn test_incompatible_type_named_fnrust-analyzer cargo libloading 0.8.9 test_incompatible_type_named_fn().() {
149 make_helpersrust-analyzer cargo libloading 0.8.9 make_helpers().();
150 unsafe fn getrust-analyzer cargo libloading 0.8.9 get().<'a, T>(l: &'a Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#, _: T) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Symbolrust-analyzer cargo libloading 0.8.9 safe/Symbol#<'a, T>, libloadingrust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#> {
151 l.getrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]get().::<T>(b"test_identity_u32\0")
152 }
153 unsafe {
154 let lib = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::newrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]new().(lib_pathrust-analyzer cargo libloading 0.8.9 lib_path().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
155 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(match getrust-analyzer cargo libloading 0.8.9 get().(&lib, test_incompatible_type_named_fnrust-analyzer cargo libloading 0.8.9 test_incompatible_type_named_fn().) {
156 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(libloadingrust-analyzer cargo libloading 0.8.9 crate/::Errorrust-analyzer cargo libloading 0.8.9 error/Error#::IncompatibleSizerust-analyzer cargo libloading 0.8.9 error/Error#IncompatibleSize#) => true,
157 _ => false,
158 })
159 }
160 }
161
162 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
163 fn test_static_u32rust-analyzer cargo libloading 0.8.9 test_static_u32().() {
164 make_helpersrust-analyzer cargo libloading 0.8.9 make_helpers().();
165 unsafe {
166 let lib = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::newrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]new().(lib_pathrust-analyzer cargo libloading 0.8.9 lib_path().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
167 let var: Symbolrust-analyzer cargo libloading 0.8.9 safe/Symbol#<*mut u32> = lib.getrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]get().(b"TEST_STATIC_U32\0").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
168 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().*rust-analyzer cargo libloading 0.8.9 safe/impl#[`Symbol<'_, T>`][Deref]deref().var = 42;
169 let help: Symbolrust-analyzer cargo libloading 0.8.9 safe/Symbol#<unsafe extern "C" fn() -> u32> =
170 lib.getrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]get().(b"test_get_static_u32\0").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
171 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(42, help());
172 }
173 }
174
175 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
176 fn test_static_ptrrust-analyzer cargo libloading 0.8.9 test_static_ptr().() {
177 make_helpersrust-analyzer cargo libloading 0.8.9 make_helpers().();
178 unsafe {
179 let lib = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::newrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]new().(lib_pathrust-analyzer cargo libloading 0.8.9 lib_path().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
180 let var: Symbolrust-analyzer cargo libloading 0.8.9 safe/Symbol#<*mut *mut ()> = lib.getrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]get().(b"TEST_STATIC_PTR\0").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
181 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#deref().*rust-analyzer cargo libloading 0.8.9 safe/impl#[`Symbol<'_, T>`][Deref]deref().var = *rust-analyzer cargo libloading 0.8.9 safe/impl#[`Symbol<'_, T>`][Deref]deref().var as *mut _;
182 let works: Symbolrust-analyzer cargo libloading 0.8.9 safe/Symbol#<unsafe extern "C" fn() -> bool> =
183 lib.getrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]get().(b"test_check_static_ptr\0").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
184 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(works());
185 }
186 }
187
188 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
189 // Something about i686-pc-windows-gnu, makes dll initialisation code call abort when it is loaded
190 // and unloaded many times. So far it seems like an issue with mingw, not libloading, so ignoring
191 // the target. Especially since it is very unlikely to be fixed given the state of support its
192 // support.
193 #[cfg(not(all(target_arch = "x86", target_os = "windows", target_env = "gnu")))]
194 // Cygwin returns errors on `close`.
195 #[cfg(not(target_os = "cygwin"))]
196 fn manual_close_many_timesrust-analyzer cargo libloading 0.8.9 manual_close_many_times().() {
197 make_helpersrust-analyzer cargo libloading 0.8.9 make_helpers().();
198 let join_handles: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#16)
199 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|_| {
200 stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::threadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/::spawnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/functions/spawn().(|| unsafe {
201 for _ in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#10000 {
202 let lib = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::newrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]new().(lib_pathrust-analyzer cargo libloading 0.8.9 lib_path().()).expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("open library");
203 let _: Symbolrust-analyzer cargo libloading 0.8.9 safe/Symbol#<unsafe extern "C" fn(u32) -> u32> =
204 lib.getrust-analyzer cargo libloading 0.8.9 safe/impl#[Library]get().(b"test_identity_u32").expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("get fn");
205 lib.closerust-analyzer cargo libloading 0.8.9 safe/impl#[Library]close().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("close is successful");
206 }
207 })
208 })
209 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
210 for handle in join_handles {
211 handle.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std thread/join_handle/impl#[`JoinHandle<T>`]join().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]expect().("thread should succeed");
212 }
213 }
214
215 #[cfg(unix)]
216 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
217 fn library_this_getrust-analyzer cargo libloading 0.8.9 library_this_get().() {
218 use libloadingrust-analyzer cargo libloading 0.8.9 crate/::osrust-analyzer cargo libloading 0.8.9 os/::unixrust-analyzer cargo libloading 0.8.9 os/unix/::Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library#;
219 make_helpersrust-analyzer cargo libloading 0.8.9 make_helpers().();
220 // SAFE: functions are never called
221 unsafe {
222 let _lib = Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library#::newrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]new().(lib_pathrust-analyzer cargo libloading 0.8.9 lib_path().()).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().();
223 let this = Libraryrust-analyzer cargo libloading 0.8.9 os/unix/Library#::thisrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]this().();
224 // Library we loaded in `_lib` (should be RTLD_LOCAL).
225 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(this
226 .getrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]get().::<unsafe extern "C" fn()>(b"test_identity_u32")
227 .is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().());
228 // Something obscure from libc...
229 // Cygwin behaves like Windows so ignore it.
230 #[cfg(not(target_os = "cygwin"))]
231 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(this.getrust-analyzer cargo libloading 0.8.9 os/unix/impl#[Library]get().::<unsafe extern "C" fn()>(b"freopen").is_okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_ok().());
232 }
233 }
234
235 #[cfg(windows)]
236 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
237 fn library_this() {
238 use libloadingrust-analyzer cargo libloading 0.8.9 crate/::osrust-analyzer cargo libloading 0.8.9 os/::windows::Library;
239 make_helpersrust-analyzer cargo libloading 0.8.9 make_helpers().();
240 unsafe {
241 // SAFE: well-known library without initialisers is loaded.
242 let _lib = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::new(lib_pathrust-analyzer cargo libloading 0.8.9 lib_path().()).unwrap();
243 let this = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::this().expect("this library");
244 // SAFE: functions are never called.
245 // Library we loaded in `_lib`.
246 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(this
247 .get::<unsafe extern "C" fn()>(b"test_identity_u32")
248 .is_err());
249 // Something "obscure" from kernel32...
250 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(this.get::<unsafe extern "C" fn()>(b"GetLastError").is_err());
251 }
252 }
253
254 #[cfg(windows)]
255 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
256 fn works_getlasterror() {
257 use libloadingrust-analyzer cargo libloading 0.8.9 crate/::osrust-analyzer cargo libloading 0.8.9 os/::windows::{Library, Symbol};
258 use windows_sys::Win32::Foundation::{GetLastError, SetLastError};
259
260 unsafe {
261 let lib = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::new("kernel32.dll").unwrap();
262 let gle: Symbolrust-analyzer cargo libloading 0.8.9 safe/Symbol#<unsafe extern "system" fn() -> u32> = lib.get(b"GetLastError").unwrap();
263 SetLastError(42);
264 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(GetLastError(), gle())
265 }
266 }
267
268 #[cfg(windows)]
269 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
270 fn works_getlasterror0() {
271 use libloadingrust-analyzer cargo libloading 0.8.9 crate/::osrust-analyzer cargo libloading 0.8.9 os/::windows::{Library, Symbol};
272 use windows_sys::Win32::Foundation::{GetLastError, SetLastError};
273
274 unsafe {
275 let lib = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::new("kernel32.dll").unwrap();
276 let gle: Symbolrust-analyzer cargo libloading 0.8.9 safe/Symbol#<unsafe extern "system" fn() -> u32> = lib.get(b"GetLastError\0").unwrap();
277 SetLastError(42);
278 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(GetLastError(), gle())
279 }
280 }
281
282 #[cfg(windows)]
283 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
284 fn works_pin_module() {
285 use libloadingrust-analyzer cargo libloading 0.8.9 crate/::osrust-analyzer cargo libloading 0.8.9 os/::windows::Library;
286
287 unsafe {
288 let lib = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::new("kernel32.dll").unwrap();
289 lib.pin().unwrap();
290 }
291 }
292
293 #[cfg(windows)]
294 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
295 fn library_open_already_loaded() {
296 use libloadingrust-analyzer cargo libloading 0.8.9 crate/::osrust-analyzer cargo libloading 0.8.9 os/::windows::Library;
297
298 // Present on Windows systems and NOT used by any other tests to prevent races.
299 const LIBPATH: &str = "Msftedit.dll";
300
301 // Not loaded yet.
302 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(match Library::open_already_loaded(LIBPATH) {
303 Err(libloading::Error::GetModuleHandleExW { .. }) => true,
304 _ => false,
305 });
306
307 unsafe {
308 let _lib = Libraryrust-analyzer cargo libloading 0.8.9 safe/Library#::new(LIBPATH).unwrap();
309 // Loaded now.
310 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(Library::open_already_loaded(LIBPATH).is_ok());
311 }
312 }