• Thomas Haller's avatar
    device/trivial: add comment about lifetime of "kind" in tc_commit() · f2ae994b
    Thomas Haller authored
    In general, all fields of public NMPlatform* structs must be
    plain/simple. Meaning: copying the struct must be possible without
    caring about cloning/duplicating memory.
    In other words, if there are fields which lifetime is limited,
    then these fields cannot be inside the public part NMPlatform*.
    
    That is why
    
      - "NMPlatformLink.kind", "NMPlatformQdisc.kind", "NMPlatformTfilter.kind"
        are set by platform code to an interned string (g_intern_string())
        that has a static lifetime.
    
      - the "ingress_qos_map" field is inside the ref-counted struct NMPObjectLnkVlan
        and not NMPlatformLnkVlan. This field requires managing the lifetime
        of the array and NMPlatformLnkVlan cannot provide that.
    
    See also for example NMPClass.cmd_obj_copy() which can deep-copy an object.
    But this is only suitable for fields in NMPObject*. The purpose of this
    rule is that you always can safely copy a NMPlatform* struct without
    worrying about the ownership and lifetime of the fields (the field's
    lifetime is unlimited).
    
    This rule and managing of resource lifetime is the main reason for the
    NMPlatform*/NMPObject* split. NMPlatform* structs simply have no mechanism
    for copying/releasing fields, that is why the NMPObject* counterpart exists
    (which is ref-counted and has a copy and destructor function).
    
    This is violated in tc_commit() for the "kind" strings. The lifetime
    of these strings is tied to the setting instance.
    
    We cannot intern the strings (because these are arbitrary strings
    and interned strings are leaked indefinitely). We also cannot g_strdup()
    the strings, because NMPlatform* is not supposed to own strings.
    
    So, just add comments that warn about this ugliness.
    
    The more correct solution would be to move the "kind" fields inside
    NMPObjectQdisc and NMPObjectTfilter, but that is a lot of extra effort.
    f2ae994b
Name
Last commit
Last update
clients Loading commit data...
contrib Loading commit data...
data Loading commit data...
dispatcher Loading commit data...
docs Loading commit data...
examples Loading commit data...
introspection Loading commit data...
libnm Loading commit data...
libnm-core Loading commit data...
m4 Loading commit data...
man Loading commit data...
po Loading commit data...
shared Loading commit data...
src Loading commit data...
tools Loading commit data...
vapi Loading commit data...
.dir-locals.el Loading commit data...
.gitignore Loading commit data...
.gitlab-ci.yml Loading commit data...
.mailmap Loading commit data...
.travis.yml Loading commit data...
AUTHORS Loading commit data...
CONTRIBUTING Loading commit data...
COPYING Loading commit data...
ChangeLog Loading commit data...
MAINTAINERS Loading commit data...
Makefile.am Loading commit data...
Makefile.examples Loading commit data...
Makefile.glib Loading commit data...
Makefile.vapigen Loading commit data...
NEWS Loading commit data...
NetworkManager.pc.in Loading commit data...
README Loading commit data...
TODO Loading commit data...
autogen.sh Loading commit data...
config-extra.h.meson Loading commit data...
config.h.meson Loading commit data...
configure.ac Loading commit data...
linker-script-binary.ver Loading commit data...
linker-script-devices.ver Loading commit data...
linker-script-settings.ver Loading commit data...
meson.build Loading commit data...
meson_options.txt Loading commit data...
valgrind.suppressions Loading commit data...
zanata.xml Loading commit data...