> On Jan 24, 2023, at 5:30 AM, Alicia Boya García via webkit-dev 
> <webkit-dev@lists.webkit.org> wrote:
> 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 is 
> different: 
> 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.
That’s also the semantics of Ref/RefPtr in WebKit. But we’re expanding the use 
of Ref/RefPtr to be beyond just owners for memory safety. I don’t see how the 
situation is any different with GRefPtr/GUniquePtr. If an explicit ownership 
isn’t appropriate, then CheckedPtr/CheckedRef should be used instead.

- R. Niwa

webkit-dev mailing list

Reply via email to