libctf: add ctf_ref
authorNick Alcock <nick.alcock@oracle.com>
Mon, 8 Jun 2020 08:24:01 +0000 (09:24 +0100)
committerNick Alcock <nick.alcock@oracle.com>
Wed, 22 Jul 2020 16:57:49 +0000 (17:57 +0100)
This allows you to bump the refcount on a ctf_file_t, so that you can
smuggle it out of iterators which open and close the ctf_file_t for you
around the loop body (like ctf_archive_iter).

You still can't use this to preserve a ctf_file_t for longer than the
lifetime of its containing entity (e.g. ctf_archive).

include/
* ctf-api.h (ctf_ref): New.
libctf/
* libctf.ver (ctf_ref): New.
* ctf-open.c (ctf_ref): Implement it.

include/ChangeLog
include/ctf-api.h
libctf/ChangeLog
libctf/ctf-open.c
libctf/libctf.ver

index dd9d5e075ca2fcbb780529a493c4f9c2b92e39f2..3e3bb0a7d4fbf3d58ce19edf24b5b9599734cce9 100644 (file)
@@ -1,3 +1,7 @@
+2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
+
+       * ctf-api.h (ctf_ref): New.
+
 2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-api.h (ctf_archive_count): New.
index fb797a3346db33cb6b91be38933991d2acfce652..faa7b727fb8d78e23bf72ffd7d73c95bd918700f 100644 (file)
@@ -285,6 +285,7 @@ extern ctf_file_t *ctf_simple_open (const char *, size_t, const char *, size_t,
                                   size_t, const char *, size_t, int *);
 extern ctf_file_t *ctf_bufopen (const ctf_sect_t *, const ctf_sect_t *,
                                const ctf_sect_t *, int *);
+extern void ctf_ref (ctf_file_t *);
 extern void ctf_file_close (ctf_file_t *);
 
 extern int ctf_arc_write (const char *, ctf_file_t **, size_t,
index c22cba0d84a257adf4397db1d8b3ec989dad6bc1..84f82fa9a41104f6b744b2307200e5e1893170b8 100644 (file)
@@ -1,3 +1,8 @@
+2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
+
+       * libctf.ver (ctf_ref): New.
+       * ctf-open.c (ctf_ref): Implement it.
+
 2020-07-22  Nick Alcock  <nick.alcock@oracle.com>
 
        * ctf-inlines.h (ctf_forwardable_kind): New.
index 05672f36498b64e9f27cf31e3706380ecb7e54b1..b7846bd001473bd9889ee2a293fecd36be64e578 100644 (file)
@@ -1620,6 +1620,17 @@ bad:
   return NULL;
 }
 
+/* Bump the refcount on the specified CTF container, to allow export of
+   ctf_file_t's from iterators that open and close the ctf_file_t around the
+   loop.  (This does not extend their lifetime beyond that of the ctf_archive_t
+   in which they are contained.)  */
+
+void
+ctf_ref (ctf_file_t *fp)
+{
+  fp->ctf_refcnt++;
+}
+
 /* Close the specified CTF container and free associated data structures.  Note
    that ctf_file_close() is a reference counted operation: if the specified file
    is the parent of other active containers, its reference count will be greater
index 375dee8fc770a8fe03ccee40b6fc6b0adaa17f46..93616d83691dacc6e19c80d29371530109cc85bb 100644 (file)
@@ -24,6 +24,7 @@ LIBCTF_1.0 {
        ctf_simple_open;
        ctf_create;
        ctf_close;
+       ctf_ref;
        ctf_file_close;
 
        ctf_cuname;
This page took 0.028144 seconds and 4 git commands to generate.