@@ -2,36 +2,39 @@ extern crate libloading;
22
33pub use libloading:: { Library , Symbol } ;
44
5- #[ cfg( feature = "dlopen" ) ]
65#[ macro_export]
76macro_rules! ffi_dispatch(
8- ( $handle: ident, $func: ident, $( $arg: expr) ,* ) => (
9- ( $handle. $func) ( $( $arg) ,* )
10- )
11- ) ;
7+ ( feature=$feature: expr, $handle: ident, $func: ident, $( $arg: expr) ,* ) => (
8+ {
9+ #[ cfg( feature = $feature) ]
10+ let ret = ( $handle. $func) ( $( $arg) ,* ) ;
11+ #[ cfg( not( feature = $feature) ) ]
12+ let ret = $func( $( $arg) ,* ) ;
1213
13- # [ cfg ( not ( feature = "dlopen" ) ) ]
14- # [ macro_export ]
15- macro_rules! ffi_dispatch (
14+ ret
15+ }
16+ ) ;
1617 ( $handle: ident, $func: ident, $( $arg: expr) ,* ) => (
17- $func( $( $arg) ,* )
18- )
18+ // NOTE: this "dlopen" refers to a feature on the crate *using* dlib
19+ $crate:: ffi_dispatch!( feature="dlopen" , $handle, $func, $( $arg) ,* )
20+ ) ;
1921) ;
2022
21- #[ cfg( feature = "dlopen" ) ]
2223#[ macro_export]
2324macro_rules! ffi_dispatch_static(
24- ( $handle: ident, $name: ident) => (
25- $handle. $name
26- )
27- ) ;
25+ ( feature=$feature: expr, $handle: ident, $name: ident) => (
26+ {
27+ #[ cfg( feature = $feature) ]
28+ let ret = $handle. $name;
29+ #[ cfg( not( feature = $feature) ) ]
30+ let ret = & $name;
2831
29- # [ cfg ( not ( feature = "dlopen" ) ) ]
30- # [ macro_export ]
31- macro_rules! ffi_dispatch_static (
32- ( $handle: ident, $name: ident) => (
33- & $ name
34- )
32+ ret
33+ }
34+ ) ;
35+ ( $handle: ident, $name: ident) => (
36+ $crate :: ffi_dispatch_static! ( feature= "dlopen" , $handle , $ name)
37+ ) ;
3538) ;
3639
3740#[ macro_export]
@@ -132,12 +135,12 @@ macro_rules! dlopen_external_library(
132135 $( functions: $( fn $fname: ident( $( $farg: ty) ,* ) -> $fret: ty) ,+, ) |*
133136 $( varargs: $( fn $vname: ident( $( $vargs: ty) ,+) -> $vret: ty) ,+, ) |*
134137 ) => (
135- dlopen_external_library!( __struct,
138+ $crate :: dlopen_external_library!( __struct,
136139 $structname, $( statics: $( $sname: $stype) ,+, ) |*
137140 $( functions: $( fn $fname( $( $farg) ,* ) -> $fret) ,+, ) |*
138141 $( varargs: $( fn $vname( $( $vargs) ,+) -> $vret) ,+, ) |*
139142 ) ;
140- dlopen_external_library!( __impl,
143+ $crate :: dlopen_external_library!( __impl,
141144 $structname, $( statics: $( $sname: $stype) ,+, ) |*
142145 $( functions: $( fn $fname( $( $farg) ,* ) -> $fret) ,+, ) |*
143146 $( varargs: $( fn $vname( $( $vargs) ,+) -> $vret) ,+, ) |*
@@ -146,32 +149,35 @@ macro_rules! dlopen_external_library(
146149 ) ;
147150) ;
148151
149- #[ cfg( not( feature = "dlopen" ) ) ]
150152#[ macro_export]
151153macro_rules! external_library(
152- ( $structname: ident, $link: expr,
154+ ( feature=$feature : expr , $structname: ident, $link: expr,
153155 $( statics: $( $sname: ident: $stype: ty) ,+, ) |*
154156 $( functions: $( fn $fname: ident( $( $farg: ty) ,* ) -> $fret: ty) ,+, ) |*
155157 $( varargs: $( fn $vname: ident( $( $vargs: ty) ,+) -> $vret: ty) ,+, ) |*
156158 ) => (
157- link_external_library!(
159+ #[ cfg( feature = $feature) ]
160+ $crate:: dlopen_external_library!(
161+ $structname, $( statics: $( $sname: $stype) ,+, ) |*
162+ $( functions: $( fn $fname( $( $farg) ,* ) -> $fret) ,+, ) |*
163+ $( varargs: $( fn $vname( $( $vargs) ,+) -> $vret) ,+, ) |*
164+ ) ;
165+
166+ #[ cfg( not( feature = $feature) ) ]
167+ $crate:: link_external_library!(
158168 $link, $( statics: $( $sname: $stype) ,+, ) |*
159169 $( functions: $( fn $fname( $( $farg) ,* ) -> $fret) ,+, ) |*
160170 $( varargs: $( fn $vname( $( $vargs) ,+) -> $vret) ,+, ) |*
161171 ) ;
162172 ) ;
163- ) ;
164-
165- #[ cfg( feature = "dlopen" ) ]
166- #[ macro_export]
167- macro_rules! external_library(
168173 ( $structname: ident, $link: expr,
169174 $( statics: $( $sname: ident: $stype: ty) ,+, ) |*
170175 $( functions: $( fn $fname: ident( $( $farg: ty) ,* ) -> $fret: ty) ,+, ) |*
171176 $( varargs: $( fn $vname: ident( $( $vargs: ty) ,+) -> $vret: ty) ,+, ) |*
172177 ) => (
173- dlopen_external_library!(
174- $structname, $( statics: $( $sname: $stype) ,+, ) |*
178+ $crate:: external_library!(
179+ feature="dlopen" , $structname, $link,
180+ $( statics: $( $sname: $stype) ,+, ) |*
175181 $( functions: $( fn $fname( $( $farg) ,* ) -> $fret) ,+, ) |*
176182 $( varargs: $( fn $vname( $( $vargs) ,+) -> $vret) ,+, ) |*
177183 ) ;
0 commit comments