[{"id":26196,"web_url":"https://patchwork.libcamera.org/comment/26196/","msgid":"<167322015770.3175711.16947363745060220393@Monstersaurus>","date":"2023-01-08T23:22:37","subject":"Re: [libcamera-devel] [PATCH v1 2/2] libcamera: base: utils:\n\tSupport C libraries lacking locale support","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Laurent Pinchart via libcamera-devel (2023-01-08 21:43:57)\n> Not all C libraries include support for locale objects (locale_t) and\n> the strto*_l() family of functions. A notable example is uClibc that can\n> be compiled with a hardcoded \"C\" locale. Compilation then fails as the\n> newlocale(), freelocale() and strtod_l() functions are not defined.\n> \n> Fix the compilation breakage by checking for the availability of\n> newlocale(), and fall back to strtod() when the function isn't\n> available. This may not lead to the correct result if support for locale\n> objects isn't available and the locale isn't hardcoded to \"C\", but that\n> is such a corner case that we will likely never encounter it.\n\nAgreed.\n\nAnd this is fine by me, as long as it all compiles. I'm not yet aware of\nanyone actually using libcamera with uClibc (I'd love to hear if anyone\nis using it ...) - so I think this is just to maintain compatibility for\nnow.\n\nDoes the same issue happen in musl - or does that have locale support ?\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n> Fixes: e8ae254970cf (\"libcamera: yaml_parser: Use C locale\")\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  meson.build                  |  4 ++++\n>  src/libcamera/base/utils.cpp | 12 ++++++++++++\n>  2 files changed, 16 insertions(+)\n> \n> diff --git a/meson.build b/meson.build\n> index e86673dd5c0c..7dcd34d3e6b3 100644\n> --- a/meson.build\n> +++ b/meson.build\n> @@ -72,6 +72,10 @@ if cc.has_header_symbol('unistd.h', 'issetugid')\n>      config_h.set('HAVE_ISSETUGID', 1)\n>  endif\n>  \n> +if cc.has_header_symbol('locale.h', 'newlocale', prefix : '#define _GNU_SOURCE')\n> +    config_h.set('HAVE_NEWLOCALE', 1)\n> +endif\n> +\n>  if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix : '#define _GNU_SOURCE')\n>      config_h.set('HAVE_SECURE_GETENV', 1)\n>  endif\n> diff --git a/src/libcamera/base/utils.cpp b/src/libcamera/base/utils.cpp\n> index 4a239427a4d9..ac3e1311995e 100644\n> --- a/src/libcamera/base/utils.cpp\n> +++ b/src/libcamera/base/utils.cpp\n> @@ -464,6 +464,8 @@ std::string toAscii(const std::string &str)\n>   * \\a b\n>   */\n>  \n> +#if HAVE_NEWLOCALE\n> +\n>  namespace {\n>  \n>  /*\n> @@ -493,6 +495,8 @@ Locale cLocale(\"C\");\n>  \n>  } /* namespace */\n>  \n> +#endif /* HAVE_NEWLOCALE */\n> +\n>  /**\n>   * \\brief Convert a string to a double independently of the current locale\n>   * \\param[in] nptr The string to convert\n> @@ -506,7 +510,15 @@ Locale cLocale(\"C\");\n>   */\n>  double strtod(const char *__restrict nptr, char **__restrict endptr)\n>  {\n> +#if HAVE_NEWLOCALE\n>         return strtod_l(nptr, endptr, cLocale.locale());\n> +#else\n> +       /*\n> +        * If the libc implementation doesn't provide locale object support,\n> +        * assume that strtod() is locale-independent.\n> +        */\n> +       return strtod(nptr, endptr);\n> +#endif\n>  }\n>  \n>  } /* namespace utils */\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 44996C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun,  8 Jan 2023 23:22:43 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id A1733625CF;\n\tMon,  9 Jan 2023 00:22:42 +0100 (CET)","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 0093D625CC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  9 Jan 2023 00:22:40 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust3082.18-1.cable.virginm.net [86.31.172.11])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 789A4492;\n\tMon,  9 Jan 2023 00:22:40 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1673220162;\n\tbh=duKR12v51RcQAJRoBijmQ/kwZq6pTTM011Q6PTQbtLU=;\n\th=In-Reply-To:References:To:Date:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=FIyQEy3+vQUjNsKA73Tfqy3N06JIKyaae4gZQI0hZXQs+JfkWXZFM+ecSHAQkPs6C\n\t4W3l8sWTzYtrEkDFzNT3fl+ZwbX9p5SgM3hftlFzU5OnMGWvc7ZTsW6Ba0wWWAlqiC\n\tV9DhTVJ4c5Idy/ar79XM2MQiNqJ4Wi/NKBbGwcc41EHp7tArHGp3DTD43ibCALExEH\n\thcyvLZjuHUV2q7lUF335u5BVl6qYvArqvLhJDMF0eJb+rAurTNGIIgM+DALBc3GPFq\n\te5WkiK5uXQZAvPNEVV5Uax8LRkffpdsdLmjGPINa1c1Yd1YhiX+eIi5usPlik5hPNq\n\tqm3Q6fX+yrkJw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1673220160;\n\tbh=duKR12v51RcQAJRoBijmQ/kwZq6pTTM011Q6PTQbtLU=;\n\th=In-Reply-To:References:Subject:From:To:Date:From;\n\tb=ZHtMhfLHk1oP9NShUUx5dBFTECjRJQXK78rZP1C51Xkuy7boN3sPoX+2QhyOD0xkF\n\tg5pUKzNy8SoZDHUQ+bfA+VqNvEqlt3dlsPdLIvoNJ0hAdKqDJ9tU8gT8Wj5bqYDxv4\n\tmqyEKwO6MWqMrPXcNz0HQA/rG7o3jrp+Guu3yDNY="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"ZHtMhfLH\"; dkim-atps=neutral","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20230108214357.12641-3-laurent.pinchart@ideasonboard.com>","References":"<20230108214357.12641-1-laurent.pinchart@ideasonboard.com>\n\t<20230108214357.12641-3-laurent.pinchart@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Sun, 08 Jan 2023 23:22:37 +0000","Message-ID":"<167322015770.3175711.16947363745060220393@Monstersaurus>","User-Agent":"alot/0.10","Subject":"Re: [libcamera-devel] [PATCH v1 2/2] libcamera: base: utils:\n\tSupport C libraries lacking locale support","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":"Kieran Bingham via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>","Reply-To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"}},{"id":26197,"web_url":"https://patchwork.libcamera.org/comment/26197/","msgid":"<Y7tUWUEmAEJy+Z0n@pendragon.ideasonboard.com>","date":"2023-01-08T23:40:09","subject":"Re: [libcamera-devel] [PATCH v1 2/2] libcamera: base: utils:\n\tSupport C libraries lacking locale support","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Sun, Jan 08, 2023 at 11:22:37PM +0000, Kieran Bingham wrote:\n> Quoting Laurent Pinchart via libcamera-devel (2023-01-08 21:43:57)\n> > Not all C libraries include support for locale objects (locale_t) and\n> > the strto*_l() family of functions. A notable example is uClibc that can\n> > be compiled with a hardcoded \"C\" locale. Compilation then fails as the\n> > newlocale(), freelocale() and strtod_l() functions are not defined.\n> > \n> > Fix the compilation breakage by checking for the availability of\n> > newlocale(), and fall back to strtod() when the function isn't\n> > available. This may not lead to the correct result if support for locale\n> > objects isn't available and the locale isn't hardcoded to \"C\", but that\n> > is such a corner case that we will likely never encounter it.\n> \n> Agreed.\n> \n> And this is fine by me, as long as it all compiles. I'm not yet aware of\n> anyone actually using libcamera with uClibc (I'd love to hear if anyone\n> is using it ...) - so I think this is just to maintain compatibility for\n> now.\n> \n> Does the same issue happen in musl - or does that have locale support ?\n\nNo, musl has locale object support.\n\n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> > Fixes: e8ae254970cf (\"libcamera: yaml_parser: Use C locale\")\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  meson.build                  |  4 ++++\n> >  src/libcamera/base/utils.cpp | 12 ++++++++++++\n> >  2 files changed, 16 insertions(+)\n> > \n> > diff --git a/meson.build b/meson.build\n> > index e86673dd5c0c..7dcd34d3e6b3 100644\n> > --- a/meson.build\n> > +++ b/meson.build\n> > @@ -72,6 +72,10 @@ if cc.has_header_symbol('unistd.h', 'issetugid')\n> >      config_h.set('HAVE_ISSETUGID', 1)\n> >  endif\n> >  \n> > +if cc.has_header_symbol('locale.h', 'newlocale', prefix : '#define _GNU_SOURCE')\n> > +    config_h.set('HAVE_NEWLOCALE', 1)\n> > +endif\n> > +\n> >  if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix : '#define _GNU_SOURCE')\n> >      config_h.set('HAVE_SECURE_GETENV', 1)\n> >  endif\n> > diff --git a/src/libcamera/base/utils.cpp b/src/libcamera/base/utils.cpp\n> > index 4a239427a4d9..ac3e1311995e 100644\n> > --- a/src/libcamera/base/utils.cpp\n> > +++ b/src/libcamera/base/utils.cpp\n> > @@ -464,6 +464,8 @@ std::string toAscii(const std::string &str)\n> >   * \\a b\n> >   */\n> >  \n> > +#if HAVE_NEWLOCALE\n> > +\n> >  namespace {\n> >  \n> >  /*\n> > @@ -493,6 +495,8 @@ Locale cLocale(\"C\");\n> >  \n> >  } /* namespace */\n> >  \n> > +#endif /* HAVE_NEWLOCALE */\n> > +\n> >  /**\n> >   * \\brief Convert a string to a double independently of the current locale\n> >   * \\param[in] nptr The string to convert\n> > @@ -506,7 +510,15 @@ Locale cLocale(\"C\");\n> >   */\n> >  double strtod(const char *__restrict nptr, char **__restrict endptr)\n> >  {\n> > +#if HAVE_NEWLOCALE\n> >         return strtod_l(nptr, endptr, cLocale.locale());\n> > +#else\n> > +       /*\n> > +        * If the libc implementation doesn't provide locale object support,\n> > +        * assume that strtod() is locale-independent.\n> > +        */\n> > +       return strtod(nptr, endptr);\n> > +#endif\n> >  }\n> >  \n> >  } /* namespace utils */","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 E6692C322E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun,  8 Jan 2023 23:40:15 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 5066F625CF;\n\tMon,  9 Jan 2023 00:40:15 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 790F8625CC\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  9 Jan 2023 00:40:13 +0100 (CET)","from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi\n\t[213.243.189.158])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D32DD492;\n\tMon,  9 Jan 2023 00:40:12 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1673221215;\n\tbh=bbm9S9Bes4++lg37e0zHUKwC2DW4+wZSICrV+SMdShQ=;\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=X4aeQfCNmpBZUEgeo91cdEwg+PQYzmvaJgW4INAeavN4z4Tbx9nVrrdmLoIcgYdxz\n\t712ofVgPiNlCQPwXR+fVJb+wFHXTjLTPallfYqke1WShZr+LMfxw6oY9UrFLfOaFV2\n\tCUUZpNl5IK1KlrYBn46oW2Sj3kQPlklqJXq1sK5tVUmU+qFw+T8MHFtopdzmE3d4OL\n\txRZC/xouiwv4a+XKQumr7aGkUV+9nTGi9D4oToj2a9+qbh4WtO5iV01XtYzzpIo6AE\n\tDo1BpJ5Kvax456hopTJH6+jI3nUtL1BO3qjdbaw9/BNReT5/SMo7jvvll+aRMd/V1/\n\tT5mV31WFl3O2w==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1673221213;\n\tbh=bbm9S9Bes4++lg37e0zHUKwC2DW4+wZSICrV+SMdShQ=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=qVqJVEm9Y78jl8n75Gr3V/IBUk8UXlWej0VFMhZMjfNAmbLPVVWfr1lq1boDeu1ig\n\tq4FhS5v9nCebeCqq+6egynnCHGuA3U+74ZM3Sx3Uz2mWZq0TdPyS/f9770AsIALp7j\n\tV/gLsKCj2KDKNAtgvCjfEha/epAYsYXKEMyfGx5c="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"qVqJVEm9\"; dkim-atps=neutral","Date":"Mon, 9 Jan 2023 01:40:09 +0200","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Message-ID":"<Y7tUWUEmAEJy+Z0n@pendragon.ideasonboard.com>","References":"<20230108214357.12641-1-laurent.pinchart@ideasonboard.com>\n\t<20230108214357.12641-3-laurent.pinchart@ideasonboard.com>\n\t<167322015770.3175711.16947363745060220393@Monstersaurus>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<167322015770.3175711.16947363745060220393@Monstersaurus>","Subject":"Re: [libcamera-devel] [PATCH v1 2/2] libcamera: base: utils:\n\tSupport C libraries lacking locale support","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>"}},{"id":26200,"web_url":"https://patchwork.libcamera.org/comment/26200/","msgid":"<20230110081353.ck7yle2f2tnrxz4g@uno.localdomain>","date":"2023-01-10T08:13:53","subject":"Re: [libcamera-devel] [PATCH v1 2/2] libcamera: base: utils:\n\tSupport C libraries lacking locale support","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent\n\nOn Sun, Jan 08, 2023 at 11:43:57PM +0200, Laurent Pinchart via libcamera-devel wrote:\n> Not all C libraries include support for locale objects (locale_t) and\n> the strto*_l() family of functions. A notable example is uClibc that can\n> be compiled with a hardcoded \"C\" locale. Compilation then fails as the\n> newlocale(), freelocale() and strtod_l() functions are not defined.\n>\n> Fix the compilation breakage by checking for the availability of\n> newlocale(), and fall back to strtod() when the function isn't\n> available. This may not lead to the correct result if support for locale\n> objects isn't available and the locale isn't hardcoded to \"C\", but that\n> is such a corner case that we will likely never encounter it.\n>\n> Fixes: e8ae254970cf (\"libcamera: yaml_parser: Use C locale\")\n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> ---\n>  meson.build                  |  4 ++++\n>  src/libcamera/base/utils.cpp | 12 ++++++++++++\n>  2 files changed, 16 insertions(+)\n>\n> diff --git a/meson.build b/meson.build\n> index e86673dd5c0c..7dcd34d3e6b3 100644\n> --- a/meson.build\n> +++ b/meson.build\n> @@ -72,6 +72,10 @@ if cc.has_header_symbol('unistd.h', 'issetugid')\n>      config_h.set('HAVE_ISSETUGID', 1)\n>  endif\n>\n> +if cc.has_header_symbol('locale.h', 'newlocale', prefix : '#define _GNU_SOURCE')\n> +    config_h.set('HAVE_NEWLOCALE', 1)\n> +endif\n> +\n>  if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix : '#define _GNU_SOURCE')\n>      config_h.set('HAVE_SECURE_GETENV', 1)\n>  endif\n> diff --git a/src/libcamera/base/utils.cpp b/src/libcamera/base/utils.cpp\n> index 4a239427a4d9..ac3e1311995e 100644\n> --- a/src/libcamera/base/utils.cpp\n> +++ b/src/libcamera/base/utils.cpp\n> @@ -464,6 +464,8 @@ std::string toAscii(const std::string &str)\n>   * \\a b\n>   */\n>\n> +#if HAVE_NEWLOCALE\n> +\n\nJust bikeshedding on the NEWLOCALE symbol. \"New\" to implies there's an\nold vs new version, while you're just here checking that locale is\nsupported. Maybe just HAVE_LOCALE ?\n\nApart from this:\nReviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n\nThanks\n  j\n\n>  namespace {\n>\n>  /*\n> @@ -493,6 +495,8 @@ Locale cLocale(\"C\");\n>\n>  } /* namespace */\n>\n> +#endif /* HAVE_NEWLOCALE */\n> +\n>  /**\n>   * \\brief Convert a string to a double independently of the current locale\n>   * \\param[in] nptr The string to convert\n> @@ -506,7 +510,15 @@ Locale cLocale(\"C\");\n>   */\n>  double strtod(const char *__restrict nptr, char **__restrict endptr)\n>  {\n> +#if HAVE_NEWLOCALE\n>  \treturn strtod_l(nptr, endptr, cLocale.locale());\n> +#else\n> +\t/*\n> +\t * If the libc implementation doesn't provide locale object support,\n> +\t * assume that strtod() is locale-independent.\n> +\t */\n> +\treturn strtod(nptr, endptr);\n> +#endif\n>  }\n>\n>  } /* namespace utils */\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 DC678C3237\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 10 Jan 2023 08:13:56 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 1BF2F625DE;\n\tTue, 10 Jan 2023 09:13:56 +0100 (CET)","from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net\n\t[IPv6:2001:4b98:dc4:8::221])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 9FB5561F05\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 10 Jan 2023 09:13:54 +0100 (CET)","(Authenticated sender: jacopo@jmondi.org)\n\tby mail.gandi.net (Postfix) with ESMTPSA id 282A8240005;\n\tTue, 10 Jan 2023 08:13:53 +0000 (UTC)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1673338436;\n\tbh=aaz4EcB7jKMxOOtzJq8wv210HQSqtOz8uwJ671y4msY=;\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=oJNrdkQ39WJlsJdKFxjJ7LEplXRlVfnw8iRINuTbVaNLLQk9r/IApf+GclhblZ936\n\tK9cC8rDhcgiEVRbXnfwcXKkMi+zXVmIAlGnbHGlrwr6iqBCK5PgObqJrmNagqqQpZw\n\tNR6Cmo6b8cYOD8pm/4DfOYxnNQCfd+8n9i4fi6tInPkAD92z9hHYxQ5msVQ/GVBvtI\n\tTSpOCztpT81FL34vqijd64UJqlCY7jpIUCCKh1zQkJ4ghxLH4RaRqjgp32iqTfVtjo\n\tYpW7bbTlzMeTZ5mJ9BsPBSwbavfOgeJ6mx+2K6BXK42dPtJ/b6h8VCmcWC4shPLfu0\n\tSod+g8Uxv5+MA==","Date":"Tue, 10 Jan 2023 09:13:53 +0100","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20230110081353.ck7yle2f2tnrxz4g@uno.localdomain>","References":"<20230108214357.12641-1-laurent.pinchart@ideasonboard.com>\n\t<20230108214357.12641-3-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230108214357.12641-3-laurent.pinchart@ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v1 2/2] libcamera: base: utils:\n\tSupport C libraries lacking locale support","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":26203,"web_url":"https://patchwork.libcamera.org/comment/26203/","msgid":"<Y70m22gVcsJbPpoy@pendragon.ideasonboard.com>","date":"2023-01-10T08:50:35","subject":"Re: [libcamera-devel] [PATCH v1 2/2] libcamera: base: utils:\n\tSupport C libraries lacking locale support","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nOn Tue, Jan 10, 2023 at 09:13:53AM +0100, Jacopo Mondi wrote:\n> On Sun, Jan 08, 2023 at 11:43:57PM +0200, Laurent Pinchart via libcamera-devel wrote:\n> > Not all C libraries include support for locale objects (locale_t) and\n> > the strto*_l() family of functions. A notable example is uClibc that can\n> > be compiled with a hardcoded \"C\" locale. Compilation then fails as the\n> > newlocale(), freelocale() and strtod_l() functions are not defined.\n> >\n> > Fix the compilation breakage by checking for the availability of\n> > newlocale(), and fall back to strtod() when the function isn't\n> > available. This may not lead to the correct result if support for locale\n> > objects isn't available and the locale isn't hardcoded to \"C\", but that\n> > is such a corner case that we will likely never encounter it.\n> >\n> > Fixes: e8ae254970cf (\"libcamera: yaml_parser: Use C locale\")\n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> > ---\n> >  meson.build                  |  4 ++++\n> >  src/libcamera/base/utils.cpp | 12 ++++++++++++\n> >  2 files changed, 16 insertions(+)\n> >\n> > diff --git a/meson.build b/meson.build\n> > index e86673dd5c0c..7dcd34d3e6b3 100644\n> > --- a/meson.build\n> > +++ b/meson.build\n> > @@ -72,6 +72,10 @@ if cc.has_header_symbol('unistd.h', 'issetugid')\n> >      config_h.set('HAVE_ISSETUGID', 1)\n> >  endif\n> >\n> > +if cc.has_header_symbol('locale.h', 'newlocale', prefix : '#define _GNU_SOURCE')\n> > +    config_h.set('HAVE_NEWLOCALE', 1)\n> > +endif\n> > +\n> >  if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix : '#define _GNU_SOURCE')\n> >      config_h.set('HAVE_SECURE_GETENV', 1)\n> >  endif\n> > diff --git a/src/libcamera/base/utils.cpp b/src/libcamera/base/utils.cpp\n> > index 4a239427a4d9..ac3e1311995e 100644\n> > --- a/src/libcamera/base/utils.cpp\n> > +++ b/src/libcamera/base/utils.cpp\n> > @@ -464,6 +464,8 @@ std::string toAscii(const std::string &str)\n> >   * \\a b\n> >   */\n> >\n> > +#if HAVE_NEWLOCALE\n> > +\n> \n> Just bikeshedding on the NEWLOCALE symbol. \"New\" to implies there's an\n> old vs new version, while you're just here checking that locale is\n> supported. Maybe just HAVE_LOCALE ?\n\nIt comes directly from the name of the function being checked in\nmeson.build, newlocale(). I could replace that with a check for the\nlocale_t type and use HAVE_LOCALE_T if preferred.\n\n> Apart from this:\n> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>\n> \n> >  namespace {\n> >\n> >  /*\n> > @@ -493,6 +495,8 @@ Locale cLocale(\"C\");\n> >\n> >  } /* namespace */\n> >\n> > +#endif /* HAVE_NEWLOCALE */\n> > +\n> >  /**\n> >   * \\brief Convert a string to a double independently of the current locale\n> >   * \\param[in] nptr The string to convert\n> > @@ -506,7 +510,15 @@ Locale cLocale(\"C\");\n> >   */\n> >  double strtod(const char *__restrict nptr, char **__restrict endptr)\n> >  {\n> > +#if HAVE_NEWLOCALE\n> >  \treturn strtod_l(nptr, endptr, cLocale.locale());\n> > +#else\n> > +\t/*\n> > +\t * If the libc implementation doesn't provide locale object support,\n> > +\t * assume that strtod() is locale-independent.\n> > +\t */\n> > +\treturn strtod(nptr, endptr);\n> > +#endif\n> >  }\n> >\n> >  } /* namespace utils */","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 5C14FC322E\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 10 Jan 2023 08:50:41 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B1A3F625DE;\n\tTue, 10 Jan 2023 09:50:40 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 38FA261F05\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 10 Jan 2023 09:50:39 +0100 (CET)","from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi\n\t[213.243.189.158])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 8F1306CF;\n\tTue, 10 Jan 2023 09:50:38 +0100 (CET)"],"DKIM-Signature":["v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1673340640;\n\tbh=HtrXVXP4kwPI0TW6XgvH5mAGrNCaALl4nIkk3HwOG/E=;\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=FeCJ2+A0O4weFeRybID8jFZlCj3U5EXCblp+GbyaB4tgxc0BO/wyrT7yREK5KxM4R\n\tjRl15jQ7dGebVpTjkDPGuRK6iSnLwUd5LjvKnokA+2X96qdyIO57+11hILUQKFnTuc\n\t2edggDXoQAS7ML6fzfRdThBGJY7QWAV0hZzA+xXyRrlqPyIsgFJc/7/6TkQU0F/WsA\n\tQ59Mz+5u+IZyC0d8f1aAHHxPrqcLuoxdhSimbM1kzYSTdbJtoNOqIX4lk3BOrV7vNA\n\tuCsP3WDOYwX8ZVi4oexaJtPaoQDqox0OCMHifE0eCYRk7iIFCZUgUIfqR3lVsnr3gp\n\tywNi4B0yyAFOw==","v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1673340638;\n\tbh=HtrXVXP4kwPI0TW6XgvH5mAGrNCaALl4nIkk3HwOG/E=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=b7ecWiCGSR9yQS/KE2GndjPc31coBcvSCao4rjkA1XKWQEvtA59YabhvM/D0VsAbD\n\t4tB0yS2wgBbmDKwWA1JxE4qDOu+zM/RTj2A98B3wQfdJJZrujiMBLFVSu0/nIkIWTX\n\tjPquuPvZcV8rGr0SnI7iKiaxehDqFtyS5xpzCW7A="],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"b7ecWiCG\"; dkim-atps=neutral","Date":"Tue, 10 Jan 2023 10:50:35 +0200","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<Y70m22gVcsJbPpoy@pendragon.ideasonboard.com>","References":"<20230108214357.12641-1-laurent.pinchart@ideasonboard.com>\n\t<20230108214357.12641-3-laurent.pinchart@ideasonboard.com>\n\t<20230110081353.ck7yle2f2tnrxz4g@uno.localdomain>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20230110081353.ck7yle2f2tnrxz4g@uno.localdomain>","Subject":"Re: [libcamera-devel] [PATCH v1 2/2] libcamera: base: utils:\n\tSupport C libraries lacking locale support","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>"}}]