From patchwork Sun Jan 8 21:43:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 18099 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id D1718C3292 for ; Sun, 8 Jan 2023 21:44:05 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 41234625CF; Sun, 8 Jan 2023 22:44:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1673214245; bh=ma5lAArjP3pxlwDCj4C5a6tW6F1ZaaPcb5DIgycmRMc=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=V2HNjZ0ZdJJyj7Xi2N0JUI1G0NFmh/XSNmZM6E5ASsvzkRJmz63w2nDetgQMBHDXw sFk5AS7llvzgO4lfRy98fRJBSJ8EDEZV801/Y6dxeTA3iSNK1DFunh455Wi1la0VCx eybeSPB3+2eIkTZ/r0+EH89kNgXS8EXQd44gxS0ZzFb9XRJPRRM64xS9ztpcVenHl1 TkaTl62cSl5Zz/4kOQqoqUXZtKsuIm03REHvJhIuKzqdLUN/r1uywuyqupFwgqh9Oy pG5B3df1uHYfoccrwxPs7LkTTwM8whV5GRqLjqx0IjW8p/wlpOrlIaQV1djy2MhciZ YCSgf6H9SGySQ== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 60DDF625CF for ; Sun, 8 Jan 2023 22:44:04 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="Y0N6alnc"; dkim-atps=neutral Received: from pendragon.ideasonboard.com (213-243-189-158.bb.dnainternet.fi [213.243.189.158]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DAECC6DB for ; Sun, 8 Jan 2023 22:44:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1673214244; bh=ma5lAArjP3pxlwDCj4C5a6tW6F1ZaaPcb5DIgycmRMc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Y0N6alncshtHXtb7qyjBf06Kom2LI9aZOxfaI6r9wo2msHhl32LYjKq1iBdTCyzsx fsxfFt9G7LweULJPgWGwkP/uG9xPP2+TsXSkToiZTiUPi5FwQ6vNbsE/eY4RxyWqsW 8gjg8STqeKxRKzAEKzqNkZNoc52P7nmV41P5Y6fU= To: libcamera-devel@lists.libcamera.org Date: Sun, 8 Jan 2023 23:43:57 +0200 Message-Id: <20230108214357.12641-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.38.2 In-Reply-To: <20230108214357.12641-1-laurent.pinchart@ideasonboard.com> References: <20230108214357.12641-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v1 2/2] libcamera: base: utils: Support C libraries lacking locale support X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Laurent Pinchart via libcamera-devel From: Laurent Pinchart Reply-To: Laurent Pinchart Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Not all C libraries include support for locale objects (locale_t) and the strto*_l() family of functions. A notable example is uClibc that can be compiled with a hardcoded "C" locale. Compilation then fails as the newlocale(), freelocale() and strtod_l() functions are not defined. Fix the compilation breakage by checking for the availability of newlocale(), and fall back to strtod() when the function isn't available. This may not lead to the correct result if support for locale objects isn't available and the locale isn't hardcoded to "C", but that is such a corner case that we will likely never encounter it. Fixes: e8ae254970cf ("libcamera: yaml_parser: Use C locale") Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Jacopo Mondi --- meson.build | 4 ++++ src/libcamera/base/utils.cpp | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/meson.build b/meson.build index e86673dd5c0c..7dcd34d3e6b3 100644 --- a/meson.build +++ b/meson.build @@ -72,6 +72,10 @@ if cc.has_header_symbol('unistd.h', 'issetugid') config_h.set('HAVE_ISSETUGID', 1) endif +if cc.has_header_symbol('locale.h', 'newlocale', prefix : '#define _GNU_SOURCE') + config_h.set('HAVE_NEWLOCALE', 1) +endif + if cc.has_header_symbol('stdlib.h', 'secure_getenv', prefix : '#define _GNU_SOURCE') config_h.set('HAVE_SECURE_GETENV', 1) endif diff --git a/src/libcamera/base/utils.cpp b/src/libcamera/base/utils.cpp index 4a239427a4d9..ac3e1311995e 100644 --- a/src/libcamera/base/utils.cpp +++ b/src/libcamera/base/utils.cpp @@ -464,6 +464,8 @@ std::string toAscii(const std::string &str) * \a b */ +#if HAVE_NEWLOCALE + namespace { /* @@ -493,6 +495,8 @@ Locale cLocale("C"); } /* namespace */ +#endif /* HAVE_NEWLOCALE */ + /** * \brief Convert a string to a double independently of the current locale * \param[in] nptr The string to convert @@ -506,7 +510,15 @@ Locale cLocale("C"); */ double strtod(const char *__restrict nptr, char **__restrict endptr) { +#if HAVE_NEWLOCALE return strtod_l(nptr, endptr, cLocale.locale()); +#else + /* + * If the libc implementation doesn't provide locale object support, + * assume that strtod() is locale-independent. + */ + return strtod(nptr, endptr); +#endif } } /* namespace utils */