-
Notifications
You must be signed in to change notification settings - Fork 2
Rework ffi with new logging
, error handling
and some improvements in arch and safe
#10
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
Open
uselessgoddess
wants to merge
77
commits into
main
Choose a base branch
from
ffi-rework
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
77 commits
Select commit
Hold shift + click to select a range
7333525
Remove ffi with new `logging` and some improvements in arch and safe
uselessgoddess 4d59bae
Improve logging (via `instrument`s) and naming
uselessgoddess e0edd83
Add ffi context to callbacks
uselessgoddess e8691c2
Add ffi `examples` crate
uselessgoddess 63be554
Fix too long ptr cast
uselessgoddess b1a3d77
Improve safety docs
uselessgoddess f4c7cb4
Improve error handling:
uselessgoddess a40e21e
Use `thread_local` attribute for `ERROR_PLACE`
uselessgoddess 7dd3cd9
Improve `warn` message in `query_from_raw`
uselessgoddess 4600061
Improvements list:
uselessgoddess 4f6b95b
Improvements list:
uselessgoddess a11188f
Update outdated data
uselessgoddess edd0b87
Use `NonNull` instead of raw pointer
uselessgoddess 646f1ae
`cargo fix` unused imports
uselessgoddess 6d7c353
`cargo fix` unused imports
uselessgoddess abee06b
Improve `ffi-attributes`:
uselessgoddess 8420a12
Remove forgotten comment
uselessgoddess 4ec685a
Fix type `lit` => `ty`
uselessgoddess 6c71760
Add `attributes` keyword to delegate some attrs to parent function im…
uselessgoddess cc2eee1
Fix some externs
uselessgoddess 2c10ab3
Add some doc comments to `Range`
uselessgoddess fdc90c9
Fix brackets in `error-handling` example
uselessgoddess f48486c
Use `usize` instead of `c_size_t`
uselessgoddess b7e8a25
Use modern `StoreHandle` without `Box::from_raw/into_raw`
uselessgoddess 7454ec0
Add error handling without bottleneck (`ERROR_PLACE`) and `take_last_…
uselessgoddess d54db5d
Improve `OpaqueSlice` in favor of `OwnedSlice`
uselessgoddess fba6e78
Fix some typos in readme
uselessgoddess d5025c0
Revert changes in README.md
uselessgoddess 0890293
Fix some typos in readme
uselessgoddess 56ae6bc
Use `Box` instead of raw ptrs
uselessgoddess 7061c37
Stop logging if channel is disconnected
uselessgoddess 2de822a
Remove useless `todo` message
uselessgoddess 0f4d4fa
Improve repr of `StoreHandle`
uselessgoddess 9c58bb0
Fix macro error message
uselessgoddess f570601
Change pair from Ident => Ident to Type => Ident
Mitron57 a2ba506
Make code more cleaned and self-doc+friendly for parsing
uselessgoddess 4752904
Some improvements:
uselessgoddess 18ed088
Fix useless `.clone` in `ffi-attributes`
uselessgoddess 6a7a90f
Fix imports and useless in examples
uselessgoddess a57cec3
Add `backtrace` feature and make `doublets-ffi` features-free:
uselessgoddess 67afd89
Update building guide
uselessgoddess 367b05a
Fix copy typo in readme
uselessgoddess 74fbc82
Install stable rust in readme
uselessgoddess 804823b
Add `Off` for `Level` and simplify `EnvFilter` to `match`
uselessgoddess 056c7e2
Add colored shows to `log-context` example
uselessgoddess 4adab77
Fix typo in example
uselessgoddess 6b1345a
Improve colors and reset
uselessgoddess 3338ba8
Start queries reworking
uselessgoddess 78cf083
Merge remote-tracking branch 'origin/ffi-rework' into ffi-rework
uselessgoddess 97c2640
Revert queries reworking
uselessgoddess 918d255
Forbid dynamic lib to ffi
uselessgoddess 26927a7
Add docs to `FFICallbackContextWrapper`
uselessgoddess 8561b07
Improve `Range` and add `Maybe` to simplify constants conversion
uselessgoddess 903d07e
Fix typo
uselessgoddess ae182b5
Improve `backtrace` feature in favor of `unstable_backtrace`
uselessgoddess 3eb54ef
Fix `if-else-let` lint
uselessgoddess d6de95a
Add marker<Box<[T]>> to `OwnedSlice`
uselessgoddess c2a4813
allow(clippy::borrowed_box) for `assume_ref`
uselessgoddess 766df15
Use `while let` instead of `loop { if let }` in logging loop
uselessgoddess 2e7e592
Use slice as queries
uselessgoddess 155f475
Add error handling to store creation
uselessgoddess d619560
explain `if let` to `.is_ok`
uselessgoddess af3fef0
Use shortest error messages
uselessgoddess 722094c
Shortest ptr cast
uselessgoddess 8da33d5
Improve error handling in favor of Rust looks like
uselessgoddess 3bf0a7e
Fix priv `utils` mod
uselessgoddess 0e71c0e
Disable clippy with bug
uselessgoddess 8433376
Fix fallible example
uselessgoddess a5156ed
Really disable clippy
uselessgoddess a95d580
Use shortest names
uselessgoddess fb70b9c
Improve code for future readers
uselessgoddess 9042ce8
Improve code for future readers - two-step
uselessgoddess 3754990
Add `cbindgen` config for cxx (but with problems):
uselessgoddess 3b272d9
Cosmetic improvements
uselessgoddess fb2aad6
Remove unused imports
uselessgoddess ce9449a
Improve `Fallible` messages and idioms
uselessgoddess 97e12b2
Remove type - useless import
uselessgoddess 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
There are no files selected for viewing
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,2 @@ | ||
.cargo | ||
/target |
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,112 @@ | ||
language = "C++" | ||
|
||
############## Options for Wrapping the Contents of the Header ################# | ||
|
||
# header = "/* Text to put at the beginning of the generated file. Probably a license. */" | ||
# trailer = "/* Text to put at the end of the generated file */" | ||
# include_guard = "my_bindings_h" | ||
pragma_once = true | ||
# autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" | ||
include_version = false | ||
# namespace = "my_namespace" | ||
namespaces = [] | ||
using_namespaces = [] | ||
sys_includes = [] | ||
includes = [] | ||
no_includes = false | ||
after_includes = """ | ||
|
||
template<typename T> | ||
using Box = T*; | ||
|
||
template<typename T> | ||
using ManuallyDrop = T; | ||
|
||
""" | ||
|
||
braces = "SameLine" | ||
line_length = 100 | ||
tab_width = 2 | ||
documentation = true | ||
documentation_style = "auto" | ||
documentation_length = "full" | ||
line_endings = "LF" # also "CR", "CRLF", "Native" | ||
|
||
style = "both" | ||
sort_by = "Name" # default for `fn.sort_by` and `const.sort_by` | ||
usize_is_size_t = true | ||
|
||
[defines] | ||
unstable_backtrace = "UNSTABLE_BACKTRACE" | ||
# "target_os = freebsd" = "DEFINE_FREEBSD" | ||
# "feature = serde" = "DEFINE_SERDE" | ||
|
||
[export] | ||
include = [] | ||
exclude = [ | ||
"Box", "ManuallyDrop" | ||
] | ||
# prefix = "CAPI_" | ||
item_types = [] | ||
renaming_overrides_prefixing = false | ||
|
||
[export.rename] | ||
|
||
[export.body] | ||
|
||
[export.mangle] | ||
|
||
[fn] | ||
rename_args = "None" | ||
# must_use = "MUST_USE_FUNC" | ||
# no_return = "NO_RETURN" | ||
# prefix = "START_FUNC" | ||
# postfix = "END_FUNC" | ||
args = "auto" | ||
sort_by = "Name" | ||
|
||
[struct] | ||
rename_fields = "None" | ||
# must_use = "MUST_USE_STRUCT" | ||
derive_constructor = false | ||
derive_eq = false | ||
derive_neq = false | ||
derive_lt = false | ||
derive_lte = false | ||
derive_gt = false | ||
derive_gte = false | ||
|
||
[enum] | ||
rename_variants = "None" | ||
# must_use = "MUST_USE_ENUM" | ||
add_sentinel = false | ||
prefix_with_name = false | ||
derive_helper_methods = false | ||
derive_const_casts = false | ||
derive_mut_casts = false | ||
# cast_assert_name = "ASSERT" | ||
derive_tagged_enum_destructor = false | ||
derive_tagged_enum_copy_constructor = false | ||
enum_class = true | ||
private_default_tagged_enum_constructor = false | ||
|
||
[const] | ||
allow_static_const = true | ||
allow_constexpr = true | ||
sort_by = "Name" | ||
|
||
[macro_expansion] | ||
# bitflags = false | ||
|
||
[parse] | ||
parse_deps = true | ||
include = ["doublets", "platform-data"] | ||
exclude = [] | ||
clean = false | ||
extra_bindings = [] | ||
|
||
[parse.expand] | ||
crates = ["doublets-ffi"] | ||
all_features = true | ||
default_features = true | ||
features = [] |
Submodule data-rs
updated
from 95b7d4 to cd3cd4
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,12 @@ | ||
[package] | ||
name = "doublets-ffi-examples" | ||
version = "0.0.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies] | ||
doublets-ffi = { path = "../../../doublets-ffi" } | ||
doublets = { path = "../../../doublets" } | ||
tracing = { version = "0.1.36" } | ||
# dev | ||
termcolor = { version = "1.1.3" } |
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,45 @@ | ||
#![feature(const_option_ext)] | ||
|
||
use doublets_ffi::{ | ||
export::{doublets_create_log_handle, doublets_free_log_handle}, | ||
logging::{Format, Level}, | ||
FFIContext, | ||
}; | ||
use std::{ | ||
ffi::{c_char, CStr}, | ||
ptr, | ||
}; | ||
|
||
unsafe extern "C" fn callback(_: FFIContext, ptr: *const c_char) { | ||
let cstr = CStr::from_ptr(ptr); | ||
print!("{}", cstr.to_str().unwrap()); | ||
} | ||
|
||
const FORMAT: &str = option_env!("RUST_EXAMPLES_FORMAT").unwrap_or("virgin"); | ||
|
||
fn main() { | ||
let ctx = ptr::null_mut(); | ||
let level = Level::Trace; | ||
let use_ansi = true; | ||
|
||
let format = match &FORMAT.to_ascii_lowercase()[..] { | ||
"virgin" => Format::Virgin, | ||
"pretty" => Format::Pretty, | ||
"json" => Format::Json, | ||
_ => { | ||
panic!("allow only: `virgin`, `pretty`, `json`") | ||
} | ||
}; | ||
|
||
unsafe { | ||
let handle = doublets_create_log_handle(ctx, callback, level, format, use_ansi); | ||
|
||
tracing::error!("SOMETHING IS SERIOUSLY WRONG!!!"); | ||
tracing::warn!("important informational messages; might indicate an error"); | ||
tracing::info!("general informational messages relevant to users"); | ||
tracing::debug!("diagnostics used for internal debugging of a library or application"); | ||
tracing::trace!("very verbose diagnostic events"); | ||
Comment on lines
+37
to
+41
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move logs out |
||
|
||
doublets_free_log_handle(handle); | ||
} | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.