Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move libfsm/start.c to Rust #344

Open
wants to merge 21 commits into
base: main
Choose a base branch
from

Commits on Apr 20, 2021

  1. Initial import for Cargo.

    katef committed Apr 20, 2021
    3 Configuration menu
    Copy the full SHA
    8d24c4f View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    a643036 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    00c33df View commit details
    Browse the repository at this point in the history
  4. Run cargo test.

    katef committed Apr 20, 2021
    Configuration menu
    Copy the full SHA
    9772089 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    6e05435 View commit details
    Browse the repository at this point in the history
  6. Remove support for building shared libraries.

    This is a shame, but gets in the way of porting to Rust.
    katef committed Apr 20, 2021
    Configuration menu
    Copy the full SHA
    34e8b49 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    b572d09 View commit details
    Browse the repository at this point in the history
  8. Switch to ld -r linking the cargo-generated .a archive when producing…

    … the partially linked .o files.
    
    This hopefully avoids an ld bug where `-undefined dynamic_lookup` doesn't work on MacOS, and also removes the need for programs to link both the C and Rust libraries directly.
    katef committed Apr 20, 2021
    Configuration menu
    Copy the full SHA
    bb83fd4 View commit details
    Browse the repository at this point in the history
  9. Replace bitfields in struct fsm_state and struct fsm with bool

    C bitfields in Rust are painful, and I'd like something that has the
    same ABI as Rust's bool.  stdbool.h's bool is just the thing.
    
    In both struct fsm_state and struct fsm:
    
    * All the bitfields are packed together.
    
    * The field that follows the bitfields is a pointer, so it has pointer
    alignment, so the overall size of the structs shouldn't change.
    federicomenaquintero committed Apr 20, 2021
    Configuration menu
    Copy the full SHA
    d0be59a View commit details
    Browse the repository at this point in the history
  10. Start sketching types for State and Fsm

    These come from internal.h.
    
    For now the Rust types have the same ABI as the C types; we'll have
    parallel structs for a while until all the internals get rustified.
    federicomenaquintero committed Apr 20, 2021
    Configuration menu
    Copy the full SHA
    8fb687b View commit details
    Browse the repository at this point in the history
  11. Move all of start.c to Rust

    The strategy for this commit:
    
    * Implement clear_start / set_start / get_start in Rust as methods,
    with argument checks as assertions.
    
    * Implement a C ABI wrapper to match the fsm_clearstart() /
    etc. functions.  The non-null argument checks go there.
    
    * Test both sets of functions right there.  We cannot construct a Fsm
    in Rust just yet, so the tests hack up just enough initial state for
    the code to run; this can be removed later.
    
    * Remove start.c.
    
    Later we can move all of the C API to a c_api.rs or whatever.
    federicomenaquintero committed Apr 20, 2021
    Configuration menu
    Copy the full SHA
    b4a98c2 View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    4277bb4 View commit details
    Browse the repository at this point in the history
  13. Hack in -lpthread -ldl everywhere needed

    I really don't know the best way to do this with pmake; someone who
    knows better should fix this :)
    federicomenaquintero committed Apr 20, 2021
    Configuration menu
    Copy the full SHA
    918798e View commit details
    Browse the repository at this point in the history
  14. Move end.c to Rust

    Another easy function, wheeee!
    federicomenaquintero committed Apr 20, 2021
    Configuration menu
    Copy the full SHA
    84d60c7 View commit details
    Browse the repository at this point in the history
  15. cargo fmt

    federicomenaquintero committed Apr 20, 2021
    Configuration menu
    Copy the full SHA
    701f0fc View commit details
    Browse the repository at this point in the history

Commits on Apr 23, 2021

  1. Configuration menu
    Copy the full SHA
    d2aab46 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    036d1eb View commit details
    Browse the repository at this point in the history
  3. state.c: Extract function to initialize a state

    Instead of duplicating the code.
    federicomenaquintero committed Apr 23, 2021
    Configuration menu
    Copy the full SHA
    ce58305 View commit details
    Browse the repository at this point in the history
  4. fsm_addstate(): no need to initialize has_capture_actions in the real…

    …loc block
    
    In all places where a state's .has_capture_actions gets accessed, there is an
    assert that the index of the state fits within the fsm->statecount.
    
    Since in the previous commit we initialize the has_capture_actions
    field when a new state is added, there is no need to initialize that
    field for all the as-yet-unused state structs in the realloc block.
    federicomenaquintero committed Apr 23, 2021
    Configuration menu
    Copy the full SHA
    73cdd10 View commit details
    Browse the repository at this point in the history
  5. fsm_addstate(): Remove non-working test for statecount == -1

    The -1 was meant to be an OOM sentinel, but there is no place in the
    code that actually sets fsm->statecount to -1 when the states array
    cannot be (re)allocated.
    
    The code after the patch does the realloc(), and properly returns a
    failure code if realloc() fails.  I don't think we need to preserve
    setting "errno = ENOMEM" since there is no other place in the code
    that signals OOM through errno.
    federicomenaquintero committed Apr 23, 2021
    Configuration menu
    Copy the full SHA
    8a5468c View commit details
    Browse the repository at this point in the history
  6. fsm_capture_init(): Initialize up to fsm->statecount fields, not the …

    …whole statealloc
    
    Only the first statecount state structs are valid, anyway.
    federicomenaquintero committed Apr 23, 2021
    Configuration menu
    Copy the full SHA
    840b847 View commit details
    Browse the repository at this point in the history