From patchwork Sun Apr 26 07:49:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 19248 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id C6354449F26 for ; Sun, 26 Apr 2020 10:50:12 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9507B68C5C3; Sun, 26 Apr 2020 10:50:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E75A268C338 for ; Sun, 26 Apr 2020 10:50:06 +0300 (EEST) Received: by mail-wr1-f65.google.com with SMTP id b11so16684878wrs.6 for ; Sun, 26 Apr 2020 00:50:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5UIjE7eDPv4E4tlc83L8QvujW+L6uDQnLM7MTfokjO0=; b=Pdb31Aia8X0htWBvGNgVBmbVcigAf8ehbXIujP8aq5TTMoNWUjoZ6QVkJO3UcmfmV7 i8bEtZpbBWBWPuAo79+wUWDwE722uv2cJsWqLThOc8c7ifieca46Ej/Z15mwbjcwjEQ8 R4uOCLA4BcF0U4mn88U2mX0nlBOact6WqvtpEN/kezWZ8OQ211HBWAbl54ac7iLS5EKm n64BVcFGac28+BIh4o3wYBCxfeY04vohJHbFQKFFCmXHR0Z0b48sXCGJvx2aeC0tmn7d eJxhxuJgXb1gk0m6hSaZWtOEseKedRAKJl0j/DxTjY7YzVpwDqOTh7vk6+knvdJcSCPi 9Ybg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=5UIjE7eDPv4E4tlc83L8QvujW+L6uDQnLM7MTfokjO0=; b=pY/zpv6ewwBOsT96tVybg3lw2r+igSHXXTXRk184/I+KF+RJGvBaj45Y8xoiZ4RY5q 1072tbdtuiR3gpkD11CeuKGQo87Ignyoz9fvni9UfpIAJQofBGBTU2FRL5aW6n8j7Hzj 2aFmcgcdP78/Ma9ldfNFVwLqCkKl5/tGMYUt9XxIBSF2Pk03scbtn+ry6cJBZUVHmd6z hm/hPdNnAO+cP5byJaWAtH1Q0OBLwvJECfakPhGGOFfcoUOxIY7FNd8CpDKY4R6mCfFP g2ciaDudM/JX4iWFEMAEZ0NmObOZGyVmfMMrSHvQ/Ag3ZsTFZ/SK+TG8EoQ1NFle7IT3 P4VQ== X-Gm-Message-State: AGi0PuaCP3sbrEVhjdYnl9r3NrhfAl5+3wzK2egmWnB/3oUwmE9+rVbd mm3jBXjk6TCxW+FMY0e6dE/k2JWI X-Google-Smtp-Source: APiQypLc5APd1bHTbqqfJ0ZFT8LA6R4JYYGOazckEMd7V3CN82xvCSZPmq7HPIbxhYTsUsbu+9ddsg== X-Received: by 2002:adf:f9c6:: with SMTP id w6mr21121025wrr.341.1587887405876; Sun, 26 Apr 2020 00:50:05 -0700 (PDT) Received: from sblaptop.fritz.box ([188.193.171.87]) by smtp.gmail.com with ESMTPSA id e2sm15585160wrv.89.2020.04.26.00.50.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Apr 2020 00:50:05 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 26 Apr 2020 09:49:57 +0200 Message-Id: <20200426074957.12526-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] swscale/vscale: Increase type strictness X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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 Cc: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" libswscale/vscale.c makes extensive use of function pointers and in doing so it converts these function pointers to and from a pointer to void. Yet this is actually against the C standard: C90 only guarantees that one can convert a pointer to any incomplete type or object type to void* and back with the result comparing equal to the original which makes pointers to void generic pointers to incomplete or object type. Yet C90 lacks a generic function pointer type. C99 additionally guarantees that a pointer to a function of one type may be converted to a pointer to a function of another type and when converting back with the original and the result comparing equal. This makes any function pointer type a generic function pointer type. Yet even this does not make pointers to void generic function pointers. Both GCC and Clang emit warnings for this when in pedantic mode. This commit fixes this by using a union that can hold one member of any of the required function pointer types to store the function pointer. This works even for C90. Signed-off-by: Andreas Rheinhardt --- libswscale/vscale.c | 51 ++++++++++++++++++++++++++------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/libswscale/vscale.c b/libswscale/vscale.c index 72352dedb3..9ed227e908 100644 --- a/libswscale/vscale.c +++ b/libswscale/vscale.c @@ -25,7 +25,14 @@ typedef struct VScalerContext int32_t *filter_pos; int filter_size; int isMMX; - void *pfn; + union { + yuv2planar1_fn yuv2planar1; + yuv2planarX_fn yuv2planarX; + yuv2interleavedX_fn yuv2interleavedX; + yuv2packed1_fn yuv2packed1; + yuv2packed2_fn yuv2packed2; + yuv2anyX_fn yuv2anyX; + } pfn; yuv2packedX_fn yuv2packedX; } VScalerContext; @@ -43,9 +50,9 @@ static int lum_planar_vscale(SwsContext *c, SwsFilterDescriptor *desc, int slice uint16_t *filter = inst->filter[0] + (inst->isMMX ? 0 : sliceY * inst->filter_size); if (inst->filter_size == 1) - ((yuv2planar1_fn)inst->pfn)((const int16_t*)src[0], dst[0], dstW, c->lumDither8, 0); + inst->pfn.yuv2planar1((const int16_t*)src[0], dst[0], dstW, c->lumDither8, 0); else - ((yuv2planarX_fn)inst->pfn)(filter, inst->filter_size, (const int16_t**)src, dst[0], dstW, c->lumDither8, 0); + inst->pfn.yuv2planarX(filter, inst->filter_size, (const int16_t**)src, dst[0], dstW, c->lumDither8, 0); if (desc->alpha) { int sp = first - desc->src->plane[3].sliceY; @@ -55,9 +62,9 @@ static int lum_planar_vscale(SwsContext *c, SwsFilterDescriptor *desc, int slice uint16_t *filter = inst->filter[1] + (inst->isMMX ? 0 : sliceY * inst->filter_size); if (inst->filter_size == 1) - ((yuv2planar1_fn)inst->pfn)((const int16_t*)src[0], dst[0], dstW, c->lumDither8, 0); + inst->pfn.yuv2planar1((const int16_t*)src[0], dst[0], dstW, c->lumDither8, 0); else - ((yuv2planarX_fn)inst->pfn)(filter, inst->filter_size, (const int16_t**)src, dst[0], dstW, c->lumDither8, 0); + inst->pfn.yuv2planarX(filter, inst->filter_size, (const int16_t**)src, dst[0], dstW, c->lumDither8, 0); } return 1; @@ -85,13 +92,13 @@ static int chr_planar_vscale(SwsContext *c, SwsFilterDescriptor *desc, int slice uint16_t *filter = inst->filter[0] + (inst->isMMX ? 0 : chrSliceY * inst->filter_size); if (c->yuv2nv12cX) { - ((yuv2interleavedX_fn)inst->pfn)(c, filter, inst->filter_size, (const int16_t**)src1, (const int16_t**)src2, dst1[0], dstW); + inst->pfn.yuv2interleavedX(c, filter, inst->filter_size, (const int16_t**)src1, (const int16_t**)src2, dst1[0], dstW); } else if (inst->filter_size == 1) { - ((yuv2planar1_fn)inst->pfn)((const int16_t*)src1[0], dst1[0], dstW, c->chrDither8, 0); - ((yuv2planar1_fn)inst->pfn)((const int16_t*)src2[0], dst2[0], dstW, c->chrDither8, 3); + inst->pfn.yuv2planar1((const int16_t*)src1[0], dst1[0], dstW, c->chrDither8, 0); + inst->pfn.yuv2planar1((const int16_t*)src2[0], dst2[0], dstW, c->chrDither8, 3); } else { - ((yuv2planarX_fn)inst->pfn)(filter, inst->filter_size, (const int16_t**)src1, dst1[0], dstW, c->chrDither8, 0); - ((yuv2planarX_fn)inst->pfn)(filter, inst->filter_size, (const int16_t**)src2, dst2[0], dstW, c->chrDither8, inst->isMMX ? (c->uv_offx2 >> 1) : 3); + inst->pfn.yuv2planarX(filter, inst->filter_size, (const int16_t**)src1, dst1[0], dstW, c->chrDither8, 0); + inst->pfn.yuv2planarX(filter, inst->filter_size, (const int16_t**)src2, dst2[0], dstW, c->chrDither8, inst->isMMX ? (c->uv_offx2 >> 1) : 3); } } @@ -125,13 +132,13 @@ static int packed_vscale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, i if (c->yuv2packed1 && lum_fsize == 1 && chr_fsize == 1) { // unscaled RGB - ((yuv2packed1_fn)inst->pfn)(c, (const int16_t*)*src0, (const int16_t**)src1, (const int16_t**)src2, + inst->pfn.yuv2packed1(c, (const int16_t*)*src0, (const int16_t**)src1, (const int16_t**)src2, (const int16_t*)(desc->alpha ? *src3 : NULL), *dst, dstW, 0, sliceY); } else if (c->yuv2packed1 && lum_fsize == 1 && chr_fsize == 2 && chr_filter[2 * chrSliceY + 1] + chr_filter[2 * chrSliceY] == 4096 && chr_filter[2 * chrSliceY + 1] <= 4096U) { // unscaled RGB int chrAlpha = chr_filter[2 * chrSliceY + 1]; - ((yuv2packed1_fn)inst->pfn)(c, (const int16_t*)*src0, (const int16_t**)src1, (const int16_t**)src2, + inst->pfn.yuv2packed1(c, (const int16_t*)*src0, (const int16_t**)src1, (const int16_t**)src2, (const int16_t*)(desc->alpha ? *src3 : NULL), *dst, dstW, chrAlpha, sliceY); } else if (c->yuv2packed2 && lum_fsize == 2 && chr_fsize == 2 && lum_filter[2 * sliceY + 1] + lum_filter[2 * sliceY] == 4096 && @@ -145,7 +152,7 @@ static int packed_vscale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, i c->lumMmxFilter[3] = lum_filter[2 * sliceY] * 0x10001; c->chrMmxFilter[2] = c->chrMmxFilter[3] = chr_filter[2 * chrSliceY] * 0x10001; - ((yuv2packed2_fn)inst->pfn)(c, (const int16_t**)src0, (const int16_t**)src1, (const int16_t**)src2, (const int16_t**)src3, + inst->pfn.yuv2packed2(c, (const int16_t**)src0, (const int16_t**)src1, (const int16_t**)src2, (const int16_t**)src3, *dst, dstW, lumAlpha, chrAlpha, sliceY); } else { // general RGB if ((c->yuv2packed1 && lum_fsize == 1 && chr_fsize == 2) || @@ -195,7 +202,7 @@ static int any_vscale(SwsContext *c, SwsFilterDescriptor *desc, int sliceY, int desc->alpha ? desc->dst->plane[3].line[dp3] : NULL }; av_assert1(!c->yuv2packed1 && !c->yuv2packed2); - ((yuv2anyX_fn)inst->pfn)(c, lum_filter + sliceY * lum_fsize, + inst->pfn.yuv2anyX(c, lum_filter + sliceY * lum_fsize, (const int16_t**)src0, lum_fsize, chr_filter + sliceY * chr_fsize, (const int16_t**)src1, (const int16_t**)src2, chr_fsize, (const int16_t**)src3, dst, dstW, sliceY); @@ -270,9 +277,9 @@ void ff_init_vscale_pfn(SwsContext *c, chrCtx->isMMX = use_mmx; --idx; - if (yuv2nv12cX) chrCtx->pfn = yuv2nv12cX; - else if (c->vChrFilterSize == 1) chrCtx->pfn = yuv2plane1; - else chrCtx->pfn = yuv2planeX; + if (yuv2nv12cX) chrCtx->pfn.yuv2interleavedX = yuv2nv12cX; + else if (c->vChrFilterSize == 1) chrCtx->pfn.yuv2planar1 = yuv2plane1; + else chrCtx->pfn.yuv2planarX = yuv2planeX; } lumCtx = c->desc[idx].instance; @@ -283,8 +290,8 @@ void ff_init_vscale_pfn(SwsContext *c, lumCtx->filter_pos = c->vLumFilterPos; lumCtx->isMMX = use_mmx; - if (c->vLumFilterSize == 1) lumCtx->pfn = yuv2plane1; - else lumCtx->pfn = yuv2planeX; + if (c->vLumFilterSize == 1) lumCtx->pfn.yuv2planar1 = yuv2plane1; + else lumCtx->pfn.yuv2planarX = yuv2planeX; } else { lumCtx = c->desc[idx].instance; @@ -303,12 +310,12 @@ void ff_init_vscale_pfn(SwsContext *c, if (yuv2packedX) { if (c->yuv2packed1 && c->vLumFilterSize == 1 && c->vChrFilterSize <= 2) - lumCtx->pfn = yuv2packed1; + lumCtx->pfn.yuv2packed1 = yuv2packed1; else if (c->yuv2packed2 && c->vLumFilterSize == 2 && c->vChrFilterSize == 2) - lumCtx->pfn = yuv2packed2; + lumCtx->pfn.yuv2packed2 = yuv2packed2; lumCtx->yuv2packedX = yuv2packedX; } else - lumCtx->pfn = yuv2anyX; + lumCtx->pfn.yuv2anyX = yuv2anyX; } }