Skip to content

Commit 8e09d90

Browse files
davidbenagl
authored andcommitted
Clarify "reference" and fix typo.
It was pointed out that "a reference" to C++ programmers means something very different from what we intend. Change-Id: I508196f8e3427ea71439c7871eae9b735a4fa5ca Reviewed-on: https://boringssl-review.googlesource.com/31544 Reviewed-by: Adam Langley <[email protected]>
1 parent 8cd61f7 commit 8e09d90

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

API-CONVENTIONS.md

+14-9
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,14 @@ used freely without special cleanup conventions.
182182

183183
When working with allocated objects, it is important to think about *ownership*
184184
of each object, or what code is responsible for releasing it. This matches the
185-
corresponding notion in higher-level languages like C++ and Rust. Ownership
186-
applies to both uniquely-owned types and reference-counted types. For the
187-
latter, ownership means the code is responsible for releasing one reference.
185+
corresponding notion in higher-level languages like C++ and Rust.
186+
187+
Ownership applies to both uniquely-owned types and reference-counted types. For
188+
the latter, ownership means the code is responsible for releasing one
189+
reference. Note a *reference* in BoringSSL refers to an increment (and eventual
190+
decrement) of an object's reference count, not `T&` in C++. Thus, to "take a
191+
reference" means to increment the reference count and take ownership of
192+
decrementing it.
188193

189194
As BoringSSL's APIs are primarily in C, ownership and lifetime obligations are
190195
not rigorously annotated in the type signatures or checked at compile-time.
@@ -217,12 +222,12 @@ sooner on state change in the parent object.
217222
If documented to output a *newly-allocated* object or a *reference* or *copy* of
218223
one, the caller is responsible for releasing the object when it is done.
219224

220-
By convention, functions named `get0` return non-owning pointers. Functions name
221-
`new` or `get1` return owning pointers. Functions named `set0` take ownership of
222-
arguments. Functions named `set1` do not. They typically take a reference or
223-
make a copy internally. These names originally referred to the effect on a
224-
reference count, but the convention applies equally to non-reference-counted
225-
types.
225+
By convention, functions named `get0` return non-owning pointers. Functions
226+
named `new` or `get1` return owning pointers. Functions named `set0` take
227+
ownership of arguments. Functions named `set1` do not. They typically take a
228+
reference or make a copy internally. These names originally referred to the
229+
effect on a reference count, but the convention applies equally to
230+
non-reference-counted types.
226231

227232
API documentation may also describe more complex obligations. For instance, an
228233
object may borrow a pointer for longer than the duration of a single function

0 commit comments

Comments
 (0)