From patchwork Wed Oct 23 13:52:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2211 Return-Path: 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 2A8066138B for ; Wed, 23 Oct 2019 15:54:01 +0200 (CEST) Received: from pendragon.ideasonboard.com (143.121.2.93.rev.sfr.net [93.2.121.143]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id ABA6171F for ; Wed, 23 Oct 2019 15:54:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1571838840; bh=Dw2zSmuQ4ZAjdEVFMkfMIMApPUxbKHYW5Cr6RHVStv0=; h=From:To:Subject:Date:From; b=fRgTkJ2GIep85xx044Vm3rKnQZgqjyzcB8j/lidVnmfj8He86vvdK6cK6z7LihSuS KdgvD+bwU6vq07WPUo+gKXK5t/W+YnOacx1COyESFUNRthDl5SrX3Vs6m1xKuacgTg d6usKaHpW1l6yncSx4n88gwdXIdmHEwuop4vYFOs= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Oct 2019 16:52:55 +0300 Message-Id: <20191023135258.32256-1-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 1/4] Documentation: coding-style: Document usage of C compatibility headers 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-List-Received-Date: Wed, 23 Oct 2019 13:54:01 -0000 The C++ standard defines a set of C++ standard library headers, and for some of 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. We want to standardise on one set of headers through libcamera, and don't want to rely on optional behaviour. We can thus either use the C++ headers with an explicit std:: namespace qualifier through the code, or the C headers without the qualifier. Both set of headers are defined by the C++ standard, and are thus valid choices. After weighting pros and cons, we have decided to use the C compatibility headers, as nobody wanted to write std::uint32_t. Document this decision. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham Reviewed-by: Niklas Söderlund --- Documentation/coding-style.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Documentation/coding-style.rst b/Documentation/coding-style.rst index 8dd1afce1a2c..ced3155169a6 100644 --- a/Documentation/coding-style.rst +++ b/Documentation/coding-style.rst @@ -170,6 +170,18 @@ These rules match the `object ownership rules from the Chromium C++ Style Guide` long term borrowing isn't marked through language constructs, it shall be documented explicitly in details in the API. +C Compatibility Headers +~~~~~~~~~~~~~~~~~~~~~~~ + +The C++ standard defines a set of C++ standard library headers, and for some of +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. + Documentation ------------- From patchwork Wed Oct 23 13:52:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2212 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3FB2C6138D for ; Wed, 23 Oct 2019 15:54:01 +0200 (CEST) Received: from pendragon.ideasonboard.com (143.121.2.93.rev.sfr.net [93.2.121.143]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D946F814 for ; Wed, 23 Oct 2019 15:54:00 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1571838840; bh=0qI1bjkBKakM0C0NEQRoFbFrjCAnpDloioehclwe/hQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=DHCmyPXfFpc7DSpkSbOnq5eO7c1n7NlrAeVw5N2YkpDCyrGx69kdziJ/v91va1mxS /fAhbXLvjap2nSZmmmJhXin5aG3GDOneOkwqxVzPe+6t796TbCNYw1OFWeBfqGdlKl Ut+oeLB8Xgzu/eLCECgxkO+v8h/DcgHuyT1Mv7ds= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Oct 2019 16:52:56 +0300 Message-Id: <20191023135258.32256-2-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191023135258.32256-1-laurent.pinchart@ideasonboard.com> References: <20191023135258.32256-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 2/4] Documentation: coding-style: Document order of includes 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-List-Received-Date: Wed, 23 Oct 2019 13:54:01 -0000 We follow the Google C++ Style Guide rule on include ordering with a few tweaks. Document our rule explicitly. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- Documentation/coding-style.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Documentation/coding-style.rst b/Documentation/coding-style.rst index ced3155169a6..c53248234c34 100644 --- a/Documentation/coding-style.rst +++ b/Documentation/coding-style.rst @@ -61,6 +61,29 @@ document: Code Style for indentation, braces, spacing, etc * Header guards are formatted as '__LIBCAMERA_FILE_NAME_H__' +Order of Includes +~~~~~~~~~~~~~~~~~ + +Headers shall be included at the beginning of .c, .cpp and .h files, right +after the file description comment block and, for .h files, the header guard +macro. For .cpp files, if the file implements an API declared in a header file, +that header file shall be included first in order to ensure it is +self-contained. + +The headers shall be grouped and ordered as follows. + + # The header declaring the API being implemented (if any) + # The C and C++ system and standard library headers + # Other libraries' headers, with one group per library + # Other project's headers + +Groups of headers shall be separated by a single blank line. Headers within +each group shall be sorted alphabetically. + +System and library headers shall be included with angle brackets. Project +headers shall be included with angle brackets for the libcamera public API +headers, and with double quotes for other libcamera headers. + C++ Specific Rules ------------------ From patchwork Wed Oct 23 13:52:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2213 Return-Path: Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6AAF06138F for ; Wed, 23 Oct 2019 15:54:01 +0200 (CEST) Received: from pendragon.ideasonboard.com (143.121.2.93.rev.sfr.net [93.2.121.143]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 11169A24 for ; Wed, 23 Oct 2019 15:54:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1571838841; bh=DxRBXOFYmDhQwqHU0Iuu5vpN/Q10ulADw5PZNF8qoR8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=YSHoydqyje2yDzp5wH6YDFSf/BtFqj62g7pkcBYfuCdahMnzpgwPZdROjPtxW4Flu oo5eNDn35K5J9p2Vk6Qub0R0thTZQ7ypzPhExEgVWRXftCFSDSI00yuQDlZU4RqUNV 1Fx5shRa+he/GsO11IeB2z4FPstWob7tgmt84rVM= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Oct 2019 16:52:57 +0300 Message-Id: <20191023135258.32256-3-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191023135258.32256-1-laurent.pinchart@ideasonboard.com> References: <20191023135258.32256-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 3/4] utils: checkstyle.py: Add include checker 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-List-Received-Date: Wed, 23 Oct 2019 13:54:01 -0000 --- utils/checkstyle.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) Signed-off-by: Laurent Pinchart Reviewed-by: <...insert tag here...> diff --git a/utils/checkstyle.py b/utils/checkstyle.py index 42a96f6d6102..335e58f5fddf 100755 --- a/utils/checkstyle.py +++ b/utils/checkstyle.py @@ -240,6 +240,38 @@ class StyleIssue(object): self.msg = msg +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') + include_regex = re.compile('^#include ') + + def __init__(self, content): + super().__init__() + self.__content = content + + def check(self, line_numbers): + issues = [] + + for line_number in line_numbers: + line = self.__content[line_number - 1] + match = IncludeChecker.include_regex.match(line) + if not match: + continue + + header = match.group(1) + if header not in IncludeChecker.headers: + continue + + issues.append(StyleIssue(line_number, line, + 'C compatibility header <%s.h> is preferred' % header)) + + return issues + + class LogCategoryChecker(StyleChecker): log_regex = re.compile('\\bLOG\((Debug|Info|Warning|Error|Fatal)\)') patterns = ('*.cpp',) From patchwork Wed Oct 23 13:52:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laurent Pinchart X-Patchwork-Id: 2214 Return-Path: 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 95DC96138B for ; Wed, 23 Oct 2019 15:54:01 +0200 (CEST) Received: from pendragon.ideasonboard.com (143.121.2.93.rev.sfr.net [93.2.121.143]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 465C971F for ; Wed, 23 Oct 2019 15:54:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1571838841; bh=4WxC05OZFfV/oLQL/ZJLIbyvjLLOd8U6xruAJjZ1tg4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bkcx0eyqPAErTuFbK2Itz51v+im7+jEGfxdauF0JxMGNVYK72OeoXKRipCUT/0UBm C1OlOvgTgVg6VPg6BSWaTNX3NyVhYRNdNn9E1egEfCN8X74O3bZ2dhc1fQUtCmUV5b lndJ/qYMFVwtVCWvDloqFj97qtV8gnngbP2pz2VI= From: Laurent Pinchart To: libcamera-devel@lists.libcamera.org Date: Wed, 23 Oct 2019 16:52:58 +0300 Message-Id: <20191023135258.32256-4-laurent.pinchart@ideasonboard.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191023135258.32256-1-laurent.pinchart@ideasonboard.com> References: <20191023135258.32256-1-laurent.pinchart@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH 4/4] libcamera: Standardise on C compatibility headers 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-List-Received-Date: Wed, 23 Oct 2019 13:54:01 -0000 Now that our usage of C compatibility header is documented, use them consistently through the source code. While at it, group the C and C++ include statements, and fix a handful of #include ordering issues. Signed-off-by: Laurent Pinchart Reviewed-by: Kieran Bingham --- include/libcamera/timer.h | 2 +- src/cam/capture.cpp | 2 +- src/cam/options.cpp | 2 +- src/ipa/rkisp1/rkisp1.cpp | 2 +- src/libcamera/device_enumerator_udev.cpp | 5 ++--- src/libcamera/include/event_dispatcher_poll.h | 4 ++-- src/libcamera/include/ipc_unixsocket.h | 2 +- src/libcamera/log.cpp | 6 +++--- src/libcamera/media_device.cpp | 3 +-- src/libcamera/media_object.cpp | 3 +-- src/libcamera/stream.cpp | 2 +- test/ipa/ipa_interface_test.cpp | 3 +-- test/media_device/media_device_print_test.cpp | 2 +- test/pipeline/ipu3/ipu3_pipeline_test.cpp | 1 - test/v4l2_subdevice/test_formats.cpp | 2 +- test/v4l2_videodevice/capture_async.cpp | 4 ++-- test/v4l2_videodevice/controls.cpp | 2 +- test/v4l2_videodevice/formats.cpp | 2 +- 18 files changed, 22 insertions(+), 27 deletions(-) diff --git a/include/libcamera/timer.h b/include/libcamera/timer.h index 34e7b8ac8e87..f55fe3c09660 100644 --- a/include/libcamera/timer.h +++ b/include/libcamera/timer.h @@ -8,7 +8,7 @@ #define __LIBCAMERA_TIMER_H__ #include -#include +#include #include #include diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp index 8a939c622703..d05c01f1b13e 100644 --- a/src/cam/capture.cpp +++ b/src/cam/capture.cpp @@ -6,9 +6,9 @@ */ #include -#include #include #include +#include #include #include "capture.h" diff --git a/src/cam/options.cpp b/src/cam/options.cpp index 7c3948df3b5c..1f0631eccfba 100644 --- a/src/cam/options.cpp +++ b/src/cam/options.cpp @@ -5,7 +5,7 @@ * options.cpp - cam - Options parsing */ -#include +#include #include #include #include diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp index 570145ce71b2..9a13f5c7df17 100644 --- a/src/ipa/rkisp1/rkisp1.cpp +++ b/src/ipa/rkisp1/rkisp1.cpp @@ -6,9 +6,9 @@ */ #include -#include #include #include +#include #include #include diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp index ddcd59ea52c1..b2c5fd221dcd 100644 --- a/src/libcamera/device_enumerator_udev.cpp +++ b/src/libcamera/device_enumerator_udev.cpp @@ -8,11 +8,10 @@ #include "device_enumerator_udev.h" #include -#include -#include - #include #include +#include +#include #include #include #include diff --git a/src/libcamera/include/event_dispatcher_poll.h b/src/libcamera/include/event_dispatcher_poll.h index d82b302c4aea..1f0738617425 100644 --- a/src/libcamera/include/event_dispatcher_poll.h +++ b/src/libcamera/include/event_dispatcher_poll.h @@ -7,12 +7,12 @@ #ifndef __LIBCAMERA_EVENT_DISPATCHER_POLL_H__ #define __LIBCAMERA_EVENT_DISPATCHER_POLL_H__ -#include - #include #include #include +#include + struct pollfd; namespace libcamera { diff --git a/src/libcamera/include/ipc_unixsocket.h b/src/libcamera/include/ipc_unixsocket.h index 03e9fe492bde..820d05611049 100644 --- a/src/libcamera/include/ipc_unixsocket.h +++ b/src/libcamera/include/ipc_unixsocket.h @@ -8,7 +8,7 @@ #ifndef __LIBCAMERA_IPC_UNIXSOCKET_H__ #define __LIBCAMERA_IPC_UNIXSOCKET_H__ -#include +#include #include #include diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp index 51f9f86b4c44..50f345b98c74 100644 --- a/src/libcamera/log.cpp +++ b/src/libcamera/log.cpp @@ -7,14 +7,14 @@ #include "log.h" -#include -#include -#include #include #include #include +#include +#include #include #include +#include #include #include diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp index bd99deba098d..0d6630fbd1f4 100644 --- a/src/libcamera/media_device.cpp +++ b/src/libcamera/media_device.cpp @@ -9,11 +9,10 @@ #include #include +#include #include #include #include - -#include #include #include diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp index 8794ff4578c9..ef32065c161d 100644 --- a/src/libcamera/media_object.cpp +++ b/src/libcamera/media_object.cpp @@ -8,10 +8,9 @@ #include "media_object.h" #include +#include #include #include - -#include #include #include diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp index 610920d1e5b3..b8e7209c1047 100644 --- a/src/libcamera/stream.cpp +++ b/src/libcamera/stream.cpp @@ -9,8 +9,8 @@ #include #include -#include #include +#include #include #include diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp index 0bdeb167a675..cafc249bbbc9 100644 --- a/test/ipa/ipa_interface_test.cpp +++ b/test/ipa/ipa_interface_test.cpp @@ -6,13 +6,12 @@ */ #include +#include #include #include #include #include -#include - #include #include #include diff --git a/test/media_device/media_device_print_test.cpp b/test/media_device/media_device_print_test.cpp index 30d929b8c763..8dd8a151266d 100644 --- a/test/media_device/media_device_print_test.cpp +++ b/test/media_device/media_device_print_test.cpp @@ -4,8 +4,8 @@ * * media_device_print_test.cpp - Print out media devices */ -#include +#include #include #include #include diff --git a/test/pipeline/ipu3/ipu3_pipeline_test.cpp b/test/pipeline/ipu3/ipu3_pipeline_test.cpp index 8bfcd609a071..a5c6be0955df 100644 --- a/test/pipeline/ipu3/ipu3_pipeline_test.cpp +++ b/test/pipeline/ipu3/ipu3_pipeline_test.cpp @@ -6,7 +6,6 @@ */ #include - #include #include #include diff --git a/test/v4l2_subdevice/test_formats.cpp b/test/v4l2_subdevice/test_formats.cpp index e90c2c2426da..5cf5d5664b04 100644 --- a/test/v4l2_subdevice/test_formats.cpp +++ b/test/v4l2_subdevice/test_formats.cpp @@ -5,8 +5,8 @@ * libcamera V4L2 Subdevice format handling test */ -#include #include +#include #include "v4l2_subdevice.h" #include "v4l2_subdevice_test.h" diff --git a/test/v4l2_videodevice/capture_async.cpp b/test/v4l2_videodevice/capture_async.cpp index 17eb528b12fd..442a4fe56eac 100644 --- a/test/v4l2_videodevice/capture_async.cpp +++ b/test/v4l2_videodevice/capture_async.cpp @@ -5,12 +5,12 @@ * libcamera V4L2 API tests */ +#include + #include #include #include -#include - #include "thread.h" #include "v4l2_videodevice_test.h" diff --git a/test/v4l2_videodevice/controls.cpp b/test/v4l2_videodevice/controls.cpp index 975c852b8cbf..42c653d4435a 100644 --- a/test/v4l2_videodevice/controls.cpp +++ b/test/v4l2_videodevice/controls.cpp @@ -5,8 +5,8 @@ * controls.cpp - V4L2 device controls handling test */ -#include #include +#include #include "v4l2_videodevice.h" diff --git a/test/v4l2_videodevice/formats.cpp b/test/v4l2_videodevice/formats.cpp index ee7d357de075..d504d1788d02 100644 --- a/test/v4l2_videodevice/formats.cpp +++ b/test/v4l2_videodevice/formats.cpp @@ -5,8 +5,8 @@ * libcamera V4L2 device format handling test */ -#include #include +#include #include "v4l2_videodevice.h"