@@ -61,11 +61,11 @@ pub unsafe extern "C" fn yrx_scanner_set_timeout(
61
61
scanner : * mut YRX_SCANNER ,
62
62
timeout : u64 ,
63
63
) -> YRX_RESULT {
64
- if scanner. is_null ( ) {
65
- return YRX_RESULT :: INVALID_ARGUMENT ;
66
- }
64
+ let scanner = match scanner. as_mut ( ) {
65
+ Some ( s) => s,
66
+ None => return YRX_RESULT :: INVALID_ARGUMENT ,
67
+ } ;
67
68
68
- let scanner = scanner. as_mut ( ) . unwrap ( ) ;
69
69
scanner. inner . set_timeout ( Duration :: from_secs ( timeout) ) ;
70
70
71
71
YRX_RESULT :: SUCCESS
@@ -84,16 +84,16 @@ pub unsafe extern "C" fn yrx_scanner_scan(
84
84
) -> YRX_RESULT {
85
85
_yrx_set_last_error :: < ScanError > ( None ) ;
86
86
87
- if scanner. is_null ( ) {
88
- return YRX_RESULT :: INVALID_ARGUMENT ;
89
- }
87
+ let scanner = match scanner. as_mut ( ) {
88
+ Some ( s) => s,
89
+ None => return YRX_RESULT :: INVALID_ARGUMENT ,
90
+ } ;
90
91
91
92
let data = match slice_from_ptr_and_len ( data, len) {
92
93
Some ( data) => data,
93
94
None => return YRX_RESULT :: INVALID_ARGUMENT ,
94
95
} ;
95
96
96
- let scanner = scanner. as_mut ( ) . unwrap ( ) ;
97
97
let scan_results = scanner. inner . scan ( data) ;
98
98
99
99
if let Err ( err) = scan_results {
@@ -178,9 +178,10 @@ pub unsafe extern "C" fn yrx_scanner_set_module_output(
178
178
data : * const u8 ,
179
179
len : usize ,
180
180
) -> YRX_RESULT {
181
- if scanner. is_null ( ) {
182
- return YRX_RESULT :: INVALID_ARGUMENT ;
183
- }
181
+ let scanner = match scanner. as_mut ( ) {
182
+ Some ( s) => s,
183
+ None => return YRX_RESULT :: INVALID_ARGUMENT ,
184
+ } ;
184
185
185
186
let module_name = match CStr :: from_ptr ( name) . to_str ( ) {
186
187
Ok ( name) => name,
@@ -195,8 +196,6 @@ pub unsafe extern "C" fn yrx_scanner_set_module_output(
195
196
None => return YRX_RESULT :: INVALID_ARGUMENT ,
196
197
} ;
197
198
198
- let scanner = scanner. as_mut ( ) . unwrap ( ) ;
199
-
200
199
match scanner. inner . set_module_output_raw ( module_name, data) {
201
200
Ok ( _) => {
202
201
_yrx_set_last_error :: < ScanError > ( None ) ;
@@ -216,9 +215,10 @@ unsafe extern "C" fn yrx_scanner_set_global<
216
215
ident : * const c_char ,
217
216
value : T ,
218
217
) -> YRX_RESULT {
219
- if scanner. is_null ( ) {
220
- return YRX_RESULT :: INVALID_ARGUMENT ;
221
- }
218
+ let scanner = match scanner. as_mut ( ) {
219
+ Some ( s) => s,
220
+ None => return YRX_RESULT :: INVALID_ARGUMENT ,
221
+ } ;
222
222
223
223
let ident = match CStr :: from_ptr ( ident) . to_str ( ) {
224
224
Ok ( ident) => ident,
@@ -228,8 +228,6 @@ unsafe extern "C" fn yrx_scanner_set_global<
228
228
}
229
229
} ;
230
230
231
- let scanner = scanner. as_mut ( ) . unwrap ( ) ;
232
-
233
231
match scanner. inner . set_global ( ident, value) {
234
232
Ok ( _) => {
235
233
_yrx_set_last_error :: < ScanError > ( None ) ;
@@ -327,35 +325,40 @@ pub type YRX_MOST_EXPENSIVE_RULES_CALLBACK = extern "C" fn(
327
325
/// Iterates over the top N most expensive rules, calling the callback for
328
326
/// each rule.
329
327
///
330
- /// Requires the `rules-profiling` feature.
328
+ /// Requires the `rules-profiling` feature, otherwise the
331
329
///
332
330
/// See [`YRX_MOST_EXPENSIVE_RULES_CALLBACK`] for more details.
333
- #[ cfg( feature = "rules-profiling" ) ]
334
331
#[ no_mangle]
332
+ #[ allow( unused_variables) ]
335
333
pub unsafe extern "C" fn yrx_scanner_iter_most_expensive_rules (
336
334
scanner : * mut YRX_SCANNER ,
337
335
n : usize ,
338
336
callback : YRX_MOST_EXPENSIVE_RULES_CALLBACK ,
339
337
user_data : * mut c_void ,
340
338
) -> YRX_RESULT {
341
- if scanner. is_null ( ) {
342
- return YRX_RESULT :: INVALID_ARGUMENT ;
343
- }
344
-
345
- let scanner = scanner. as_ref ( ) . unwrap ( ) ;
339
+ #[ cfg( not( feature = "rules-profiling" ) ) ]
340
+ return YRX_RESULT :: NOT_SUPPORTED ;
341
+
342
+ #[ cfg( feature = "rules-profiling" ) ]
343
+ {
344
+ let scanner = match scanner. as_ref ( ) {
345
+ Some ( s) => s,
346
+ None => return YRX_RESULT :: INVALID_ARGUMENT ,
347
+ } ;
346
348
347
- for profiling_info in scanner. inner . most_expensive_rules ( n) {
348
- let namespace = CString :: new ( profiling_info. namespace ) . unwrap ( ) ;
349
- let rule = CString :: new ( profiling_info. rule ) . unwrap ( ) ;
349
+ for profiling_info in scanner. inner . most_expensive_rules ( n) {
350
+ let namespace = CString :: new ( profiling_info. namespace ) . unwrap ( ) ;
351
+ let rule = CString :: new ( profiling_info. rule ) . unwrap ( ) ;
352
+
353
+ callback (
354
+ namespace. as_ptr ( ) ,
355
+ rule. as_ptr ( ) ,
356
+ profiling_info. pattern_matching_time . as_secs_f64 ( ) ,
357
+ profiling_info. condition_exec_time . as_secs_f64 ( ) ,
358
+ user_data,
359
+ ) ;
360
+ }
350
361
351
- callback (
352
- namespace. as_ptr ( ) ,
353
- rule. as_ptr ( ) ,
354
- profiling_info. pattern_matching_time . as_secs_f64 ( ) ,
355
- profiling_info. condition_exec_time . as_secs_f64 ( ) ,
356
- user_data,
357
- ) ;
362
+ YRX_RESULT :: SUCCESS
358
363
}
359
-
360
- YRX_RESULT :: SUCCESS
361
364
}
0 commit comments