@@ -11,9 +11,9 @@ use objc2_app_kit::{
1111 NSOpenGLPixelFormat , NSOpenGLProfileVersion3_2Core , NSOpenGLProfileVersion4_1Core ,
1212 NSOpenGLProfileVersionLegacy , NSOpenGLView , NSView ,
1313} ;
14- use objc2_core_foundation:: { CFBundle , CFString } ;
14+ use objc2_core_foundation:: { CFBundle , CFString , CFStringBuiltInEncodings } ;
1515use objc2_foundation:: NSSize ;
16- use std:: ffi:: c_void;
16+ use std:: ffi:: { c_void, CStr } ;
1717use std:: ptr:: NonNull ;
1818
1919pub type CreationFailedError = ( ) ;
@@ -103,8 +103,19 @@ impl GlContext {
103103 NSOpenGLContext :: clearCurrentContext ( ) ;
104104 }
105105
106- pub fn get_proc_address ( & self , symbol : & str ) -> * const c_void {
107- let symbol_name = CFString :: from_str ( symbol) ;
106+ pub fn get_proc_address ( & self , symbol : & CStr ) -> * const c_void {
107+ // SAFETY: The string pointer is valid
108+ let symbol_name = unsafe {
109+ CFString :: with_bytes (
110+ None ,
111+ symbol. as_ptr ( ) . cast ( ) ,
112+ symbol. count_bytes ( ) . try_into ( ) . unwrap ( ) ,
113+ CFStringBuiltInEncodings :: EncodingUTF8 . 0 ,
114+ false ,
115+ )
116+ }
117+ . unwrap ( ) ;
118+
108119 let framework_name = CFString :: from_static_str ( "com.apple.opengl" ) ;
109120 let framework = CFBundle :: bundle_with_identifier ( Some ( & framework_name) ) . unwrap ( ) ;
110121
0 commit comments