Commit Graph

6 Commits

Author SHA1 Message Date
Stephen Chung
094eb5878a Add info into README's. 2023-04-12 12:09:14 +08:00
Stephen Chung
7cda806b53 Move tools out of src. 2023-03-17 07:09:56 +08:00
Stephen Chung
41636eac55 Fine tune table-driven tokenizing. 2023-03-15 17:22:11 +08:00
Nathan Kent
86d86a85e4 Remove unsound casting functions
The casting functions in `unsafe.rs` were unsound (i.e., they allowed
safe code to cause undefined behavior). While they did appear to be used
in a way that wouldn't cause UB the fact that there exists unsound
functions is unsettling.

This commit removes those functions and replaces it with a macro that
performs the same reification - the difference is that the macro call
will also include the checks which are required to prevent UB. A macro
was chosen instead of a function for two reasons:

1. A macro can keep the same code generation whereas a function would
   require going through an `Option` which has negative impacts on code
   generation (niche values cause poor DCE).
2. There exist other `unsafe` code blocks in the crate and an attempt to
   make Rhai 100% safe is completely out-of-scope for this merge
   request, so we may as well use `unsafe` in the macro.

Regarding (2) above, I may come back at a later date with a 100% safe
`reify` function but only once the other `unsafe` blocks are removed.
For posterity, said function would look something like:

```rust
fn reify<A: Any, C>(value: A) -> Option<C> {
    let mut v = Some(value);
    let v: &mut dyn Any = &mut v;
    v.downcast_mut::<Option<C>>().map(Option::take)
}
```
2022-02-05 16:29:05 -08:00
Stephen Chung
047e65223d Fix builds. 2022-01-07 12:19:01 +08:00
Stephen Chung
a267ac5e54 Split Engine into eval folder. 2022-01-07 11:43:47 +08:00