[webkit-dev] Stop Using Raw Pointers & References in New Code
Alicia Boya García
aboya at igalia.com
Tue Jan 24 05:30:08 PST 2023
On 12/01/2023 06.21, Ryosuke Niwa via webkit-dev wrote:
> I suggest we *stop using raw pointers and references in any local or
> heap stored variable*.
I don't think this is feasible for code using non-WebKit libraries, and
would expect it to not apply to such cases.
For instance, many GLib and GStreamer objects are refcounted, and we
even have smart pointers for them in WebKit: GRefPtr, which refs/unref
using RAII, and GUniquePtr, which frees GLib non-refcounted objects.
We use both GRefPtr/GUniquePtr and raw pointers, but the meaning of each
GRefPtr and GUniquePtr mean the code owns a reference, and will
unref/free when the variable goes out of scope. Raw pointer means the
code is borrowing a reference. The code will do something with the
object, then leave it, without establishing ownership of a reference to
it. This is especially the case for const raw pointers, which you are
meant to use within scope and are not allowed to free() them, as you are
just borrowing them.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the webkit-dev