Skip to content

Commit

Permalink
Work around rust-lang/rust#4865
Browse files Browse the repository at this point in the history
Shuffles around how exactly libc is used to work around a nasty bug in glob
imports. Unfortunately now requires users of the syntax extension to have an
`extern crate libc`.
  • Loading branch information
emberian committed Jul 31, 2014
1 parent 052895c commit e76c378
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 135 deletions.
3 changes: 1 addition & 2 deletions src/examples/struct_triangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use self::gl::types::*;
#[allow(non_camel_case_types)]
#[allow(non_snake_case_functions)]
pub mod gl {
use super::libc;
use std::mem;
use self::types::*;
generate_gl_bindings!("gl", "gl", "core", "3.2", "struct")
Expand Down Expand Up @@ -150,7 +149,7 @@ fn main() {
gl::STATIC_DRAW);

// Use shader program
gl::UseProgram(program);
gl.UseProgram(program);
"out_color".with_c_str(|ptr| gl.BindFragDataLocation(program, 0, ptr));

// Specify the layout of the vertex data
Expand Down
2 changes: 0 additions & 2 deletions src/gl_generator/src/static_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ impl<'a, W: Writer> StaticGenerator<'a, W> {
fn write_type_aliases(&mut self) {
self.write_line("pub mod types {");
self.incr_indent();
self.write_line("use libc::*;");
self.write_line("");
match self.ns {
Gl => {
Expand Down Expand Up @@ -163,7 +162,6 @@ impl<'a, W: Writer> StaticGenerator<'a, W> {
fn write_failing_fns(&mut self) {
self.write_line("mod failing {");
self.incr_indent();
self.write_line("use libc;");
self.write_line("use super::types::*;");
self.write_line("");
for c in self.registry.cmd_iter() {
Expand Down
12 changes: 5 additions & 7 deletions src/gl_generator/src/struct_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,9 @@ impl<'a, W: Writer> StructGenerator<'a, W> {
self.write_line("#![feature(globs)]");
self.write_line("#![allow(non_camel_case_types)]");
self.write_line("#![allow(non_snake_case_functions)]");
self.write_line("#![allow(unused_variable)]");
self.write_line("");
self.write_line("extern crate libc;");
self.write_line("");
self.write_line("use libc::*;");
self.write_line("use std::mem;");
self.write_line("");
self.write_line("use self::types::*;");
Expand All @@ -125,7 +123,6 @@ impl<'a, W: Writer> StructGenerator<'a, W> {
fn write_type_aliases(&mut self) {
self.write_line("pub mod types {");
self.incr_indent();
self.write_line("use libc::*;");
self.write_line("");
match self.ns {
Gl => {
Expand All @@ -146,12 +143,12 @@ impl<'a, W: Writer> StructGenerator<'a, W> {

fn write_fnptr_struct_def(&mut self) {
self.write_line("pub struct FnPtr {");
self.write_line(" f: *const libc::c_void,");
self.write_line(" f: *const ::libc::c_void,");
self.write_line(" is_loaded: bool,");
self.write_line("}");
self.write_line("");
self.write_line("impl FnPtr {");
self.write_line(" fn new(ptr: *const libc::c_void, failing_fn: *const libc::c_void) -> FnPtr {");
self.write_line(" fn new(ptr: *const ::libc::c_void, failing_fn: *const ::libc::c_void) -> FnPtr {");
self.write_line(" if ptr.is_null() {");
self.write_line(" FnPtr { f: failing_fn, is_loaded: false }");
self.write_line(" } else {");
Expand All @@ -172,6 +169,7 @@ impl<'a, W: Writer> StructGenerator<'a, W> {
self.write_line("use super::types::*;");
self.write_line("");
for c in self.registry.cmd_iter() {
self.write_line("#[allow(unused_variable)]");
self.write_line(format!(
"pub extern \"system\" fn {name}({params}){return_suffix} {{ \
fail!(\"`{name}` was not loaded\") \
Expand Down Expand Up @@ -212,14 +210,14 @@ impl<'a, W: Writer> StructGenerator<'a, W> {
self.write_line("/// let gl = Gl::load_with(|s| glfw.get_proc_address(s));");
self.write_line("/// ~~~");
self.write_line(format!(
"pub fn load_with(loadfn: |symbol: &str| -> *const libc::c_void) -> {:c} {{", ns
"pub fn load_with(loadfn: |symbol: &str| -> *const ::libc::c_void) -> {:c} {{", ns
).as_slice());
self.incr_indent();
self.write_line(format!("{:c} {{", ns).as_slice());
self.incr_indent();
for c in self.registry.cmd_iter() {
self.write_line(format!(
"{name}: FnPtr::new(loadfn(\"{symbol}\"), failing::{name} as *const libc::c_void),",
"{name}: FnPtr::new(loadfn(\"{symbol}\"), failing::{name} as *const ::libc::c_void),",
name = c.proto.ident,
symbol = common::gen_symbol_name(&ns, c)
).as_slice());
Expand Down
Loading

0 comments on commit e76c378

Please sign in to comment.