Skip to content

Commit 0d6e36d

Browse files
authored
Merge pull request #166 from baszalmstra/feature/function_prototype
misc: adds function prototype
2 parents ff08f1c + cfc210e commit 0d6e36d

File tree

18 files changed

+348
-287
lines changed

18 files changed

+348
-287
lines changed

crates/mun/src/main.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,16 @@ fn start(matches: &ArgMatches) -> Result<(), failure::Error> {
9898

9999
let borrowed = runtime.borrow();
100100
let entry_point = matches.value_of("entry").unwrap_or("main");
101-
let fn_info = borrowed.get_function_info(entry_point).ok_or_else(|| {
102-
std::io::Error::new(
103-
std::io::ErrorKind::InvalidInput,
104-
format!("Failed to obtain entry point '{}'", entry_point),
105-
)
106-
})?;
107-
108-
if let Some(ret_type) = fn_info.signature.return_type() {
101+
let fn_definition = borrowed
102+
.get_function_definition(entry_point)
103+
.ok_or_else(|| {
104+
std::io::Error::new(
105+
std::io::ErrorKind::InvalidInput,
106+
format!("Failed to obtain entry point '{}'", entry_point),
107+
)
108+
})?;
109+
110+
if let Some(ret_type) = fn_definition.prototype.signature.return_type() {
109111
let type_guid = &ret_type.guid;
110112
if *type_guid == bool::type_guid() {
111113
let result: bool =

crates/mun_abi/c

crates/mun_abi/src/autogen.rs

Lines changed: 60 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* automatically generated by rust-bindgen */
44

55
#![allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
6-
use crate::{Privacy, StructMemoryKind, TypeGroup};
6+
use crate::{StructMemoryKind, TypeGroup};
77

88
#[doc = " Represents a globally unique identifier (GUID)."]
99
#[doc = ""]
@@ -122,22 +122,18 @@ fn bindgen_test_layout_TypeInfo() {
122122
#[repr(C)]
123123
#[derive(Clone, Debug)]
124124
pub struct FunctionSignature {
125-
#[doc = " Function name"]
126-
pub name: *const ::std::os::raw::c_char,
127125
#[doc = " Argument types"]
128126
pub arg_types: *const *const TypeInfo,
129127
#[doc = " Optional return type"]
130128
pub return_type: *const TypeInfo,
131129
#[doc = " Number of argument types"]
132130
pub num_arg_types: u16,
133-
#[doc = " Function accessibility level"]
134-
pub privacy: Privacy,
135131
}
136132
#[test]
137133
fn bindgen_test_layout_FunctionSignature() {
138134
assert_eq!(
139135
::std::mem::size_of::<FunctionSignature>(),
140-
32usize,
136+
24usize,
141137
concat!("Size of: ", stringify!(FunctionSignature))
142138
);
143139
assert_eq!(
@@ -146,97 +142,123 @@ fn bindgen_test_layout_FunctionSignature() {
146142
concat!("Alignment of ", stringify!(FunctionSignature))
147143
);
148144
assert_eq!(
149-
unsafe { &(*(::std::ptr::null::<FunctionSignature>())).name as *const _ as usize },
145+
unsafe { &(*(::std::ptr::null::<FunctionSignature>())).arg_types as *const _ as usize },
150146
0usize,
151147
concat!(
152148
"Offset of field: ",
153149
stringify!(FunctionSignature),
154150
"::",
155-
stringify!(name)
151+
stringify!(arg_types)
156152
)
157153
);
158154
assert_eq!(
159-
unsafe { &(*(::std::ptr::null::<FunctionSignature>())).arg_types as *const _ as usize },
155+
unsafe { &(*(::std::ptr::null::<FunctionSignature>())).return_type as *const _ as usize },
160156
8usize,
161157
concat!(
162158
"Offset of field: ",
163159
stringify!(FunctionSignature),
164160
"::",
165-
stringify!(arg_types)
161+
stringify!(return_type)
166162
)
167163
);
168164
assert_eq!(
169-
unsafe { &(*(::std::ptr::null::<FunctionSignature>())).return_type as *const _ as usize },
165+
unsafe { &(*(::std::ptr::null::<FunctionSignature>())).num_arg_types as *const _ as usize },
170166
16usize,
171167
concat!(
172168
"Offset of field: ",
173169
stringify!(FunctionSignature),
174170
"::",
175-
stringify!(return_type)
171+
stringify!(num_arg_types)
176172
)
177173
);
174+
}
175+
#[doc = " Represents a function prototype. A function prototype contains the name,"]
176+
#[doc = " type signature, but not an implementation."]
177+
#[doc = ""]
178+
#[doc = " <div rustbindgen derive=\"Clone\" derive=\"Debug\"></div>"]
179+
#[repr(C)]
180+
#[derive(Clone, Debug)]
181+
pub struct FunctionPrototype {
182+
#[doc = " Function name"]
183+
pub name: *const ::std::os::raw::c_char,
184+
#[doc = " The type signature of the function"]
185+
pub signature: FunctionSignature,
186+
}
187+
#[test]
188+
fn bindgen_test_layout_FunctionPrototype() {
178189
assert_eq!(
179-
unsafe { &(*(::std::ptr::null::<FunctionSignature>())).num_arg_types as *const _ as usize },
180-
24usize,
190+
::std::mem::size_of::<FunctionPrototype>(),
191+
32usize,
192+
concat!("Size of: ", stringify!(FunctionPrototype))
193+
);
194+
assert_eq!(
195+
::std::mem::align_of::<FunctionPrototype>(),
196+
8usize,
197+
concat!("Alignment of ", stringify!(FunctionPrototype))
198+
);
199+
assert_eq!(
200+
unsafe { &(*(::std::ptr::null::<FunctionPrototype>())).name as *const _ as usize },
201+
0usize,
181202
concat!(
182203
"Offset of field: ",
183-
stringify!(FunctionSignature),
204+
stringify!(FunctionPrototype),
184205
"::",
185-
stringify!(num_arg_types)
206+
stringify!(name)
186207
)
187208
);
188209
assert_eq!(
189-
unsafe { &(*(::std::ptr::null::<FunctionSignature>())).privacy as *const _ as usize },
190-
26usize,
210+
unsafe { &(*(::std::ptr::null::<FunctionPrototype>())).signature as *const _ as usize },
211+
8usize,
191212
concat!(
192213
"Offset of field: ",
193-
stringify!(FunctionSignature),
214+
stringify!(FunctionPrototype),
194215
"::",
195-
stringify!(privacy)
216+
stringify!(signature)
196217
)
197218
);
198219
}
199-
#[doc = " Represents a function declaration."]
220+
#[doc = " Represents a function definition. A function definition contains the name,"]
221+
#[doc = " type signature, and a pointer to the implementation."]
200222
#[doc = ""]
201223
#[doc = " `fn_ptr` can be used to call the declared function."]
202224
#[doc = ""]
203225
#[doc = " <div rustbindgen derive=\"Clone\" derive=\"Debug\"></div>"]
204226
#[repr(C)]
205227
#[derive(Clone, Debug)]
206-
pub struct FunctionInfo {
207-
#[doc = " Function signature"]
208-
pub signature: FunctionSignature,
228+
pub struct FunctionDefinition {
229+
#[doc = " Function prototype"]
230+
pub prototype: FunctionPrototype,
209231
#[doc = " Function pointer"]
210232
pub fn_ptr: *const ::std::os::raw::c_void,
211233
}
212234
#[test]
213-
fn bindgen_test_layout_FunctionInfo() {
235+
fn bindgen_test_layout_FunctionDefinition() {
214236
assert_eq!(
215-
::std::mem::size_of::<FunctionInfo>(),
237+
::std::mem::size_of::<FunctionDefinition>(),
216238
40usize,
217-
concat!("Size of: ", stringify!(FunctionInfo))
239+
concat!("Size of: ", stringify!(FunctionDefinition))
218240
);
219241
assert_eq!(
220-
::std::mem::align_of::<FunctionInfo>(),
242+
::std::mem::align_of::<FunctionDefinition>(),
221243
8usize,
222-
concat!("Alignment of ", stringify!(FunctionInfo))
244+
concat!("Alignment of ", stringify!(FunctionDefinition))
223245
);
224246
assert_eq!(
225-
unsafe { &(*(::std::ptr::null::<FunctionInfo>())).signature as *const _ as usize },
247+
unsafe { &(*(::std::ptr::null::<FunctionDefinition>())).prototype as *const _ as usize },
226248
0usize,
227249
concat!(
228250
"Offset of field: ",
229-
stringify!(FunctionInfo),
251+
stringify!(FunctionDefinition),
230252
"::",
231-
stringify!(signature)
253+
stringify!(prototype)
232254
)
233255
);
234256
assert_eq!(
235-
unsafe { &(*(::std::ptr::null::<FunctionInfo>())).fn_ptr as *const _ as usize },
257+
unsafe { &(*(::std::ptr::null::<FunctionDefinition>())).fn_ptr as *const _ as usize },
236258
32usize,
237259
concat!(
238260
"Offset of field: ",
239-
stringify!(FunctionInfo),
261+
stringify!(FunctionDefinition),
240262
"::",
241263
stringify!(fn_ptr)
242264
)
@@ -331,7 +353,7 @@ pub struct ModuleInfo {
331353
#[doc = " Module path"]
332354
pub path: *const ::std::os::raw::c_char,
333355
#[doc = " Module functions"]
334-
pub functions: *const FunctionInfo,
356+
pub functions: *const FunctionDefinition,
335357
#[doc = " Number of module functions"]
336358
pub num_functions: u32,
337359
#[doc = " Module types"]
@@ -411,7 +433,7 @@ fn bindgen_test_layout_ModuleInfo() {
411433
#[derive(Debug)]
412434
pub struct DispatchTable {
413435
#[doc = " Function signatures"]
414-
pub signatures: *const FunctionSignature,
436+
pub prototypes: *const FunctionPrototype,
415437
#[doc = " Function pointers"]
416438
pub fn_ptrs: *mut *const ::std::os::raw::c_void,
417439
#[doc = " Number of functions"]
@@ -430,13 +452,13 @@ fn bindgen_test_layout_DispatchTable() {
430452
concat!("Alignment of ", stringify!(DispatchTable))
431453
);
432454
assert_eq!(
433-
unsafe { &(*(::std::ptr::null::<DispatchTable>())).signatures as *const _ as usize },
455+
unsafe { &(*(::std::ptr::null::<DispatchTable>())).prototypes as *const _ as usize },
434456
0usize,
435457
concat!(
436458
"Offset of field: ",
437459
stringify!(DispatchTable),
438460
"::",
439-
stringify!(signatures)
461+
stringify!(prototypes)
440462
)
441463
);
442464
assert_eq!(

0 commit comments

Comments
 (0)