Skip to content

Commit 3894be8

Browse files
Martin Belangerigaw
authored andcommitted
swig: replace libnvmf_context with dict-based ctrl constructor
The libnvmf_context object was a leaky abstraction: Python callers had to create it, configure it, pass it to ctrl(), then discard it — despite never needing it after construction. This commit restores the ergonomics that were lost when the C API switched from libnvme_fabrics_config to libnvmf_context. The public header declares libnvmf_context as an opaque forward declaration, which caused SWIG to treat it as an opaque pointer type and override any user-defined %typemap. Fix this by providing an empty struct body in the SWIG parsed section, which gives SWIG a complete type and restores normal typemap precedence without modifying any C header. The %typemap(in) / %typemap(freearg) pair for struct libnvmf_context * now handles the full fctx lifecycle transparently: the typemap creates the fctx from the Python dict (using arg1 as the global context), the constructor body calls libnvmf_create_ctrl(), and freearg frees the fctx. The typemap is reusable for any future function that takes struct libnvmf_context *. The dict supports all configurable fields: connection identity (subsysnqn, transport, traddr, trsvcid, host_traddr, host_iface), the full libnvme_fabrics_config (via libnvme_fabrics_config_set_* accessors and libnvmf_context_get_fabrics_config), host identity (hostnqn, hostid), crypto and TLS (hostkey, ctrlkey, keyring, tls_key, tls_key_identity), and persistence. All context-level fields are set via their public API setters. An autodoc string on the constructor documents every supported key so that help(nvme.ctrl) is the complete reference. Tests are updated to use the new dict-based API. Signed-off-by: Martin Belanger <[email protected]> Assisted-by: Claude Sonnet 4.6 <[email protected]>
1 parent e9cd107 commit 3894be8

4 files changed

Lines changed: 304 additions & 176 deletions

File tree

0 commit comments

Comments
 (0)