-
Notifications
You must be signed in to change notification settings - Fork 115
Add method to get the ValueType of a TypedValue as a keyword to Android API #820
base: master
Are you sure you want to change the base?
Add method to get the ValueType of a TypedValue as a keyword to Android API #820
Conversation
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.
I think this works, but we're allocating memory on both sides of the FFI boundary. If we turned the underlying int
into a static Java String
on the Java side of the FFI boundary, we'd both have a simpler memory-safety story, and we'd allocate less. How do you feel about doing that?
ffi/src/lib.rs
Outdated
@@ -1666,6 +1666,14 @@ pub unsafe extern "C" fn typed_value_value_type_kw(typed_value: *mut Binding) -> | |||
string_to_c_char(value.clone()) | |||
} | |||
|
|||
/// Returns the size of a `row` as usize |
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.
nit: full sentences please, so: trailing period.
let values = &*values; | ||
values.len () as c_int | ||
} | ||
|
||
/// Returns the value at the provided `index` as a `Vec<ValueType>`. |
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.
nit: no space between function and arguments, so: .len()
.
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.
The formatting is done. I am happy to try and implement your suggestion but I don't understand. Please could you walk me through it? What should all the return types be? Should the java class size method return a String?
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.
Ok, reading this again, I am guessing that you mean rust to write to some memory owned by the java class (which just happens to be a static string)
Are there any good examples or bits of docs that would help me?
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.
Ok, my current idea would be to do this by passing a direct allocated static final byteBuffer from java. To do this it seems easiest if I have access to JNIEnv, is there a reason why you don't seem to use this style?
https://mozilla.github.io/firefox-browser-architecture/experiments/2017-09-21-rust-on-android.html
Would need to use synchronise(this) around the call to rust within the constructor.
8ad05c8
to
ca460fa
Compare
Also remove a println (leftover from debug?)
This makes life easier when dealing with query results, as it allows them to be extracted without knowing the types in advance. This makes use from clojure easier.
Returning standard data structures and types instead (commented on elsewhere) is something that I think is also worth a look.
I would be interested in helping out with this project so I would be happy to chat sometime.