From patchwork Thu Nov 25 15:05:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 31663 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp850296iob; Thu, 25 Nov 2021 07:06:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJwpuS5hjYjp8GKmGvF0yL1iyyou6goMcg3DidmXpBWEPGNcPPayHRTa9UflpXcgAp7qgcsa X-Received: by 2002:a17:907:9612:: with SMTP id gb18mr32057611ejc.205.1637852817570; Thu, 25 Nov 2021 07:06:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637852817; cv=none; d=google.com; s=arc-20160816; b=GEs3PwIvpKfJN3N3TJxggRJY0FVOViWell0mGbnuuWdiGWQBmCzr7EOVEAziDvJiDz 3YhqaxvgnXh145LHtaJ/bCGUtRDrsHQaPHwpluVRV7nPadTmXLvF/q+aZ4N3ynytn1wZ mkwGKe0ZejufUcVheGCiwfLzxL5dS5hMRo0rydk0o9QQNuNR0f7eyf1ruRDYfK0vkRZ8 wRGqLih61YlncBUrmDB4DFQu7ubMiTOJaY2+y6Kmf2xgjLo6dkKhnBag2dZEAxIYTjqe 0lRNBYrCJbpi39AkkcOC2kA2XcVqeRZi9euMhkp5ci2QnFLqcEZwN7mssq9TxcRTuSjB zwGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=YD3T08sVqjo/j+qgS1wvRrbs2wobUNB0PUfTB2Ev1Ko=; b=BhwwDwmPr5WqvnAmSYRz73efPbpqTzTd1Ih6e/K9LTzPRhE7QS1gLDA2TR7DyRMdtG OS2J3Z+27q2sczPMDXBnqRU8p7blljE3dySKg1b1v9gv8tqNYN0TtyGTfMPuskl0cM/G kaijGMT965zeyWzlpoFKPSJTYC3GW52B4K7tRbFaVusggisHmJKRTzzpmp69ryGvVBWT 9EDMg2zZLNC3pMjSL0IE31SGYDM6cVfHvkcCFPCr+ijjFefCc4QQqoZ0hbp9srHtYxrh /KQXTmUQ4lCNqXg1+qd3yqhTnjRi3JS8+rcSBXgKJ8U55cljJlj+q7C3XFRRATgrt0xY NhUg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id u18si7032484eda.491.2021.11.25.07.06.57; Thu, 25 Nov 2021 07:06:57 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6361568AED3; Thu, 25 Nov 2021 17:05:23 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 58F6E68AEA0 for ; Thu, 25 Nov 2021 17:05:14 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id BF4D8240506 for ; Thu, 25 Nov 2021 16:05:09 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id 1jzElXWYkeQ3 for ; Thu, 25 Nov 2021 16:05:09 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id AB6A524050B for ; Thu, 25 Nov 2021 16:05:06 +0100 (CET) Received: by libav.khirnov.net (Postfix, from userid 1000) id C845E3A09CE; Thu, 25 Nov 2021 16:05:05 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Thu, 25 Nov 2021 16:05:00 +0100 Message-Id: <20211125150500.25040-9-anton@khirnov.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211125150500.25040-1-anton@khirnov.net> References: <20211125150500.25040-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 9/9] lavf/protocols: avoid discarding const in avio_enum_protocols() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: nftOD58UNGCW Instead of storing the protocol pointer in the opaque iteration state, store just the index of the next protocol, similarly to how ff_urlcontext_child_class_iterate() works. --- libavformat/protocols.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/libavformat/protocols.c b/libavformat/protocols.c index b108aa6c7e..948fae411f 100644 --- a/libavformat/protocols.c +++ b/libavformat/protocols.c @@ -93,17 +93,17 @@ const AVClass *ff_urlcontext_child_class_iterate(void **iter) const char *avio_enum_protocols(void **opaque, int output) { - const URLProtocol **p = *opaque; + uintptr_t i; - p = p ? p + 1 : url_protocols; - *opaque = p; - if (!*p) { - *opaque = NULL; - return NULL; + for (i = (uintptr_t)*opaque; url_protocols[i]; i++) { + const URLProtocol *p = url_protocols[i]; + if ((output && p->url_write) || (!output && p->url_read)) { + *opaque = (void*)(uintptr_t)(i + 1); + return p->name; + } } - if ((output && (*p)->url_write) || (!output && (*p)->url_read)) - return (*p)->name; - return avio_enum_protocols(opaque, output); + *opaque = NULL; + return NULL; } const AVClass *avio_protocol_get_class(const char *name)