cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: http headers free and multi

From: Brian Dessent <brian_at_dessent.net>
Date: Fri, 13 Oct 2006 21:48:18 -0700

Mohun Biswas wrote:

> BTW, the solution can be cleaner than "CURLINFO_GETPTR_*". All these
> values are set with "curl_easy_setopt(CURLOPT_FOO)". Why can't they be
> retrieved with "curl_easy_getopt(CURLOPT_FOO). No new constants need be
> invented.

Because from an ABI point of view it is a lot less pain to add new
#defines/enums than to add a new exported function. If you do the
former then new code can co-exist with old versions of the library, if
implemented properly. I.e. the library returns a defined error code for
options it does not understand, and the calling code checks for these
errors and works around them. If you do it by adding a new export you
create a hard line in the sand that can never be crossed; you have to
bump the ABI number and doom all your users to installing both libcurl3
and libcurl4 for some indeterminate period of time, potentially years.

In a perfect world this would never matter and the more aesthetically
pleasing solution of just adding an export would be obvious, but as
author of a library that is consumed by many others, one cannot take
such decisions lightly.

> Notice that (a) there are two copies of 'errbuf' and (b) the freeing
> code block is utterly opaque in terms of WHAT it's freeing. Whereas if
> we free the result of
>
> curl_easy_getopt(CURLOPT_ERRORBUFFER);
>
> then the lifespan of the error buffer is better documented before a
> single comment is written.

You're kind of setting up a straw man here. OF COURSE there must be two
copies of the pointer to errbuf (not two copies of errbuf), because if
there weren't and the original pointer were still in scope then you
could just free that. But since in your example the original "errbuf"
pointer was an automatic variable it does not even exist by the time the
second snippet gets called (assuming that the init was in a function
that has returned), so it's not really fair to say that there are two
copies.

Regarding transparency, this is easily fixed by always using a structure
for the CURLOPT_PRIVATE, even if it just has a single member, so that it
is always clear precisely what is being freed.

Brian
Received on 2006-10-14