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 <wk@gnupg.org>
This commit is contained in:
parent
3cf9aedc92
commit
0c1244a2b7
@ -683,9 +683,10 @@ uses, this function provides a run-time check if the necessary
|
|||||||
features are provided by the installed version of the library.
|
features are provided by the installed version of the library.
|
||||||
|
|
||||||
If a selftest fails, the function may still succeed. Selftest errors
|
If a selftest fails, the function may still succeed. Selftest errors
|
||||||
are returned later when invoking @code{gpgme_new}, so that a detailed
|
are returned later when invoking @code{gpgme_new} or
|
||||||
error code can be returned (historically, @code{gpgme_check_version}
|
@code{gpgme-data_new}, so that a detailed error code can be returned
|
||||||
does not return a detailed error code).
|
(historically, @code{gpgme_check_version} does not return a detailed
|
||||||
|
error code).
|
||||||
@end deftypefun
|
@end deftypefun
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,6 +46,10 @@ _gpgme_data_new (gpgme_data_t *r_dh, struct _gpgme_data_cbs *cbs)
|
|||||||
return gpg_error (GPG_ERR_INV_VALUE);
|
return gpg_error (GPG_ERR_INV_VALUE);
|
||||||
|
|
||||||
*r_dh = NULL;
|
*r_dh = NULL;
|
||||||
|
|
||||||
|
if (_gpgme_selftest)
|
||||||
|
return _gpgme_selftest;
|
||||||
|
|
||||||
dh = calloc (1, sizeof (*dh));
|
dh = calloc (1, sizeof (*dh));
|
||||||
if (!dh)
|
if (!dh)
|
||||||
return gpg_error_from_syserror ();
|
return gpg_error_from_syserror ();
|
||||||
|
@ -102,7 +102,7 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
init_gpgme (GPGME_PROTOCOL_OpenPGP);
|
init_gpgme_basic ();
|
||||||
|
|
||||||
for (; argc; argc--, argv++)
|
for (; argc; argc--, argv++)
|
||||||
{
|
{
|
||||||
|
@ -107,7 +107,11 @@ make_filename (const char *fname)
|
|||||||
srcdir = ".";
|
srcdir = ".";
|
||||||
buf = malloc (strlen(srcdir) + strlen(fname) + 2);
|
buf = malloc (strlen(srcdir) + strlen(fname) + 2);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
exit (8);
|
{
|
||||||
|
fprintf (stderr, "%s:%d: could not allocate string: %s\n",
|
||||||
|
__FILE__, __LINE__, strerror (errno));
|
||||||
|
exit (8);
|
||||||
|
}
|
||||||
strcpy (buf, srcdir);
|
strcpy (buf, srcdir);
|
||||||
strcat (buf, "/");
|
strcat (buf, "/");
|
||||||
strcat (buf, fname);
|
strcat (buf, fname);
|
||||||
@ -116,17 +120,23 @@ make_filename (const char *fname)
|
|||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
init_gpgme (gpgme_protocol_t proto)
|
init_gpgme_basic (void)
|
||||||
{
|
{
|
||||||
gpgme_error_t err;
|
|
||||||
|
|
||||||
gpgme_check_version (NULL);
|
gpgme_check_version (NULL);
|
||||||
setlocale (LC_ALL, "");
|
setlocale (LC_ALL, "");
|
||||||
gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
|
gpgme_set_locale (NULL, LC_CTYPE, setlocale (LC_CTYPE, NULL));
|
||||||
#ifndef HAVE_W32_SYSTEM
|
#ifndef HAVE_W32_SYSTEM
|
||||||
gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
|
gpgme_set_locale (NULL, LC_MESSAGES, setlocale (LC_MESSAGES, NULL));
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
init_gpgme (gpgme_protocol_t proto)
|
||||||
|
{
|
||||||
|
gpg_error_t err;
|
||||||
|
|
||||||
|
init_gpgme_basic ();
|
||||||
err = gpgme_engine_check_version (proto);
|
err = gpgme_engine_check_version (proto);
|
||||||
fail_if_err (err);
|
fail_if_err (err);
|
||||||
}
|
}
|
||||||
|
@ -30,8 +30,10 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#include <gpgme.h>
|
#define PGM "t-data"
|
||||||
|
#include "run-support.h"
|
||||||
|
|
||||||
|
#undef fail_if_err
|
||||||
#define fail_if_err(a) do { if(a) { \
|
#define fail_if_err(a) do { if(a) { \
|
||||||
fprintf (stderr, "%s:%d: (%i) gpgme_error_t " \
|
fprintf (stderr, "%s:%d: (%i) gpgme_error_t " \
|
||||||
"%s\n", __FILE__, __LINE__, round, \
|
"%s\n", __FILE__, __LINE__, round, \
|
||||||
@ -39,27 +41,6 @@
|
|||||||
exit (1); } \
|
exit (1); } \
|
||||||
} while(0)
|
} while(0)
|
||||||
|
|
||||||
static char *
|
|
||||||
make_filename (const char *fname)
|
|
||||||
{
|
|
||||||
const char *srcdir = getenv ("srcdir");
|
|
||||||
char *buf;
|
|
||||||
|
|
||||||
if (!srcdir)
|
|
||||||
srcdir = ".";
|
|
||||||
buf = malloc (strlen(srcdir) + strlen(fname) + 2 );
|
|
||||||
if (!buf)
|
|
||||||
{
|
|
||||||
fprintf (stderr, "%s:%d: could not allocate string: %s\n",
|
|
||||||
__FILE__, __LINE__, strerror (errno));
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
strcpy (buf, srcdir);
|
|
||||||
strcat (buf, "/");
|
|
||||||
strcat (buf, fname);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
TEST_INITIALIZER,
|
TEST_INITIALIZER,
|
||||||
@ -203,6 +184,8 @@ main (void)
|
|||||||
gpgme_error_t err = 0;
|
gpgme_error_t err = 0;
|
||||||
gpgme_data_t data;
|
gpgme_data_t data;
|
||||||
|
|
||||||
|
init_gpgme_basic ();
|
||||||
|
|
||||||
while (++round)
|
while (++round)
|
||||||
{
|
{
|
||||||
switch (round)
|
switch (round)
|
||||||
|
Loading…
Reference in New Issue
Block a user