11use std:: cmp;
2- use std:: iter:: repeat;
32
43use proc_macro2:: { Literal , TokenStream } ;
54use quote:: { format_ident, quote} ;
@@ -27,14 +26,13 @@ pub(crate) fn generate_interfaces_prefix(protocol: &Protocol) -> TokenStream {
2726
2827 let types_null_len = Literal :: usize_unsuffixed ( longest_nulls) ;
2928
30- let nulls = repeat ( quote ! { NULLPTR as * const wayland_backend:: protocol:: wl_interface } )
31- . take ( longest_nulls) ;
32-
3329 quote ! {
34- const NULLPTR : * const std:: os:: raw:: c_void = 0 as * const std:: os:: raw:: c_void;
35- static mut types_null: [ * const wayland_backend:: protocol:: wl_interface; #types_null_len] = [
36- #( #nulls, ) *
37- ] ;
30+ use std:: ptr:: null;
31+ struct SyncWrapper <T >( T ) ;
32+ unsafe impl <T > Sync for SyncWrapper <T > { }
33+ static types_null: SyncWrapper <[ * const wayland_backend:: protocol:: wl_interface; #types_null_len] > = SyncWrapper ( [
34+ null:: <wayland_backend:: protocol:: wl_interface>( ) ; #types_null_len
35+ ] ) ;
3836 }
3937}
4038
@@ -47,24 +45,24 @@ pub(crate) fn generate_interface(interface: &Interface) -> TokenStream {
4745 let version_value = Literal :: i32_unsuffixed ( interface. version as i32 ) ;
4846 let request_count_value = Literal :: i32_unsuffixed ( interface. requests . len ( ) as i32 ) ;
4947 let requests_value = if interface. requests . is_empty ( ) {
50- quote ! { NULLPTR as * const wayland_backend:: protocol:: wl_message }
48+ quote ! { null :: < wayland_backend:: protocol:: wl_message> ( ) }
5149 } else {
5250 let requests_ident = format_ident ! ( "{}_requests" , interface. name) ;
53- quote ! { unsafe { & #requests_ident as * const _ } }
51+ quote ! { #requests_ident. 0 . as_ptr ( ) }
5452 } ;
5553 let event_count_value = Literal :: i32_unsuffixed ( interface. events . len ( ) as i32 ) ;
5654 let events_value = if interface. events . is_empty ( ) {
57- quote ! { NULLPTR as * const wayland_backend:: protocol:: wl_message }
55+ quote ! { null :: < wayland_backend:: protocol:: wl_message> ( ) }
5856 } else {
5957 let events_ident = format_ident ! ( "{}_events" , interface. name) ;
60- quote ! { unsafe { & #events_ident as * const _ } }
58+ quote ! { #events_ident. 0 . as_ptr ( ) }
6159 } ;
6260
6361 quote ! {
6462 #requests
6563 #events
6664
67- pub static mut #interface_ident: wayland_backend:: protocol:: wl_interface = wayland_backend:: protocol:: wl_interface {
65+ pub static #interface_ident: wayland_backend:: protocol:: wl_interface = wayland_backend:: protocol:: wl_interface {
6866 name: #name_value as * const u8 as * const std:: os:: raw:: c_char,
6967 version: #version_value,
7068 request_count: #request_count_value,
@@ -89,15 +87,15 @@ fn gen_messages(interface: &Interface, messages: &[Message], which: &str) -> Tok
8987 let array_values = msg. args . iter ( ) . map ( |arg| match ( arg. typ , & arg. interface ) {
9088 ( Type :: Object , & Some ( ref inter) ) | ( Type :: NewId , & Some ( ref inter) ) => {
9189 let interface_ident =format_ident ! ( "{}_interface" , inter) ;
92- quote ! { unsafe { & #interface_ident as * const wayland_backend:: protocol:: wl_interface } }
90+ quote ! { & #interface_ident as * const wayland_backend:: protocol:: wl_interface }
9391 }
94- _ => quote ! { NULLPTR as * const wayland_backend:: protocol:: wl_interface } ,
92+ _ => quote ! { null :: < wayland_backend:: protocol:: wl_interface> ( ) } ,
9593 } ) ;
9694
9795 Some ( quote ! {
98- static mut #array_ident: [ * const wayland_backend:: protocol:: wl_interface; #array_len] = [
96+ static #array_ident: SyncWrapper < [ * const wayland_backend:: protocol:: wl_interface; #array_len] > = SyncWrapper ( [
9997 #( #array_values, ) *
100- ] ;
98+ ] ) ;
10199 } )
102100 }
103101 } ) ;
@@ -118,17 +116,17 @@ fn gen_messages(interface: &Interface, messages: &[Message], which: &str) -> Tok
118116 wayland_backend:: protocol:: wl_message {
119117 name: #name_value as * const u8 as * const std:: os:: raw:: c_char,
120118 signature: #signature_value as * const u8 as * const std:: os:: raw:: c_char,
121- types: unsafe { & #types_ident as * const _ } ,
119+ types: #types_ident. 0 . as_ptr ( ) ,
122120 }
123121 }
124122 } ) ;
125123
126124 quote ! {
127125 #( #types_arrays) *
128126
129- pub static mut #message_array_ident: [ wayland_backend:: protocol:: wl_message; #message_array_len] = [
127+ static #message_array_ident: SyncWrapper < [ wayland_backend:: protocol:: wl_message; #message_array_len] > = SyncWrapper ( [
130128 #( #message_array_values, ) *
131- ] ;
129+ ] ) ;
132130 }
133131}
134132
0 commit comments