[Mesa-dev] [PATCH mesa 2/2] mapi: add asserts to enforce ordering and uniqueness

Eric Engestrom eric at engestrom.ch
Sun Sep 25 04:14:38 UTC 2016


On Sat, Sep 24, 2016 at 10:27:52PM -0400, Ilia Mirkin wrote:
> On Sat, Sep 24, 2016 at 10:17 PM, Eric Engestrom <eric at engestrom.ch> wrote:
> > Dylan Baker recently added functions to that list and had to try a couple times
> > to avoid duplicates. He said [1] he ended up testing it using:
> >   len(functions) == len(set(functions))
> > which I thought should always be done.
> >
> > Add this and a couple other tests using asserts to enforce the ordering and
> > uniqueness of the `functions` list, and the uniqueness and compactness of the
> > `offsets` dictionary.
> >
> > [1] https://lists.freedesktop.org/archives/mesa-dev/2016-September/129525.html
> >
> > Signed-off-by: Eric Engestrom <eric at engestrom.ch>
> > ---
> >
> > If people don't like enforcing the order, I'm happy to drop the previous patch
> > and send a revised version of this patch with this last assert removed.
> >
> > ---
> >  src/mapi/glapi/gen/static_data.py | 6 ++++++
> >  1 file changed, 6 insertions(+)
> >
> > diff --git a/src/mapi/glapi/gen/static_data.py b/src/mapi/glapi/gen/static_data.py
> > index bb11c1d..ef35b24 100644
> > --- a/src/mapi/glapi/gen/static_data.py
> > +++ b/src/mapi/glapi/gen/static_data.py
> > @@ -435,6 +435,9 @@ offsets = {
> >      "MultiTexCoord4sv": 407
> >  }
> >
> > +assert len(offsets) == len(set(offsets.keys())),  "The offsets dictionary contains duplicates"
> 
> set(offsets) should be enough, I think.

You are right, I'll send a v2 in a minute.

> 
> > +assert len(offsets) == max(offsets.values()) + 1, "The offsets dictionary has gaps"
> 
> offsets.itervalues()

This doesn't exist in python3 anymore, which means we'd need to explicitly
limit this script to python2. I'm not even sure how to use it, how would that
help?

> 
> > +
> >  functions = [
> >      "Accum",
> >      "ActiveShaderProgram",
> > @@ -1723,6 +1726,9 @@ functions = [
> >      "WindowPos3svARB",
> >  ]
> >
> > +assert len(functions) == len(set(functions)), "The functions list contains duplicates"
> > +assert functions == sorted(functions),        "The functions list is not sorted"
> 
> I'm surprised this passes. Functions is an array, while sorted() is,
> iirc, an iterator (or maybe a generator). Does list.__eq__ have some
> sort of special cleverness to deal with that?

Honestly, I only dabble with python. I tried this and it worked (on both
python 2 & 3), and I'm guessing underneath it iterates over the two arrays
and compares them element by elements, but that's about as much as I know.

I should've mentioned that my python skill are weak at best, and you are
welcome to suggest improvements :)

Cheers,
  Eric


More information about the mesa-dev mailing list