-
-
Notifications
You must be signed in to change notification settings - Fork 105
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
generate nullable arrays as options #1136
Conversation
You could take the Thanks for working on this :) |
let nullable = function_parameters | ||
.iter() | ||
.find(|p| p.name == array_name) | ||
.unwrap() |
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.
This panics when running ./generator.py --gir-path path/to/gir
while generating code for glib
:
[...]
[WARN libgir::analysis::functions] `g_variant_new_from_data`: destructor without linked callback
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value', src/analysis/function_parameters.rs:255:18
stack backtrace:
0: rust_begin_unwind
at /rustc/88f19c6dab716c6281af7602e30f413e809c5974/library/std/src/panicking.rs:493:5
1: core::panicking::panic_fmt
at /rustc/88f19c6dab716c6281af7602e30f413e809c5974/library/core/src/panicking.rs:92:14
2: core::panicking::panic
at /rustc/88f19c6dab716c6281af7602e30f413e809c5974/library/core/src/panicking.rs:50:5
3: libgir::analysis::function_parameters::analyze
4: libgir::analysis::functions::analyze_function
5: libgir::analysis::functions::analyze
6: libgir::analysis::run
7: gir::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
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.
Line 239 to 247 try to get the array name in various ways. It would probably be best to directly return the nullable
in those places.
We discussed a similar problem very recently for the Ash (Vulkan wrapper) crate. Theoretically a zero-length slice ( However, on the other hand this might more clearly signal that an array is indeed optional and not hidden behind a zero-length slice "trick". Complementing that, codegen might assert that slices are never empty? It's a complicated and ambiguous subject :/ |
It's tricky. I think |
646a5a2
to
be7e431
Compare
@sdroege Finally found some time to get back to this. I've fixed the crash. Changes are visible on my gtk-rs-core fork. |
This needs some more changes:
|
Tracked it down to this line. Removing it outright is not correct, because that will cause functions like |
It will have to check if the return value is nullable there, I guess. For |
I'm going to close this for now since I don't know when I'll have time to get back to it, and it doesn't affect me anymore. Anyone seeing this should feel free to continue where I left off. |
Fixes #1133.
First time contributor, would appreciate some pointers on how to test this.