[webkit-dev] Naming singletons

Chris Dumez cdumez at apple.com
Fri Sep 13 14:47:24 PDT 2024


Happens to match our coding style already: https://webkit.org/code-style-guidelines/#singleton-static-member

> On Sep 13, 2024, at 2:41 PM, Ryosuke Niwa via webkit-dev <webkit-dev at lists.webkit.org> wrote:
> 
> Hi all,
> 
> TL; DR: Add “Singleton” suffix to a function which returns a singleton to help aid WebKit static analyzers.
> 
> It’s fairly common for some classes to provide a static member function which returns a singleton. Such a function typically holds NeverDestroyed instance of an object and it’s safe to call any mutating member functions on it without locally storing Ref/RefPtr/CheckedRef/CheckedPtr.
> 
> Unfortunately, this poses a challenge for WebKit static analyzers which enforces safe smart pointer usage because the static analyzers can’t differentiate a static function which returns a singleton and a static function which returns a non-singleton instance of an object. For this reason, I suggest we start suffixing the name of each function which returns a singleton with “Singleton” e.g. IOSurfacePool::sharedPoolSingleton instead of IOSurfacePool::sharedPool. This will help aid static analyzers to identify a function which returns a singleton and not generate superfluous warnings for it.
> 
> - R. Niwa
> 
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20240913/1c00a97f/attachment.htm>


More information about the webkit-dev mailing list