@@ -173,25 +173,36 @@ impl_traits!(t0: T0, t1: T1, t2: T2, t3: T3, t4: T4, t5: T5, t6: T6, t7: T7, t8:
173
173
/// about what exactly goes on behind the scenes in order to justify all the
174
174
/// following precautions.
175
175
///
176
- /// The simplest way to achieve this is to somehow obtain a block with the
177
- /// correct signature from the Objective-C runtime and [`Debug`]-display it to
178
- /// copy its `encoding` C string .
176
+ /// The easiest way to do this is probably to ask Clang; the following program
177
+ /// will print the signature of the block (if you're having trouble linking,
178
+ /// you should be able to find the signature in the assembly output) .
179
179
///
180
- /// Another possibility is to help yourself with [`Encoding::to_string`][enc2s]
181
- /// in order to get the various components of the signature string separately
182
- /// and then concatenate them manually with the required numbers described
183
- /// below inserted at their correct place.
180
+ /// ```objective-c
181
+ /// #import <Foundation/Foundation.h>
184
182
///
185
- /// Yet another possibility is to compile a small Objective-C program, with GCC
186
- /// and GNUstep for example, that simply displays the result of
187
- /// `method_getTypeEncoding(class_getClassMethod([MyClass class] @selector(sel)))`
188
- /// where `MyClass::sel` has a signature compatible with the block you want,
189
- /// after which the string can be slightly modified to fit an actual block
190
- /// instead of a method: see below.
183
+ /// // Unstable API, but fine for test usage like this.
184
+ /// const char * _Block_signature(void *);
185
+ ///
186
+ /// int main() {
187
+ /// // Declare the signature of your block.
188
+ /// // This one takes `id` and `int`, and returns `NSString*`.
189
+ /// id block = ^NSString* (id a, int b) {
190
+ /// return nil;
191
+ /// };
192
+ ///
193
+ /// printf("%s\n", _Block_signature((void*)block));
194
+ /// return 0;
195
+ /// }
196
+ /// ```
191
197
///
192
198
/// A more thorough but manual approach is to only follow the rules described
193
199
/// below.
194
200
///
201
+ /// In this process, you may be able to use [`Encoding::to_string`][enc2s] in
202
+ /// order to get the various components of the signature string and then
203
+ /// concatenate them manually with the required numbers (described below)
204
+ /// inserted at their correct place.
205
+ ///
195
206
/// [enc2s]: objc2::encode::Encoding#impl-Display-for-Encoding
196
207
/// [i442-sign-check]: https://github.com/madsmtm/objc2/issues/442#issuecomment-2284932726
197
208
///
0 commit comments