[Gnucash-changes] r13786 - gnucash/trunk - The
kvp_frame_get_string() function returns a pointer to an internal
Neil Williams
linux at codehelp.co.uk
Sat Apr 15 14:23:15 EDT 2006
On Saturday 15 April 2006 5:40 pm, David Hampton wrote:
> gnucash/trunk/lib/libqof/qof/kvp_frame.c
> gnucash/trunk/lib/libqof/qof/kvp_frame.h
> Log:
> The kvp_frame_get_string() function returns a pointer to an internal
> string. Mark it 'const' to prevent callers from trying to free it.
And the API clearly marks it as such - this is gnucash's error, not QOF.
kvp_frame_get_string is a wrapper around kvp_value_get_string. It simply gets
the value at the path requested in the frame specified and calls
kvp_value_get_string for that value.
/** Value accessor. This one is non-copying -- the caller can modify
* the value directly. */
The values returned for GUID, binary, GList, KvpFrame and string
are "non-copying" -- the returned item is the actual item stored. Do not
delete this item unless you take the required care to avoid possible bad
pointer derefrences (i.e. core dumps). Also, be careful hanging on to those
references if you are also storing at the same path names: the referenced
item will be freed during the store.
http://qof.sourceforge.net/doxy/group__KVP.html
(Section on KvpFrame Value Fetching that includes kvp_frame_get_string)
The current API requires that the user keeps tabs on which functions are used
to set and get values, which ones are copying and which are non-copying.
I can't accept your changes, David. Fix the gnucash code, don't break QOF.
> + * lib/libqof/qof/kvp_frame.[ch]: The kvp_frame_get_string()
> + function returns a pointer to an internal string. Mark it 'const'
> + to prevent callers from trying to free it.
The error is in the gnucash functions, not QOF.
I'll be reviewing Kvp during the libqof1->libqof2 transition, but right now
Kvp is the original API and it puts the onus on the USER to handle the data
properly.
--
Neil Williams
=============
http://www.data-freedom.org/
http://www.nosoftwarepatents.com/
http://www.linux.codehelp.co.uk/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.gnucash.org/pipermail/gnucash-devel/attachments/20060415/915d656d/attachment.bin
More information about the gnucash-devel
mailing list