From: Nikos Mavrogiannopoulos Date: Sat, 7 Dec 2002 11:19:53 +0000 (+0000) Subject: Exported the more convenient gnutls_malloc() and gnutls_free() functions. Actually... X-Git-Tag: gnutls_0_6_0~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8293b7b08c24d6ebd54ebb52baeced2ce818bc03;p=thirdparty%2Fgnutls.git Exported the more convenient gnutls_malloc() and gnutls_free() functions. Actually pointers to functions. --- diff --git a/NEWS b/NEWS index 27ad887648..727c1b4794 100644 --- a/NEWS +++ b/NEWS @@ -14,10 +14,10 @@ Version 0.5.12 than password files. - Added the function gnutls_openpgp_set_recv_key_function() which can be used to set a callback, to get OpenPGP keys. -- Added the new functions: - gnutls_get_malloc_function() - gnutls_get_free_function() - to be used in callbacks. +- Exported the functions: + gnutls_malloc() + gnutls_free() + which should be used in callbacks. - Changed the semantics of gnutls_pem_base64_encode_alloc() and gnutls_pem_base64_decode_alloc(). In the default case were the gnutls library is used with malloc/realloc/free, diff --git a/doc/tex/callbacks.tex b/doc/tex/callbacks.tex index 59f3fff868..edd718a802 100644 --- a/doc/tex/callbacks.tex +++ b/doc/tex/callbacks.tex @@ -16,9 +16,8 @@ data to the transport layer. Other callback functions such as the one set by \printfunc{gnutls_srp_set_server_credentials_function}{gnutls\_srp\_set\_server\_credentials\_function}, may require more complicated input, including data to be allocated. -These callbacks should use the following function to get a malloc() -and a free() like functions, to allocate data. +These callbacks should allocate and free memory using the functions shown below. \begin{itemize} -\item \printfunc{gnutls_global_get_malloc_function}{gnutls\_global\_get\_malloc\_function} -\item \printfunc{gnutls_global_get_free_function}{gnutls\_global\_get\_free\_function} +\item \printfunc{gnutls_malloc}{gnutls\_malloc} +\item \printfunc{gnutls_free}{gnutls\_free} \end{itemize} diff --git a/lib/gnutls.h.in.in b/lib/gnutls.h.in.in index 49da8fc268..5c5998bdf3 100644 --- a/lib/gnutls.h.in.in +++ b/lib/gnutls.h.in.in @@ -322,8 +322,8 @@ void gnutls_global_set_mem_functions( gnutls_free_function); /* For use in callbacks */ -gnutls_alloc_function gnutls_global_get_malloc_function(void); -gnutls_free_function gnutls_global_get_free_function(void); +extern gnutls_alloc_function gnutls_malloc; +extern gnutls_free_function gnutls_free; typedef void (*gnutls_log_func)( const char*); void gnutls_global_set_log_function( gnutls_log_func log_func); diff --git a/lib/gnutls_db.c b/lib/gnutls_db.c index 404afea8c5..3a67bdca61 100644 --- a/lib/gnutls_db.c +++ b/lib/gnutls_db.c @@ -39,8 +39,8 @@ * sessions database. This function must return a gnutls_datum containing the * data on success, or a gnutls_datum containing null and 0 on failure. * - * The datum's data must be allocated using the function returned by - * gnutls_global_get_malloc_function(). + * The datum's data must be allocated using the function + * gnutls_malloc(). * * The first argument to store_function() will be null unless gnutls_db_set_ptr() * has been called. diff --git a/lib/gnutls_global.c b/lib/gnutls_global.c index fd225bda83..32a67af374 100644 --- a/lib/gnutls_global.c +++ b/lib/gnutls_global.c @@ -343,32 +343,3 @@ gnutls_check_version( const char *req_version ) } return NULL; } - -/** - * gnutls_global_get_malloc_function - Returns a malloc() like function - * @session: is a &gnutls_session structure. - * - * This function will return a malloc() compatible function to be - * used by callbacks. The returned function is the one set by - * gnutls_global_set_mem_functions(). - * - **/ -gnutls_alloc_function gnutls_global_get_malloc_function(void) -{ - return gnutls_malloc; -} - -/** - * gnutls_global_get_free_function - Returns a free() like function - * @session: is a &gnutls_session structure. - * - * This function will return a free() compatible function to be - * used by callbacks. The returned function is the one set by - * gnutls_global_set_mem_functions(). - * - **/ -gnutls_free_function gnutls_global_get_free_function(void) -{ - return gnutls_free; -} - diff --git a/lib/gnutls_mem.c b/lib/gnutls_mem.c index 9dea5e3451..05d204fded 100644 --- a/lib/gnutls_mem.c +++ b/lib/gnutls_mem.c @@ -79,8 +79,8 @@ void *ret; } char* _gnutls_strdup( const char* str) { -int siz = strlen( str); -char * ret; +size_t siz = strlen( str); +char* ret; ret = gnutls_malloc( siz + 1); if (ret == NULL) @@ -91,3 +91,34 @@ char * ret; return ret; } + + +#if 0 +/* don't use them. They are included for documentation. + */ + +/** + * gnutls_malloc - Allocates and returns data + * + * This function will allocate 's' bytes data, and + * return a pointer to memory. This function is supposed + * to be used by callbacks. + * + * The allocation function used is the one set by gnutls_global_set_mem_functions(). + * + **/ +void* gnutls_malloc( size_t s); + +/** + * gnutls_free - Returns a free() like function + * @d: pointer to memory + * + * This function will free data pointed by ptr. + * + * The deallocation function used is the one set by gnutls_global_set_mem_functions(). + * + **/ +void gnutls_free( void* ptr); + +#endif + diff --git a/lib/x509_b64.c b/lib/x509_b64.c index 538b3e7ead..145c11a538 100644 --- a/lib/x509_b64.c +++ b/lib/x509_b64.c @@ -293,7 +293,7 @@ int size; * encoding. This is the encoding used in PEM messages. This function will * allocate the required memory to hold the encoded data. * - * You should use the function returned by gnutls_global_get_free_function() to + * You should use the function gnutls_free() to * free the returned data. * **/ @@ -506,7 +506,7 @@ int size; * "-----BEGIN header" and decode only this part. Otherwise it will decode the * first PEM packet found. * - * You should use the function returned by gnutls_global_get_free_function() to + * You should use the function gnutls_free() to * free the returned data. * * Note that b64_data should be null terminated. diff --git a/libextra/auth_srp_sb64.c b/libextra/auth_srp_sb64.c index 2f3e313e81..bf9b160df0 100644 --- a/libextra/auth_srp_sb64.c +++ b/libextra/auth_srp_sb64.c @@ -315,7 +315,7 @@ int size; * encoding. This is the encoding used in SRP password files. This function will * allocate the required memory to hold the encoded data. * - * You should use the function returned by gnutls_global_get_free_function() to + * You should use the function returned by gnutls_free() to * free the returned data. * **/ @@ -385,7 +385,7 @@ int size; * will be allocated, and stored into result. * It will decode using the base64 algorithm found in libsrp. * - * You should use the function returned by gnutls_global_get_free_function() to + * You should use the function returned by gnutls_free() to * free the returned data. * **/ diff --git a/libextra/gnutls_srp.c b/libextra/gnutls_srp.c index 32b921f452..9c042002c4 100644 --- a/libextra/gnutls_srp.c +++ b/libextra/gnutls_srp.c @@ -514,7 +514,7 @@ void gnutls_srp_server_set_select_function(gnutls_session session, * 'username' contains the actual username. * * The 'salt', 'verifier', 'generator' and 'prime' must be filled - * in using the malloc returned by gnutls_global_get_malloc_function(). + * in using the gnutls_malloc(). * * In case the callback returned a negative number then gnutls will * assume that the username does not exist.