Skip to content

Commit 03bd3da

Browse files
committed
DOC: Fix PySequence_GetItem null guard and section numbering
- §11b: add mandatory null check before Py_DECREF after PySequence_GetItem — omitting it is UB if the call returns NULL - Renumber §12/§13: clang-tidy section was numbered 13 but appeared before §12 (Checklist) in the file; renumber to match physical order
1 parent 08a59b5 commit 03bd3da

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

Documentation/AI/compiler-cautions.md

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -479,26 +479,29 @@ np.dtype(np.bool_)
479479
// BAD — removed in Python 3.14:
480480
item = PySequence_Fast_GET_ITEM(seq, i);
481481

482-
// GOOD — reference-counted correctly:
482+
// GOOD — reference-counted correctly, with mandatory null guard:
483483
item = PySequence_GetItem(seq, i);
484-
// ... use item ...
485-
Py_DECREF(item);
484+
if (item != nullptr)
485+
{
486+
// ... use item ...
487+
Py_DECREF(item);
488+
}
486489
```
487490

488491
**References:** Commit `1726d3e5`, PR #5504.
489492

490493
---
491494

492-
## 13. clang-tidy Warnings During Refactoring
495+
## 12. clang-tidy Warnings During Refactoring
493496

494-
### 13a. Do Not Introduce New clang-tidy Diagnostics
497+
### 12a. Do Not Introduce New clang-tidy Diagnostics
495498

496499
Refactoring commits should leave the clang-tidy diagnostic count no worse than before.
497500
If a refactoring triggers warnings in code it did not touch, those are pre-existing
498501
issues and must **not** be fixed in the same commit. Mixing style fixes with
499502
behavioral changes obscures commit intent and complicates `git bisect`.
500503

501-
### 13b. clang-tidy Check Families That Conflict with ITK Coding Standards
504+
### 12b. clang-tidy Check Families That Conflict with ITK Coding Standards
502505

503506
Several clang-tidy check categories produce warnings that are **incorrect or
504507
inapplicable** in an ITK context. Do not "fix" these — doing so either breaks
@@ -513,15 +516,15 @@ ITK conventions or introduces irrelevant churn:
513516
| `google-*` | Enforces Google style, which differs from ITK naming and formatting rules |
514517
| `cppcoreguidelines-avoid-magic-numbers` | ITK uses literal dimension constants (e.g., `2`, `3`) as template arguments |
515518

516-
### 13c. Suppressing False-Positive Checks
519+
### 12c. Suppressing False-Positive Checks
517520

518521
For legitimate ITK code that a clang-tidy check incorrectly flags, prefer a
519522
`.clang-tidy` config exclusion (`Checks: '-llvmlibc-*'`) over inline
520523
`// NOLINT` comments. Inline suppressions accumulate and can mask real issues.
521524

522525
---
523526

524-
## 12. Quick-Reference Checklist for Refactoring
527+
## 13. Quick-Reference Checklist for Refactoring
525528

526529
When refactoring existing code, verify each item:
527530

0 commit comments

Comments
 (0)