Andy Thomson

Results 80 comments of Andy Thomson

The magic is here. https://github.com/extendr/extendr/blob/1bdd03f08c14a781ba7b3d0ae628b10cf2425b95/extendr-macros/src/wrappers.rs#L106 *handle_panic* uses *catch_unwind* to do the conversion. In theory, the unwind should free any allocated variables, especially the formal arguments which are reference counted *Robj*s....

In C++ you can call `longjump` and just ignore the mess this creates, but Rust is a little more careful - `longjump` does not exist in Rust, nor should it....

We do have a function for throwing R errors. This is very dangerous, however as it could leave objects on the stack in an undefined state. In the wrapper, we...

It is worth noting that a CString will leak memory as nothing will deallocate it. This may not be a problem for occasional errors - I'm pretty certain that R...

Currently, we represent class objects as a Rust Box. Although this is indeed a pointer, the underlying SEXP controls the lifetime of the object, freeing the Box when the last...

https://github.com/extendr/extendr/blob/master/extendr-api/src/wrapper/s4.rs

Example ```rust S4::set_class("fred", pairlist!(xyz="numeric"), r!(()))?; let mut robj : S4 = R!(r#"new("fred")"#)?.try_into()?; let xyz = sym!(xyz); assert_eq!(robj.get_slot(xyz.clone()).unwrap().len(), 0); robj.set_slot(xyz.clone(), r!([0.0, 1.0])); assert_eq!(robj.get_slot(xyz), Some(r!([0.0, 1.0]))); ```

The primary reason for this is to access S4 classes generated externally to extendr.

Have a look in metadata.rs at the current r6-like implementation. It would be possible to parameterise this to emit S4 classes also.

I would be happy, as long as it is an option. How do the others think about this?