python, swig: add missing controller attributes#970
Merged
igaw merged 1 commit intolinux-nvme:masterfrom Mar 14, 2025
Merged
Conversation
Found that some controller attributes (e.g. tls_key) were missing from the SWIG wrapper code. Also found that for some of the attributes, SWIG was generating code that accessed to attributes directly instead of using the getter/setter methods. For example, SWIG would generate code like this: name = c->name; Instead of that: name = nvme_ctrl_get_name(c); This may have been OK in most cases, but the Python code should really use the getter/setter methods instead of accessing the controller object directly. SWIG is a weird beast to tame. For example, all the setter/getter methods must exactly match the syntax: [class]_[member]_[set|get] (e.g. nvme_ctrl_traddr_get) However, most of the libnvme functions follow this syntax: [class]_[set|get]_[member] (e.g. nvme_ctrl_get_traddr) The trick to force SWIG to use the setter/getter methods is to define the attributes in a %extend block and provide explicit translation methods for all the setter/getter methods. Signed-off-by: Martin Belanger <[email protected]>
21acb6d to
1fb6316
Compare
Collaborator
|
Just to understand it, these |
Collaborator
|
BTW, we should keep this in mind: #206 |
Contributor
Author
Yes. It's all internal. The interface has not changed. From the Python code, everything is accessed as a property just like before, but internally the setter/getter methods will now be invoked instead of directly accessing the class members. |
Collaborator
|
Thanks! |
This was referenced Mar 14, 2025
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.
Found that some controller attributes (e.g. tls_key) were missing from the SWIG wrapper code. Also found that for some of the attributes, SWIG was generating code that accessed to attributes directly instead of using the getter/setter methods.
For example, SWIG would generate code like this:
name = c->name;
Instead of that:
name = nvme_ctrl_get_name(c);
This may have been OK in most cases, but the Python code should really use the getter/setter methods instead of accessing the controller object directly.
SWIG is a weird beast to tame. For example, all the setter/getter methods must exactly match the syntax:
[class][member][set|get] (e.g. nvme_ctrl_traddr_get)
However, most of the libnvme functions follow this syntax:
[class][set|get][member] (e.g. nvme_ctrl_get_traddr)
The trick to force SWIG to use the setter/getter methods is to define the attributes in a %extend block and provide explicit translation methods for all the setter/getter methods.