{"id":51614027,"url":"https://github.com/state-machines/libstatemachines","last_synced_at":"2026-07-12T11:31:23.674Z","repository":{"id":366653813,"uuid":"1234513338","full_name":"state-machines/libstatemachines","owner":"state-machines","description":"A freestanding, dependency-free finite state machine runtime in C11.","archived":false,"fork":false,"pushed_at":"2026-06-22T18:40:03.000Z","size":38,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-06-22T20:12:33.381Z","etag":null,"topics":["c","c11","embedded","finite-state-machine","freestanding","fsm","hsm","kernel","state-machine","zero-allocation"],"latest_commit_sha":null,"homepage":null,"language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/state-machines.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-10T09:30:47.000Z","updated_at":"2026-06-22T18:40:08.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/state-machines/libstatemachines","commit_stats":null,"previous_names":["state-machines/libstatemachines"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/state-machines/libstatemachines","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/state-machines%2Flibstatemachines","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/state-machines%2Flibstatemachines/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/state-machines%2Flibstatemachines/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/state-machines%2Flibstatemachines/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/state-machines","download_url":"https://codeload.github.com/state-machines/libstatemachines/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/state-machines%2Flibstatemachines/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35391313,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-12T02:00:06.386Z","response_time":87,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","c11","embedded","finite-state-machine","freestanding","fsm","hsm","kernel","state-machine","zero-allocation"],"created_at":"2026-07-12T11:31:18.918Z","updated_at":"2026-07-12T11:31:23.668Z","avatar_url":"https://github.com/state-machines.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libstatemachines\n\nA freestanding, dependency-free finite state machine runtime in C11.\n\nSchemas are plain data: you describe states, events, guards, and actions as\nstatic tables, hand them to the runtime, and dispatch events. The library does\nno allocation and pulls in nothing beyond the standard C headers.\n\n## Features\n\n- **Zero dependencies, zero allocation.** No libc requirement beyond freestanding\n  headers; all storage is caller-provided.\n- **Flat and hierarchical machines.** Nested states with `initial_child` descent\n  and ancestor-aware matching (`state_machine_is_in`).\n- **Deterministic selection.** Transitions are evaluated in declaration order;\n  guards short-circuit; the first match wins.\n- **Rich dispatch diagnostics.** `state_machine_dispatch_ex` reports the outcome,\n  the transition taken, which guard failed, and how many transitions were tested.\n- **Schema validation.** `state_machine_init` fully validates a schema before use\n  and fails closed (`EINVAL`) on malformed input.\n- **Frozen ABI.** Struct layouts are pinned with static assertions on LP64/LLP64\n  targets; `state_machine_abi_version()` exposes the runtime ABI at load time.\n- **Portable C11.** Standard headers only (`\u003cstdint.h\u003e`, `\u003cstdbool.h\u003e`,\n  `\u003cstddef.h\u003e`, `\u003cerrno.h\u003e`); no platform-specific dependencies.\n\n## Build\n\n```sh\nmake            # build/libstate_machine.a\nmake test       # build + run smoke tests, conformance corpus, and example\nmake example    # build + run the reference consumer\nmake clean\n```\n\nOverride the toolchain as usual:\n\n```sh\nmake CC=clang\n```\n\nThe library builds under `-std=c11 -Wall -Wextra -Wpedantic -Werror` with\n`-Wconversion` and `-Wshadow` enabled.\n\n## Usage\n\n```c\n#include \"state_machine.h\"\n\n/* Describe the machine as static data (see examples/ for a full schema). */\nextern const state_machine_def_t my_def;\n\nint main(void)\n{\n    state_machine_t m = STATE_MACHINE_INITIALIZER;\n\n    if (state_machine_init(\u0026m, \u0026my_def, /*userdata=*/NULL) != 0)\n        return 1;\n\n    state_machine_result_t r;\n    state_machine_dispatch_ex(\u0026m, EV_START, /*payload=*/NULL, \u0026r);\n\n    if (r.outcome == STATE_MACHINE_OUTCOME_ACCEPTED)\n        printf(\"now in: %s\\n\", state_machine_state_name(\u0026my_def, r.to));\n    else\n        printf(\"rejected: %s\\n\", state_machine_outcome_name(r.outcome));\n\n    state_machine_destroy(\u0026m);\n    return 0;\n}\n```\n\nDispatch outcomes:\n\n| Outcome | Meaning |\n| --- | --- |\n| `ACCEPTED` | A transition fired; state changed (or self-transitioned). |\n| `INVALID_ARG` | Null/invalid arguments; the instance is untouched. |\n| `NO_TRANSITION` | No transition matched the event in the current state. |\n| `GUARD_FAILED` | A transition matched but every candidate guard returned false. |\n| `REENTRY` | Dispatch was called re-entrantly on the same instance. |\n\nA worked example - a circuit breaker built on top of the runtime - lives in\n[`examples/circuit_breaker`](examples/circuit_breaker).\n\n## Testing\n\n`make test` runs the smoke suite (flat machines, hierarchical machines, action\ndispatch, and invalid-schema rejection), the JSON-driven conformance corpus\nunder `test/conformance/`, and the reference example. CI runs the same against\nboth GCC and Clang.\n\n## License\n\nBSD-2-Clause. See [LICENSE](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstate-machines%2Flibstatemachines","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstate-machines%2Flibstatemachines","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstate-machines%2Flibstatemachines/lists"}