[Mesa-dev] [PATCH 09/41] glapi: fix singleton comparisons to use 'is' in python

Ian Romanick idr at freedesktop.org
Tue Apr 19 21:51:55 UTC 2016


This patch is

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

On 03/31/2016 05:04 PM, Dylan Baker wrote:
> Python has two equality comparitors, 'is' and '=='. The difference is
> that 'is' determines whether instance A *is* instance B, while '=='
> determines if instance A *has the same value as* instance B.
> 
> Comparisons with singletons (the notable ones being None, True, and
> False) should always by done with 'is', basically everything else should
> always be done with '=='.
> 
> Signed-off-by: Dylan Baker <dylanx.c.baker at intel.com>
> ---
>  src/mapi/glapi/gen/glX_XML.py          | 2 +-
>  src/mapi/glapi/gen/glX_proto_send.py   | 8 ++++----
>  src/mapi/glapi/gen/glX_proto_size.py   | 6 +++---
>  src/mapi/glapi/gen/glX_server_table.py | 2 +-
>  src/mapi/glapi/gen/gl_XML.py           | 2 +-
>  5 files changed, 10 insertions(+), 10 deletions(-)
> 
> diff --git a/src/mapi/glapi/gen/glX_XML.py b/src/mapi/glapi/gen/glX_XML.py
> index 9090b76..580a241 100644
> --- a/src/mapi/glapi/gen/glX_XML.py
> +++ b/src/mapi/glapi/gen/glX_XML.py
> @@ -391,7 +391,7 @@ class glx_function(gl_XML.gl_function):
>          name of the equivalent vector (e.g., glVertex3fv for
>          glVertex3f) function."""
>  
> -        if self.vectorequiv == None:
> +        if self.vectorequiv is None:
>              return self.name
>          else:
>              return self.vectorequiv
> diff --git a/src/mapi/glapi/gen/glX_proto_send.py b/src/mapi/glapi/gen/glX_proto_send.py
> index 8a656c5..9dcffa6 100644
> --- a/src/mapi/glapi/gen/glX_proto_send.py
> +++ b/src/mapi/glapi/gen/glX_proto_send.py
> @@ -111,14 +111,14 @@ class glx_pixel_function_stub(glX_XML.glx_function):
>                  self.images.append(p)
>                  p.height = "height"
>  
> -                if p.img_yoff == None:
> +                if p.img_yoff is None:
>                      p.img_yoff = "yoffset"
>  
>                  if p.depth:
> -                    if p.extent == None:
> +                    if p.extent is None:
>                          p.extent = "extent"
>  
> -                    if p.img_woff == None:
> +                    if p.img_woff is None:
>                          p.img_woff = "woffset"
>  
>              pad_name = func.pad_after(p)
> @@ -845,7 +845,7 @@ class PrintGlxProtoStubs(glX_proto_common.glx_print_proto):
>          # of them, special case them with generic functions.  On
>          # x86, this saves about 26KB in the libGL.so binary.
>  
> -        if f.variable_length_parameter() == None and len(f.parameters) == 1:
> +        if f.variable_length_parameter() is None and len(f.parameters) == 1:
>              p = f.parameters[0]
>              if p.is_pointer():
>                  cmdlen = f.command_fixed_length()
> diff --git a/src/mapi/glapi/gen/glX_proto_size.py b/src/mapi/glapi/gen/glX_proto_size.py
> index d499294..c157c00 100644
> --- a/src/mapi/glapi/gen/glX_proto_size.py
> +++ b/src/mapi/glapi/gen/glX_proto_size.py
> @@ -91,10 +91,10 @@ class glx_enum_function(object):
>                      self.count[count].append(e.value)
>  
>      def signature(self):
> -        if self.sig == None:
> +        if self.sig is None:
>              self.sig = ""
>              for i in self.count:
> -                if i == None:
> +                if i is None:
>                      raise RuntimeError("i is None.  WTF?")
>  
>                  self.count[i].sort()
> @@ -237,7 +237,7 @@ class glx_server_enum_function(glx_enum_function):
>          self.function = func
>  
>      def signature(self):
> -        if self.sig == None:
> +        if self.sig is None:
>              sig = glx_enum_function.signature(self)
>  
>              p = self.function.variable_length_parameter()
> diff --git a/src/mapi/glapi/gen/glX_server_table.py b/src/mapi/glapi/gen/glX_server_table.py
> index 9d55426..880ab87 100644
> --- a/src/mapi/glapi/gen/glX_server_table.py
> +++ b/src/mapi/glapi/gen/glX_server_table.py
> @@ -355,7 +355,7 @@ class PrintGlxDispatchTables(glX_proto_common.glx_print_proto):
>  
>      def printBody(self, api):
>          for f in api.functionIterateAll():
> -            if not f.ignore and f.vectorequiv == None:
> +            if not f.ignore and f.vectorequiv is None:
>                  if f.glx_rop != 0:
>                      self.rop_functions.append(f.glx_rop, f)
>                  if f.glx_sop != 0:
> diff --git a/src/mapi/glapi/gen/gl_XML.py b/src/mapi/glapi/gen/gl_XML.py
> index b1f8ecc..f857ad6 100644
> --- a/src/mapi/glapi/gen/gl_XML.py
> +++ b/src/mapi/glapi/gen/gl_XML.py
> @@ -914,7 +914,7 @@ class gl_api(object):
>          for func in self.functionIterateAll():
>              [cat_name, cat_number] = self.category_dict[func.name]
>  
> -            if (cat == None) or (cat == cat_name):
> +            if cat is None or cat == cat_name:
>                  [func_cat_type, key] = classify_category(cat_name, cat_number)
>  
>                  if not lists[func_cat_type].has_key(key):
> 



More information about the mesa-dev mailing list