aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcus Brinkmann <[email protected]>2009-06-15 17:05:47 +0000
committerMarcus Brinkmann <[email protected]>2009-06-15 17:05:47 +0000
commit59eecf421e42cb929794f31e6387dbfb5b6a543b (patch)
tree6cd59c2639f6a81fb1a998b871b571a21e23fc27
parentImproved W32 SetForegroundWindow hacks. (diff)
downloadgpgme-59eecf421e42cb929794f31e6387dbfb5b6a543b.tar.gz
gpgme-59eecf421e42cb929794f31e6387dbfb5b6a543b.zip
2009-06-15 Marcus Brinkmann <[email protected]>
* gpgme.h.in (gpgme_result_ref, gpgme_result_unref): Add prototypes. * gpgme.def, libgpgme.vers (gpgme_result_ref, gpgme_result_unref): Add these. * context.h (struct ctx_op_data): Add member "references". * gpgme.c (gpgme_result_ref, gpgme_result_unref): New functions. (_gpgme_release_result): Use gpgme_result_unref. * op-support.c (_gpgme_op_data_lookup): Initialize references.
Diffstat (limited to '')
-rw-r--r--src/ChangeLog11
-rw-r--r--src/context.h5
-rw-r--r--src/gpgme.c36
-rw-r--r--src/gpgme.def2
-rw-r--r--src/gpgme.h.in4
-rw-r--r--src/libgpgme.vers4
-rw-r--r--src/op-support.c1
7 files changed, 57 insertions, 6 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index db21dc4b..35622ee6 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,14 @@
+2009-06-15 Marcus Brinkmann <[email protected]>
+
+ * gpgme.h.in (gpgme_result_ref, gpgme_result_unref): Add
+ prototypes.
+ * gpgme.def, libgpgme.vers (gpgme_result_ref, gpgme_result_unref):
+ Add these.
+ * context.h (struct ctx_op_data): Add member "references".
+ * gpgme.c (gpgme_result_ref, gpgme_result_unref): New functions.
+ (_gpgme_release_result): Use gpgme_result_unref.
+ * op-support.c (_gpgme_op_data_lookup): Initialize references.
+
2009-06-12 Werner Koch <[email protected]>
* gpgme-w32spawn.c (translate_get_from_file): Parse optional spawn
diff --git a/src/context.h b/src/context.h
index 472b8beb..63af1d10 100644
--- a/src/context.h
+++ b/src/context.h
@@ -45,7 +45,7 @@ typedef enum
struct ctx_op_data
{
/* The next element in the linked list, or NULL if this is the last
- element. */
+ element. Used by op data structures linked into a context. */
struct ctx_op_data *next;
/* The type of the hook data, which can be used by a routine to
@@ -58,6 +58,9 @@ struct ctx_op_data
/* The hook that points to the operation data. */
void *hook;
+
+ /* The number of outstanding references. */
+ int references;
};
typedef struct ctx_op_data *ctx_op_data_t;
diff --git a/src/gpgme.c b/src/gpgme.c
index 203cd711..2372a06a 100644
--- a/src/gpgme.c
+++ b/src/gpgme.c
@@ -176,6 +176,35 @@ gpgme_release (gpgme_ctx_t ctx)
void
+gpgme_result_ref (void *result)
+{
+ struct ctx_op_data *data = result - sizeof (struct ctx_op_data);
+
+ if (! result)
+ return;
+
+ data->references++;
+}
+
+
+void
+gpgme_result_unref (void *result)
+{
+ struct ctx_op_data *data = result - sizeof (struct ctx_op_data);
+
+ if (! result)
+ return;
+
+ if (--data->references == 0)
+ {
+ if (data->cleanup)
+ (*data->cleanup) (data->hook);
+ free (data);
+ }
+}
+
+
+void
_gpgme_release_result (gpgme_ctx_t ctx)
{
struct ctx_op_data *data = ctx->op_data;
@@ -183,9 +212,8 @@ _gpgme_release_result (gpgme_ctx_t ctx)
while (data)
{
struct ctx_op_data *next_data = data->next;
- if (data->cleanup)
- (*data->cleanup) (data->hook);
- free (data);
+ data->next = NULL;
+ gpgme_result_unref (data->hook);
data = next_data;
}
ctx->op_data = NULL;
@@ -430,7 +458,7 @@ gpgme_set_io_cbs (gpgme_ctx_t ctx, gpgme_io_cbs_t io_cbs)
/* This function provides access to the internal read function; it is
- normally not used. */
+ normally not used. */
ssize_t
gpgme_io_read (int fd, void *buffer, size_t count)
{
diff --git a/src/gpgme.def b/src/gpgme.def
index b1969ea9..9bc95d00 100644
--- a/src/gpgme.def
+++ b/src/gpgme.def
@@ -177,6 +177,8 @@ EXPORTS
gpgme_io_read @136
gpgme_io_write @137
+ gpgme_release_ref @138
+ gpgme_release_unref @139
; END
diff --git a/src/gpgme.h.in b/src/gpgme.h.in
index 46f8769c..8e224a47 100644
--- a/src/gpgme.h.in
+++ b/src/gpgme.h.in
@@ -1934,6 +1934,10 @@ gpgme_error_t gpgme_set_engine_info (gpgme_protocol_t proto,
gpgme_error_t gpgme_engine_check_version (gpgme_protocol_t proto);
+void gpgme_result_ref (void *result);
+void gpgme_result_unref (void *result);
+
+
/* Deprecated types. */
typedef gpgme_ctx_t GpgmeCtx _GPGME_DEPRECATED;
typedef gpgme_data_t GpgmeData _GPGME_DEPRECATED;
diff --git a/src/libgpgme.vers b/src/libgpgme.vers
index fe32392b..44f61760 100644
--- a/src/libgpgme.vers
+++ b/src/libgpgme.vers
@@ -56,7 +56,9 @@ GPGME_1.1 {
gpgme_io_read;
gpgme_io_write;
-
+
+ gpgme_result_ref;
+ gpgme_result_unref;
};
diff --git a/src/op-support.c b/src/op-support.c
index fefccc67..19b24205 100644
--- a/src/op-support.c
+++ b/src/op-support.c
@@ -52,6 +52,7 @@ _gpgme_op_data_lookup (gpgme_ctx_t ctx, ctx_op_data_id_t type, void **hook,
data->type = type;
data->cleanup = cleanup;
data->hook = (void *) (((char *) data) + sizeof (struct ctx_op_data));
+ data->references = 1;
ctx->op_data = data;
}
*hook = data->hook;