cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: living without global variables

From: Bryan Henderson <bryanh_at_giraffe-data.com>
Date: Mon, 31 Oct 2005 18:45:42 +0100

>There is basically two reasons for curl_global_init/cleanup:
>
> 1) OpenSSL's use of globals
>
> 2) Windows' winsock initialization requirements that aren't really globals
> but that I believe good apps should only do once.

I looked at the code, and saw several other global variables:

   3) identity of the memory management functions (this is
      curl_global_init_mem(), which would be nice to use in a modular
      program too).

   4) some kind of idna environment.

   5) some kind of Amiga environment.

Are those not significant?

In any case, then, I see these steps toward making a global variable
free world:

1. Document that you don't have to do curl_global_init() if you aren't
using OpenSSL, Windows, Amiga, or Idna. (I.e. if you avoid those, you
can have a modular user of libcurl). Maybe better still -- document
that you can skip curl_global_init() if you do those initializations
that are relevant to your program yourself. (As global
initializations, they fit better in the caller than in Curl anyway).

2. Make the sub-global object I described, with the memory allocation
functions in it.

3. Get a global-variable-free version of OpenSSL and use it with the
sub-global Curl object.

4. Do the same for those other global environments (Windows, idna, Amiga).

I put the steps in the order they would be useful to me. I have neither
the interest nor the ability to do (4).

-- 
Bryan Henderson                                    Phone 408-621-2000
San Jose, California
Received on 2005-10-31