new client plans and libpurple

Zoltán Sólyom z-ismeretlen at freemail.hu
Wed Apr 3 09:01:10 EDT 2013


On 13/04/01 20:49, Mark Doliner wrote:
> On Sat, Mar 30, 2013 at 1:48 PM, Zoltán Sólyom <z-ismeretlen at freemail.hu> wrote:
>> I was wondering why is that, that some functions return char* and not const char*?
> "const" is a loosely enforced contract that describes who is
> responsible for the memory.  Generally if one of our functions returns
> a const value then a caller should not modify that value.  In this
> case the caller does not own the return value.  It does not need to
> worry about freeing the memory.  It should be careful about keeping a
> reference to the return value, because something else in libpurple
> might decide to free that value.  A lack of const generally means the
> caller owns the memory and can do whatever it wants with it.  And the
> caller is expected to free the memory.
>
> Sometimes we choose to return "const char*" because it's feasible for
> us to use a fixed size, static buffer, which is more efficient than
> allocating memory.  Sometimes it's infeasible to use a fixed buffer,
> so we allocate memory.
>
>> Same about some that are expecting const arguments while others not.
> If a function does not modify the argument then it should be const.
> If the function modifies or takes ownership of the memory then the
> argument should not be const.

What I meant is whether it is possible that in some cases someone forgot 
to add the const qualifier, or the ownership of the passed pointer is 
just not mentioned in the documentation/comment.




More information about the Devel mailing list