[gnutls-dev] living without global variables

Bryan Henderson bryanh at giraffe-data.com
Wed Dec 21 19:04:01 CET 2005


It would be nice for GnuTLS not to use program-global variables.  That
way, it could be used in a modular program -- i.e. two different parts
of a program that don't know about each other could use GnuTLS under
the covers without interfering with each other.  I'm especially
concerned about independently distributed libraries that use Gnu TLS.

GnuTLS contains two global variables of interest: the handles of the two
ASN1 trees: _gnutls_pkix1_asn and _gnutls_gnutls_asn.  (I'm not concerned
about debugging features or alternative memory allocators).

To work without these, I propose having a new session group object
that contains the two trees.  A program creates that object instead of
calling gnutls_global_init() and passes that object as a parameter
when creating a session (with a new variation of gnutls_init()).  All
functions that access those global variables get a session group
object as a parameter.

gnutls_global_init() would still be around for programs that want the
simplicity of global variables and don't care about modularity.
gnutls_global_init() would create a session group object and assign
its handle to a global variable.  gnutls_init() uses the global
session group handle.

Would this be acceptable?  I'm willing to write whatever code and
documentation is necessary.

-- 
Bryan Henderson                                    Phone 408-621-2000
San Jose, California




More information about the Gnutls-devel mailing list