1
- // Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
2
- // This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present Datadog, Inc.
1
+ // Unless explicitly stated otherwise all files in this repository are licensed under the Apache
2
+ // License Version 2.0. This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2021-Present Datadog, Inc.
3
3
4
- use std :: borrow :: Cow ;
4
+ use datadog_live_debugger :: debugger_defs :: SnapshotEvaluationError ;
5
5
use datadog_live_debugger:: { DslString , ProbeCondition } ;
6
+ use ddcommon_ffi:: slice:: AsBytes ;
6
7
use ddcommon_ffi:: CharSlice ;
8
+ use std:: borrow:: Cow ;
7
9
use std:: ffi:: c_void;
8
- use ddcommon_ffi:: slice:: AsBytes ;
9
- use datadog_live_debugger:: debugger_defs:: SnapshotEvaluationError ;
10
10
11
11
#[ repr( C ) ]
12
12
pub enum IntermediateValue < ' a > {
@@ -50,7 +50,7 @@ pub struct Evaluator {
50
50
pub greater_or_equals :
51
51
for <' a > extern "C" fn ( & ' a mut c_void , IntermediateValue < ' a > , IntermediateValue < ' a > ) -> bool ,
52
52
pub fetch_identifier :
53
- for <' a , ' b > extern "C" fn ( & ' a mut c_void , & CharSlice < ' b > ) -> Option < & ' static c_void > , // special values: @duration, @return, @exception
53
+ for <' a , ' b > extern "C" fn ( & ' a mut c_void , & CharSlice < ' b > ) -> Option < & ' static c_void > , /* special values: @duration, @return, @exception */
54
54
pub fetch_index : for <' a , ' b > extern "C" fn (
55
55
& ' a mut c_void ,
56
56
& ' a c_void ,
@@ -65,7 +65,7 @@ pub struct Evaluator {
65
65
pub try_enumerate : for <' a > extern "C" fn ( & ' a mut c_void , & ' a c_void ) -> VoidCollection ,
66
66
pub stringify : for <' a > extern "C" fn ( & ' a mut c_void , & ' a c_void ) -> CharSlice < ' static > ,
67
67
pub get_string : for <' a > extern "C" fn ( & ' a mut c_void , & ' a c_void ) -> CharSlice < ' static > ,
68
- pub convert_index : for <' a > extern "C" fn ( & ' a mut c_void , & ' a c_void ) -> isize , // return < 0 on error
68
+ pub convert_index : for <' a > extern "C" fn ( & ' a mut c_void , & ' a c_void ) -> isize , /* return < 0 on error */
69
69
pub instanceof : for <' a > extern "C" fn ( & ' a mut c_void , & ' a c_void , & CharSlice < ' a > ) -> bool ,
70
70
}
71
71
@@ -80,33 +80,53 @@ impl<'e> EvalCtx<'e> {
80
80
fn new ( context : & ' e mut c_void ) -> Self {
81
81
EvalCtx {
82
82
context,
83
- eval : unsafe { FFI_EVALUATOR . as_ref ( ) . unwrap ( ) }
83
+ eval : unsafe { FFI_EVALUATOR . as_ref ( ) . unwrap ( ) } ,
84
84
}
85
85
}
86
86
}
87
87
88
88
impl < ' e > datadog_live_debugger:: Evaluator < ' e , c_void > for EvalCtx < ' e > {
89
- fn equals ( & mut self , a : datadog_live_debugger:: IntermediateValue < ' e , c_void > , b : datadog_live_debugger:: IntermediateValue < ' e , c_void > ) -> bool {
89
+ fn equals (
90
+ & mut self ,
91
+ a : datadog_live_debugger:: IntermediateValue < ' e , c_void > ,
92
+ b : datadog_live_debugger:: IntermediateValue < ' e , c_void > ,
93
+ ) -> bool {
90
94
( self . eval . equals ) ( self . context , ( & a) . into ( ) , ( & b) . into ( ) )
91
95
}
92
96
93
- fn greater_than ( & mut self , a : datadog_live_debugger:: IntermediateValue < ' e , c_void > , b : datadog_live_debugger:: IntermediateValue < ' e , c_void > ) -> bool {
97
+ fn greater_than (
98
+ & mut self ,
99
+ a : datadog_live_debugger:: IntermediateValue < ' e , c_void > ,
100
+ b : datadog_live_debugger:: IntermediateValue < ' e , c_void > ,
101
+ ) -> bool {
94
102
( self . eval . greater_than ) ( self . context , ( & a) . into ( ) , ( & b) . into ( ) )
95
103
}
96
104
97
- fn greater_or_equals ( & mut self , a : datadog_live_debugger:: IntermediateValue < ' e , c_void > , b : datadog_live_debugger:: IntermediateValue < ' e , c_void > ) -> bool {
105
+ fn greater_or_equals (
106
+ & mut self ,
107
+ a : datadog_live_debugger:: IntermediateValue < ' e , c_void > ,
108
+ b : datadog_live_debugger:: IntermediateValue < ' e , c_void > ,
109
+ ) -> bool {
98
110
( self . eval . greater_or_equals ) ( self . context , ( & a) . into ( ) , ( & b) . into ( ) )
99
111
}
100
112
101
113
fn fetch_identifier ( & mut self , identifier : & str ) -> Option < & ' e c_void > {
102
114
( self . eval . fetch_identifier ) ( self . context , & CharSlice :: from ( identifier) )
103
115
}
104
116
105
- fn fetch_index ( & mut self , value : & ' e c_void , index : datadog_live_debugger:: IntermediateValue < ' e , c_void > ) -> Option < & ' e c_void > {
117
+ fn fetch_index (
118
+ & mut self ,
119
+ value : & ' e c_void ,
120
+ index : datadog_live_debugger:: IntermediateValue < ' e , c_void > ,
121
+ ) -> Option < & ' e c_void > {
106
122
( self . eval . fetch_index ) ( self . context , value, ( & index) . into ( ) )
107
123
}
108
124
109
- fn fetch_nested ( & mut self , value : & ' e c_void , member : datadog_live_debugger:: IntermediateValue < ' e , c_void > ) -> Option < & ' e c_void > {
125
+ fn fetch_nested (
126
+ & mut self ,
127
+ value : & ' e c_void ,
128
+ member : datadog_live_debugger:: IntermediateValue < ' e , c_void > ,
129
+ ) -> Option < & ' e c_void > {
110
130
( self . eval . fetch_nested ) ( self . context , value, ( & member) . into ( ) )
111
131
}
112
132
@@ -119,12 +139,15 @@ impl<'e> datadog_live_debugger::Evaluator<'e, c_void> for EvalCtx<'e> {
119
139
if collection. count < 0 {
120
140
None
121
141
} else {
122
- // We need to copy, Vec::from_raw_parts with only free in the allocator would be unstable...
142
+ // We need to copy, Vec::from_raw_parts with only free in the allocator would be
143
+ // unstable...
123
144
let mut vec = Vec :: with_capacity ( collection. count as usize ) ;
124
- unsafe { vec. extend_from_slice ( std:: slice:: from_raw_parts (
125
- collection. elements as * const & c_void ,
126
- collection. count as usize ,
127
- ) ) } ;
145
+ unsafe {
146
+ vec. extend_from_slice ( std:: slice:: from_raw_parts (
147
+ collection. elements as * const & c_void ,
148
+ collection. count as usize ,
149
+ ) )
150
+ } ;
128
151
( collection. free ) ( collection) ;
129
152
Some ( vec)
130
153
}
@@ -162,20 +185,27 @@ pub unsafe extern "C" fn ddog_register_expr_evaluator(eval: &Evaluator) {
162
185
pub enum ConditionEvaluationResult {
163
186
Success ,
164
187
Failure ,
165
- Error ( Box < Vec < SnapshotEvaluationError > > )
188
+ Error ( Box < Vec < SnapshotEvaluationError > > ) ,
166
189
}
167
190
168
191
#[ no_mangle]
169
- pub extern "C" fn ddog_evaluate_condition ( condition : & ProbeCondition , context : & mut c_void ) -> ConditionEvaluationResult {
192
+ pub extern "C" fn ddog_evaluate_condition (
193
+ condition : & ProbeCondition ,
194
+ context : & mut c_void ,
195
+ ) -> ConditionEvaluationResult {
170
196
let mut ctx = EvalCtx :: new ( context) ;
171
197
match datadog_live_debugger:: eval_condition ( & mut ctx, condition) {
172
198
Ok ( true ) => ConditionEvaluationResult :: Success ,
173
199
Ok ( false ) => ConditionEvaluationResult :: Failure ,
174
- Err ( error) => ConditionEvaluationResult :: Error ( Box :: new ( vec ! [ error] ) )
200
+ Err ( error) => ConditionEvaluationResult :: Error ( Box :: new ( vec ! [ error] ) ) ,
175
201
}
176
202
}
177
203
178
- pub fn ddog_evaluate_string < ' a > ( condition : & ' a DslString , context : & ' a mut c_void , errors : & mut Option < Box < Vec < SnapshotEvaluationError > > > ) -> Cow < ' a , str > {
204
+ pub fn ddog_evaluate_string < ' a > (
205
+ condition : & ' a DslString ,
206
+ context : & ' a mut c_void ,
207
+ errors : & mut Option < Box < Vec < SnapshotEvaluationError > > > ,
208
+ ) -> Cow < ' a , str > {
179
209
let mut ctx = EvalCtx :: new ( context) ;
180
210
let ( result, new_errors) = datadog_live_debugger:: eval_string ( & mut ctx, condition) ;
181
211
if !new_errors. is_empty ( ) {
0 commit comments