Skip to content

Commit

Permalink
Documentation: document difference between release and free
Browse files Browse the repository at this point in the history
We semi-regularly have discussions around whether a function shall be
named `release()` or `free()`. For most of the part we use these two
terminologies quite consistently though:

  - `release()` only frees internal state of a structure, whereas the
    structure itself is not free'd.

  - `free()` frees both internal state and the structure itself.

Carve out a space where we can add idiomatic names for common functions
in our coding guidelines. This space can get extended in the future when
we feel the need to document more idiomatic names.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
pks-t authored and gitster committed Jul 24, 2024
1 parent 6f075bc commit 56cb070
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions Documentation/CodingGuidelines
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,18 @@ For C programs:

void reset_strbuf(struct strbuf *buf);

- There are several common idiomatic names for functions performing
specific tasks on structures:

- `<struct>_init()` initializes a structure without allocating the
structure itself.

- `<struct>_release()` releases a structure's contents without
freeing the structure.

- `<struct>_free()` releases a structure's contents and frees the
structure.

For Perl programs:

- Most of the C guidelines above apply.
Expand Down

0 comments on commit 56cb070

Please sign in to comment.