Skip to content

Commit c2a94de

Browse files
committed
investigation
Signed-off-by: Anand Krishnamoorthi <anakrish@microsoft.com>
1 parent b16a167 commit c2a94de

3 files changed

Lines changed: 44 additions & 1 deletion

File tree

bindings/csharp/Regorus/MemoryLimits.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,9 @@ public static void SetThreadFlushThresholdOverride(ulong? bytes)
7575

7676
if (result.data_type != RegorusDataType.Integer)
7777
{
78-
throw new InvalidOperationException($"{errorContext}: native call did not return an integer");
78+
throw new InvalidOperationException(
79+
$"{errorContext}: native call returned {result.data_type} ({(int)result.data_type}) with bool_value={result.bool_value}"
80+
);
7981
}
8082

8183
if (result.int_value < 0)

bindings/csharp/Regorus/NativeMethods.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ internal unsafe partial struct RegorusResult
560560
/// Boolean value.
561561
/// Valid when data_type is Boolean.
562562
/// </summary>
563+
[MarshalAs(UnmanagedType.I1)]
563564
public bool bool_value;
564565
/// <summary>
565566
/// Integer value.

bindings/ffi/src/limits.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,43 @@ fn feature_disabled(function: &str) -> RegorusResult {
130130
format!("{function} unavailable: regorus built without allocator-memory-limits feature"),
131131
)
132132
}
133+
134+
#[cfg(test)]
135+
mod tests {
136+
use super::{optional_u64_to_result, regorus_get_global_memory_limit, regorus_set_global_memory_limit};
137+
use crate::common::{regorus_result_drop, RegorusDataType, RegorusStatus};
138+
139+
#[test]
140+
fn optional_some_returns_integer() {
141+
let result = optional_u64_to_result(Some(123));
142+
assert!(result.bool_value);
143+
assert!(matches!(result.data_type, RegorusDataType::Integer));
144+
assert_eq!(result.int_value, 123);
145+
}
146+
147+
#[test]
148+
fn optional_none_returns_void() {
149+
let result = optional_u64_to_result(None);
150+
assert!(!result.bool_value);
151+
assert!(matches!(result.data_type, RegorusDataType::None));
152+
assert_eq!(result.int_value, 0);
153+
}
154+
155+
#[test]
156+
fn ffi_roundtrips_global_limit() {
157+
let limit = 456_u64;
158+
let result = regorus_set_global_memory_limit(limit, true);
159+
assert!(matches!(result.status, RegorusStatus::Ok));
160+
regorus_result_drop(result);
161+
162+
let result = regorus_get_global_memory_limit();
163+
assert!(matches!(result.status, RegorusStatus::Ok));
164+
assert!(result.bool_value);
165+
assert!(matches!(result.data_type, RegorusDataType::Integer));
166+
assert_eq!(result.int_value, 456);
167+
regorus_result_drop(result);
168+
169+
let result = regorus_set_global_memory_limit(0, false);
170+
regorus_result_drop(result);
171+
}
172+
}

0 commit comments

Comments
 (0)