[Swan-dev] naming of functions that return something

Andrew Cagney andrew.cagney at gmail.com
Fri Jun 25 14:21:01 UTC 2021

On Sat, 8 May 2021 at 17:50, Andrew Cagney <andrew.cagney at gmail.com> wrote:

>>   extern pb_stream same_chunk_as_in_pbs(chunk_t chunk, const char *name);
> It should be renamed to:
>   struct pbs_in chunk_as_pbs_in(chunk_t)
> or
>   struct pbs_in same_chunk_as_pbs_in(chunk_t)

I went through and updated the names.  Hopefully pbs_in and pbs_out are
used consistently.

The convention {same,clone}_<foo>_as_<blah>() came out of an earlier
discussion.  Because it was never really obvious if the handle being
returned was referring to the same or a clone of the buffer, it was spelt

This buffer sharing is also why <blah>_from_<foo>() struggled.  For
addresses, functions are pure so:
is pretty clear.  Not so when there's an underlying buffer.  While
technically shunk_from_pbs_out() has to return the same buffer (since a
shunk can't be freed it must be shared, right), chunk_from_pbs_out() feels
like it returned a clone ...., and chunk_for_pbs_out() makes me wonder if
I'm feeding the pbs chocolate chunk cookies.

On the bright side, it looks like same_pbs_out_as_chunk() can be eliminated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.libreswan.org/pipermail/swan-dev/attachments/20210625/b9d91cd6/attachment.html>

More information about the Swan-dev mailing list