Skip to content

Commit bfbf771

Browse files
committed
Add comments for undo actions in Rust API
1 parent 7fc3a68 commit bfbf771

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

rust/src/file_metadata.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,16 @@ impl FileMetadata {
113113
unsafe { BNIsBackedByDatabase(self.handle, view_type.as_ref().as_ptr() as *const _) }
114114
}
115115

116+
/// Runs a failable function where the failure state will revert any undo actions that occurred
117+
/// during the time of the function's execution.
118+
///
119+
/// NOTE: This will commit or undo any actions that occurred on **any** thread as this state is not thread local.
120+
///
121+
/// NOTE: This is **NOT** thread safe, if you are holding any locks that might be held by both the main thread
122+
/// and the thread executing this function, you can deadlock. You should also never call this function
123+
/// on multiple threads at a time. See the following issues:
124+
/// - https://github.com/Vector35/binaryninja-api/issues/6289
125+
/// - https://github.com/Vector35/binaryninja-api/issues/6325
116126
pub fn run_undoable_transaction<F: FnOnce() -> Result<T, E>, T, E>(
117127
&self,
118128
func: F,
@@ -131,17 +141,38 @@ impl FileMetadata {
131141
}
132142
}
133143

144+
/// Creates a new undo entry, any undo actions after this will be added to this entry.
145+
///
146+
/// NOTE: This is **NOT** thread safe, if you are holding any locks that might be held by both the main thread
147+
/// and the thread executing this function, you can deadlock. You should also never call this function
148+
/// on multiple threads at a time. See the following issues:
149+
/// - https://github.com/Vector35/binaryninja-api/issues/6289
150+
/// - https://github.com/Vector35/binaryninja-api/issues/6325
134151
pub fn begin_undo_actions(&self, anonymous_allowed: bool) -> String {
135152
unsafe { BnString::into_string(BNBeginUndoActions(self.handle, anonymous_allowed)) }
136153
}
137154

155+
/// Commits the undo entry with the id to the undo buffer.
156+
///
157+
/// NOTE: This is **NOT** thread safe, if you are holding any locks that might be held by both the main thread
158+
/// and the thread executing this function, you can deadlock. You should also never call this function
159+
/// on multiple threads at a time. See the following issues:
160+
/// - https://github.com/Vector35/binaryninja-api/issues/6289
161+
/// - https://github.com/Vector35/binaryninja-api/issues/6325
138162
pub fn commit_undo_actions(&self, id: &str) {
139163
let id = id.to_cstr();
140164
unsafe {
141165
BNCommitUndoActions(self.handle, id.as_ref().as_ptr() as *const _);
142166
}
143167
}
144168

169+
/// Reverts the undo actions committed in the undo entry.
170+
///
171+
/// NOTE: This is **NOT** thread safe, if you are holding any locks that might be held by both the main thread
172+
/// and the thread executing this function, you can deadlock. You should also never call this function
173+
/// on multiple threads at a time. See the following issues:
174+
/// - https://github.com/Vector35/binaryninja-api/issues/6289
175+
/// - https://github.com/Vector35/binaryninja-api/issues/6325
145176
pub fn revert_undo_actions(&self, id: &str) {
146177
let id = id.to_cstr();
147178
unsafe {

0 commit comments

Comments
 (0)