From patchwork Sun Sep 20 17:34:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 9674 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 141B5C3B5B for ; Sun, 20 Sep 2020 17:35:26 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 986F662FBF; Sun, 20 Sep 2020 19:35:25 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="rGqYO5q1"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 5DAE962E65 for ; Sun, 20 Sep 2020 19:35:23 +0200 (CEST) Received: from pendragon.lan (62-78-145-57.bb.dnainternet.fi [62.78.145.57]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D0EAC2D7; Sun, 20 Sep 2020 19:35:22 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1600623323; bh=mGWKYAUOUhb9R5hPBlWA+kxWJrhVepOAcGRrhACVHMc=; h=From:To:Cc:Subject:Date:From; b=rGqYO5q1zCIIlvugTqmwbIJB/dZAJYIf+KOM5ZZFc4Fdv0AcnUladMA2yfO7FNKBR +Iw5hcX8YpL+FvUeQIccuBAGw7hW7+0Yc58/OEjAQc8BeFxwT1uYRRejtMqg6CjyBh mG6zqv3EJFmKe1uoclAQtcF0E+NqVcHXSPf1SrOw= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Sun, 20 Sep 2020 20:34:47 +0300 Message-Id: <20200920173447.10064-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] Documentation: Adjust guidelines regarding math.h header 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" While libcamera prefers usage of the C standard library headers (xxx.h) over the C++ version (cxxx), we make an exception for cmath as the overloaded versions of the math functions are convenient. Document this, and adjust checkstyle.py accordingly. Signed-off-by: Laurent Pinchart Reviewed-by: Jacopo Mondi Reviewed-by: Niklas Söderlund --- Documentation/coding-style.rst | 14 +++++++++++--- utils/checkstyle.py | 6 +++--- 2 files changed, 14 insertions(+), 6 deletions(-) Jacopo, this originates from a discussion in the review of "[PATCH] libcamera: ipu3: Fix compilation issues with gcc5". I haven't assigned the authorship to you as you didn't provide a formal patch with an SoB line. Please let me know if I should (and give me your SoB in that case). Otherwise, a review is always appreciated :-) diff --git a/Documentation/coding-style.rst b/Documentation/coding-style.rst index 7c56a1b70014..d467a5a1b1ad 100644 --- a/Documentation/coding-style.rst +++ b/Documentation/coding-style.rst @@ -195,9 +195,17 @@ them, defines C compatibility headers. The former have a name of the form while the later are named . The C++ headers declare names in the std namespace, and may declare the same names in the global namespace. The C compatibility headers declare names in the global namespace, and may declare -the same names in the std namespace. Usage of the C compatibility headers is -strongly preferred. Code shall not rely on the optional declaration of names in -the global or std namespace. +the same names in the std namespace. Code shall not rely on the optional +declaration of names in the global or std namespace. + +Usage of the C compatibility headers is preferred, except for the math.h header. +Where math.h defines separate functions for different argument types (e.g. +abs(int), labs(long int), fabs(double) and fabsf(float)) and requires the +developer to pick the right function, cmath defines overloaded functions +(std::abs(int), std::abs(long int), std::abs(double) and std::abs(float) and let +the compiler select the right function. This avoids potential errors such as +calling abs(int) with a float argument, performing an unwanted implicit integer +conversion. For this reason, cmath is preferred over math.h. Documentation diff --git a/utils/checkstyle.py b/utils/checkstyle.py index b594a19aed5b..d5dc26c0f666 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -244,9 +244,9 @@ class IncludeChecker(StyleChecker): patterns = ('*.cpp', '*.h') headers = ('assert', 'ctype', 'errno', 'fenv', 'float', 'inttypes', - 'limits', 'locale', 'math', 'setjmp', 'signal', 'stdarg', - 'stddef', 'stdint', 'stdio', 'stdlib', 'string', 'time', 'uchar', - 'wchar', 'wctype') + 'limits', 'locale', 'setjmp', 'signal', 'stdarg', 'stddef', + 'stdint', 'stdio', 'stdlib', 'string', 'time', 'uchar', 'wchar', + 'wctype') include_regex = re.compile('^#include ') def __init__(self, content):