Repository: brendanzab/gl-rs (language: rust)

Issue:
Upgrade to latest rust (DANGEROUS)
Closes https://github.com/bjz/gl-rs/issues/76

Notice the transmute is replaced by direct casting by pointers. I do
not know how this affects the usage of the library. I left the ‘unused
import’ warning on in case this can be fixed later. If this is
critical, I would recommend doing an analysis and document which uses
cases one should be careful.



Discussion / hints:
I've been thinking for a while that we should use a function that returns a *c_void instead of an `extern fn`.

I might have to do a simultaneous update with glfw-rs :S

I will merge this for now, but I will do a refactor.

Hmm - there is an error building though :/


Fix patch:
diff --git a/deps/glfw-rs b/deps/glfw-rs
index 44a3c953..423533e0 160000
--- a/deps/glfw-rs
+++ b/deps/glfw-rs
@@ -1,1 +1,1 @@
-Subproject commit 44a3c953d39a14015d4e3dfcf2a4ee982e3ead31
+Subproject commit 423533e00d92aa8dffc13f43cf32dfdd07f96299
diff --git a/src/gen/main.rs b/src/gen/main.rs
index d965ac2e..7f20f6ca 100644
--- a/src/gen/main.rs
+++ b/src/gen/main.rs
@@ -32,7 +32,7 @@
 
 extern crate getopts;
 
-#[phase(syntax, link)]
+#[phase(plugin, link)]
 extern crate log;
 
 use getopts::{optopt, optmulti, optflag, getopts, usage};
@@ -241,7 +241,7 @@ impl<'a, W: Writer> Generator<'a, W> {
         self.write_line("// limitations under the License.");
         self.write_line("");
         let ns = self.ns.to_str();
-        self.write_line(format!(r#"\#![crate_id = "github.com/bjz/gl-rs\#{}:0.1"]"#, ns).as_slice());
+        self.write_line(format!("#![crate_id = \"github.com/bjz/gl-rs#{}:0.1\"]", ns).as_slice());
         self.write_line("#![comment = \"An OpenGL function loader.\"]");
         self.write_line("#![license = \"ASL2\"]");
         self.write_line("#![crate_type = \"lib\"]");
@@ -284,9 +284,8 @@ impl<'a, W: Writer> Generator<'a, W> {
         self.write_line("");
         self.write_line("impl<F> FnPtr<F> {");
         self.write_line("    pub fn new(ptr: Option<extern \"system\" fn()>, failing_fn: F) -> FnPtr<F> {");
-        self.write_line("        use std::mem::transmute;");
         self.write_line("        match ptr {");
-        self.write_line("            std::option::Some(p) => FnPtr { f: unsafe { transmute(p) }, is_loaded: true },");
+        self.write_line("            std::option::Some(p) => FnPtr { f: unsafe { std::ptr::read(&p as *_ as *F) }, is_loaded: true },");
         self.write_line("            None => FnPtr { f: failing_fn, is_loaded: false },");
         self.write_line("        }");
         self.write_line("    }");
@@ -321,7 +320,7 @@ impl<'a, W: Writer> Generator<'a, W> {
     fn write_fns(&mut self) {
         for c in self.registry.cmd_iter() {
             self.write_line(format!(
-                "\\#[inline] pub {}fn {}({}){} \\{ {}(storage::{}.f)({}){} \\}",
+                "#[inline] pub {}fn {}({}){} {{ {}(storage::{}.f)({}){} }}",
                 if c.is_safe { "" } else { "unsafe " },
                 c.proto.ident,
                 gen_param_list(c, true),


Test patch: