From 2399827bfa1062c7f782499e6dcd9f988318d422 Mon Sep 17 00:00:00 2001 From: Nick Alcock Date: Mon, 8 Jun 2020 09:24:01 +0100 Subject: libctf: add ctf_ref 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. --- libctf/ChangeLog | 5 +++++ libctf/ctf-open.c | 11 +++++++++++ libctf/libctf.ver | 1 + 3 files changed, 17 insertions(+) (limited to 'libctf') diff --git a/libctf/ChangeLog b/libctf/ChangeLog index c22cba0..84f82fa 100644 --- a/libctf/ChangeLog +++ b/libctf/ChangeLog @@ -1,5 +1,10 @@ 2020-07-22 Nick Alcock + * libctf.ver (ctf_ref): New. + * ctf-open.c (ctf_ref): Implement it. + +2020-07-22 Nick Alcock + * ctf-inlines.h (ctf_forwardable_kind): New. * ctf-create.c (ctf_add_forward): Use it. diff --git a/libctf/ctf-open.c b/libctf/ctf-open.c index 05672f3..b7846bd 100644 --- a/libctf/ctf-open.c +++ b/libctf/ctf-open.c @@ -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 diff --git a/libctf/libctf.ver b/libctf/libctf.ver index 375dee8..93616d8 100644 --- a/libctf/libctf.ver +++ b/libctf/libctf.ver @@ -24,6 +24,7 @@ LIBCTF_1.0 { ctf_simple_open; ctf_create; ctf_close; + ctf_ref; ctf_file_close; ctf_cuname; -- cgit v1.1