diff options
author | Marcus Brinkmann <[email protected]> | 2009-05-28 15:16:01 +0000 |
---|---|---|
committer | Marcus Brinkmann <[email protected]> | 2009-05-28 15:16:01 +0000 |
commit | bdb7bcf93889c279c48acb0b75792ba310116074 (patch) | |
tree | 8cf57dce655b2572a08dca4ef70735c0bbedc57b /src/version.c | |
parent | doc/ (diff) | |
download | gpgme-bdb7bcf93889c279c48acb0b75792ba310116074.tar.gz gpgme-bdb7bcf93889c279c48acb0b75792ba310116074.zip |
doc/
2009-05-28 Marcus Brinkmann <[email protected]>
* gpgme.texi (Library Version Check): Document selftest error.
(Creating Contexts): Likewise.
src/
2009-05-28 Marcus Brinkmann <[email protected]>
* gpgme.h.in (gpgme_check_version_internal): New prototype.
(gpgme_check_version): New macro, overriding function of the same
name.
* libgpgme.vers, gpgme.def: Add gpgme_check_version_internal.o
* context.h (_gpgme_selftest): New variable declaration.
* version.c: Include "context.h".
(gpgme_check_version): Set _gpgme_selftest on success.
(gpgme_check_version_internal): New function.
* gpgme.c (_gpgme_selftest): Define it.
(gpgme_new): Check the selftest result.
Diffstat (limited to 'src/version.c')
-rw-r--r-- | src/version.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/version.c b/src/version.c index c6fb52b9..213df6de 100644 --- a/src/version.c +++ b/src/version.c @@ -32,6 +32,7 @@ #include "gpgme.h" #include "priv-io.h" #include "debug.h" +#include "context.h" /* For _gpgme_sema_subsystem_init (). */ #include "sema.h" @@ -44,6 +45,10 @@ #include "windows.h" #endif +/* We implement this function, so we have to disable the overriding + macro. */ +#undef gpgme_check_version + /* Bootstrap the subsystems needed for concurrent operation. This must be done once at startup. We can not guarantee this using a @@ -183,6 +188,7 @@ _gpgme_compare_versions (const char *my_version, const char * gpgme_check_version (const char *req_version) { + char *result; do_subsystem_inits (); /* Catch-22: We need to get at least the debug subsystem ready @@ -193,7 +199,39 @@ gpgme_check_version (const char *req_version) "req_version=%s, VERSION=%s", req_version? req_version:"(null)", VERSION); - return _gpgme_compare_versions (VERSION, req_version) ? VERSION : NULL; + result = _gpgme_compare_versions (VERSION, req_version) ? VERSION : NULL; + if (result != NULL) + _gpgme_selftest = 0; + + return result; +} + +/* Check the version and also at runtime if the struct layout of the + library matches the one of the user. This is particular useful for + Windows targets (-mms-bitfields). */ +const char * +gpgme_check_version_internal (const char *req_version, + size_t offset_sig_validity) +{ + char *result; + + TRACE2 (DEBUG_INIT, "gpgme_check_version_internal: ", 0, + "req_version=%s, offset_sig_validity=%i", + req_version ? req_version : "(null)", offset_sig_validity); + + result = gpgme_check_version (req_version); + if (result == NULL) + return result; + + if (offset_sig_validity != offsetof (struct _gpgme_signature, validity)) + { + TRACE1 (DEBUG_INIT, "gpgme_check_version_internal: ", 0, + "offset_sig_validity mismatch: expected %i", + offsetof (struct _gpgme_signature, validity)); + _gpgme_selftest = GPG_ERR_SELFTEST_FAILED; + } + + return result; } |