Skip to content

Commit

Permalink
Merge pull request #209 from tomaka/fix-ice
Browse files Browse the repository at this point in the history
Update for rustc
  • Loading branch information
tomaka committed Nov 8, 2014
2 parents 678346e + 7a4c470 commit 79cd3b3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 59 deletions.
57 changes: 29 additions & 28 deletions src/gl_generator/generators/global_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,42 +127,43 @@ fn write_fns(ecx: &ExtCtxt, registry: &Registry) -> Vec<P<ast::Item>> {

/// Creates a `FnPtr` structure which contains the store for a single binding.
fn write_fnptr_struct_def(ecx: &ExtCtxt) -> Vec<P<ast::Item>> {
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<ast::Item> {
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::<Vec<P<ast::Item>>>();

(quote_item!(ecx,
Expand Down
64 changes: 33 additions & 31 deletions src/gl_generator/generators/struct_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,40 +76,42 @@ fn write_enums(ecx: &ExtCtxt, registry: &Registry) -> Vec<P<ast::Item>> {

/// Creates a `FnPtr` structure which contains the store for a single binding.
fn write_fnptr_struct_def(ecx: &ExtCtxt) -> Vec<P<ast::Item>> {
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.
Expand Down

0 comments on commit 79cd3b3

Please sign in to comment.