From 0c1244a2b7e30ab0610ae70166e1b5d0219782c3 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 4 Dec 2017 12:08:31 +0100 Subject: core: Also check for a failed selftest in gpgm_data_new. * src/data.c (_gpgme_data_new): Check for failed selftest. * tests/run-support.h (make_filename): Print a message on mallooc failure. (init_gpgme_basic): New. * tests/run-identify.c (main): Call init_gpgme_basic becuase we do not need to setup a protocol. * tests/t-data.c: Define PGM and include run-support.h. (make_filename): Remove. (main): Call init_gpgme_basic. -- Note: This patch may break applications which used gpgme_data but no gpgme_new without having called the required gpgme_check_version. GPGME can be used without a protocol for example to work with the data object abstraction. Thus a call to gpgme_data_new also needs to check the result of the core selftests - including on whether gpgme_check_version has been called. Signed-off-by: Werner Koch --- tests/run-support.h | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'tests/run-support.h') diff --git a/tests/run-support.h b/tests/run-support.h index 841b2232..6a2170b0 100644 --- a/tests/run-support.h +++ b/tests/run-support.h @@ -107,7 +107,11 @@ make_filename (const char *fname) srcdir = "."; buf = malloc (strlen(srcdir) + strlen(fname) + 2); if (!buf) - exit (8); + { + fprintf (stderr, "%s:%d: could not allocate string: %s\n", + __FILE__, __LINE__, strerror (errno)); + exit (8); + } strcpy (buf, srcdir); strcat (buf, "/"); strcat (buf, fname); @@ -116,17 +120,23 @@ make_filename (const char *fname) void -init_gpgme (gpgme_protocol_t proto) +init_gpgme_basic (void) { - gpgme_error_t err; - gpgme_check_version (NULL); setlocale (LC_ALL, ""); gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL)); #ifndef HAVE_W32_SYSTEM gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL)); #endif +} + + +void +init_gpgme (gpgme_protocol_t proto) +{ + gpg_error_t err; + init_gpgme_basic (); err = gpgme_engine_check_version (proto); fail_if_err (err); } -- cgit v1.2.3