[waffle] [PATCH 02/11] core: Define intptr_t variants of wcore_attrib_list functions

Chad Versace chad.versace at intel.com
Mon Dec 22 16:53:58 PST 2014


On 12/21/2014 08:22 AM, Emil Velikov wrote:
> On 16 December 2014 at 08:18, Chad Versace <chad.versace at linux.intel.com> wrote:
>> When designing the original Waffle 1.0 API, I made a mistake when
>> I chose to declare attribute lists as arrays of int32_t. Instead, they
>> should have been arrays of intptr_t.
>>
>> A new public function, waffle_window_create2, will have a `const
>> intptr_t attrib_list[]` parameter. Therefore waffle needs intptr_t
>> variants of the wcore_attrib_list functions.
>>
>> Signed-off-by: Chad Versace <chad.versace at linux.intel.com>
>> ---
>>  src/waffle/core/wcore_attrib_list.c | 73 +++++++++++++++++++++++++++++++++++++
>>  src/waffle/core/wcore_attrib_list.h | 23 ++++++++++++
>>  2 files changed, 96 insertions(+)
>>
>> diff --git a/src/waffle/core/wcore_attrib_list.c b/src/waffle/core/wcore_attrib_list.c
>> index 09a4dec..a7f087d 100644
>> --- a/src/waffle/core/wcore_attrib_list.c
>> +++ b/src/waffle/core/wcore_attrib_list.c
>> @@ -29,6 +29,79 @@
>>  #include <stdint.h>
>>  #include <stddef.h>
>>
>> +size_t
>> +wcore_attrib_list_length(const intptr_t attrib_list[])
>> +{
>> +    const intptr_t *i = attrib_list;
>> +
>> +    if (attrib_list == NULL)
>> +        return 0;
>> +
>> +    while (*i != 0)
>> +        i += 2;
>> +
>> +    return (i - attrib_list) / 2;
> Guessing that 2 is meant sizeof(intptr_t). If so can we use it ?
> Similar request for the other 2's in this patch.

The factor of 2 is a common idiom when parsing data structures like
this attribute list. For example, see http://cgit.freedesktop.org/mesa/mesa/tree/src/egl/main/eglconfig.c?id=mesa-10.4.0#n520
and http://cgit.freedesktop.org/mesa/mesa/tree/src/glx/glxext.c?id=mesa-10.4.0#n397

The 2 is there because elements always come in (key, value) pairs like this:

   {
      key1, val1,
      key2, val2,
      key3, val3,
      ...., ....,
      sentinel,
    }

Hmmm... maybe I need to add a little comment explaining that.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 884 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freedesktop.org/archives/waffle/attachments/20141222/01c177b9/attachment.sig>


More information about the waffle mailing list