{"id":12028,"url":"https://patchwork.libcamera.org/api/patches/12028/?format=json","web_url":"https://patchwork.libcamera.org/patch/12028/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20210421093857.391409-1-hiroh@chromium.org>","date":"2021-04-21T09:38:55","name":"[libcamera-devel,v3,1/3] libcamera: V4L2Device: Use std::vector for v4l2_ext_control in getControls()","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"81a5cf849467519d0c435cd40bd86e3e011c4fa5","submitter":{"id":63,"url":"https://patchwork.libcamera.org/api/people/63/?format=json","name":"Hirokazu Honda","email":"hiroh@chromium.org"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/12028/mbox/","series":[{"id":1955,"url":"https://patchwork.libcamera.org/api/series/1955/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1955","date":"2021-04-21T09:38:55","name":"[libcamera-devel,v3,1/3] libcamera: V4L2Device: Use std::vector for v4l2_ext_control in getControls()","version":3,"mbox":"https://patchwork.libcamera.org/series/1955/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/12028/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/12028/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id CD197BDB16\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 21 Apr 2021 09:39:05 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 8CA8568847;\n\tWed, 21 Apr 2021 11:39:05 +0200 (CEST)","from mail-pl1-x635.google.com (mail-pl1-x635.google.com\n\t[IPv6:2607:f8b0:4864:20::635])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 2EB3468806\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 21 Apr 2021 11:39:04 +0200 (CEST)","by mail-pl1-x635.google.com with SMTP id u7so19505735plr.6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 21 Apr 2021 02:39:04 -0700 (PDT)","from hiroh2.tok.corp.google.com\n\t([2401:fa00:8f:2:7aaa:cbeb:5d87:4ab6])\n\tby smtp.gmail.com with ESMTPSA id\n\to11sm1305939pfu.188.2021.04.21.02.39.01\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 21 Apr 2021 02:39:01 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=chromium.org header.i=@chromium.org\n\theader.b=\"b7pI52M8\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; h=from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=aL6F25+hayUMfwdqm82sea9jwpijub9/hGWor4Bf3R0=;\n\tb=b7pI52M8KvlUUpt9nppi7upF8RnsozaK53ubV49evvU4TaWMNhO/XtlV4cQs/CJ9u4\n\tyfDr0Mc80afqgiVpHdxpxhnjuBIErlah8oMpbRvOVpF1noV251aF8xwtoTO4AiWZLMf8\n\tLR5g3fb29Gt95JF9u10sFejt2K3ufleM3q92g=","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version\n\t:content-transfer-encoding;\n\tbh=aL6F25+hayUMfwdqm82sea9jwpijub9/hGWor4Bf3R0=;\n\tb=ZrEe1PAyrWmjtMDuv2iMlQFv5+7q2lS9dI2gJkdKtOSqZwIY4p99jsBilBbrENpASr\n\tPkw2dm+WwXIbIXiteJFHz2ACGuH5OjsXyVVwP0L+i8D08lp+OldlKWRQqLzhyb94Mv90\n\tPbnSxy2vE0pK1EPCHFZ5+XHk1Lkf7ySl3c5o8EXssKGomR6ZOeu4lmNkj+T01q/TDBGd\n\tbEO+1uw4GbnuTnedl1qXX6gK8aHuBzgl0a+JvZJq3wqT7MmFAGfLYor9mHrVwPMDMzDy\n\ta5wWG8UTtwHXlxoI8X1/peW+2tC5WdX9tnfy4raUCB0vmjzRIMMN6criaEU/nLhaJzQD\n\tfJqQ==","X-Gm-Message-State":"AOAM532x6eCOxlQELcByjVQORxnwtMX7wLGM/okWLGbyzSSQfNWz65UR\n\tAJrVcqSbBUAoxv1RXjpPvzeTTDu8HkD9qQ==","X-Google-Smtp-Source":"ABdhPJzlP9rKZSS38OzFYpzUceRwdSmlrv37DbGANtGNNdSrDOFqBKFUrb0Z4Om0ENnvmBFBc0999A==","X-Received":"by 2002:a17:902:7043:b029:ec:939f:c9e5 with SMTP id\n\th3-20020a1709027043b02900ec939fc9e5mr20231485plt.64.1618997942429; \n\tWed, 21 Apr 2021 02:39:02 -0700 (PDT)","From":"Hirokazu Honda <hiroh@chromium.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Wed, 21 Apr 2021 18:38:55 +0900","Message-Id":"<20210421093857.391409-1-hiroh@chromium.org>","X-Mailer":"git-send-email 2.31.1.368.gbe11c130af-goog","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v3 1/3] libcamera: V4L2Device: Use\n\tstd::vector for v4l2_ext_control in getControls()","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"The original code uses Variable-Length-Array, which is not\nofficially supported in C++. This replaces the array with\nstd::vector.\n\nSigned-off-by: Hirokazu Honda <hiroh@chromium.org>\n---\n src/libcamera/v4l2_device.cpp | 31 ++++++++++++++-----------------\n 1 file changed, 14 insertions(+), 17 deletions(-)","diff":"diff --git a/src/libcamera/v4l2_device.cpp b/src/libcamera/v4l2_device.cpp\nindex aad442de..c95c5e2a 100644\n--- a/src/libcamera/v4l2_device.cpp\n+++ b/src/libcamera/v4l2_device.cpp\n@@ -173,8 +173,7 @@ void V4L2Device::close()\n  */\n ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n {\n-\tunsigned int count = ids.size();\n-\tif (count == 0)\n+\tif (ids.empty())\n \t\treturn {};\n \n \tControlList ctrls{ controls_ };\n@@ -196,22 +195,20 @@ ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n \t\tctrls.set(id, {});\n \t}\n \n-\tstruct v4l2_ext_control v4l2Ctrls[count];\n-\tmemset(v4l2Ctrls, 0, sizeof(v4l2Ctrls));\n+\tstd::vector<v4l2_ext_control> v4l2Ctrls(ctrls.size());\n+\tmemset(v4l2Ctrls.data(), 0, sizeof(v4l2_ext_control) * ctrls.size());\n \n-\tunsigned int i = 0;\n-\tfor (auto &ctrl : ctrls) {\n-\t\tunsigned int id = ctrl.first;\n+\tfor (auto [ctrl, i] = std::pair(ctrls.begin(), 0u); i < ctrls.size(); ctrl++, i++) {\n+\t\tconst unsigned int id = ctrl->first;\n \t\tconst struct v4l2_query_ext_ctrl &info = controlInfo_[id];\n+\t\tv4l2_ext_control &v4l2Ctrl = v4l2Ctrls[i];\n \n \t\tif (info.flags & V4L2_CTRL_FLAG_HAS_PAYLOAD) {\n \t\t\tControlType type;\n-\n \t\t\tswitch (info.type) {\n \t\t\tcase V4L2_CTRL_TYPE_U8:\n \t\t\t\ttype = ControlTypeByte;\n \t\t\t\tbreak;\n-\n \t\t\tdefault:\n \t\t\t\tLOG(V4L2, Error)\n \t\t\t\t\t<< \"Unsupported payload control type \"\n@@ -219,7 +216,7 @@ ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n \t\t\t\treturn {};\n \t\t\t}\n \n-\t\t\tControlValue &value = ctrl.second;\n+\t\t\tControlValue &value = ctrl->second;\n \t\t\tvalue.reserve(type, true, info.elems);\n \t\t\tSpan<uint8_t> data = value.data();\n \n@@ -227,21 +224,20 @@ ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n \t\t\tv4l2Ctrls[i].size = data.size();\n \t\t}\n \n-\t\tv4l2Ctrls[i].id = id;\n-\t\ti++;\n+\t\tv4l2Ctrl.id = id;\n \t}\n \n \tstruct v4l2_ext_controls v4l2ExtCtrls = {};\n \tv4l2ExtCtrls.which = V4L2_CTRL_WHICH_CUR_VAL;\n-\tv4l2ExtCtrls.controls = v4l2Ctrls;\n-\tv4l2ExtCtrls.count = count;\n+\tv4l2ExtCtrls.controls = v4l2Ctrls.data();\n+\tv4l2ExtCtrls.count = v4l2Ctrls.size();\n \n \tint ret = ioctl(VIDIOC_G_EXT_CTRLS, &v4l2ExtCtrls);\n \tif (ret) {\n \t\tunsigned int errorIdx = v4l2ExtCtrls.error_idx;\n \n \t\t/* Generic validation error. */\n-\t\tif (errorIdx == 0 || errorIdx >= count) {\n+\t\tif (errorIdx == 0 || errorIdx >= v4l2Ctrls.size()) {\n \t\t\tLOG(V4L2, Error) << \"Unable to read controls: \"\n \t\t\t\t\t << strerror(-ret);\n \t\t\treturn {};\n@@ -250,10 +246,11 @@ ControlList V4L2Device::getControls(const std::vector<uint32_t> &ids)\n \t\t/* A specific control failed. */\n \t\tLOG(V4L2, Error) << \"Unable to read control \" << errorIdx\n \t\t\t\t << \": \" << strerror(-ret);\n-\t\tcount = errorIdx - 1;\n+\n+\t\tv4l2Ctrls.resize(errorIdx);\n \t}\n \n-\tupdateControls(&ctrls, v4l2Ctrls, count);\n+\tupdateControls(&ctrls, v4l2Ctrls.data(), v4l2Ctrls.size());\n \n \treturn ctrls;\n }\n","prefixes":["libcamera-devel","v3","1/3"]}