[{"id":2953,"web_url":"https://patchwork.libcamera.org/comment/2953/","msgid":"<3e00e0de-c534-c8d1-7583-77cdc118205f@ideasonboard.com>","date":"2019-10-23T14:24:33","subject":"Re: [libcamera-devel] [PATCH 4/4] libcamera: Standardise on C\n\tcompatibility headers","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Hi Laurent,\n\nOn 23/10/2019 14:52, Laurent Pinchart wrote:\n> Now that our usage of C compatibility header is documented, use them\n> consistently through the source code. While at it, group the C and C++\n> include statements, and fix a handful of #include ordering issues.\n\nI think the 'handful' of include ordering issues is mostly where we\npreviously separated C and C++ header includes.\n\nIf we're removing this separation explicitly - I think stating that\nclearly here would be good.\n\ndiscussion comment down at the event_dispatcher_poll too...\n\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nBut otherwise, with those comments resolved in whichever way you deem best,\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n\n\n\n> ---\n>  include/libcamera/timer.h                     | 2 +-\n>  src/cam/capture.cpp                           | 2 +-\n>  src/cam/options.cpp                           | 2 +-\n>  src/ipa/rkisp1/rkisp1.cpp                     | 2 +-\n>  src/libcamera/device_enumerator_udev.cpp      | 5 ++---\n>  src/libcamera/include/event_dispatcher_poll.h | 4 ++--\n>  src/libcamera/include/ipc_unixsocket.h        | 2 +-\n>  src/libcamera/log.cpp                         | 6 +++---\n>  src/libcamera/media_device.cpp                | 3 +--\n>  src/libcamera/media_object.cpp                | 3 +--\n>  src/libcamera/stream.cpp                      | 2 +-\n>  test/ipa/ipa_interface_test.cpp               | 3 +--\n>  test/media_device/media_device_print_test.cpp | 2 +-\n>  test/pipeline/ipu3/ipu3_pipeline_test.cpp     | 1 -\n>  test/v4l2_subdevice/test_formats.cpp          | 2 +-\n>  test/v4l2_videodevice/capture_async.cpp       | 4 ++--\n>  test/v4l2_videodevice/controls.cpp            | 2 +-\n>  test/v4l2_videodevice/formats.cpp             | 2 +-\n>  18 files changed, 22 insertions(+), 27 deletions(-)\n> \n> diff --git a/include/libcamera/timer.h b/include/libcamera/timer.h\n> index 34e7b8ac8e87..f55fe3c09660 100644\n> --- a/include/libcamera/timer.h\n> +++ b/include/libcamera/timer.h\n> @@ -8,7 +8,7 @@\n>  #define __LIBCAMERA_TIMER_H__\n>  \n>  #include <chrono>\n> -#include <cstdint>\n> +#include <stdint.h>\n>  \n>  #include <libcamera/object.h>\n>  #include <libcamera/signal.h>\n> diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp\n> index 8a939c622703..d05c01f1b13e 100644\n> --- a/src/cam/capture.cpp\n> +++ b/src/cam/capture.cpp\n> @@ -6,9 +6,9 @@\n>   */\n>  \n>  #include <chrono>\n> -#include <climits>\n>  #include <iomanip>\n>  #include <iostream>\n> +#include <limits.h>\n>  #include <sstream>\n>  \n>  #include \"capture.h\"\n> diff --git a/src/cam/options.cpp b/src/cam/options.cpp\n> index 7c3948df3b5c..1f0631eccfba 100644\n> --- a/src/cam/options.cpp\n> +++ b/src/cam/options.cpp\n> @@ -5,7 +5,7 @@\n>   * options.cpp - cam - Options parsing\n>   */\n>  \n> -#include <cassert>\n> +#include <assert.h>\n>  #include <getopt.h>\n>  #include <iomanip>\n>  #include <iostream>\n> diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\n> index 570145ce71b2..9a13f5c7df17 100644\n> --- a/src/ipa/rkisp1/rkisp1.cpp\n> +++ b/src/ipa/rkisp1/rkisp1.cpp\n> @@ -6,9 +6,9 @@\n>   */\n>  \n>  #include <algorithm>\n> -#include <cstdint>\n>  #include <math.h>\n>  #include <queue>\n> +#include <stdint.h>\n>  #include <string.h>\n>  \n>  #include <linux/rkisp1-config.h>\n> diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp\n> index ddcd59ea52c1..b2c5fd221dcd 100644\n> --- a/src/libcamera/device_enumerator_udev.cpp\n> +++ b/src/libcamera/device_enumerator_udev.cpp\n> @@ -8,11 +8,10 @@\n>  #include \"device_enumerator_udev.h\"\n>  \n>  #include <algorithm>\n> -#include <list>\n> -#include <map>\n> -\n>  #include <fcntl.h>\n>  #include <libudev.h>\n> +#include <list>\n> +#include <map>\n>  #include <string.h>\n>  #include <sys/ioctl.h>\n>  #include <sys/sysmacros.h>\n> diff --git a/src/libcamera/include/event_dispatcher_poll.h b/src/libcamera/include/event_dispatcher_poll.h\n> index d82b302c4aea..1f0738617425 100644\n> --- a/src/libcamera/include/event_dispatcher_poll.h\n> +++ b/src/libcamera/include/event_dispatcher_poll.h\n> @@ -7,12 +7,12 @@\n>  #ifndef __LIBCAMERA_EVENT_DISPATCHER_POLL_H__\n>  #define __LIBCAMERA_EVENT_DISPATCHER_POLL_H__\n>  \n> -#include <libcamera/event_dispatcher.h>\n> -\n>  #include <list>\n>  #include <map>\n>  #include <vector>\n>  \n> +#include <libcamera/event_dispatcher.h>\n\n>From 2/4\n\n+The headers shall be grouped and ordered as follows.\n+\n+ # The header declaring the API being implemented (if any)\n+ # The C and C++ system and standard library headers\n+ # Other libraries' headers, with one group per library\n+ # Other project's headers\n\nNow that's a possible confusion point, /this/ EVENT_DISPATCHER_POLL\nheader /is/ implementing the API for an event dispatcher - so therefore\npoint one above could be seen to be declaring it should be first.\n\nHowever, I suspect the intent of the ordering might be that it should\nonly be first if this is the header for this exact implementation, not\nany virtual interface. But I don't know how to word that to remove\nambiguity :D\n\nOr maybe this one should be first ... I'll leave it to you ...\n\n> +\n>  struct pollfd;\n>  \n>  namespace libcamera {\n> diff --git a/src/libcamera/include/ipc_unixsocket.h b/src/libcamera/include/ipc_unixsocket.h\n> index 03e9fe492bde..820d05611049 100644\n> --- a/src/libcamera/include/ipc_unixsocket.h\n> +++ b/src/libcamera/include/ipc_unixsocket.h\n> @@ -8,7 +8,7 @@\n>  #ifndef __LIBCAMERA_IPC_UNIXSOCKET_H__\n>  #define __LIBCAMERA_IPC_UNIXSOCKET_H__\n>  \n> -#include <cstdint>\n> +#include <stdint.h>\n>  #include <sys/types.h>\n>  #include <vector>\n>  \n> diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\n> index 51f9f86b4c44..50f345b98c74 100644\n> --- a/src/libcamera/log.cpp\n> +++ b/src/libcamera/log.cpp\n> @@ -7,14 +7,14 @@\n>  \n>  #include \"log.h\"\n>  \n> -#include <cstdio>\n> -#include <cstdlib>\n> -#include <ctime>\n>  #include <fstream>\n>  #include <iostream>\n>  #include <list>\n> +#include <stdio.h>\n> +#include <stdlib.h>\n>  #include <string.h>\n>  #include <syslog.h>\n> +#include <time.h>\n>  #include <unordered_set>\n>  \n>  #include <libcamera/logging.h>\n> diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\n> index bd99deba098d..0d6630fbd1f4 100644\n> --- a/src/libcamera/media_device.cpp\n> +++ b/src/libcamera/media_device.cpp\n> @@ -9,11 +9,10 @@\n>  \n>  #include <errno.h>\n>  #include <fcntl.h>\n> +#include <string>\n>  #include <string.h>\n>  #include <sys/ioctl.h>\n>  #include <unistd.h>\n> -\n> -#include <string>\n>  #include <vector>\n\nI kind of really like the separation between C headers and C++\nheaders... but ho hum. It's arbitrary.\n\n\n>  #include <linux/media.h>\n> diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp\n> index 8794ff4578c9..ef32065c161d 100644\n> --- a/src/libcamera/media_object.cpp\n> +++ b/src/libcamera/media_object.cpp\n> @@ -8,10 +8,9 @@\n>  #include \"media_object.h\"\n>  \n>  #include <errno.h>\n> +#include <string>\n>  #include <string.h>\n>  #include <unistd.h>\n> -\n> -#include <string>\n>  #include <vector>\n>  \n>  #include <linux/media.h>\n> diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp\n> index 610920d1e5b3..b8e7209c1047 100644\n> --- a/src/libcamera/stream.cpp\n> +++ b/src/libcamera/stream.cpp\n> @@ -9,8 +9,8 @@\n>  \n>  #include <algorithm>\n>  #include <array>\n> -#include <climits>\n>  #include <iomanip>\n> +#include <limits.h>\n>  #include <sstream>\n>  \n>  #include <libcamera/request.h>\n> diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp\n> index 0bdeb167a675..cafc249bbbc9 100644\n> --- a/test/ipa/ipa_interface_test.cpp\n> +++ b/test/ipa/ipa_interface_test.cpp\n> @@ -6,13 +6,12 @@\n>   */\n>  \n>  #include <fcntl.h>\n> +#include <iostream>\n>  #include <string.h>\n>  #include <sys/stat.h>\n>  #include <sys/types.h>\n>  #include <unistd.h>\n>  \n> -#include <iostream>\n> -\n\nHrm ... this does show that we have considered C and C++ headers as\nseparate groups previously - so this is definitely a change ... Worth\nchecking specifically with the others.\n\nEither way, consistency is good.\n\n\n>  #include <libcamera/event_dispatcher.h>\n>  #include <libcamera/event_notifier.h>\n>  #include <libcamera/timer.h>\n> diff --git a/test/media_device/media_device_print_test.cpp b/test/media_device/media_device_print_test.cpp\n> index 30d929b8c763..8dd8a151266d 100644\n> --- a/test/media_device/media_device_print_test.cpp\n> +++ b/test/media_device/media_device_print_test.cpp\n> @@ -4,8 +4,8 @@\n>   *\n>   * media_device_print_test.cpp - Print out media devices\n>   */\n> -#include <iostream>\n>  \n> +#include <iostream>\n>  #include <sys/types.h>\n>  #include <sys/stat.h>\n>  #include <unistd.h>\n> diff --git a/test/pipeline/ipu3/ipu3_pipeline_test.cpp b/test/pipeline/ipu3/ipu3_pipeline_test.cpp\n> index 8bfcd609a071..a5c6be0955df 100644\n> --- a/test/pipeline/ipu3/ipu3_pipeline_test.cpp\n> +++ b/test/pipeline/ipu3/ipu3_pipeline_test.cpp\n> @@ -6,7 +6,6 @@\n>   */\n>  \n>  #include <iostream>\n> -\n>  #include <sys/stat.h>\n>  #include <sys/types.h>\n>  #include <unistd.h>\n> diff --git a/test/v4l2_subdevice/test_formats.cpp b/test/v4l2_subdevice/test_formats.cpp\n> index e90c2c2426da..5cf5d5664b04 100644\n> --- a/test/v4l2_subdevice/test_formats.cpp\n> +++ b/test/v4l2_subdevice/test_formats.cpp\n> @@ -5,8 +5,8 @@\n>   * libcamera V4L2 Subdevice format handling test\n>   */\n>  \n> -#include <climits>\n>  #include <iostream>\n> +#include <limits.h>\n>  \n>  #include \"v4l2_subdevice.h\"\n>  #include \"v4l2_subdevice_test.h\"\n> diff --git a/test/v4l2_videodevice/capture_async.cpp b/test/v4l2_videodevice/capture_async.cpp\n> index 17eb528b12fd..442a4fe56eac 100644\n> --- a/test/v4l2_videodevice/capture_async.cpp\n> +++ b/test/v4l2_videodevice/capture_async.cpp\n> @@ -5,12 +5,12 @@\n>   * libcamera V4L2 API tests\n>   */\n>  \n> +#include <iostream>\n> +\n>  #include <libcamera/buffer.h>\n>  #include <libcamera/event_dispatcher.h>\n>  #include <libcamera/timer.h>\n>  \n> -#include <iostream>\n> -\n>  #include \"thread.h\"\n>  #include \"v4l2_videodevice_test.h\"\n>  \n> diff --git a/test/v4l2_videodevice/controls.cpp b/test/v4l2_videodevice/controls.cpp\n> index 975c852b8cbf..42c653d4435a 100644\n> --- a/test/v4l2_videodevice/controls.cpp\n> +++ b/test/v4l2_videodevice/controls.cpp\n> @@ -5,8 +5,8 @@\n>   * controls.cpp - V4L2 device controls handling test\n>   */\n>  \n> -#include <climits>\n>  #include <iostream>\n> +#include <limits.h>\n>  \n>  #include \"v4l2_videodevice.h\"\n>  \n> diff --git a/test/v4l2_videodevice/formats.cpp b/test/v4l2_videodevice/formats.cpp\n> index ee7d357de075..d504d1788d02 100644\n> --- a/test/v4l2_videodevice/formats.cpp\n> +++ b/test/v4l2_videodevice/formats.cpp\n> @@ -5,8 +5,8 @@\n>   * libcamera V4L2 device format handling test\n>   */\n>  \n> -#include <climits>\n>  #include <iostream>\n> +#include <limits.h>\n>  \n>  #include \"v4l2_videodevice.h\"\n>  \n>","headers":{"Return-Path":"<kieran.bingham@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 4C1D16138B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 23 Oct 2019 16:24:37 +0200 (CEST)","from [192.168.0.20]\n\t(cpc89242-aztw30-2-0-cust488.18-1.cable.virginm.net [86.31.129.233])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 6CC0C2BA;\n\tWed, 23 Oct 2019 16:24:36 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1571840676;\n\tbh=JLhZ90IoeR3XLlhgnP57RpFgqnY+Rvzao0APZrH8k3g=;\n\th=Reply-To:Subject:To:References:From:Date:In-Reply-To:From;\n\tb=In/vEkaaHZdG2slIg/Ois7tjxzIsQSP2qAd/wRju7uZLkPMIiOroJ+72FI06POd/W\n\tr1JRx4gyAvNFF2b73EIGQg2L1k3qBQ2Al8OOere5TfaY+PXX+lqJB1evyeHAJQsjLj\n\t+f3tk+sZiqP3mUSdKcXUT/h/pTeFAAXum6dbt1dg=","Reply-To":"kieran.bingham@ideasonboard.com","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","References":"<20191023135258.32256-1-laurent.pinchart@ideasonboard.com>\n\t<20191023135258.32256-4-laurent.pinchart@ideasonboard.com>","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Openpgp":"preference=signencrypt","Autocrypt":"addr=kieran.bingham@ideasonboard.com; keydata=\n\tmQINBFYE/WYBEACs1PwjMD9rgCu1hlIiUA1AXR4rv2v+BCLUq//vrX5S5bjzxKAryRf0uHat\n\tV/zwz6hiDrZuHUACDB7X8OaQcwhLaVlq6byfoBr25+hbZG7G3+5EUl9cQ7dQEdvNj6V6y/SC\n\trRanWfelwQThCHckbobWiQJfK9n7rYNcPMq9B8e9F020LFH7Kj6YmO95ewJGgLm+idg1Kb3C\n\tpotzWkXc1xmPzcQ1fvQMO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QEAAYkCPAQYAQoAJgIbDBYhBJAt15g/\n\tvSj943LUeqEeRnIQpGH9BQJdizzIBQkLSKZiAAoJEKEeRnIQpGH9eYgQAJpjaWNgqNOnMTmD\n\tMJggbwjIotypzIXfhHNCeTkG7+qCDlSaBPclcPGYrTwCt0YWPU2TgGgJrVhYT20ierN8LUvj\n\t6qOPTd+Uk7NFzL65qkh80ZKNBFddx1AabQpSVQKbdcLb8OFs85kuSvFdgqZwgxA1vl4TFhNz\n\tPZ79NAmXLackAx3sOVFhk4WQaKRshCB7cSl+RIng5S/ThOBlwNlcKG7j7W2MC06BlTbdEkUp\n\tECzuuRBv8wX4OQl+hbWbB/VKIx5HKlLu1eypen/5lNVzSqMMIYkkZcjV2SWQyUGxSwq0O/sx\n\tS0A8/atCHUXOboUsn54qdxrVDaK+6jIAuo8JiRWctP16KjzUM7MO0/+4zllM8EY57rXrj48j\n\tsbEYX0YQnzaj+jO6kJtoZsIaYR7rMMq9aUAjyiaEZpmP1qF/2sYenDx0Fg2BSlLvLvXM0vU8\n\tpQk3kgDu7kb/7PRYrZvBsr21EIQoIjXbZxDz/o7z95frkP71EaICttZ6k9q5oxxA5WC6sTXc\n\tMW8zs8avFNuA9VpXt0YupJd2ijtZy2mpZNG02fFVXhIn4G807G7+9mhuC4XG5rKlBBUXTvPU\n\tAfYnB4JBDLmLzBFavQfvonSfbitgXwCG3vS+9HEwAjU30Bar1PEOmIbiAoMzuKeRm2LVpmq4\n\tWZw01QYHU/GUV/zHJSFk","Organization":"Ideas on Board","Message-ID":"<3e00e0de-c534-c8d1-7583-77cdc118205f@ideasonboard.com>","Date":"Wed, 23 Oct 2019 15:24:33 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101\n\tThunderbird/60.8.0","MIME-Version":"1.0","In-Reply-To":"<20191023135258.32256-4-laurent.pinchart@ideasonboard.com>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-GB","Content-Transfer-Encoding":"8bit","Subject":"Re: [libcamera-devel] [PATCH 4/4] libcamera: Standardise on C\n\tcompatibility headers","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>","X-List-Received-Date":"Wed, 23 Oct 2019 14:24:37 -0000"}},{"id":2954,"web_url":"https://patchwork.libcamera.org/comment/2954/","msgid":"<20191023143912.GD1904@pendragon.ideasonboard.com>","date":"2019-10-23T14:39:12","subject":"Re: [libcamera-devel] [PATCH 4/4] libcamera: Standardise on C\n\tcompatibility headers","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"On Wed, Oct 23, 2019 at 03:24:33PM +0100, Kieran Bingham wrote:\n> Hi Laurent,\n> \n> On 23/10/2019 14:52, Laurent Pinchart wrote:\n> > Now that our usage of C compatibility header is documented, use them\n> > consistently through the source code. While at it, group the C and C++\n> > include statements, and fix a handful of #include ordering issues.\n> \n> I think the 'handful' of include ordering issues is mostly where we\n> previously separated C and C++ header includes.\n> \n> If we're removing this separation explicitly - I think stating that\n> clearly here would be good.\n\nI'll expand the commit message.\n\n> discussion comment down at the event_dispatcher_poll too...\n> \n> > \n> > Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> \n> But otherwise, with those comments resolved in whichever way you deem best,\n> \n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> \n> > ---\n> >  include/libcamera/timer.h                     | 2 +-\n> >  src/cam/capture.cpp                           | 2 +-\n> >  src/cam/options.cpp                           | 2 +-\n> >  src/ipa/rkisp1/rkisp1.cpp                     | 2 +-\n> >  src/libcamera/device_enumerator_udev.cpp      | 5 ++---\n> >  src/libcamera/include/event_dispatcher_poll.h | 4 ++--\n> >  src/libcamera/include/ipc_unixsocket.h        | 2 +-\n> >  src/libcamera/log.cpp                         | 6 +++---\n> >  src/libcamera/media_device.cpp                | 3 +--\n> >  src/libcamera/media_object.cpp                | 3 +--\n> >  src/libcamera/stream.cpp                      | 2 +-\n> >  test/ipa/ipa_interface_test.cpp               | 3 +--\n> >  test/media_device/media_device_print_test.cpp | 2 +-\n> >  test/pipeline/ipu3/ipu3_pipeline_test.cpp     | 1 -\n> >  test/v4l2_subdevice/test_formats.cpp          | 2 +-\n> >  test/v4l2_videodevice/capture_async.cpp       | 4 ++--\n> >  test/v4l2_videodevice/controls.cpp            | 2 +-\n> >  test/v4l2_videodevice/formats.cpp             | 2 +-\n> >  18 files changed, 22 insertions(+), 27 deletions(-)\n> > \n> > diff --git a/include/libcamera/timer.h b/include/libcamera/timer.h\n> > index 34e7b8ac8e87..f55fe3c09660 100644\n> > --- a/include/libcamera/timer.h\n> > +++ b/include/libcamera/timer.h\n> > @@ -8,7 +8,7 @@\n> >  #define __LIBCAMERA_TIMER_H__\n> >  \n> >  #include <chrono>\n> > -#include <cstdint>\n> > +#include <stdint.h>\n> >  \n> >  #include <libcamera/object.h>\n> >  #include <libcamera/signal.h>\n> > diff --git a/src/cam/capture.cpp b/src/cam/capture.cpp\n> > index 8a939c622703..d05c01f1b13e 100644\n> > --- a/src/cam/capture.cpp\n> > +++ b/src/cam/capture.cpp\n> > @@ -6,9 +6,9 @@\n> >   */\n> >  \n> >  #include <chrono>\n> > -#include <climits>\n> >  #include <iomanip>\n> >  #include <iostream>\n> > +#include <limits.h>\n> >  #include <sstream>\n> >  \n> >  #include \"capture.h\"\n> > diff --git a/src/cam/options.cpp b/src/cam/options.cpp\n> > index 7c3948df3b5c..1f0631eccfba 100644\n> > --- a/src/cam/options.cpp\n> > +++ b/src/cam/options.cpp\n> > @@ -5,7 +5,7 @@\n> >   * options.cpp - cam - Options parsing\n> >   */\n> >  \n> > -#include <cassert>\n> > +#include <assert.h>\n> >  #include <getopt.h>\n> >  #include <iomanip>\n> >  #include <iostream>\n> > diff --git a/src/ipa/rkisp1/rkisp1.cpp b/src/ipa/rkisp1/rkisp1.cpp\n> > index 570145ce71b2..9a13f5c7df17 100644\n> > --- a/src/ipa/rkisp1/rkisp1.cpp\n> > +++ b/src/ipa/rkisp1/rkisp1.cpp\n> > @@ -6,9 +6,9 @@\n> >   */\n> >  \n> >  #include <algorithm>\n> > -#include <cstdint>\n> >  #include <math.h>\n> >  #include <queue>\n> > +#include <stdint.h>\n> >  #include <string.h>\n> >  \n> >  #include <linux/rkisp1-config.h>\n> > diff --git a/src/libcamera/device_enumerator_udev.cpp b/src/libcamera/device_enumerator_udev.cpp\n> > index ddcd59ea52c1..b2c5fd221dcd 100644\n> > --- a/src/libcamera/device_enumerator_udev.cpp\n> > +++ b/src/libcamera/device_enumerator_udev.cpp\n> > @@ -8,11 +8,10 @@\n> >  #include \"device_enumerator_udev.h\"\n> >  \n> >  #include <algorithm>\n> > -#include <list>\n> > -#include <map>\n> > -\n> >  #include <fcntl.h>\n> >  #include <libudev.h>\n> > +#include <list>\n> > +#include <map>\n> >  #include <string.h>\n> >  #include <sys/ioctl.h>\n> >  #include <sys/sysmacros.h>\n> > diff --git a/src/libcamera/include/event_dispatcher_poll.h b/src/libcamera/include/event_dispatcher_poll.h\n> > index d82b302c4aea..1f0738617425 100644\n> > --- a/src/libcamera/include/event_dispatcher_poll.h\n> > +++ b/src/libcamera/include/event_dispatcher_poll.h\n> > @@ -7,12 +7,12 @@\n> >  #ifndef __LIBCAMERA_EVENT_DISPATCHER_POLL_H__\n> >  #define __LIBCAMERA_EVENT_DISPATCHER_POLL_H__\n> >  \n> > -#include <libcamera/event_dispatcher.h>\n> > -\n> >  #include <list>\n> >  #include <map>\n> >  #include <vector>\n> >  \n> > +#include <libcamera/event_dispatcher.h>\n> \n> From 2/4\n> \n> +The headers shall be grouped and ordered as follows.\n> +\n> + # The header declaring the API being implemented (if any)\n> + # The C and C++ system and standard library headers\n> + # Other libraries' headers, with one group per library\n> + # Other project's headers\n> \n> Now that's a possible confusion point, /this/ EVENT_DISPATCHER_POLL\n> header /is/ implementing the API for an event dispatcher - so therefore\n> point one above could be seen to be declaring it should be first.\n\nNitpicking mode :-)\n\nFirst of all, this is a header file, and thus doesn't implement the API,\nit declares it (we could argue that headers can include inline\nfunctions, but I don't think that's really relevant). Furthermore, the\ndocumentation also states\n\n\"For .cpp files, if the file implements an API declared in a header file,\nthat header file shall be included first in order to ensure it is\nself-contained.\"\n\nso I would say that this rule is documented clearly enough as to only\napply to .cpp files.\n\nThen, even if this was event_dispatcher_poll.cpp, I would argue that the\nfile implements the API declared in event_dispatcher_poll.h, not the one\ndefiend in event_dispatcher.h. We can say that it implements a class\nthat implements the interface (using it in the java sense of the term)\ndeclared in event_dispatcher.h, but it doesn't really implement the API\ndeclared there.\n\n\"the API being implemented\" could be replaced by something clearer, but\nI'll then leave it to you to propose a better wording in a patch :-)\n\n> However, I suspect the intent of the ordering might be that it should\n> only be first if this is the header for this exact implementation, not\n> any virtual interface. But I don't know how to word that to remove\n> ambiguity :D\n> \n> Or maybe this one should be first ... I'll leave it to you ...\n\nWe already ensure that the header is self-contained in\nevent_dispatcher.cpp, which I think is the right place, so there's no\nneed to do it here (even if doinf so wouldn't hurt).\n\n> > +\n> >  struct pollfd;\n> >  \n> >  namespace libcamera {\n> > diff --git a/src/libcamera/include/ipc_unixsocket.h b/src/libcamera/include/ipc_unixsocket.h\n> > index 03e9fe492bde..820d05611049 100644\n> > --- a/src/libcamera/include/ipc_unixsocket.h\n> > +++ b/src/libcamera/include/ipc_unixsocket.h\n> > @@ -8,7 +8,7 @@\n> >  #ifndef __LIBCAMERA_IPC_UNIXSOCKET_H__\n> >  #define __LIBCAMERA_IPC_UNIXSOCKET_H__\n> >  \n> > -#include <cstdint>\n> > +#include <stdint.h>\n> >  #include <sys/types.h>\n> >  #include <vector>\n> >  \n> > diff --git a/src/libcamera/log.cpp b/src/libcamera/log.cpp\n> > index 51f9f86b4c44..50f345b98c74 100644\n> > --- a/src/libcamera/log.cpp\n> > +++ b/src/libcamera/log.cpp\n> > @@ -7,14 +7,14 @@\n> >  \n> >  #include \"log.h\"\n> >  \n> > -#include <cstdio>\n> > -#include <cstdlib>\n> > -#include <ctime>\n> >  #include <fstream>\n> >  #include <iostream>\n> >  #include <list>\n> > +#include <stdio.h>\n> > +#include <stdlib.h>\n> >  #include <string.h>\n> >  #include <syslog.h>\n> > +#include <time.h>\n> >  #include <unordered_set>\n> >  \n> >  #include <libcamera/logging.h>\n> > diff --git a/src/libcamera/media_device.cpp b/src/libcamera/media_device.cpp\n> > index bd99deba098d..0d6630fbd1f4 100644\n> > --- a/src/libcamera/media_device.cpp\n> > +++ b/src/libcamera/media_device.cpp\n> > @@ -9,11 +9,10 @@\n> >  \n> >  #include <errno.h>\n> >  #include <fcntl.h>\n> > +#include <string>\n> >  #include <string.h>\n> >  #include <sys/ioctl.h>\n> >  #include <unistd.h>\n> > -\n> > -#include <string>\n> >  #include <vector>\n> \n> I kind of really like the separation between C headers and C++\n> headers... but ho hum. It's arbitrary.\n\nWe could split them, my only requirement is consistency :-) I prefer\ngrouping them (but that's only a mild personal preference) because we\nwould then split the C++-defined C compatibility headers from the other\nC++ standard library headers.\n\n> >  #include <linux/media.h>\n> > diff --git a/src/libcamera/media_object.cpp b/src/libcamera/media_object.cpp\n> > index 8794ff4578c9..ef32065c161d 100644\n> > --- a/src/libcamera/media_object.cpp\n> > +++ b/src/libcamera/media_object.cpp\n> > @@ -8,10 +8,9 @@\n> >  #include \"media_object.h\"\n> >  \n> >  #include <errno.h>\n> > +#include <string>\n> >  #include <string.h>\n> >  #include <unistd.h>\n> > -\n> > -#include <string>\n> >  #include <vector>\n> >  \n> >  #include <linux/media.h>\n> > diff --git a/src/libcamera/stream.cpp b/src/libcamera/stream.cpp\n> > index 610920d1e5b3..b8e7209c1047 100644\n> > --- a/src/libcamera/stream.cpp\n> > +++ b/src/libcamera/stream.cpp\n> > @@ -9,8 +9,8 @@\n> >  \n> >  #include <algorithm>\n> >  #include <array>\n> > -#include <climits>\n> >  #include <iomanip>\n> > +#include <limits.h>\n> >  #include <sstream>\n> >  \n> >  #include <libcamera/request.h>\n> > diff --git a/test/ipa/ipa_interface_test.cpp b/test/ipa/ipa_interface_test.cpp\n> > index 0bdeb167a675..cafc249bbbc9 100644\n> > --- a/test/ipa/ipa_interface_test.cpp\n> > +++ b/test/ipa/ipa_interface_test.cpp\n> > @@ -6,13 +6,12 @@\n> >   */\n> >  \n> >  #include <fcntl.h>\n> > +#include <iostream>\n> >  #include <string.h>\n> >  #include <sys/stat.h>\n> >  #include <sys/types.h>\n> >  #include <unistd.h>\n> >  \n> > -#include <iostream>\n> > -\n> \n> Hrm ... this does show that we have considered C and C++ headers as\n> separate groups previously - so this is definitely a change ... Worth\n> checking specifically with the others.\n> \n> Either way, consistency is good.\n> \n> >  #include <libcamera/event_dispatcher.h>\n> >  #include <libcamera/event_notifier.h>\n> >  #include <libcamera/timer.h>\n> > diff --git a/test/media_device/media_device_print_test.cpp b/test/media_device/media_device_print_test.cpp\n> > index 30d929b8c763..8dd8a151266d 100644\n> > --- a/test/media_device/media_device_print_test.cpp\n> > +++ b/test/media_device/media_device_print_test.cpp\n> > @@ -4,8 +4,8 @@\n> >   *\n> >   * media_device_print_test.cpp - Print out media devices\n> >   */\n> > -#include <iostream>\n> >  \n> > +#include <iostream>\n> >  #include <sys/types.h>\n> >  #include <sys/stat.h>\n> >  #include <unistd.h>\n> > diff --git a/test/pipeline/ipu3/ipu3_pipeline_test.cpp b/test/pipeline/ipu3/ipu3_pipeline_test.cpp\n> > index 8bfcd609a071..a5c6be0955df 100644\n> > --- a/test/pipeline/ipu3/ipu3_pipeline_test.cpp\n> > +++ b/test/pipeline/ipu3/ipu3_pipeline_test.cpp\n> > @@ -6,7 +6,6 @@\n> >   */\n> >  \n> >  #include <iostream>\n> > -\n> >  #include <sys/stat.h>\n> >  #include <sys/types.h>\n> >  #include <unistd.h>\n> > diff --git a/test/v4l2_subdevice/test_formats.cpp b/test/v4l2_subdevice/test_formats.cpp\n> > index e90c2c2426da..5cf5d5664b04 100644\n> > --- a/test/v4l2_subdevice/test_formats.cpp\n> > +++ b/test/v4l2_subdevice/test_formats.cpp\n> > @@ -5,8 +5,8 @@\n> >   * libcamera V4L2 Subdevice format handling test\n> >   */\n> >  \n> > -#include <climits>\n> >  #include <iostream>\n> > +#include <limits.h>\n> >  \n> >  #include \"v4l2_subdevice.h\"\n> >  #include \"v4l2_subdevice_test.h\"\n> > diff --git a/test/v4l2_videodevice/capture_async.cpp b/test/v4l2_videodevice/capture_async.cpp\n> > index 17eb528b12fd..442a4fe56eac 100644\n> > --- a/test/v4l2_videodevice/capture_async.cpp\n> > +++ b/test/v4l2_videodevice/capture_async.cpp\n> > @@ -5,12 +5,12 @@\n> >   * libcamera V4L2 API tests\n> >   */\n> >  \n> > +#include <iostream>\n> > +\n> >  #include <libcamera/buffer.h>\n> >  #include <libcamera/event_dispatcher.h>\n> >  #include <libcamera/timer.h>\n> >  \n> > -#include <iostream>\n> > -\n> >  #include \"thread.h\"\n> >  #include \"v4l2_videodevice_test.h\"\n> >  \n> > diff --git a/test/v4l2_videodevice/controls.cpp b/test/v4l2_videodevice/controls.cpp\n> > index 975c852b8cbf..42c653d4435a 100644\n> > --- a/test/v4l2_videodevice/controls.cpp\n> > +++ b/test/v4l2_videodevice/controls.cpp\n> > @@ -5,8 +5,8 @@\n> >   * controls.cpp - V4L2 device controls handling test\n> >   */\n> >  \n> > -#include <climits>\n> >  #include <iostream>\n> > +#include <limits.h>\n> >  \n> >  #include \"v4l2_videodevice.h\"\n> >  \n> > diff --git a/test/v4l2_videodevice/formats.cpp b/test/v4l2_videodevice/formats.cpp\n> > index ee7d357de075..d504d1788d02 100644\n> > --- a/test/v4l2_videodevice/formats.cpp\n> > +++ b/test/v4l2_videodevice/formats.cpp\n> > @@ -5,8 +5,8 @@\n> >   * libcamera V4L2 device format handling test\n> >   */\n> >  \n> > -#include <climits>\n> >  #include <iostream>\n> > +#include <limits.h>\n> >  \n> >  #include \"v4l2_videodevice.h\"\n> >","headers":{"Return-Path":"<laurent.pinchart@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0F9A86138B\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 23 Oct 2019 16:39:19 +0200 (CEST)","from pendragon.ideasonboard.com (143.121.2.93.rev.sfr.net\n\t[93.2.121.143])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 77AA42BA;\n\tWed, 23 Oct 2019 16:39:18 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1571841558;\n\tbh=gPwtjV+li/HqUl7Iqw/bO1ZvkFKaPn8kwaFcKYQYoU8=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=jDy/46bYKN57UnHtNRlYpsmrWPQfcCzPXSHjW8hbEETZWqL85baIIDQNRAOOwbIc1\n\ta8TAWVHv2FV2Yb6DjHjbawB0qK0ulNJWqU9nZgw64CY/HSUqfJ3FrJL4PkTJtW36CR\n\tIjlyw8By18nUqx8iJO9vgeXvuZ7he201WIkKyark=","Date":"Wed, 23 Oct 2019 17:39:12 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20191023143912.GD1904@pendragon.ideasonboard.com>","References":"<20191023135258.32256-1-laurent.pinchart@ideasonboard.com>\n\t<20191023135258.32256-4-laurent.pinchart@ideasonboard.com>\n\t<3e00e0de-c534-c8d1-7583-77cdc118205f@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<3e00e0de-c534-c8d1-7583-77cdc118205f@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH 4/4] libcamera: Standardise on C\n\tcompatibility headers","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>","X-List-Received-Date":"Wed, 23 Oct 2019 14:39:20 -0000"}}]