[Webkit-unassigned] [Bug 281667] New: [GTK][WPE] Use std::array to store GObject signal and property identifiers

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu Oct 17 07:19:03 PDT 2024


https://bugs.webkit.org/show_bug.cgi?id=281667

            Bug ID: 281667
           Summary: [GTK][WPE] Use std::array to store GObject signal and
                    property identifiers
           Product: WebKit
           Version: Other
          Hardware: Unspecified
                OS: Unspecified
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: WPE WebKit
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: aperez at igalia.com
                CC: bugs-noreply at webkitgtk.org

As per the usual GObject practice, we use the following C-ism when defining
identifiers for object signals and properties, and to store their identifiers
(an “unsigned int” for signals, and a “GParamSpec* for properties):

  enum {
    PROP_0,
    PROP_FOO,
    PROP_BAR,
    N_PROPERTIES
  };

  static GParamSpec *sObjProperties[N_PROPERTIES] = { nullptr, };

Then, the sObjProperties array is subscripted in the class initializer at the
moment properties (or signals) are created and installed in the class:

  sObjProperties[PROP_FOO] = g_param_spec_...( ... );
  sObjProperties[PROP_BAR] = g_param_spec_...( ... );

  g_object_class_install_properties(objectClass, N_PROPERTIES, sObjProperties);

Also, notifying of property changes (or signal emission) would index the array
as well:

  g_object_notify_by_pspec(objectInstance, sObjProperties[PROP_FOO]);

In both cases this is doing array indexing without bounds checking. We can use
e.g. std::array<GParamSpec*, N_PROPERTIES> in such cases, and reduce the usage
of WTF_ALLOW_UNSAFE_BUFFER_USAGE_{BEGIN,END}.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20241017/7d98b05e/attachment.htm>


More information about the webkit-unassigned mailing list