From 9cf9f756a98922e1042e34a04368e57287e43ea6 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 30 May 2011 01:03:15 -0700 Subject: [PATCH] * gnutls.c: Use Emacs's memory allocators. Without this change, the gnutls library would invoke malloc etc. directly, which causes problems on non-SYNC_INPUT hosts, and which runs afoul of improving memory_full behavior. (fn_gnutls_global_set_mem_functions): New macro or function pointer. (emacs_gnutls_global_init): Use it to specify xmalloc, xrealloc, xfree instead of the default malloc, realloc, free. (Fgnutls_boot): No need to check for memory allocation failure, since xmalloc does that for us. --- src/ChangeLog | 12 ++++++++++++ src/gnutls.c | 18 +++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b53d9b49a42..353aa100e9c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,17 @@ 2011-05-30 Paul Eggert + * gnutls.c: Use Emacs's memory allocators. + Without this change, the gnutls library would invoke malloc etc. + directly, which causes problems on non-SYNC_INPUT hosts, and which + runs afoul of improving memory_full behavior. + (fn_gnutls_global_set_mem_functions): New macro or function pointer. + (emacs_gnutls_global_init): Use it to specify xmalloc, xrealloc, + xfree instead of the default malloc, realloc, free. + (Fgnutls_boot): No need to check for memory allocation failure, + since xmalloc does that for us. + +2011-05-30 Paul Eggert + * eval.c (Qdebug): Now static. * lisp.h (Qdebug): Remove decl. This reverts a part of the 2011-04-26T11:26:05Z!dan.colascione@gmail.com that inadvertently undid part of diff --git a/src/gnutls.c b/src/gnutls.c index 5558fb9ee0b..9342ce7912e 100644 --- a/src/gnutls.c +++ b/src/gnutls.c @@ -110,6 +110,10 @@ DEF_GNUTLS_FN (int, gnutls_error_is_fatal, (int)); DEF_GNUTLS_FN (int, gnutls_global_init, (void)); DEF_GNUTLS_FN (void, gnutls_global_set_log_function, (gnutls_log_func)); DEF_GNUTLS_FN (void, gnutls_global_set_log_level, (int)); +DEF_GNUTLS_FN (void, gnutls_global_set_mem_functions, + (gnutls_alloc_function, gnutls_alloc_function, + gnutls_is_secure_function, gnutls_realloc_function, + gnutls_free_function)); DEF_GNUTLS_FN (int, gnutls_handshake, (gnutls_session_t)); DEF_GNUTLS_FN (int, gnutls_init, (gnutls_session_t *, gnutls_connection_end_t)); DEF_GNUTLS_FN (int, gnutls_priority_set_direct, @@ -168,6 +172,7 @@ init_gnutls_functions (Lisp_Object libraries) LOAD_GNUTLS_FN (library, gnutls_global_init); LOAD_GNUTLS_FN (library, gnutls_global_set_log_function); LOAD_GNUTLS_FN (library, gnutls_global_set_log_level); + LOAD_GNUTLS_FN (library, gnutls_global_set_mem_functions); LOAD_GNUTLS_FN (library, gnutls_handshake); LOAD_GNUTLS_FN (library, gnutls_init); LOAD_GNUTLS_FN (library, gnutls_priority_set_direct); @@ -213,6 +218,7 @@ init_gnutls_functions (Lisp_Object libraries) #define fn_gnutls_global_init gnutls_global_init #define fn_gnutls_global_set_log_function gnutls_global_set_log_function #define fn_gnutls_global_set_log_level gnutls_global_set_log_level +#define fn_gnutls_global_set_mem_functions gnutls_global_set_mem_functions #define fn_gnutls_handshake gnutls_handshake #define fn_gnutls_init gnutls_init #define fn_gnutls_priority_set_direct gnutls_priority_set_direct @@ -582,7 +588,11 @@ emacs_gnutls_global_init (void) int ret = GNUTLS_E_SUCCESS; if (!gnutls_global_initialized) - ret = fn_gnutls_global_init (); + { + fn_gnutls_global_set_mem_functions (xmalloc, xmalloc, NULL, + xrealloc, xfree); + ret = fn_gnutls_global_init (); + } gnutls_global_initialized = 1; return gnutls_make_error (ret); @@ -768,8 +778,7 @@ one trustfile (usually a CA bundle). */) { GNUTLS_LOG (2, max_log_level, "allocating x509 credentials"); x509_cred = XPROCESS (proc)->gnutls_x509_cred; - if (fn_gnutls_certificate_allocate_credentials (&x509_cred) < 0) - memory_full (); + fn_gnutls_certificate_allocate_credentials (&x509_cred); if (NUMBERP (verify_flags)) { @@ -792,8 +801,7 @@ one trustfile (usually a CA bundle). */) { GNUTLS_LOG (2, max_log_level, "allocating anon credentials"); anon_cred = XPROCESS (proc)->gnutls_anon_cred; - if (fn_gnutls_anon_allocate_client_credentials (&anon_cred) < 0) - memory_full (); + fn_gnutls_anon_allocate_client_credentials (&anon_cred); } else { -- 2.11.4.GIT