Skip to content
Snippets Groups Projects
  • Jonathan Schöbel's avatar
    75d83bf1
    NodeFragment: changed semantics of insert_attr_new · 75d83bf1
    Jonathan Schöbel authored
    When there are methods in the api/abi, that take pointers to strings to
    store them in the library, there are two methods to do so. Either they
    are copying the string and leaving it intact, or they directly assign
    the given pointer to some internal storage. While the former method, is
    safer in terms of memory, as the user doesn't have to remember that he
    can't use the string anymore, the latter can be more efficient, as there
    is no extra strdup call, but the user is not allowed to change the
    pointer, free it and also can't use the pointer, because it can't be
    known whether it is already freed by the library. As it should be
    decideable by the user, the library often implements both approaches,
    where the method, that directly store pointers without creating a copy
    contains the raw_ prefix.
    
    The insert_attr_new methods were somewhat confusing in this regard, as
    it is likely to be expected, that they were copying the string, while in
    fact they did not. This is now fixed. The insert_attr_new methods copy
    the strings, while the added insert_attr_raw_new methods preserve the
    old behaviour of the insert_attr_new methods, thus allowing to let the
    user choose, what is more appropriate.
    75d83bf1
    History
    NodeFragment: changed semantics of insert_attr_new
    Jonathan Schöbel authored
    When there are methods in the api/abi, that take pointers to strings to
    store them in the library, there are two methods to do so. Either they
    are copying the string and leaving it intact, or they directly assign
    the given pointer to some internal storage. While the former method, is
    safer in terms of memory, as the user doesn't have to remember that he
    can't use the string anymore, the latter can be more efficient, as there
    is no extra strdup call, but the user is not allowed to change the
    pointer, free it and also can't use the pointer, because it can't be
    known whether it is already freed by the library. As it should be
    decideable by the user, the library often implements both approaches,
    where the method, that directly store pointers without creating a copy
    contains the raw_ prefix.
    
    The insert_attr_new methods were somewhat confusing in this regard, as
    it is likely to be expected, that they were copying the string, while in
    fact they did not. This is now fixed. The insert_attr_new methods copy
    the strings, while the added insert_attr_raw_new methods preserve the
    old behaviour of the insert_attr_new methods, thus allowing to let the
    user choose, what is more appropriate.