[webkit-dev] Stop Using Raw Pointers & References in New Code
Ryosuke Niwa
rniwa at apple.com
Thu Jan 12 18:34:54 PST 2023
> On Jan 12, 2023, at 1:27 PM, Darin Adler <darin at apple.com> wrote:
>
>> On Jan 12, 2023, at 3:35 PM, Ryosuke Niwa via webkit-dev <webkit-dev at lists.webkit.org> wrote:
>>
>>> On Jan 12, 2023, at 6:13 AM, Darin Adler <darin at apple.com> wrote:
>>>
>>>> On Jan 12, 2023, at 12:21 AM, Ryosuke Niwa via webkit-dev <webkit-dev at lists.webkit.org> wrote:
>>>>
>>>> assuming every local variable / variable in stack is stored in a smart pointer, function arguments are safe to be raw pointers / references via transitive property
>>>
>>> What about the case where the function argument is the return value from another function?
>>
>> In those cases, the value should be stored in a local variable using a smart pointer first.
>>
>> So… instead of:
>> foo(bar());
>>
>> do:
>> foo(RefPtr { bar() }.get());
>
> This seems impractical. How will I remember to do this?
The smart pointer analysis tool I've been working with the clang team should be able to tell you that once it becomes available. Until then, we probably need to rely on reviewers to notice these patterns.
One alternative is to make bar() return RefPtr although that would be a bit heavy handed in the case of trivial function calls like this: document().frame()->ownerElement()
- R. Niwa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20230112/47ad1f49/attachment.htm>
More information about the webkit-dev
mailing list