Commit 61d76753 authored by Raul Tambre's avatar Raul Tambre Committed by Commit Bot

mojo: Fix sorting None ordinals in Python 3

None is comparable in Python 2, but not in Python 3.
None compares less than anything else, including empty strings, on Python 2.

Emulate this behaviour for compatibility with Python 3 by returning an empty string if the ordinal is None.
The code fortunately doesn't seem to rely on the very special None sorting.

Traceback (most recent call last):
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 556, in <module>
    sys.exit(main())
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 551, in main
    return args.func(args, remaining_args)
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 267, in _Generate
    processor._GenerateModule(args, remaining_args, generator_modules,
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 199, in _GenerateModule
    imports[parsed_imp.import_filename] = self._GenerateModule(
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 199, in _GenerateModule
    imports[parsed_imp.import_filename] = self._GenerateModule(
  File "../../mojo/public/tools/bindings/mojom_bindings_generator.py", line 238, in _GenerateModule
    generator.GenerateFiles(filtered_args)
  File "C:\Google\chromium\src\mojo\public\tools\bindings\generators\mojom_cpp_generator.py", line 474, in GenerateFiles
    self.WriteWithComment(self._GenerateModuleHeader(),
  File "C:\Google\chromium\src\mojo\public\tools\bindings\pylib\mojom\generate\template_expander.py", line 38, in GeneratorInternal
    return ApplyTemplate(args[0], path_to_template, parameters, **kwargs)
  File "C:\Google\chromium\src\mojo\public\tools\bindings\pylib\mojom\generate\template_expander.py", line 31, in ApplyTemplate
    return template.render(params)
  File "C:\Google\chromium\src\mojo\public\tools\bindings\pylib\mojom\generate\..\..\..\..\..\..\..\third_party\jinja2\asyncsupport.py", line 76, in render
    return original_render(self, *args, **kwargs)
  File "C:\Google\chromium\src\mojo\public\tools\bindings\pylib\mojom\generate\..\..\..\..\..\..\..\third_party\jinja2\environment.py", line 1008, in render
    return self.environment.handle_exception(exc_info, True)
  File "C:\Google\chromium\src\mojo\public\tools\bindings\pylib\mojom\generate\..\..\..\..\..\..\..\third_party\jinja2\environment.py", line 780, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "C:\Google\chromium\src\mojo\public\tools\bindings\pylib\mojom\generate\..\..\..\..\..\..\..\third_party\jinja2\_compat.py", line 37, in reraise
    raise value.with_traceback(tb)
  File "gen\mojo\public\tools\bindings\cpp_templates.zip\tmpl_4b4c750a11f14c4ee990ca69a07408825b11d62d.py", line 179, in <module>
  File "gen\mojo\public\tools\bindings\cpp_templates.zip\tmpl_3cfd1c143e820f5d5f5c850420142fd64dfa3890.py", line 39, in <module>
  File "C:\Google\chromium\src\mojo\public\tools\bindings\generators\mojom_cpp_generator.py", line 878, in _GetStructConstructors
    ordinal_fields = sorted(struct.fields, key=lambda field: field.ordinal)
TypeError: '<' not supported between instances of 'NoneType' and 'NoneType'

Bug: 941669
Change-Id: Id659a362fb5f3c56163b8164766d3f6963960c4b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2044080
Commit-Queue: Raul Tambre <raul@tambre.ee>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#740326}
parent a6a32d5e
......@@ -896,7 +896,8 @@ class Generator(generator.Generator):
if param_counts[-1] != version.num_fields:
param_counts.append(version.num_fields)
ordinal_fields = sorted(struct.fields, key=lambda field: field.ordinal)
ordinal_fields = sorted(
struct.fields, key=lambda field: field.ordinal or "")
return (StructConstructor(struct.fields, ordinal_fields[:param_count])
for param_count in param_counts)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment