diff --git a/src/gl_generator/generators/global_gen.rs b/src/gl_generator/generators/global_gen.rs index 32e5b926..5b60f6d5 100644 --- a/src/gl_generator/generators/global_gen.rs +++ b/src/gl_generator/generators/global_gen.rs @@ -127,42 +127,43 @@ fn write_fns(ecx: &ExtCtxt, registry: &Registry) -> Vec> { /// Creates a `FnPtr` structure which contains the store for a single binding. fn write_fnptr_struct_def(ecx: &ExtCtxt) -> Vec> { - vec![ - (quote_item!(ecx, - pub struct FnPtr { - /// The function pointer that will be used when calling the function. - f: *const __gl_imports::libc::c_void, - /// True if the pointer points to a real function, false if points to a `panic!` fn. - is_loaded: bool, - } - )).unwrap(), - - (quote_item!(ecx, - impl FnPtr { - /// Creates a `FnPtr` from a load attempt. - pub fn new(ptr: *const __gl_imports::libc::c_void, failing_fn: *const __gl_imports::libc::c_void) -> FnPtr { - if ptr.is_null() { - FnPtr { f: failing_fn, is_loaded: false } - } else { - FnPtr { f: ptr, is_loaded: true } - } + let mut result = Vec::new(); + + result.push((quote_item!(ecx, + pub struct FnPtr { + /// The function pointer that will be used when calling the function. + f: *const __gl_imports::libc::c_void, + /// True if the pointer points to a real function, false if points to a `panic!` fn. + is_loaded: bool, + } + )).unwrap()); + + result.push((quote_item!(ecx, + impl FnPtr { + /// Creates a `FnPtr` from a load attempt. + pub fn new(ptr: *const __gl_imports::libc::c_void, failing_fn: *const __gl_imports::libc::c_void) -> FnPtr { + if ptr.is_null() { + FnPtr { f: failing_fn, is_loaded: false } + } else { + FnPtr { f: ptr, is_loaded: true } } } - )).unwrap() - ] + } + )).unwrap()); + + result } /// Creates a `storage` module which contains a static `FnPtr` per GL command in the registry. fn write_ptrs(ecx: &ExtCtxt, registry: &Registry) -> P { let storages = registry.cmd_iter().map(|c| { - let name = ecx.ident_of(c.proto.ident.as_slice()); - - (quote_item!(ecx, - pub static mut $name: FnPtr = FnPtr { - f: failing::$name as *const libc::c_void, + ecx.parse_item(format!( + "pub static mut {name}: FnPtr = FnPtr {{ + f: failing::{name} as *const libc::c_void, is_loaded: false - }; - )).unwrap() + }};", + name = c.proto.ident + )) }).collect::>>(); (quote_item!(ecx, diff --git a/src/gl_generator/generators/struct_gen.rs b/src/gl_generator/generators/struct_gen.rs index fe667f35..dc874ca4 100644 --- a/src/gl_generator/generators/struct_gen.rs +++ b/src/gl_generator/generators/struct_gen.rs @@ -76,40 +76,42 @@ fn write_enums(ecx: &ExtCtxt, registry: &Registry) -> Vec> { /// Creates a `FnPtr` structure which contains the store for a single binding. fn write_fnptr_struct_def(ecx: &ExtCtxt) -> Vec> { - vec![ - (quote_item!(ecx, - #[allow(dead_code)] - pub struct FnPtr { - /// The function pointer that will be used when calling the function. - f: *const __gl_imports::libc::c_void, - /// True if the pointer points to a real function, false if points to a `panic!` fn. - is_loaded: bool, - } - )).unwrap(), - - (quote_item!(ecx, - impl FnPtr { - /// Creates a `FnPtr` from a load attempt. - fn new(ptr: *const __gl_imports::libc::c_void, - failing_fn: *const __gl_imports::libc::c_void) -> FnPtr { - if ptr.is_null() { - FnPtr { f: failing_fn, is_loaded: false } - } else { - FnPtr { f: ptr, is_loaded: true } - } - } + let mut result = Vec::new(); - /// Returns `true` if the function has been successfully loaded. - /// - /// If it returns `false`, calling the corresponding function will fail. - #[inline] - #[allow(dead_code)] - pub fn is_loaded(&self) -> bool { - self.is_loaded + result.push((quote_item!(ecx, + #[allow(dead_code)] + pub struct FnPtr { + /// The function pointer that will be used when calling the function. + f: *const __gl_imports::libc::c_void, + /// True if the pointer points to a real function, false if points to a `panic!` fn. + is_loaded: bool, + } + )).unwrap()); + + result.push((quote_item!(ecx, + impl FnPtr { + /// Creates a `FnPtr` from a load attempt. + fn new(ptr: *const __gl_imports::libc::c_void, + failing_fn: *const __gl_imports::libc::c_void) -> FnPtr { + if ptr.is_null() { + FnPtr { f: failing_fn, is_loaded: false } + } else { + FnPtr { f: ptr, is_loaded: true } } } - )).unwrap() - ] + + /// Returns `true` if the function has been successfully loaded. + /// + /// If it returns `false`, calling the corresponding function will fail. + #[inline] + #[allow(dead_code)] + pub fn is_loaded(&self) -> bool { + self.is_loaded + } + } + )).unwrap()); + + result } /// Creates a `failing` module which contains one function per GL command.