@@ -27,6 +27,35 @@ impl CppFn {
2727 self . type_name ( ) . write ( config, & [ ] )
2828 }
2929
30+ pub fn write_fn_ptr ( & self , config : & Config < ' _ > , underlying_types : bool ) -> TokenStream {
31+ let ptr_name = self . method . name ( ) . to_string ( ) ;
32+ let name = to_ident ( & ptr_name) ;
33+ let abi = self . method . calling_convention ( ) ;
34+ let signature = self . method . signature ( self . namespace , & [ ] ) ;
35+
36+ let params = signature. params . iter ( ) . map ( |param| {
37+ let name = param. write_ident ( ) ;
38+ let ty = if underlying_types {
39+ param. underlying_type ( ) . write_abi ( config)
40+ } else {
41+ param. write_abi ( config)
42+ } ;
43+ quote ! { #name: #ty }
44+ } ) ;
45+
46+ let return_sig = config. write_return_sig ( self . method , & signature, underlying_types) ;
47+
48+ let vararg = if config. sys && signature. call_flags . contains ( MethodCallAttributes :: VARARG ) {
49+ quote ! { , ... }
50+ } else {
51+ quote ! { }
52+ } ;
53+
54+ quote ! {
55+ pub type #name = unsafe extern #abi fn ( #( #params) , * #vararg) #return_sig;
56+ }
57+ }
58+
3059 pub fn write_link ( & self , config : & Config , underlying_types : bool ) -> TokenStream {
3160 let library = self . method . module_name ( ) ;
3261 let symbol = self . method . import_name ( ) ;
@@ -71,18 +100,30 @@ impl CppFn {
71100 let name = to_ident ( self . method . name ( ) ) ;
72101 let signature = self . method . signature ( self . namespace , & [ ] ) ;
73102
103+ let fn_ptr = self . write_fn_ptr ( config, false ) ;
74104 let link = self . write_link ( config, false ) ;
75105 let arches = write_arches ( self . method ) ;
76106 let cfg = self . write_cfg ( config) ;
77107 let cfg = quote ! { #arches #cfg } ;
78108 let window_long = self . write_window_long ( ) ;
79109
80110 if config. sys {
81- return quote ! {
82- #cfg
83- #link
84- #window_long
85- } ;
111+ if config. sys_fn_ptrs {
112+ return quote ! {
113+ #cfg
114+ #fn_ptr
115+ #window_long
116+ #cfg
117+ #link
118+ #window_long
119+ } ;
120+ } else {
121+ return quote ! {
122+ #cfg
123+ #link
124+ #window_long
125+ } ;
126+ }
86127 }
87128
88129 let method = CppMethod :: new ( self . method , self . namespace ) ;
0 commit comments