From 92883efe7176c2022e25e913c1d2f40c35a0754a Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 7 Jun 2019 12:10:40 +0200 Subject: core: Introduce a context serial number. * src/context.h: Include stdint.h. (struct gpgme_context): Add field 'serial'. (CTXSERIAL): New. * src/gpgme.c: (last_ctx_serial): New. (gpgme_new): Set serial. * src/gpgme.c: Change trace calls to use the serial. * src/wait.c (_gpgme_add_io_cb): Ditto (_gpgme_remove_io_cb): Ditto. Signed-off-by: Werner Koch --- src/context.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/context.h') diff --git a/src/context.h b/src/context.h index d65bf9b5..076d0731 100644 --- a/src/context.h +++ b/src/context.h @@ -21,6 +21,8 @@ #ifndef CONTEXT_H #define CONTEXT_H +#include + #include "gpgme.h" #include "engine.h" #include "wait.h" @@ -78,6 +80,12 @@ struct gpgme_context { DECLARE_LOCK (lock); + /* The unique serial number of this context object. This is used + * for a weak reference of the context. Using the address of the + * context is not always possible becuase it might have already been + * freed and reused. */ + uint64_t serial; + /* True if the context was canceled asynchronously. */ int canceled; @@ -186,4 +194,9 @@ struct gpgme_context struct gpgme_io_cbs io_cbs; }; + +/* Macro to retrieve the serial number. Returns 0 if CTX is NULL. */ +#define CTXSERIAL(ctx) (ctx? (unsigned long)ctx->serial : 0) + + #endif /* CONTEXT_H */ -- cgit