[{"id":23731,"web_url":"https://patchwork.libcamera.org/comment/23731/","msgid":"<YsN9UN5nzDxO6196@pendragon.ideasonboard.com>","date":"2022-07-04T23:52:48","subject":"Re: [libcamera-devel] [PATCH v8 3/4] libcamera: controls: Generate\n\tfixed- and variable-sized Span Controls","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Christian,\n\nThank you for the patch.\n\nOn Fri, Jun 10, 2022 at 01:03:37PM +0100, Christian Rauch via libcamera-devel wrote:\n> This defines Controls with a 'size' as either variable-sized Span<T> or as\n> fixed-sized Span<T,N>.\n\nThis patch alone breaks compilation, it needs to be squashed with 4/4.\n\n> Signed-off-by: Christian Rauch <Rauch.Christian@gmx.de>\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  utils/gen-controls.py | 32 ++++++++++++++++++++++----------\n>  1 file changed, 22 insertions(+), 10 deletions(-)\n> \n> diff --git a/utils/gen-controls.py b/utils/gen-controls.py\n> index 3f99b5e2..46ba4394 100755\n> --- a/utils/gen-controls.py\n> +++ b/utils/gen-controls.py\n> @@ -7,6 +7,8 @@\n>  # gen-controls.py - Generate control definitions from YAML\n> \n>  import argparse\n> +from functools import reduce\n> +import operator\n>  import string\n>  import sys\n>  import yaml\n> @@ -22,6 +24,24 @@ def format_description(description):\n>      return '\\n'.join([(line and ' * ' or ' *') + line for line in description])\n> \n> \n> +def get_ctrl_type(ctrl):\n> +    ctrl_type = ctrl['type']\n> +    ctrl_size_arr = ctrl.get('size')\n> +\n> +    if ctrl_type == 'string':\n> +        return 'std::string'\n> +    elif ctrl_size_arr is not None:\n> +        if len(ctrl_size_arr) > 0:\n> +            # fixed-sized Span\n> +            ctrl_span_size = reduce(operator.mul, ctrl_size_arr)\n> +            return f\"Span<const {ctrl_type}, {ctrl_span_size}>\"\n> +        else:\n> +            # variable-sized Span\n> +            return f\"Span<const {ctrl_type}>\"\n> +    else:\n> +        return ctrl_type\n> +\n> +\n>  def generate_cpp(controls):\n>      enum_doc_start_template = string.Template('''/**\n>   * \\\\enum ${name}Enum\n> @@ -50,11 +70,7 @@ ${description}\n>          name, ctrl = ctrl.popitem()\n>          id_name = snake_case(name).upper()\n> \n> -        ctrl_type = ctrl['type']\n> -        if ctrl_type == 'string':\n> -            ctrl_type = 'std::string'\n> -        elif ctrl.get('size'):\n> -            ctrl_type = 'Span<const %s>' % ctrl_type\n> +        ctrl_type = get_ctrl_type(ctrl)\n> \n>          info = {\n>              'name': name,\n> @@ -135,11 +151,7 @@ def generate_h(controls):\n> \n>          ids.append('\\t' + id_name + ' = ' + str(id_value) + ',')\n> \n> -        ctrl_type = ctrl['type']\n> -        if ctrl_type == 'string':\n> -            ctrl_type = 'std::string'\n> -        elif ctrl.get('size'):\n> -            ctrl_type = 'Span<const %s>' % ctrl_type\n> +        ctrl_type = get_ctrl_type(ctrl)\n> \n>          info = {\n>              'name': name,","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 0235EBD808\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  4 Jul 2022 23:53:14 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3F0FE6330C;\n\tTue,  5 Jul 2022 01:53:13 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id F01986042E\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  5 Jul 2022 01:53:11 +0200 (CEST)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 67AC36D7;\n\tTue,  5 Jul 2022 01:53:11 +0200 (CEST)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1656978793;\n\tbh=BNxPiEr0czuVjYK87wN71CHByKvnGzv7pNy+Ax5BrNg=;\n\th=Date:To:References:In-Reply-To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=RMCjBhHsLKuk0kJRP76SG36Y6eIcRlSIUpfN8krT0bRA3fBvUr4xC5YC45+QTz54q\n\tumcwW7LVxHR9Z07qUWFJZSa9k7qr+vwe9HYtDqTAEzKRbSSN95LxWihkjgRfZGM8P2\n\t0YEm8u4ESG7fpwbriLgdmJt9VHlqtljk9qqvqyvRmXmmTHkgQL5qwh3nxVrlElm1Z0\n\tmK9DBH5yMV6VxieV8y8H8n6BKr6rESrYdzo9OAEEGSK4wP+TOznNE6iBZxfVrGn8Al\n\tQNsbJs402U/hRZNU/8Gn+D0SrYt4AeRhhuXsAr088+tPmSoRM8HwZBV0LxbmNNOPh2\n\trj0dmNzBqSQFQ==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1656978791;\n\tbh=BNxPiEr0czuVjYK87wN71CHByKvnGzv7pNy+Ax5BrNg=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=nJSm6pTj+Lp1mViJcm87AlKVcBZzkKuUbCGPFDM/w0q1h1K+FAU8we5GtOwwsNrpR\n\tAea6BmH2UNZLP6TN/texWgT6uZbNWjExj7X8Owqn+sl4RBK+rg9MRHTM6yxwmYx7bU\n\tA1P2lvde3ss6SQ93AphVm+fmOWldFgGU1+xLtuHQ="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"nJSm6pTj\"; dkim-atps=neutral","Date":"Tue, 5 Jul 2022 02:52:48 +0300","To":"Christian Rauch <Rauch.Christian@gmx.de>","Message-ID":"<YsN9UN5nzDxO6196@pendragon.ideasonboard.com>","References":"<20220610120338.96883-1-Rauch.Christian@gmx.de>\n\t<20220610120338.96883-4-Rauch.Christian@gmx.de>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220610120338.96883-4-Rauch.Christian@gmx.de>","Subject":"Re: [libcamera-devel] [PATCH v8 3/4] libcamera: controls: Generate\n\tfixed- and variable-sized Span Controls","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>","From":"Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]