Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions crates/celox-vpi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,9 @@ enum HandleKind {
/// Opaque allocation referenced by the C `vpiHandle` pointer type.
pub struct VpiHandleObject {
kind: HandleKind,
name: CString,
full_name: CString,
// Unnamed temporary handles share the empty C string without allocating it.
name: Option<CString>,
full_name: Option<CString>,
value_string: Vec<u8>,
value_vector: Vec<VpiVecVal>,
}
Expand Down Expand Up @@ -868,8 +869,8 @@ fn new_object_handle(object: ObjectRef) -> VpiHandle {
.unwrap_or_default();
Box::into_raw(Box::new(VpiHandleObject {
kind: HandleKind::Object(object),
name: c_string(&name),
full_name: c_string(&full_name),
name: Some(c_string(&name)),
full_name: Some(c_string(&full_name)),
value_string: Vec::new(),
value_vector: Vec::new(),
}))
Expand All @@ -881,8 +882,8 @@ fn new_iterator_handle(objects: Vec<ObjectRef>) -> VpiHandle {
}
Box::into_raw(Box::new(VpiHandleObject {
kind: HandleKind::Iterator { objects, next: 0 },
name: c_string(""),
full_name: c_string(""),
name: None,
full_name: None,
value_string: Vec::new(),
value_vector: Vec::new(),
}))
Expand All @@ -891,8 +892,8 @@ fn new_iterator_handle(objects: Vec<ObjectRef>) -> VpiHandle {
fn new_constant_handle(value: i32) -> VpiHandle {
Box::into_raw(Box::new(VpiHandleObject {
kind: HandleKind::Constant(value),
name: c_string(""),
full_name: c_string(""),
name: None,
full_name: None,
value_string: Vec::new(),
value_vector: Vec::new(),
}))
Expand All @@ -901,8 +902,8 @@ fn new_constant_handle(value: i32) -> VpiHandle {
fn new_callback_handle(id: u64) -> VpiHandle {
Box::into_raw(Box::new(VpiHandleObject {
kind: HandleKind::Callback(id),
name: c_string(""),
full_name: c_string(""),
name: None,
full_name: None,
value_string: Vec::new(),
value_vector: Vec::new(),
}))
Expand Down Expand Up @@ -1272,8 +1273,13 @@ pub unsafe extern "C" fn vpi_get_str(property: i32, reference: VpiHandle) -> *mu
return ptr::null_mut();
};
match property {
VPI_NAME => handle.name.as_ptr().cast_mut(),
VPI_FULL_NAME => handle.full_name.as_ptr().cast_mut(),
VPI_NAME => handle.name.as_deref().unwrap_or(c"").as_ptr().cast_mut(),
VPI_FULL_NAME => handle
.full_name
.as_deref()
.unwrap_or(c"")
.as_ptr()
.cast_mut(),
VPI_DEF_NAME => {
let HandleKind::Object(ObjectRef::Scope(id)) = handle.kind else {
return ptr::null_mut();
Expand Down
7 changes: 7 additions & 0 deletions crates/celox-vpi/tests/basic_vpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,8 @@ fn vpi_discovers_hierarchy_and_reads_and_writes_values() {
assert_eq!(CStr::from_ptr(vpi_get_str(VPI_NAME, top)), c"Top");

let modules = vpi_iterate(VPI_MODULE, top);
assert_eq!(CStr::from_ptr(vpi_get_str(VPI_NAME, modules)), c"");
assert_eq!(CStr::from_ptr(vpi_get_str(VPI_FULL_NAME, modules)), c"");
let child = vpi_scan(modules);
assert!(!child.is_null());
assert_eq!(
Expand Down Expand Up @@ -1940,6 +1942,11 @@ fn callback_registration_owns_copied_time_and_value_records() {
let a = vpi_handle_by_name(c"Top.a".as_ptr(), ptr::null_mut());
let value_change = register_stack_value_callback(a);
assert!(!value_change.is_null());
assert_eq!(CStr::from_ptr(vpi_get_str(VPI_NAME, value_change)), c"");
assert_eq!(
CStr::from_ptr(vpi_get_str(VPI_FULL_NAME, value_change)),
c""
);
register_stack_timer(a);

// Reuse the caller stack after both registration functions returned.
Expand Down
Loading