@@ -6,6 +6,7 @@ use core::panic::{RefUnwindSafe, UnwindSafe};
66#[ cfg( debug_assertions) ]
77use std:: collections:: HashSet ;
88
9+ use crate :: encode:: { EncodeArguments , EncodeReturn } ;
910use crate :: runtime:: { AnyClass , ClassBuilder , MethodImplementation , Sel } ;
1011#[ cfg( debug_assertions) ]
1112use crate :: runtime:: { AnyProtocol , MethodDescription } ;
@@ -215,21 +216,43 @@ impl<T: DefinedClass> ClassBuilderHelper<T> {
215216
216217 // Addition: This restricts to callee `T`
217218 #[ inline]
218- pub unsafe fn add_method < F > ( & mut self , sel : Sel , func : F )
219+ pub unsafe fn add_method < F > ( & mut self , sel : Sel , func : F , encoding : & CStr )
219220 where
220221 F : MethodImplementation < Callee = T > ,
221222 {
223+ if cfg ! ( all(
224+ debug_assertions,
225+ not( feature = "disable-encoding-assertions" )
226+ ) ) {
227+ self . builder
228+ . verify_method ( sel, F :: Arguments :: ENCODINGS , & F :: Return :: ENCODING_RETURN ) ;
229+ }
230+
222231 // SAFETY: Checked by caller
223- unsafe { self . builder . add_method ( sel, func) }
232+ unsafe { self . builder . add_method_inner ( sel, func. __imp ( ) , encoding ) }
224233 }
225234
226235 #[ inline]
227- pub unsafe fn add_class_method < F > ( & mut self , sel : Sel , func : F )
236+ pub unsafe fn add_class_method < F > ( & mut self , sel : Sel , func : F , encoding : & CStr )
228237 where
229238 F : MethodImplementation < Callee = AnyClass > ,
230239 {
240+ if cfg ! ( all(
241+ debug_assertions,
242+ not( feature = "disable-encoding-assertions" )
243+ ) ) {
244+ self . builder . verify_class_method (
245+ sel,
246+ F :: Arguments :: ENCODINGS ,
247+ & F :: Return :: ENCODING_RETURN ,
248+ ) ;
249+ }
250+
231251 // SAFETY: Checked by caller
232- unsafe { self . builder . add_class_method ( sel, func) }
252+ unsafe {
253+ self . builder
254+ . add_class_method_inner ( sel, func. __imp ( ) , encoding)
255+ }
233256 }
234257}
235258
@@ -259,7 +282,7 @@ pub struct ClassProtocolMethodsBuilder<'a, T: ?Sized> {
259282impl < T : DefinedClass > ClassProtocolMethodsBuilder < ' _ , T > {
260283 // Addition: This restricts to callee `T`
261284 #[ inline]
262- pub unsafe fn add_method < F > ( & mut self , sel : Sel , func : F )
285+ pub unsafe fn add_method < F > ( & mut self , sel : Sel , func : F , encoding : & CStr )
263286 where
264287 F : MethodImplementation < Callee = T > ,
265288 {
@@ -279,7 +302,7 @@ impl<T: DefinedClass> ClassProtocolMethodsBuilder<'_, T> {
279302 }
280303
281304 // SAFETY: Checked by caller
282- unsafe { self . builder . add_method ( sel, func) } ;
305+ unsafe { self . builder . add_method ( sel, func, encoding ) } ;
283306
284307 #[ cfg( debug_assertions) ]
285308 if !self . registered_instance_methods . insert ( sel) {
@@ -288,7 +311,7 @@ impl<T: DefinedClass> ClassProtocolMethodsBuilder<'_, T> {
288311 }
289312
290313 #[ inline]
291- pub unsafe fn add_class_method < F > ( & mut self , sel : Sel , func : F )
314+ pub unsafe fn add_class_method < F > ( & mut self , sel : Sel , func : F , encoding : & CStr )
292315 where
293316 F : MethodImplementation < Callee = AnyClass > ,
294317 {
@@ -308,7 +331,7 @@ impl<T: DefinedClass> ClassProtocolMethodsBuilder<'_, T> {
308331 }
309332
310333 // SAFETY: Checked by caller
311- unsafe { self . builder . add_class_method ( sel, func) } ;
334+ unsafe { self . builder . add_class_method ( sel, func, encoding ) } ;
312335
313336 #[ cfg( debug_assertions) ]
314337 if !self . registered_class_methods . insert ( sel) {
0 commit comments