Skip to content

Commit be8ab31

Browse files
authored
Improve C ABI struct change error handling (#2386)
Over in #2369 I saw this C ABI change error ``` Traceback (most recent call last): File "/opt/hostedtoolcache/Python/3.11.15/x64/bin/check-c-abi", line 6, in <module> sys.exit(main_cli()) using dlpack from /home/runner/work/cuvs/cuvs/dlpack/include ^^^^^^^^^^ File "/opt/hostedtoolcache/Python/3.11.15/x64/lib/python3.11/site-packages/check_c_abi/main.py", line 136, in main_cli errors = analyze_c_abi(old_abi, new_abi) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/hostedtoolcache/Python/3.11.15/x64/lib/python3.11/site-packages/check_c_abi/abi.py", line 351, in analyze_c_abi errors.extend(_analyze_struct_abi(old_abi, new_abi)) File "/opt/hostedtoolcache/Python/3.11.15/x64/lib/python3.11/site-packages/check_c_abi/abi.py", line 293, in _analyze_struct_abi new_struct.members, ^^^^^^^^^^ UnboundLocalError: cannot access local variable 'new_struct' where it is not associated with a value ``` This PR adds a `continue` so we avoid any unbounded variables. Authors: - James Bourbeau (https://github.com/jrbourbeau) - Corey J. Nolet (https://github.com/cjnolet) Approvers: - Corey J. Nolet (https://github.com/cjnolet) - Gil Forsyth (https://github.com/gforsyth) URL: #2386
1 parent 90992ea commit be8ab31

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

ci/check_c_abi/check_c_abi/abi.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION.
2+
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
33
# SPDX-License-Identifier: Apache-2.0
44
#
55

@@ -287,6 +287,7 @@ def _analyze_struct_abi(
287287
symbol=name,
288288
location=old_struct.location,
289289
)
290+
continue
290291

291292
for (old_type, old_name), (new_type, new_name) in zip_longest(
292293
old_struct.members,

ci/check_c_abi/check_c_abi/tests/test_abi.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION.
2+
# SPDX-FileCopyrightText: Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
33
# SPDX-License-Identifier: Apache-2.0
44
#
55

@@ -65,6 +65,13 @@ def test_struct():
6565
errors = analyze_c_abi(old_abi, old_abi)
6666
assert not errors
6767

68+
# removing a struct should return an error
69+
new_abi = abi_from_str("")
70+
errors = analyze_c_abi(old_abi, new_abi)
71+
assert len(errors) == 1
72+
assert errors[0].symbol == "Foo"
73+
assert errors[0].error == "Struct has been removed"
74+
6875
# removing a field should return an error
6976
new_abi = abi_from_str("""
7077
struct Foo {

0 commit comments

Comments
 (0)