search for: from_ptr

Displaying 20 results from an estimated 24 matches for "from_ptr".

2019 Jun 27
0
Re: [PATCH 08/11] Rust bindings: Fix memory management and format the file
...char) -> Result<collections::HashMap<String, String>, Error> { let mut map = collections::HashMap::new(); let mut iter = NullTerminatedIter::new(l); while let Some(key) = iter.next() { if let Some(val) = iter.next() { - let key = unsafe { ffi::CStr::from_ptr(key) }.to_str().unwrap(); - let val = unsafe { ffi::CStr::from_ptr(val) }.to_str().unwrap(); + let key = unsafe { ffi::CStr::from_ptr(key) }.to_str()?; + let val = unsafe { ffi::CStr::from_ptr(val) }.to_str()?; map.insert(key.to_string(), val.to_string(...
2019 Jun 27
0
[PATCH 7/9] Rust bindings: Complete actions
...(l: *const *const c_char) -> collections::HashMap<String, String> { + let mut map = collections::HashMap::new(); + let mut iter = NullTerminatedIter::new(l); + while let Some(key) = iter.next() { + if let Some(val) = iter.next() { + let key = unsafe { ffi::CStr::from_ptr(key) }.to_str().unwrap(); + let val = unsafe { ffi::CStr::from_ptr(val) }.to_str().unwrap(); + map.insert(key.to_string(), val.to_string()); + } else { + panic!(\"odd number of items in hash table\"); + } + } + map +} + +fn struct_list&...
2019 Jun 27
4
Re: [PATCH 9/9] Rust bindings: Complete bindings
Patch 9 is a kind of dumping ground of all kinds of stuff. It may be better to spend some time with git rebase -i trying to work this into more coherent patches. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live
2019 Jun 27
0
[PATCH 9/9] Rust bindings: Complete bindings
...char) -> Result<collections::HashMap<String, String>, Error> { let mut map = collections::HashMap::new(); let mut iter = NullTerminatedIter::new(l); while let Some(key) = iter.next() { if let Some(val) = iter.next() { - let key = unsafe { ffi::CStr::from_ptr(key) }.to_str().unwrap(); - let val = unsafe { ffi::CStr::from_ptr(val) }.to_str().unwrap(); + let key = unsafe { ffi::CStr::from_ptr(key) }.to_str()?; + let val = unsafe { ffi::CStr::from_ptr(val) }.to_str()?; map.insert(key.to_string(), val.to_string(...
2023 Apr 05
3
[PATCH v2 0/2] rust: virtio: add virtio support
This used to be a single patch, but I split it into two with the addition of struct Scatterlist. Again a bit new with Rust submissions. I was told by Gary Guo to rebase on top of rust-next, but it seems *very* behind? The first patch does not build on its own due to a dead_code warning. It is hard to not have dead code when one is adding infrastructure to be used by others at a later
2019 Jul 02
16
[PATCH] Add Rust bindings
I fixed the patch I submitted before based on comments, and there are some commits which are merged or divided. So, I will re-send all the patches. Regards, Hiroyuki Katsura
2019 Jun 27
16
[PATCH 1/9] Rust bindings: Add Rust bindings
From: Hiroyuki_Katsura <hiroyuki.katsura.0513@gmail.com> --- Makefile.am | 4 ++++ configure.ac | 3 +++ generator/Makefile.am | 3 +++ generator/bindtests.ml | 3 +++ generator/bindtests.mli | 1 + generator/main.ml | 5 +++++ generator/rust.ml | 34 ++++++++++++++++++++++++++++++++++ generator/rust.mli | 19 +++++++++++++++++++
2019 Jul 20
0
[PATCH] Rust bindings: Add Rust bindings
...List.iter ( + fun x -> + indent 4; + match x with + | n, FChar -> + pr "%s: (*raw).%s as i8,\n" n n; + | n, FString -> + pr "%s: {\n" n; + indent 5; + pr "let s = ffi::CStr::from_ptr((*raw).%s);\n" n; + indent 5; + pr "s.to_str()?.to_string()\n"; + indent 4; + pr "},\n" + | n, FBuffer -> + pr "%s: slice::from_raw_parts((*raw).%s as *const u8, (*raw).%s_len).to_vec(),\n" n n n +...
2019 Jul 20
2
Re: [PATCH] Rust bindings: Add Rust bindings
> Is this just trying if the guestfs can be linked with? Yes. In OCaml bindings, there is the corresponding test( https://github.com/libguestfs/libguestfs/blob/master/ocaml/t/guestfs_010_load.ml). I just mimicked it. If it is not required, I will remove it. divided the generated files and handmade files in rust/src/ directory. I'll send this fixed patch to this mailing list. I'm not
2019 Jul 08
2
Re: [PATCH] Add Rust bindings
On Mon, Jul 08, 2019 at 10:04:57AM +0100, Richard W.M. Jones wrote: >On Mon, Jul 08, 2019 at 10:49:55AM +0200, Martin Kletzander wrote: >> On Mon, Jul 08, 2019 at 10:10:10AM +0200, Pino Toscano wrote: >> >On Saturday, 6 July 2019 13:03:24 CEST Martin Kletzander wrote: >> >>Just one thing, the Cargo.toml includes a version under which the crate would be >>
2019 Aug 31
1
[PATCH libnbd] Add bindings for Rust language
Still not working, but I took the latest patch and: - rebased it against libnbd 1.0 - fixed it so it handles new args and cbargs The generator now runs without warnings. This patch doesn't handle optargs at all. In C these are converted to non-optional parameter. Rust doesn't (AFAIK) have optional or labelled arguments unfortunately. Rich.
2019 Jul 30
4
[PATCH] Rust bindings: Implement Event features
...guestfs::Event]) -> Result<String, error::Error> { + let bitmask = events_to_bitmask(events); + + let r = unsafe { guestfs_event_to_string(bitmask) }; + if r.is_null() { + Err(error::unix_error("event_to_string")) + } else { + let s = unsafe { ffi::CStr::from_ptr(r) }; + let s = s.to_str()?.to_string(); + unsafe { free(r as *const c_void) }; + Ok(s) + } +} + +/* -- Why Not Box<Callback> but Arc<Callback> (in struct base::Handle)? -- + * Assume that there are more than threads. While callback is running, + * if a thread...
2019 Jun 27
0
[PATCH 4/9] Rust bindings: Add generator of structs
...List.iter ( + fun x -> + indent 3; + match x with + | n, FChar -> + pr "%s: (*raw).%s as i8,\n" n n; + | n, FString -> + pr "%s: {\n" n; + indent 4; + pr "let s = ffi::CStr::from_ptr((*raw).%s);\n" n; + indent 4; + pr "s.to_str().unwrap().to_string()\n"; + indent 3; + pr "},\n" + | n, FBuffer -> + pr "%s: slice::from_raw_parts((*raw).%s as *const u8, (*raw).%s_len).to_vec(),\n"...
2019 Jul 17
2
[PATCH] Rust bindings: Add Rust bindings
...char) -> Result<collections::HashMap<String, String>, Error> { + let mut map = collections::HashMap::new(); + let mut iter = NullTerminatedIter::new(l); + while let Some(key) = iter.next() { + if let Some(val) = iter.next() { + let key = unsafe { ffi::CStr::from_ptr(key) }.to_str()?; + let val = unsafe { ffi::CStr::from_ptr(val) }.to_str()?; + map.insert(key.to_string(), val.to_string()); + } else { + // Internal Error -> panic + panic!(\"odd number of items in hash table\"); + } + } +...
2019 Jul 07
2
[libnbd PATCH] RFC: Add bindings for Rust language
...eturn Err(NbdError::from_libnbd());"; + "}"; + ] + in + let trans = + match ret with + | RBool + | RErr + | RFd + | RInt + | RInt64 -> [] + | RConstString -> [ + "let ret = unsafe { CStr::from_ptr(ret) };"; + "let ret = ret.to_str().unwrap();"; + ] + | RString -> [ + "let c_str = unsafe { CStr::from_ptr(ret as *const c_char) };"; + "let ret = c_str.to_string_lossy().into_owned();"; + "unsaf...
2019 Jul 23
2
Re: [PATCH] Rust bindings: Add Rust bindings
...t; + indent 4; > + match x with > + | n, FChar -> > + pr "%s: (*raw).%s as i8,\n" n n; > + | n, FString -> > + pr "%s: {\n" n; > + indent 5; > + pr "let s = ffi::CStr::from_ptr((*raw).%s);\n" n; > + indent 5; > + pr "s.to_str()?.to_string()\n"; > + indent 4; > + pr "},\n" > + | n, FBuffer -> > + pr "%s: slice::from_raw_parts((*raw).%s as *const u8, > (*raw...
2019 Jul 30
0
Re: [PATCH] Rust bindings: Implement Event features
...t<String, error::Error> { >+ let bitmask = events_to_bitmask(events); >+ >+ let r = unsafe { guestfs_event_to_string(bitmask) }; >+ if r.is_null() { >+ Err(error::unix_error("event_to_string")) >+ } else { >+ let s = unsafe { ffi::CStr::from_ptr(r) }; >+ let s = s.to_str()?.to_string(); >+ unsafe { free(r as *const c_void) }; >+ Ok(s) >+ } >+} >+ >+/* -- Why Not Box<Callback> but Arc<Callback> (in struct base::Handle)? -- >+ * Assume that there are more than threads. While callb...
2019 Jul 31
0
Re: [PATCH] Rust bindings: Implement Event features
...ring, error::Error> { > + let bitmask = events_to_bitmask(events); > + > + let r = unsafe { guestfs_event_to_string(bitmask) }; > + if r.is_null() { > + Err(error::unix_error("event_to_string")) > + } else { > + let s = unsafe { ffi::CStr::from_ptr(r) }; > + let s = s.to_str()?.to_string(); These two look like utils::char_ptr_to_string(). > diff --git a/rust/tests/410_close_event.rs b/rust/tests/410_close_event.rs > new file mode 100644 > index 000000000..308471098 > --- /dev/null > +++ b/rust/tests/410_close_event....
2019 Jun 05
2
The way of implementing structs of Rust bindings
...std::str; #[repr(C)] struct RawA { x: *const i8 } enum guestfs_A {} // opaque struct extern { fn to_RawA( src: *const guestfs_A ) -> RawA; } struct A { x: String } impl A { fn new(src: *const guestfs_A) -> A { let dst = unsafe {to_RawA(src)}; let c_str = unsafe { CStr::from_ptr(dst.x) }; let s = c_str.to_str().unwrap().to_string(); A{ x: s } } } ``` This is a little verbose and inefficient. # 2nd approach The above is easily done by 'bindgen', which automatically generates rust ffi bindings to C library. By using this, API struct is automati...
2019 Jul 30
1
Re: [PATCH] Rust bindings: Implement Event features
...; >+ let bitmask = events_to_bitmask(events); > >+ > >+ let r = unsafe { guestfs_event_to_string(bitmask) }; > >+ if r.is_null() { > >+ Err(error::unix_error("event_to_string")) > >+ } else { > >+ let s = unsafe { ffi::CStr::from_ptr(r) }; > >+ let s = s.to_str()?.to_string(); > >+ unsafe { free(r as *const c_void) }; > >+ Ok(s) > >+ } > >+} > >+ > >+/* -- Why Not Box<Callback> but Arc<Callback> (in struct base::Handle)? > -- > >+ * Assume t...