[{"id":23456,"web_url":"https://patchwork.libcamera.org/comment/23456/","msgid":"<20220617141829.3tf2diknnzbttvst@uno.localdomain>","date":"2022-06-17T14:18:29","subject":"Re: [libcamera-devel] [PATCH 7/7] libcamera: yaml_parser: Add get()\n\tspecializations for 16-bit integers","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent\n\nOn Thu, Jun 16, 2022 at 05:24:03PM +0300, Laurent Pinchart via libcamera-devel wrote:\n> Extend the YamlObject::get() function template to support 16-bit\n> integers.\n>\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nSeems in-line with the other specializations\n\nReviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n\nThanks\n   j\n\n> ---\n>  include/libcamera/internal/yaml_parser.h |  2 +\n>  src/libcamera/yaml_parser.cpp            | 61 ++++++++++++++++++++++++\n>  2 files changed, 63 insertions(+)\n>\n> diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\n> index 811be1affcc0..90d348eac74c 100644\n> --- a/include/libcamera/internal/yaml_parser.h\n> +++ b/include/libcamera/internal/yaml_parser.h\n> @@ -156,6 +156,8 @@ public:\n>  \t\t typename std::enable_if_t<\n>  \t\t\t std::is_same_v<bool, T> ||\n>  \t\t\t std::is_same_v<double, T> ||\n> +\t\t\t std::is_same_v<int16_t, T> ||\n> +\t\t\t std::is_same_v<uint16_t, T> ||\n>  \t\t\t std::is_same_v<int32_t, T> ||\n>  \t\t\t std::is_same_v<uint32_t, T> ||\n>  \t\t\t std::is_same_v<std::string, T> ||\n> diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\n> index bd4b501b1422..5c45e44e49c3 100644\n> --- a/src/libcamera/yaml_parser.cpp\n> +++ b/src/libcamera/yaml_parser.cpp\n> @@ -138,6 +138,67 @@ bool YamlObject::get(const bool &defaultValue, bool *ok) const\n>  \treturn defaultValue;\n>  }\n>\n> +template<>\n> +int16_t YamlObject::get(const int16_t &defaultValue, bool *ok) const\n> +{\n> +\tsetOk(ok, false);\n> +\n> +\tif (type_ != Type::Value)\n> +\t\treturn defaultValue;\n> +\n> +\tif (value_ == \"\")\n> +\t\treturn defaultValue;\n> +\n> +\tchar *end;\n> +\n> +\terrno = 0;\n> +\tint16_t value = std::strtol(value_.c_str(), &end, 10);\n> +\n> +\tif ('\\0' != *end || errno == ERANGE ||\n> +\t    value < std::numeric_limits<int16_t>::min() ||\n> +\t    value > std::numeric_limits<int16_t>::max())\n> +\t\treturn defaultValue;\n> +\n> +\tsetOk(ok, true);\n> +\treturn value;\n> +}\n> +\n> +template<>\n> +uint16_t YamlObject::get(const uint16_t &defaultValue, bool *ok) const\n> +{\n> +\tsetOk(ok, false);\n> +\n> +\tif (type_ != Type::Value)\n> +\t\treturn defaultValue;\n> +\n> +\tif (value_ == \"\")\n> +\t\treturn defaultValue;\n> +\n> +\t/*\n> +\t * libyaml parses all scalar values as strings. When a string has\n> +\t * leading spaces before a minus sign, for example \"  -10\", strtoul\n> +\t * skips leading spaces, accepts the leading minus sign, and the\n> +\t * calculated digits are negated as if by unary minus. Rule it out in\n> +\t * case the user gets a large number when the value is negative.\n> +\t */\n> +\tstd::size_t found = value_.find_first_not_of(\" \\t\");\n> +\tif (found != std::string::npos && value_[found] == '-')\n> +\t\treturn defaultValue;\n> +\n> +\tchar *end;\n> +\n> +\terrno = 0;\n> +\tuint16_t value = std::strtoul(value_.c_str(), &end, 10);\n> +\n> +\tif ('\\0' != *end || errno == ERANGE ||\n> +\t    value < std::numeric_limits<uint16_t>::min() ||\n> +\t    value > std::numeric_limits<uint16_t>::max())\n> +\t\treturn defaultValue;\n> +\n> +\tsetOk(ok, true);\n> +\treturn value;\n> +}\n> +\n>  template<>\n>  int32_t YamlObject::get(const int32_t &defaultValue, bool *ok) const\n>  {\n> --\n> Regards,\n>\n> Laurent Pinchart\n>","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 D66F1BD161\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 17 Jun 2022 14:18:33 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 20A4065635;\n\tFri, 17 Jun 2022 16:18:33 +0200 (CEST)","from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net\n\t[217.70.183.196])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3D7CB65632\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Jun 2022 16:18:32 +0200 (CEST)","(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id B5CC0E000D;\n\tFri, 17 Jun 2022 14:18:31 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1655475513;\n\tbh=aq3nQF+bsf/E3YkoEwcHexwKS92EHYB2Eh1OG9hQMks=;\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=cdXRqP6vYhAoHj9+JDcQ2GZv1RaUx0WlvIDpDAF6Z4lDwbYoapKIZPGl6enSpQG2+\n\tkOIZzfRv9eP3+4Dt2rOBWHdKkquvJjFOP1gbAFQIBIEzfgTr0An0Cu3+jub3giTDlx\n\tvk9LZ+9Z42Tw1ESNej+f0qtvW7RISKGdLs1J4tmDjuQtJplQCGH/Ba2KhxndJ6WeBs\n\tt1UXz3h4jS80DEnM7VL8Rz2X6IwjTTjw/0WRDUwI79CCSvY14jxM0n6doqUY0o+scM\n\tB0Gd9Ye4adzJ9ahWjJOvv9l4xhdQht9tufGk1aSb7ycdnuMwoGWM2pWzqB5UmTs0GM\n\tVRn7fOVNJX0Qg==","Date":"Fri, 17 Jun 2022 16:18:29 +0200","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20220617141829.3tf2diknnzbttvst@uno.localdomain>","References":"<20220616142403.20723-1-laurent.pinchart@ideasonboard.com>\n\t<20220616142403.20723-8-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20220616142403.20723-8-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH 7/7] libcamera: yaml_parser: Add get()\n\tspecializations for 16-bit integers","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":"Jacopo Mondi via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Jacopo Mondi <jacopo@jmondi.org>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":23487,"web_url":"https://patchwork.libcamera.org/comment/23487/","msgid":"<CAJAuwMmQR4ywxux2MQGCOMLy2s39WGg2awLq-uSM8PaOfrv52g@mail.gmail.com>","date":"2022-06-20T12:08:08","subject":"Re: [libcamera-devel] [PATCH 7/7] libcamera: yaml_parser: Add get()\n\tspecializations for 16-bit integers","submitter":{"id":98,"url":"https://patchwork.libcamera.org/api/people/98/","name":"Hanlin Chen","email":"hanlinchen@chromium.org"},"content":"Hi Laurent,\n\nReviewed-by: Han-Lin Chen <hanlinchen@chromium.org>\nThanks.\n\nOn Fri, Jun 17, 2022 at 10:18 PM Jacopo Mondi via libcamera-devel\n<libcamera-devel@lists.libcamera.org> wrote:\n>\n> Hi Laurent\n>\n> On Thu, Jun 16, 2022 at 05:24:03PM +0300, Laurent Pinchart via libcamera-devel wrote:\n> > Extend the YamlObject::get() function template to support 16-bit\n> > integers.\n> >\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n>\n> Seems in-line with the other specializations\n>\n> Reviewed-by: Jacopo Mondi <jacopo@jmondi.org>\n>\n> Thanks\n>    j\n>\n> > ---\n> >  include/libcamera/internal/yaml_parser.h |  2 +\n> >  src/libcamera/yaml_parser.cpp            | 61 ++++++++++++++++++++++++\n> >  2 files changed, 63 insertions(+)\n> >\n> > diff --git a/include/libcamera/internal/yaml_parser.h b/include/libcamera/internal/yaml_parser.h\n> > index 811be1affcc0..90d348eac74c 100644\n> > --- a/include/libcamera/internal/yaml_parser.h\n> > +++ b/include/libcamera/internal/yaml_parser.h\n> > @@ -156,6 +156,8 @@ public:\n> >                typename std::enable_if_t<\n> >                        std::is_same_v<bool, T> ||\n> >                        std::is_same_v<double, T> ||\n> > +                      std::is_same_v<int16_t, T> ||\n> > +                      std::is_same_v<uint16_t, T> ||\n> >                        std::is_same_v<int32_t, T> ||\n> >                        std::is_same_v<uint32_t, T> ||\n> >                        std::is_same_v<std::string, T> ||\n> > diff --git a/src/libcamera/yaml_parser.cpp b/src/libcamera/yaml_parser.cpp\n> > index bd4b501b1422..5c45e44e49c3 100644\n> > --- a/src/libcamera/yaml_parser.cpp\n> > +++ b/src/libcamera/yaml_parser.cpp\n> > @@ -138,6 +138,67 @@ bool YamlObject::get(const bool &defaultValue, bool *ok) const\n> >       return defaultValue;\n> >  }\n> >\n> > +template<>\n> > +int16_t YamlObject::get(const int16_t &defaultValue, bool *ok) const\n> > +{\n> > +     setOk(ok, false);\n> > +\n> > +     if (type_ != Type::Value)\n> > +             return defaultValue;\n> > +\n> > +     if (value_ == \"\")\n> > +             return defaultValue;\n> > +\n> > +     char *end;\n> > +\n> > +     errno = 0;\n> > +     int16_t value = std::strtol(value_.c_str(), &end, 10);\n> > +\n> > +     if ('\\0' != *end || errno == ERANGE ||\n> > +         value < std::numeric_limits<int16_t>::min() ||\n> > +         value > std::numeric_limits<int16_t>::max())\n> > +             return defaultValue;\n> > +\n> > +     setOk(ok, true);\n> > +     return value;\n> > +}\n> > +\n> > +template<>\n> > +uint16_t YamlObject::get(const uint16_t &defaultValue, bool *ok) const\n> > +{\n> > +     setOk(ok, false);\n> > +\n> > +     if (type_ != Type::Value)\n> > +             return defaultValue;\n> > +\n> > +     if (value_ == \"\")\n> > +             return defaultValue;\n> > +\n> > +     /*\n> > +      * libyaml parses all scalar values as strings. When a string has\n> > +      * leading spaces before a minus sign, for example \"  -10\", strtoul\n> > +      * skips leading spaces, accepts the leading minus sign, and the\n> > +      * calculated digits are negated as if by unary minus. Rule it out in\n> > +      * case the user gets a large number when the value is negative.\n> > +      */\n> > +     std::size_t found = value_.find_first_not_of(\" \\t\");\n> > +     if (found != std::string::npos && value_[found] == '-')\n> > +             return defaultValue;\n> > +\n> > +     char *end;\n> > +\n> > +     errno = 0;\n> > +     uint16_t value = std::strtoul(value_.c_str(), &end, 10);\n> > +\n> > +     if ('\\0' != *end || errno == ERANGE ||\n> > +         value < std::numeric_limits<uint16_t>::min() ||\n> > +         value > std::numeric_limits<uint16_t>::max())\n> > +             return defaultValue;\n> > +\n> > +     setOk(ok, true);\n> > +     return value;\n> > +}\n> > +\n> >  template<>\n> >  int32_t YamlObject::get(const int32_t &defaultValue, bool *ok) const\n> >  {\n> > --\n> > Regards,\n> >\n> > Laurent Pinchart\n> >","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 4CF95BE173\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 20 Jun 2022 12:08:22 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id F212365637;\n\tMon, 20 Jun 2022 14:08:21 +0200 (CEST)","from mail-oi1-x229.google.com (mail-oi1-x229.google.com\n\t[IPv6:2607:f8b0:4864:20::229])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id BD5CE65632\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Jun 2022 14:08:20 +0200 (CEST)","by mail-oi1-x229.google.com with SMTP id bd16so13365887oib.6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Jun 2022 05:08:20 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1655726902;\n\tbh=7ybyYBFpIBElGrc/c424rq9t5rGuzvM5He720G6wAYA=;\n\th=References:In-Reply-To:Date:To:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc:\n\tFrom;\n\tb=Lt5OUEDC++SIoaLXaHBkMZ1IVZo+HTMtv9MSHVGL9NbiSYOwx/7dgxX0jJ4PZcsk+\n\tLKPKtZpQS0fbZ8WCpCDmFhg7gv9ff8/d4GekXIrURmmt2ztvXwne2rmQ9SuYosgVjD\n\tz+MA+XSllHghC2krL8k6DVD5EAg8qq+JQ/1+9lpH6oCYSLs9HRuDAZ5HTdl5H/vIRO\n\tZR7DzwXbvyJankR4B9B4TiqhsO38lNPlCjrXtgx/K03aZouiqi8aC3de7vL9B/ywZL\n\tyntBuKfwDtjax+vpYL4u5o6Yd6XR9fi9wbvs9znqjc6J1IAQId4LdXw/VQwm0BpwKW\n\tYwE25agLOtZcg==","v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org;\n\ts=google; \n\th=mime-version:references:in-reply-to:from:date:message-id:subject:to\n\t:cc; bh=3kZf29BT24zRQZhz53uisw17gGg79lM11OmBZdGUzzc=;\n\tb=mLhaB+SQUQx8YALVIuZoTY6EU8mxUx/w/hAP0m8UTjqUAps1svvx4ENnNond858j/X\n\tZ9geOeYOQfQX3udOm5n4WJ+HJGCSo4Tz+hEfUWaUiVsvF4Idwh8VBu74V8bmlYiatBFh\n\tK0SiGKMX4m6IlBRDDNtyTUzY6Ga8rG3uPnJqI="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=chromium.org\n\theader.i=@chromium.org header.b=\"mLhaB+SQ\"; \n\tdkim-atps=neutral","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20210112;\n\th=x-gm-message-state:mime-version:references:in-reply-to:from:date\n\t:message-id:subject:to:cc;\n\tbh=3kZf29BT24zRQZhz53uisw17gGg79lM11OmBZdGUzzc=;\n\tb=gyQ5IwZmuw54ljMRuSNMNedc9EZC5o1t54tMpo+LV63YfndzbbrKzF7Qt4Dbft4JeM\n\tbb+DW66hKmfjXfHBC4v+qkTM1MF/Du0uRgb3Ao4L5H1I6UgbC0Ooscb/oW9R/3fkJtBM\n\tp4UwF0NAWJezPigviFfs7bX5z2TyRx/u3AQGks/WThjomDsiZ1TgCZieEmOGgPA/BJdD\n\t0EvzNn2gMxCOsQqQ0s9u+ZOQnk9SbA2vhG/6fNfkF1OIKHIsY0HIbKeG9IW2zr3LbCzv\n\t+DDHRMmNxQLDMmViHR+oIvuyfasXTUc5gCHiZO1M6TDzAdQ/ysnYZE5tgrChBj/PJbri\n\tb8ww==","X-Gm-Message-State":"AJIora84kxweFlZMlHNHq2FtXMmTOa8w843TxVeunq4MGesmLOzKUR4b\n\tpk9qiCZhFr7XUwyFI2QyaZGL4sjIupq/CL+vR305hQ==","X-Google-Smtp-Source":"AGRyM1vYjSslGl8keXpSqMSEoncPH6Yi32t22Rkv8Cd0NXp33YGuEQ2fQZDv1W8MtbwGKU4TGnhi5GNbD7P3EdvQ9ZY=","X-Received":"by 2002:a05:6808:2384:b0:331:39ca:a507 with SMTP id\n\tbp4-20020a056808238400b0033139caa507mr11238038oib.65.1655726899498;\n\tMon, 20 Jun 2022 05:08:19 -0700 (PDT)","MIME-Version":"1.0","References":"<20220616142403.20723-1-laurent.pinchart@ideasonboard.com>\n\t<20220616142403.20723-8-laurent.pinchart@ideasonboard.com>\n\t<20220617141829.3tf2diknnzbttvst@uno.localdomain>","In-Reply-To":"<20220617141829.3tf2diknnzbttvst@uno.localdomain>","Date":"Mon, 20 Jun 2022 20:08:08 +0800","Message-ID":"<CAJAuwMmQR4ywxux2MQGCOMLy2s39WGg2awLq-uSM8PaOfrv52g@mail.gmail.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Content-Type":"text/plain; charset=\"UTF-8\"","Subject":"Re: [libcamera-devel] [PATCH 7/7] libcamera: yaml_parser: Add get()\n\tspecializations for 16-bit integers","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":"Hanlin Chen via libcamera-devel <libcamera-devel@lists.libcamera.org>","Reply-To":"Hanlin Chen <hanlinchen@chromium.org>","Cc":"libcamera-devel@lists.libcamera.org","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}}]