NodeFragment: changed semantics of insert_attr_new
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.
Showing
- sefht.geany 3 additions, 3 deletionssefht.geany
- src/lib/sefht/node_fragment.c 134 additions, 8 deletionssrc/lib/sefht/node_fragment.c
- src/lib/sefht/node_fragment.h 40 additions, 6 deletionssrc/lib/sefht/node_fragment.h
- tests/test_node_fragment.c 437 additions, 45 deletionstests/test_node_fragment.c
This diff is collapsed.
Please register or sign in to comment