Skip to content

Handle full fixed buffers, fix generator edge cases, add a CMake build (2.1.3) - #13

Open
dallison wants to merge 2 commits into
mainfrom
asil
Open

dallison wants to merge 2 commits into
mainfrom
asil

Conversation

@dallison

@dallison dallison commented Oct 9, 2026

Copy link
Copy Markdown
Owner

Summary

Messages built in caller-provided buffers now stay inside the buffer when it runs out of space, and phaser builds with -fno-exceptions -fno-rtti. The generator handles two cases that subspace.proto needs, and a CMake build is added so projects outside Bazel can use phaser.

Full fixed buffers (e7e15f7)

  • TryCreateMutable returns InvalidArgument for a buffer smaller than its header and ResourceExhausted when the message doesn't fit. CreateMutable aborts in those cases.
  • Setters and repeated fields keep their previous contents. mutable_, add_ and array element accessors return a detached handle whose writes go to per-thread scratch storage.
  • AllocationFailed() reports the failure. Serialize then fails, Deserialize returns ResourceExhausted, and CreateReadonly treats the buffer as empty.
  • Placeholder string handles ignore assignment instead of dereferencing null.
  • Without exceptions, misuse that would throw aborts instead.

Generator fixes (3d5eca6)

  • Top-level messages are emitted after the same-file messages their fields (and their nested messages' fields) use, so a message can use one defined later in the .proto file.
  • When a message has fields named both <name> and has_<name>, the presence accessor for <name> is _phaser_has_<name>(), so it doesn't collide with the has_<name> getter.

CMake build (3d5eca6)

  • CMakeLists.txt builds phaser_runtime and protoc-gen-phaser, and defines phaser_add_library(), which generates and builds a library like the Bazel phaser_library rule, short header included.
  • A parent project's Abseil, cpp_toolbelt and protobuf targets are used when present; anything missing is fetched with FetchContent.
  • The plugin is built only for the host. Cross-compiles take a host plugin in PHASER_PLUGIN_EXECUTABLE.

Dependencies

Requires cpp_toolbelt 2.1.6 (dallison/cpp_toolbelt asil branch), pinned with a git_override to commit 86b45cd until it is in the Bazel Central Registry.

Testing

  • bazelisk test //phaser/...: all 25 tests pass, including:
    • New fixed_buffer_test: builds and parses messages in every buffer size up to 4 KB with -fno-exceptions -fno-rtti, and checks that nothing is written past the end.
    • New generator_edge_cases_test: fails to compile without the generator fixes.
  • CMake: builds standalone, and inside Subspace with protobuf 29.5, where the generated library and the Subspace ASIL client tests pass. Also cross-compiles for Android x86_64 with a host plugin.

Messages in caller-provided buffers now stay inside the buffer when it runs
out of space:

- TryCreateMutable returns InvalidArgument for a buffer smaller than its
  header and ResourceExhausted when the message does not fit.  CreateMutable
  aborts in those cases.
- Setters and repeated fields keep their previous contents.  mutable_, add_
  and array element accessors return a detached handle whose writes go to
  per-thread scratch storage.
- AllocationFailed() reports the failure.  Serialize then fails, Deserialize
  returns ResourceExhausted, and CreateReadonly treats the buffer as empty.
- Placeholder string handles ignore assignment instead of dereferencing null.

The runtime and generated code build with -fno-exceptions -fno-rtti, where
misuse that would throw aborts instead.  fixed_buffer_test builds and parses
messages in every buffer size up to 4 KB under those flags and checks that
nothing is written past the end of the buffer.

Requires cpp_toolbelt 2.1.6, pinned with a git_override until it is in the
Bazel Central Registry.
…ions, add a CMake build

- Emit top-level messages after the same-file messages their fields (and
  their nested messages' fields) use, so a message can use one defined later
  in the .proto file.
- When a message has fields named both <name> and has_<name>, name <name>'s
  presence accessor _phaser_has_<name>() so it doesn't collide with the
  has_<name> field's getter.
- Add CMakeLists.txt: the phaser_runtime library, the protoc-gen-phaser
  plugin (host builds only; cross-compiles take PHASER_PLUGIN_EXECUTABLE), and
  phaser_add_library() to generate and build a library like phaser_library.
- Add generator_edge_cases_test covering both generator fixes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant