cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: living without global variables

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Sun, 6 Nov 2005 00:36:37 +0100 (CET)

On Sat, 5 Nov 2005, Bryan Henderson wrote:

> - A user can't simply skip curl_global_init() because the first
> curl_easy_init() will do it implicitly.

Right, but that could be changed in a future.

The current implicit call was a "must" since we added curl_global_init() after
curl_easy_init() so I did it this way in order to not break older programs.
And I'm quite sure numerous programs are still doing it this "sloppy" way.

> - Document in more detail the global state issue, but still require
> curl_global_init(). You can use global_init's flags to skip
> things that you have set up separately. All existing happy users
> continue to do what they're doing.

We should probably add more global_init() flags, like for the amiga thing, the
idna thing etc.

> - Add a new use paradigm for the global-state-averse. libcurl never
> does any global settings. User can explicitly tell Curl to use
> global settings he has made separately.

That would mean using CURL_GLOBAL_NOTHING I guess?

> Where Curl needs global setup and the user hasn't explicitly said to use it,
> Curl fails.

I believe we might have a hard time to detect the lack of init for some cases,
so it might have to become an undefined behaviour for that situation.

> - A new object called a "Curl client." It records:
>
> - Curl memory allocator functions.
>
> - User's request that libcurl use his global setup of Windows
> sockets, Amiga sockets, CHARSET global variable, OpenSSL, or
> GNU TLS.
>
> - A new constructor for the CURL object, curl_easy_init_c(), takes
> a Curl client as an argument. Every CURL object is linked to a
> Curl client. Same for multi object.

I could agree to this. The big problem with this approach however, is that we
have a whole bunch of functions in libcurl that don't take any easy or multi
handle as input, so thus we'd have to change the API for many functions (or
add cloned functions with the only diff that they take such a handle as
argument).

Or did you have another approach in mind?

-- 
  Commercial curl and libcurl Technical Support: http://haxx.se/curl.html
Received on 2005-11-06