On Mon, 14 Aug 2023 at 21:23, Richard Fitzgerald
<rf@xxxxxxxxxxxxxxxxxxxxx> wrote:
Re-work string_stream so that it is not tied to a struct kunit. This is
to allow using it for the log of struct kunit_suite.
Instead of resource-managing individual allocations the whole string_stream
object can be resource-managed as a single object:
alloc_string_stream() API is unchanged and takes a pointer to a
struct kunit but it now registers the returned string_stream object to
be resource-managed.
raw_alloc_string_stream() is a new function that allocates a
bare string_stream without any association to a struct kunit.
free_string_stream() is a new function that frees a resource-managed
string_stream allocated by alloc_string_stream().
raw_free_string_stream() is a new function that frees a non-managed
string_stream allocated by raw_alloc_string_stream().
The confusing function string_stream_destroy() has been removed. This only
called string_stream_clear() but didn't free the struct string_stream.
Instead string_stream_clear() has been exported, and the new functions use
the more conventional naming of "free" as the opposite of "alloc".
Signed-off-by: Richard Fitzgerald <rf@xxxxxxxxxxxxxxxxxxxxx>
---
I'm in favour of this. Should we go further and get rid of the struct
kunit member from string_stream totally?
Also, note that the kunit_action_t casting is causing warnings on some
clang configs (and technically isn't valid C). Personally, I still
like it, but expect more emails from the kernel test robot and others.