From 135b482c9dd0c5368d542bb8fe725f0d14c4e862 Mon Sep 17 00:00:00 2001 From: Yuval Tassa Date: Fri, 17 Jul 2026 10:01:47 -0700 Subject: [PATCH] Copybara import of the project: -- 7f117fa7a7060b36687e7544e8d7393d14a1fa90 by Yuval Tassa : Handle clang AST loc nodes with elided 'line' in introspect codegen. Apple's math.h (included directly by mujoco.h) contains an anonymous union whose clang-JSON 'loc' lacks the 'line' key (clang elides it when unchanged from the previous node), crashing AstProcessor._make_anonymous_key with a KeyError during bindings regeneration on macOS. glibc's math.h has no such union, so this never bites on Linux. Fall back to an offset-based key for line-less nodes; these system-header structs are never referenced by MuJoCo types, so the key only needs to be unique. COPYBARA_INTEGRATE_REVIEW=https://github.com/google-deepmind/mujoco/pull/3411 from yuvaltassa:introspect-loc-fallback 7f117fa7a7060b36687e7544e8d7393d14a1fa90 PiperOrigin-RevId: 949626713 Change-Id: I9d99b427885ede18b075db6d4e507aa8bc0d049a --- python/mujoco/introspect/codegen/ast_processor.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/python/mujoco/introspect/codegen/ast_processor.py b/python/mujoco/introspect/codegen/ast_processor.py index cbf3c677..0c97ed82 100644 --- a/python/mujoco/introspect/codegen/ast_processor.py +++ b/python/mujoco/introspect/codegen/ast_processor.py @@ -332,9 +332,13 @@ class AstProcessor: ) def _make_anonymous_key(self, node: ClangJsonNode) -> str: - line = node['loc']['line'] - col = node['loc']['col'] - return f'{line}:{col}' + loc = node['loc'] + if 'line' not in loc: + # Clang elides 'line' when unchanged from the previous node. This only + # occurs for system-header structs never referenced by MuJoCo types, so + # the key merely needs to be unique. + return f"offset{loc.get('offset')}:{loc.get('col')}" + return f"{loc['line']}:{loc['col']}" def _traverse(node, visitor):