libnvme, python: prep accessor generator for Python bindings redesign#3324
Merged
igaw merged 2 commits intolinux-nvme:masterfrom Apr 29, 2026
Merged
Conversation
…redesign
Optimize !generate-accessors struct-level defaults in private.h to minimize
per-member override annotations (libnvme_path → read=custom,write=none;
libnvme_ctrl and libnvme_subsystem → read=generated,write=none).
Extend generate-accessors.py to handle multi-word types (enum tag, unsigned
int, unsigned long long) and fixed-size scalar arrays, generating memcpy-based
setters and const-pointer getters with size-aware KernelDoc.
Regenerate accessors.{h,c,ld}, nvme-swig-accessors.i, nvme.i accordingly.
Signed-off-by: Martin Belanger <martin.belanger@dell.com>
Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
The function copies the UUID into a caller-supplied buffer rather than returning a pointer, so "copy" is a more accurate name than "get". Update the declaration in tree.h, definition in tree.c, the ABI version script, the test, and the uuid member annotation (read=none since the copy function signature is incompatible with the %extend getter pattern used by the Python bindings). Signed-off-by: Martin Belanger <Martin.Belanger@dell.com> Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Summary
This patch prepares the accessor annotation system and code generator for the upcoming Python bindings redesign. No user-visible API changes are made; the changes either reduce annotation noise in
private.hor extend the generator to handle types it previously silently skipped.1. Annotation cleanup in
private.hThe
!generate-accessorsstruct-level default was optimised for three structs to minimise the number of per-member!access:overrides needed:libnvme_pathread=custom,write=nonelibnvme_ctrlread=generated,write=nonelibnvme_subsystemread=generated,write=noneThe stat-block members (
stat[2],curr_idx,diffstat) that appear in bothlibnvme_pathandlibnvme_nsnow carry a short block comment explaining their double-buffered design and that they are managed exclusively by the stat subsystem and must not be accessed directly. Bothcurr_idxanddiffstatare now marked!access:read=none(no public getter) since they are implementation details.The
pdc_enabled/pdc_enabled_validpair inlibnvme_hostalso received a clarifying block comment explaining their relationship.2. Generator extensions (
generate-accessors.py)Multi-word type support (
MEMBER_RE):The regex previously matched only single-word type names (
uint8_t,bool,int). It now handles multi-word types such asenum nvme_csi,unsigned int, andunsigned long long. Backtracking in the regex engine resolves the inherent ambiguity between the last type-word and the member name; no downstream code in the generator required changes because the capture-group numbering is preserved.Fixed-size scalar array support (
SCALAR_ARRAY_RE):A new regex and parse branch handle members of the form
type name[N](e.g.uint8_t eui64[8],unsigned char uuid[NVME_UUID_LEN]).char name[N]members are caught first by the existingCHAR_ARRAY_REand never reach this path.For such members the generator now emits:
const type *nvme_X_get_Y(const struct X *p)returningp->y(pointer to first element). The KernelDoc explicitly states the size: "Return: Pointer to theyarray of Ntypeelements."void nvme_X_set_Y(struct X *p, const type y[N])implemented withmemcpy(p->y, y, sizeof(p->y)).A
const-qualified array member forceswrite=noneregardless of the struct-level default, consistent with howconstis handled for scalar members.3. API rename: libnvme_ns_get_uuid → libnvme_ns_copy_uuid
The existing
libnvme_ns_get_uuid(n, out)fills a caller-supplied buffer rather than returning a value, making "get" a misleading name. It is renamed tolibnvme_ns_copy_uuidto make the copy semantics explicit.Affected files:
tree.h,tree.c,libnvme.ld,test/test.c.The uuid member annotation in
private.his updated to!access:read=none,write=none— the two-argument copy signature is structurally incompatible with the single-argument getter pattern required by the Python%extendpseudo-member mechanism, so no Python property is generated for uuid. A dedicated Python helper can be added later if needed.