From 2f34622dffef79f6eebf8f8a6855af1f89063aa7 Mon Sep 17 00:00:00 2001 From: adrianrfreedman Date: Thu, 17 Sep 2026 14:10:07 +0300 Subject: [PATCH] Declare _get_hw_format nogil _get_hw_format is installed as AVCodecContext.get_format, so libavcodec calls it from inside avcodec_send_packet, which runs under `with nogil`. Any Python object operation in the callback would execute without the GIL and crash the interpreter. It is already GIL-free in practice -- AVCodecPrivateData holds only plain C fields and the loop counter is typed -- but nothing enforces that. Declaring it nogil makes Cython reject a future change that reintroduces a Python object at compile time rather than at runtime. No functional change. Co-Authored-By: Claude Opus 5 (1M context) --- av/video/codeccontext.py | 1 + 1 file changed, 1 insertion(+) diff --git a/av/video/codeccontext.py b/av/video/codeccontext.py index c01ee95c8..677539379 100644 --- a/av/video/codeccontext.py +++ b/av/video/codeccontext.py @@ -14,6 +14,7 @@ @cython.cfunc +@cython.nogil @cython.exceptval(check=False) def _get_hw_format( ctx: cython.pointer[lib.AVCodecContext],