[webkit-dev] Naming singletons
Ryosuke Niwa
rniwa at apple.com
Fri Sep 13 14:41:33 PDT 2024
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20240913/b5e3582e/attachment.htm>
More information about the webkit-dev
mailing list