These are chat archives for rust-lang/rust

20th
Aug 2018
David Vo
@auscompgeek
Aug 20 2018 02:04
@kpp do macros not fit your use case?
trsh
@trsh
Aug 20 2018 08:09
Any ideas, why compiling a rust project get's slower over time. And restart Helps
Im on Ubunut
trsh
@trsh
Aug 20 2018 09:00
@tanriol to I need to free > std::ptr::null_mut ? :D
Denis Lisov
@tanriol
Aug 20 2018 09:01
Trying to free it will segfault or worse :-)
trsh
@trsh
Aug 20 2018 09:02
I saw that! So Ican just leave it alone?
Denis Lisov
@tanriol
Aug 20 2018 09:02
Yes, you need to just leave it alone.
trsh
@trsh
Aug 20 2018 09:05
@tanriol any exp with rust builds takings longer time, when building lot's of times, without pc restart?
Denis Lisov
@tanriol
Aug 20 2018 09:06
Not with time, but I've seen some minor weirdness with incremental compilation.
trsh
@trsh
Aug 20 2018 09:07
btw I nailed the droping
Last peace was to add if null, don't drop
The best part is, when u drop parent struct, it knows childs, ad drops them ,and so on.. was easy to implement
@tanriol btw, just in theory.. when pointers come from C (way around), C should be responsible for Free memory?
Denis Lisov
@tanriol
Aug 20 2018 09:28
When pointers come from C, you shall pass it to C for freeing.
Possibly using libc::free
trsh
@trsh
Aug 20 2018 09:33
@tanriol when I remove copy from the structs, drop, I run into problems when reading results
fn get_ns2__Notification(is_op: *mut ns2__Notification) -> Result<Value, Vec<String>> {
        if is_op.is_null() {
            return Ok(json!(null));
        }
        let is = unsafe { *is_op };
cannot move out of dereference of raw pointer
Denis Lisov
@tanriol
Aug 20 2018 09:35
That's kinda expected :-) why do you do that?
trsh
@trsh
Aug 20 2018 09:36
So I can get stuff gtom struct, like let Code_op = is.Code;
Denis Lisov
@tanriol
Aug 20 2018 09:37
Why not let is = unsafe { &*is_op }; ?
To work with FFI like this, you need a good understanding of who owns your memory and how it is accessed.
trsh
@trsh
Aug 20 2018 09:38
OK, so now I dont copy, but reference
Nice that bindgen has option, to not add Copy flag
Roman Proskuryakov
@kpp
Aug 20 2018 09:43

do macros not fit your use case?

@auscompgeek well, I would like to extend the list of keywords with their aliases to get sane compiler errors in case of typos

trsh
@trsh
Aug 20 2018 09:48
@tanriol sadly I have little exp, and the internet is also no rich with FFI docs in my opinion. For example if my C looks like https://pastebin.com/T7gVgJjz and
rust
let mut sr: ns2__AddressValidationReply =
        unsafe { validate_address(soap, CString::new(base_url).unwrap().as_ptr(), input) };
I have no Idea, why owns ns2__AddressValidationReply after the call in Rust
Denis Lisov
@tanriol
Aug 20 2018 09:56
As the C code returns it by value, it transfers ownership. However, I don't know whether soap_call___ns2__addressValidation allocates anything and if it does you're likely to have some problems :-)
trsh
@trsh
Aug 20 2018 10:16
I hope that lib takes care of that
soap_destroy(soap); /* delete deserialized objects */
  soap_end(soap);     /* delete heap and temp data */
  soap_free(soap);    /* we're done with the context */
This I call when Data is collected
And if I call it before collect, stuff goes bananas
So I think it frees mem, will check will some valgrind maybe later
Denis Lisov
@tanriol
Aug 20 2018 10:21
Yeah, that's rather likely :-)
Farzeen
@happycoder97
Aug 20 2018 16:34
rusty-fork is listed under [dev-dependencies] in Cargo.toml.
I put #[macro_use] extern crate rusty_fork;in src/main.rs.
When I do cargo test, it compiles and runs successfully. But when I do cargo build, it fails by saying:
error[E0463]: can't find crate for `rusty_fork`
 --> src/main.rs:2:14
  |
2 | #[macro_use] extern crate rusty_fork;
  |              ^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error
Where do I put extern crate ... declarations for crates that are in [dev-dependencies]?
Denis Lisov
@tanriol
Aug 20 2018 16:54
You can annotate it with #[cfg(test)]
Farzeen
@happycoder97
Aug 20 2018 16:58
thanks @tanriol