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

Issue:
Sound passing of null fn pointers
There are some OpenGL APIs that allow passing of null function pointers: https://github.com/brendanzab/gl-rs/blob/667fbb36c3c629e83d4f7cb15a0e5aad52976051/gl_generator/generators/templates/types/gl.rs#L49 Rust function pointers however, even extern "system" ones, must not be null. Therefore, passing null to them is unsound and recent nightlies are warning about it (see https://github.com/glium/glium/issues/1775).

To fix this, I suggest wrapping an `Option<>` around the fn pointers in those type definitions.


Discussion / hints:

Fix patch:
diff --git a/gl_generator/generators/templates/types/gl.rs b/gl_generator/generators/templates/types/gl.rs
index 5b7cb3ff..90e46201 100644
--- a/gl_generator/generators/templates/types/gl.rs
+++ b/gl_generator/generators/templates/types/gl.rs
@@ -46,27 +46,27 @@ pub type GLsync = *const __GLsync;
 pub enum _cl_context {}
 pub enum _cl_event {}
 
-pub type GLDEBUGPROC = extern "system" fn(source: GLenum,
-                                          gltype: GLenum,
-                                          id: GLuint,
-                                          severity: GLenum,
-                                          length: GLsizei,
-                                          message: *const GLchar,
-                                          userParam: *mut super::__gl_imports::raw::c_void);
-pub type GLDEBUGPROCARB = extern "system" fn(source: GLenum,
-                                             gltype: GLenum,
-                                             id: GLuint,
-                                             severity: GLenum,
-                                             length: GLsizei,
-                                             message: *const GLchar,
-                                             userParam: *mut super::__gl_imports::raw::c_void);
-pub type GLDEBUGPROCKHR = extern "system" fn(source: GLenum,
-                                             gltype: GLenum,
-                                             id: GLuint,
-                                             severity: GLenum,
-                                             length: GLsizei,
-                                             message: *const GLchar,
-                                             userParam: *mut super::__gl_imports::raw::c_void);
+pub type GLDEBUGPROC = Option<extern "system" fn(source: GLenum,
+                                                 gltype: GLenum,
+                                                 id: GLuint,
+                                                 severity: GLenum,
+                                                 length: GLsizei,
+                                                 message: *const GLchar,
+                                                 userParam: *mut super::__gl_imports::raw::c_void)>;
+pub type GLDEBUGPROCARB = Option<extern "system" fn(source: GLenum,
+                                                    gltype: GLenum,
+                                                    id: GLuint,
+                                                    severity: GLenum,
+                                                    length: GLsizei,
+                                                    message: *const GLchar,
+                                                    userParam: *mut super::__gl_imports::raw::c_void)>;
+pub type GLDEBUGPROCKHR = Option<extern "system" fn(source: GLenum,
+                                                    gltype: GLenum,
+                                                    id: GLuint,
+                                                    severity: GLenum,
+                                                    length: GLsizei,
+                                                    message: *const GLchar,
+                                                    userParam: *mut super::__gl_imports::raw::c_void)>;
 
 // GLES 1 types
 // "pub type GLclampx = i32;",
@@ -98,11 +98,11 @@ pub type GLDEBUGPROCKHR = extern "system" fn(source: GLenum,
 // GLES 2 types (none currently)
 
 // Vendor extension types
-pub type GLDEBUGPROCAMD = extern "system" fn(id: GLuint,
-                                             category: GLenum,
-                                             severity: GLenum,
-                                             length: GLsizei,
-                                             message: *const GLchar,
-                                             userParam: *mut super::__gl_imports::raw::c_void);
+pub type GLDEBUGPROCAMD = Option<extern "system" fn(id: GLuint,
+                                                    category: GLenum,
+                                                    severity: GLenum,
+                                                    length: GLsizei,
+                                                    message: *const GLchar,
+                                                    userParam: *mut super::__gl_imports::raw::c_void)>;
 pub type GLhalfNV = super::__gl_imports::raw::c_ushort;
 pub type GLvdpauSurfaceNV = GLintptr;


Test patch: