From 8d338abb6d2fcbf35db7067b4be196ae2cd5b3d5 Mon Sep 17 00:00:00 2001 From: WyattBlue Date: Fri, 27 Feb 2026 01:29:42 -0500 Subject: [PATCH] Fix C compiler warnings --- av/codec/codec.py | 8 ++++---- av/codec/hwaccel.pxd | 6 +++--- av/codec/hwaccel.py | 6 ++++-- av/container/core.py | 4 ++-- av/container/input.py | 2 +- av/container/output.py | 6 ++++-- av/container/pyio.py | 2 +- av/format.pxd | 6 +++--- av/format.py | 3 ++- av/video/format.py | 2 +- include/avcodec.pxd | 16 ++++++++-------- include/avformat.pxd | 14 +++++++------- include/avutil.pxd | 8 ++++---- 13 files changed, 44 insertions(+), 39 deletions(-) diff --git a/av/codec/codec.py b/av/codec/codec.py index 930a9ecec..552af8284 100644 --- a/av/codec/codec.py +++ b/av/codec/codec.py @@ -182,7 +182,7 @@ def id(self): @property def frame_rates(self): """A list of supported frame rates (:class:`fractions.Fraction`), or ``None``.""" - out: cython.p_void = cython.NULL + out: cython.pointer[cython.const[cython.void]] = cython.NULL num: cython.int = 0 lib.avcodec_get_supported_config( cython.NULL, @@ -200,7 +200,7 @@ def frame_rates(self): @property def audio_rates(self): """A list of supported audio sample rates (``int``), or ``None``.""" - out: cython.p_void = cython.NULL + out: cython.pointer[cython.const[cython.void]] = cython.NULL num: cython.int = 0 lib.avcodec_get_supported_config( cython.NULL, @@ -218,7 +218,7 @@ def audio_rates(self): @property def video_formats(self): """A list of supported :class:`.VideoFormat`, or ``None``.""" - out: cython.p_void = cython.NULL + out: cython.pointer[cython.const[cython.void]] = cython.NULL num: cython.int = 0 lib.avcodec_get_supported_config( cython.NULL, @@ -236,7 +236,7 @@ def video_formats(self): @property def audio_formats(self): """A list of supported :class:`.AudioFormat`, or ``None``.""" - out: cython.p_void = cython.NULL + out: cython.pointer[cython.const[cython.void]] = cython.NULL num: cython.int = 0 lib.avcodec_get_supported_config( cython.NULL, diff --git a/av/codec/hwaccel.pxd b/av/codec/hwaccel.pxd index af8815cb6..fd9bb1720 100644 --- a/av/codec/hwaccel.pxd +++ b/av/codec/hwaccel.pxd @@ -5,10 +5,10 @@ from av.codec.codec cimport Codec cdef class HWConfig: cdef object __weakref__ - cdef lib.AVCodecHWConfig *ptr - cdef void _init(self, lib.AVCodecHWConfig *ptr) + cdef const lib.AVCodecHWConfig *ptr + cdef void _init(self, const lib.AVCodecHWConfig *ptr) -cdef HWConfig wrap_hwconfig(lib.AVCodecHWConfig *ptr) +cdef HWConfig wrap_hwconfig(const lib.AVCodecHWConfig *ptr) cdef class HWAccel: cdef int _device_type diff --git a/av/codec/hwaccel.py b/av/codec/hwaccel.py index 96175ff15..0155bdae4 100644 --- a/av/codec/hwaccel.py +++ b/av/codec/hwaccel.py @@ -43,7 +43,7 @@ class HWConfigMethod(IntEnum): @cython.cfunc -def wrap_hwconfig(ptr: cython.pointer[lib.AVCodecHWConfig]) -> HWConfig: +def wrap_hwconfig(ptr: cython.pointer[cython.const[lib.AVCodecHWConfig]]) -> HWConfig: try: return _singletons[cython.cast(cython.Py_ssize_t, ptr)] except KeyError: @@ -61,7 +61,9 @@ def __init__(self, sentinel): raise RuntimeError("Cannot instantiate CodecContext") @cython.cfunc - def _init(self, ptr: cython.pointer[lib.AVCodecHWConfig]) -> cython.void: + def _init( + self, ptr: cython.pointer[cython.const[lib.AVCodecHWConfig]] + ) -> cython.void: self.ptr = ptr def __repr__(self): diff --git a/av/container/core.py b/av/container/core.py index f4ef1a277..a651c8055 100755 --- a/av/container/core.py +++ b/av/container/core.py @@ -280,7 +280,7 @@ def __cinit__( res: cython.int name_obj: bytes = os.fsencode(self.name) name: cython.p_char = name_obj - ofmt: cython.pointer[lib.AVOutputFormat] + ofmt: cython.pointer[cython.const[lib.AVOutputFormat]] if self.writeable: ofmt = ( @@ -328,7 +328,7 @@ def __cinit__( self.ptr.io_close2 = pyav_io_close self.ptr.flags |= lib.AVFMT_FLAG_CUSTOM_IO - ifmt: cython.pointer[lib.AVInputFormat] + ifmt: cython.pointer[cython.const[lib.AVInputFormat]] c_options: Dictionary if not self.writeable: ifmt = self.format.iptr if self.format else cython.NULL diff --git a/av/container/input.py b/av/container/input.py index 2412f7744..25cebe386 100644 --- a/av/container/input.py +++ b/av/container/input.py @@ -26,7 +26,7 @@ def __cinit__(self, *args, **kwargs): py_codec_context: CodecContext i: cython.uint stream: cython.pointer[lib.AVStream] - codec: cython.pointer[lib.AVCodec] + codec: cython.pointer[cython.const[lib.AVCodec]] codec_context: cython.pointer[lib.AVCodecContext] # If we have either the global `options`, or a `stream_options`, prepare diff --git a/av/container/output.py b/av/container/output.py index 600d84720..b36cf307f 100644 --- a/av/container/output.py +++ b/av/container/output.py @@ -87,7 +87,7 @@ def add_stream(self, codec_name, rate=None, options: dict | None = None, **kwarg # Some sane audio defaults elif codec.type == lib.AVMEDIA_TYPE_AUDIO: - out: cython.p_void = cython.NULL + out: cython.pointer[cython.const[cython.void]] = cython.NULL lib.avcodec_get_supported_config( cython.NULL, codec, @@ -285,7 +285,9 @@ def add_data_stream(self, codec_name=None, options: dict | None = None): :rtype: The new :class:`~av.data.stream.DataStream`. """ codec: cython.pointer[cython.const[lib.AVCodec]] = cython.NULL - codec_descriptor: cython.pointer[lib.AVCodecDescriptor] = cython.NULL + codec_descriptor: cython.pointer[cython.const[lib.AVCodecDescriptor]] = ( + cython.NULL + ) if codec_name is not None: codec = lib.avcodec_find_encoder_by_name(codec_name.encode()) diff --git a/av/container/pyio.py b/av/container/pyio.py index ccacc01e8..6c248ba13 100644 --- a/av/container/pyio.py +++ b/av/container/pyio.py @@ -183,7 +183,7 @@ def pyio_close_gil(pb: cython.pointer[lib.AVIOContext]) -> cython.int: try: return lib.avio_close(pb) except Exception: - stash_exception() + return stash_exception() @cython.cfunc diff --git a/av/format.pxd b/av/format.pxd index 31cac50aa..4109f325c 100644 --- a/av/format.pxd +++ b/av/format.pxd @@ -5,8 +5,8 @@ cdef class ContainerFormat: cdef readonly str name - cdef lib.AVInputFormat *iptr - cdef lib.AVOutputFormat *optr + cdef const lib.AVInputFormat *iptr + cdef const lib.AVOutputFormat *optr -cdef ContainerFormat build_container_format(lib.AVInputFormat*, lib.AVOutputFormat*) +cdef ContainerFormat build_container_format(const lib.AVInputFormat*, const lib.AVOutputFormat*) diff --git a/av/format.py b/av/format.py index a0bf0bd90..aad23050d 100644 --- a/av/format.py +++ b/av/format.py @@ -9,7 +9,8 @@ @cython.cfunc def build_container_format( - iptr: cython.pointer[lib.AVInputFormat], optr: cython.pointer[lib.AVOutputFormat] + iptr: cython.pointer[cython.const[lib.AVInputFormat]], + optr: cython.pointer[cython.const[lib.AVOutputFormat]], ) -> ContainerFormat: if not iptr and not optr: raise ValueError("needs input format or output format") diff --git a/av/video/format.py b/av/video/format.py index 50fb1a89d..dbc37ed64 100644 --- a/av/video/format.py +++ b/av/video/format.py @@ -196,7 +196,7 @@ def height(self): names = set() -desc = cython.declare(cython.pointer[lib.AVPixFmtDescriptor], cython.NULL) +desc = cython.declare(cython.pointer[cython.const[lib.AVPixFmtDescriptor]], cython.NULL) while True: desc = lib.av_pix_fmt_desc_next(desc) if not desc: diff --git a/include/avcodec.pxd b/include/avcodec.pxd index 98114fa12..f471d2e75 100644 --- a/include/avcodec.pxd +++ b/include/avcodec.pxd @@ -290,18 +290,18 @@ cdef extern from "libavcodec/avcodec.h" nogil: int subtitle_header_size uint8_t *subtitle_header - cdef AVCodecContext* avcodec_alloc_context3(AVCodec *codec) + cdef AVCodecContext* avcodec_alloc_context3(const AVCodec *codec) cdef void avcodec_free_context(AVCodecContext **ctx) cdef AVClass* avcodec_get_class() - cdef AVCodec* avcodec_find_decoder(AVCodecID id) - cdef AVCodec* avcodec_find_encoder(AVCodecID id) - cdef AVCodec* avcodec_find_decoder_by_name(char *name) - cdef AVCodec* avcodec_find_encoder_by_name(char *name) + cdef const AVCodec* avcodec_find_decoder(AVCodecID id) + cdef const AVCodec* avcodec_find_encoder(AVCodecID id) + cdef const AVCodec* avcodec_find_decoder_by_name(char *name) + cdef const AVCodec* avcodec_find_encoder_by_name(char *name) cdef const AVCodec* av_codec_iterate(void **opaque) - cdef AVCodecDescriptor* avcodec_descriptor_get(AVCodecID id) - cdef AVCodecDescriptor* avcodec_descriptor_get_by_name(char *name) + cdef const AVCodecDescriptor* avcodec_descriptor_get(AVCodecID id) + cdef const AVCodecDescriptor* avcodec_descriptor_get_by_name(char *name) cdef char* avcodec_get_name(AVCodecID id) - cdef int avcodec_open2(AVCodecContext *ctx, AVCodec *codec, AVDictionary **options) + cdef int avcodec_open2(AVCodecContext *ctx, const AVCodec *codec, AVDictionary **options) cdef enum AVPacketSideDataType: pass cdef struct AVPacketSideData: diff --git a/include/avformat.pxd b/include/avformat.pxd index 89e63af2f..94bf27b2e 100644 --- a/include/avformat.pxd +++ b/include/avformat.pxd @@ -137,7 +137,7 @@ cdef extern from "libavformat/avformat.h" nogil: int flags ) - cdef AVInputFormat* av_find_input_format(const char *name) + cdef const AVInputFormat* av_find_input_format(const char *name) # http://ffmpeg.org/doxygen/trunk/structAVFormatContext.html cdef struct AVFormatContext: @@ -145,8 +145,8 @@ cdef extern from "libavformat/avformat.h" nogil: AVStream **streams unsigned int nb_chapters AVChapter **chapters - AVInputFormat *iformat - AVOutputFormat *oformat + const AVInputFormat *iformat + const AVOutputFormat *oformat AVIOContext *pb AVIOInterruptCB interrupt_callback AVDictionary *metadata @@ -170,7 +170,7 @@ cdef extern from "libavformat/avformat.h" nogil: cdef int avformat_open_input( AVFormatContext **ctx, char *filename, - AVInputFormat *format, + const AVInputFormat *format, AVDictionary **options ) @@ -181,7 +181,7 @@ cdef extern from "libavformat/avformat.h" nogil: cdef int av_write_frame(AVFormatContext *ctx, AVPacket *pkt) cdef int avio_open(AVIOContext **s, char *url, int flags) cdef int64_t avio_size(AVIOContext *s) - cdef AVOutputFormat* av_guess_format( + cdef const AVOutputFormat* av_guess_format( char *short_name, char *filename, char *mime_type ) cdef int avformat_query_codec( @@ -191,10 +191,10 @@ cdef extern from "libavformat/avformat.h" nogil: cdef int avio_close(AVIOContext *s) cdef int avio_closep(AVIOContext **s) cdef int avformat_find_stream_info(AVFormatContext *ctx, AVDictionary **options) - cdef AVStream* avformat_new_stream(AVFormatContext *ctx, AVCodec *c) + cdef AVStream* avformat_new_stream(AVFormatContext *ctx, const AVCodec *c) cdef int avformat_alloc_output_context2( AVFormatContext **ctx, - AVOutputFormat *oformat, + const AVOutputFormat *oformat, char *format_name, char *filename ) diff --git a/include/avutil.pxd b/include/avutil.pxd index 6ca52e162..c1320a97d 100644 --- a/include/avutil.pxd +++ b/include/avutil.pxd @@ -335,12 +335,12 @@ cdef extern from "libavutil/pixdesc.h" nogil: uint8_t flags AVComponentDescriptor comp[4] - cdef AVPixFmtDescriptor* av_pix_fmt_desc_get(AVPixelFormat pix_fmt) - cdef AVPixFmtDescriptor* av_pix_fmt_desc_next(AVPixFmtDescriptor *prev) + cdef const AVPixFmtDescriptor* av_pix_fmt_desc_get(AVPixelFormat pix_fmt) + cdef const AVPixFmtDescriptor* av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev) cdef char * av_get_pix_fmt_name(AVPixelFormat pix_fmt) cdef AVPixelFormat av_get_pix_fmt(char* name) - int av_get_bits_per_pixel(AVPixFmtDescriptor *pixdesc) - int av_get_padded_bits_per_pixel(AVPixFmtDescriptor *pixdesc) + int av_get_bits_per_pixel(const AVPixFmtDescriptor *pixdesc) + int av_get_padded_bits_per_pixel(const AVPixFmtDescriptor *pixdesc) cdef extern from "libavutil/rational.h" nogil: cdef int av_reduce(int *dst_num, int *dst_den, int64_t num, int64_t den, int64_t max)