generate-accessors: annotation style + lifecycle generation#3288
Merged
igaw merged 2 commits intolinux-nvme:masterfrom Apr 20, 2026
Merged
generate-accessors: annotation style + lifecycle generation#3288igaw merged 2 commits intolinux-nvme:masterfrom
igaw merged 2 commits intolinux-nvme:masterfrom
Conversation
added 2 commits
April 20, 2026 07:03
Replace the /*!annotation*/ block-comment style with // line comments
throughout. The canonical form is '// !token' (one space between // and
!). The parser accepts any amount of whitespace between // and !, so
'//!token', '// !token', and '//\t!token' are all equivalent. This
makes the annotation resilient to contributor variation.
Update all annotated structs in private.h and private-fabrics.h, and
update the documentation and helper scripts accordingly. The generated
accessors.{h,c} and accessors-fabrics.{h,c} are unchanged.
Signed-off-by: Martin Belanger <[email protected]>
Extend the generator with two new annotations:
// !generate-lifecycle (on struct brace) -- generate _new(), _free(),
and (when defaults exist) _init_defaults()
// !default:<value> (on a member line) -- set the initial value of
that member in _init_defaults()
Apply // !generate-lifecycle to struct libnvmf_discovery_args, replacing
the hand-written libnvmf_discovery_args_create() / _free() pair:
- libnvmf_discovery_args_new() replaces libnvmf_discovery_args_create().
Same int return / double-pointer signature; sets defaults via
libnvmf_discovery_args_init_defaults().
- libnvmf_discovery_args_free() is now generated (same name, same
semantics -- NULL-safe via free(NULL)).
- libnvmf_discovery_args_init_defaults() is new; sets max_retries = 6
and lsp = NVMF_LOG_DISC_LSP_NONE.
Update all callers (nvme.i, discover-loop.c, test/ioctl/discovery.c) to
use the new _new() API. Move the ABI entries for the removed functions
from libnvmf.ld to accessors-fabrics.ld.
Signed-off-by: Martin Belanger <[email protected]>
Collaborator
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR is a two-patch rework of the accessor generator, split from the earlier
generate-lifecyclebranch per reviewer's request for smaller incremental patches (see earlier PR: #3283).Patch 1 — Switch annotations to
//comment styleReplaces the
/*!annotation*/block-comment style with// !annotationline comments. The canonical form is// !token(one space between//and!). The parser accepts any amount of whitespace between//and!, so//!token,// !token, and//\t!tokenare all equivalent — making annotations resilient to contributor variation.Updates all annotated structs in
private.handprivate-fabrics.h, and updates the documentation and helper scripts. The generatedaccessors.{h,c}andaccessors-fabrics.{h,c}are unchanged by this patch.Patch 2 — Add lifecycle and default-value generation
Extends the generator with two new annotations:
// !generate-lifecycle(on astructbrace) — generates_new(),_free(), and (when defaults exist)_init_defaults()// !default:<value>(on a member line) — sets the initial value of that member in_init_defaults()Applies
// !generate-lifecycletostruct libnvmf_discovery_args, replacing the hand-writtenlibnvmf_discovery_args_create()/_free()pair:libnvmf_discovery_args_new()replaceslibnvmf_discovery_args_create()— sameintreturn / double-pointer signature; sets defaults vialibnvmf_discovery_args_init_defaults()libnvmf_discovery_args_free()is now generated (same name, same semantics —NULL-safe viafree(NULL))libnvmf_discovery_args_init_defaults()is new; setsmax_retries = 6andlsp = NVMF_LOG_DISC_LSP_NONEUpdates all callers (
nvme.i,discover-loop.c,test/ioctl/discovery.c) to use the new_new()API. Moves the ABI entries for the removed functions fromlibnvmf.ldtoaccessors-fabrics.ld.Note on
_create→_newrenamingA patch 3 to rename remaining
_createfunctions to_newwas considered but dropped. The_newsuffix generated here carries a specific contract: allocate a zeroed struct on the heap, set default field values, and return it via a double-pointer with no other parameters. The remaining_createfunctions in the public API (libnvme_create_global_ctx,libnvme_create_raw_secret,libnvmf_context_create,libnvmf_create_ctrl) are fundamentally different — they accept multiple parameters and perform substantial initialization logic beyond just setting defaults. Renaming them to_newwould misrepresent what they do and break the semantic contract that_newis meant to convey.