<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>281667</bug_id>
          
          <creation_ts>2024-10-17 07:19:03 -0700</creation_ts>
          <short_desc>[GTK][WPE] Use std::array to store GObject signal and property identifiers</short_desc>
          <delta_ts>2024-10-25 07:45:07 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WPE WebKit</component>
          <version>Other</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=282095</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>281571</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Adrian Perez">aperez</reporter>
          <assigned_to name="Adrian Perez">aperez</assigned_to>
          <cc>bugs-noreply</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2068761</commentid>
    <comment_count>0</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2024-10-17 07:19:03 -0700</bug_when>
    <thetext>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&lt;GParamSpec*, N_PROPERTIES&gt; in such cases, and reduce the usage
of WTF_ALLOW_UNSAFE_BUFFER_USAGE_{BEGIN,END}.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2068762</commentid>
    <comment_count>1</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2024-10-17 07:20:18 -0700</bug_when>
    <thetext>While there are possibilities of making the signals/properties mechanism
more idiomatic and have better type checking (maybe using EnumTraits),
this issue is only about removing unsafe buffer uses.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2068773</commentid>
    <comment_count>2</comment_count>
    <who name="Adrian Perez">aperez</who>
    <bug_when>2024-10-17 08:00:41 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/35361</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2069108</commentid>
    <comment_count>3</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-10-18 07:18:53 -0700</bug_when>
    <thetext>Committed 285400@main (9d3358a6d868): &lt;https://commits.webkit.org/285400@main&gt;

Reviewed commits have been landed. Closing PR #35361 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>