forked from utilityai/llama-cpp-rs
-
Notifications
You must be signed in to change notification settings - Fork 0
catch C++ exceptions at FFI boundary, rename utility modules #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0b9aa87
catch C++ exceptions at FFI boundary, rename utility modules
mcharytoniuk 25d9959
fix CI: align rust-toolchain to 1.93.0, mark ffi_error_reader as unsa…
mcharytoniuk 93d122c
run CI on push only for main, PRs use pull_request event
mcharytoniuk 417c00d
fix clippy: use raw mut for FFI pointers, add backticks in doc comment
mcharytoniuk 88ecfb4
remove panics from production code, fix double-accept, use env vars f…
mcharytoniuk 452860a
rename ci.yml to unit-tests.yml, add rust-cache to formatting job
mcharytoniuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
16 changes: 7 additions & 9 deletions
16
.github/workflows/ci.yml → .github/workflows/unit-tests.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| use std::ffi::{CStr, c_char}; | ||
|
|
||
| /// Reads a C error string, converts to Rust `String`, and frees the C memory. | ||
| /// | ||
| /// # Safety | ||
| /// | ||
| /// `error_ptr` must be either null or a valid pointer to a null-terminated | ||
| /// C string allocated by `llama_rs_dup_string`. | ||
| pub unsafe fn read_and_free_cpp_error(error_ptr: *mut c_char) -> String { | ||
| if error_ptr.is_null() { | ||
| return "unknown error".to_owned(); | ||
| } | ||
|
|
||
| let message = unsafe { CStr::from_ptr(error_ptr) } | ||
| .to_string_lossy() | ||
| .into_owned(); | ||
|
|
||
| unsafe { llama_cpp_bindings_sys::llama_rs_string_free(error_ptr) }; | ||
|
|
||
| message | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::read_and_free_cpp_error; | ||
|
|
||
| #[test] | ||
| fn returns_unknown_for_null_pointer() { | ||
| let result = unsafe { read_and_free_cpp_error(std::ptr::null_mut()) }; | ||
|
|
||
| assert_eq!(result, "unknown error"); | ||
| } | ||
| } |
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.