Skip to content

Commit 3564acb

Browse files
committed
actually mark functions as unsafe and add safety docs
1 parent dac3e84 commit 3564acb

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

custom.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
pub fn Tcl_DecrRefCount(objPtr: *mut Tcl_Obj) {
1+
/// Decrement the reference count of a Tcl object.
2+
/// If the reference count reaches zero, the object is freed.
3+
///
4+
/// # Safety
5+
/// If the reference count is decremented to zero, the object is freed and `objPtr` turns into a null pointer.
6+
pub unsafe fn Tcl_DecrRefCount(objPtr: *mut Tcl_Obj) {
27
let mut obj = unsafe { *objPtr };
38
obj.refCount -= 1;
49
if obj.refCount == 0 {
@@ -7,7 +12,12 @@ pub fn Tcl_DecrRefCount(objPtr: *mut Tcl_Obj) {
712
}
813
}
914

10-
pub fn Tcl_IncrRefCount(objPtr: *mut Tcl_Obj) {
15+
/// Increment the reference count of a Tcl object.
16+
/// This is used to indicate that the object is being used and should not be freed.
17+
///
18+
/// # Safety
19+
/// If [`Tcl_DecrRefCount`] is not called and the pointer is dropped, the object will be leaked.
20+
pub unsafe fn Tcl_IncrRefCount(objPtr: *mut Tcl_Obj) {
1121
let mut obj = unsafe { *objPtr };
1222
obj.refCount += 1;
1323
}

0 commit comments

Comments
 (0)