{"id":9910,"url":"https://patchwork.libcamera.org/api/patches/9910/?format=json","web_url":"https://patchwork.libcamera.org/patch/9910/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20201002143154.468162-2-paul.elder@ideasonboard.com>","date":"2020-10-02T14:31:17","name":"[libcamera-devel,v3,01/38] Documentation: coding-style: Document global variable guidelines","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"dedff91ce860d1de7790d8120d4fa9c451c48b2b","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/?format=json","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/9910/mbox/","series":[{"id":1348,"url":"https://patchwork.libcamera.org/api/series/1348/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1348","date":"2020-10-02T14:31:16","name":"IPA isolation implementation","version":3,"mbox":"https://patchwork.libcamera.org/series/1348/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9910/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9910/checks/","tags":{},"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 CA811C3B5C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  2 Oct 2020 14:32:09 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 864E663B6A;\n\tFri,  2 Oct 2020 16:32:09 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id D954763B59\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  2 Oct 2020 16:32:07 +0200 (CEST)","from pyrite.rasen.tech (unknown\n\t[IPv6:2400:4051:61:600:2c71:1b79:d06d:5032])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id ABF36528;\n\tFri,  2 Oct 2020 16:32:05 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"OklxCzZ6\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1601649127;\n\tbh=u2gyxacPihn9ZLzANFT9dxHtFdESh1oXWYz2HI8cvTg=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=OklxCzZ6Z2k6+yDqawnnKD+UHf6iF1Si0gZXwUx2bxVOscY5yqQHlPKj81lVIiz7F\n\t2Fa6qI19h9t9vN6he7qgfPnSFl5vaXNzMptlsGG6qwL7PmrEsZciGwbzSZi8r6ZG1v\n\tBBtXLQOSvObSjA1mj/FgI/KcvAPivcE/vKr6P5/I=","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Date":"Fri,  2 Oct 2020 23:31:17 +0900","Message-Id":"<20201002143154.468162-2-paul.elder@ideasonboard.com>","X-Mailer":"git-send-email 2.27.0","In-Reply-To":"<20201002143154.468162-1-paul.elder@ideasonboard.com>","References":"<20201002143154.468162-1-paul.elder@ideasonboard.com>","MIME-Version":"1.0","Subject":"[libcamera-devel] [PATCH v3 01/38] Documentation: coding-style:\n\tDocument global variable guidelines","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>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Document the issue related to global variable dependencies and how to\navoid them.\n\nSigned-off-by: Paul Elder <paul.elder@ideasonboard.com>\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n---\nChanges in v3:\n- add more detail\n\nNew in v2\n---\n Documentation/coding-style.rst | 19 +++++++++++++++++++\n 1 file changed, 19 insertions(+)","diff":"diff --git a/Documentation/coding-style.rst b/Documentation/coding-style.rst\nindex 8af06d6a..71d5c0b2 100644\n--- a/Documentation/coding-style.rst\n+++ b/Documentation/coding-style.rst\n@@ -187,6 +187,25 @@ These rules match the `object ownership rules from the Chromium C++ Style Guide`\n    long term borrowing isn't marked through language constructs, it shall be\n    documented explicitly in details in the API.\n \n+Global Variables\n+~~~~~~~~~~~~~~~~\n+\n+The order of initializations and destructions of global variables cannot be\n+reasonably controlled. This can cause problems (including segfaults) when global\n+variables depend on each other, directly or indirectly.  For example, if the\n+declaration of a global variable calls a constructor which uses another global\n+variable that hasn't been initialized yet, incorrect behavior is likely.\n+Similar issues may occur when the library is unloaded and global variables are\n+destroyed.\n+\n+Global variables that are statically initialized and have trivial destructors\n+(such as an integer constant) do not cause any issue. Other global variables\n+shall be avoided when possible, but are allowed when required (for instance to\n+implement factories with auto-registration). They shall not depend on any other\n+global variable, should run a minimal amount of code in the constructor and\n+destructor, and code that contains dependencies should be moved to a later\n+point in time. \n+\n C Compatibility Headers\n ~~~~~~~~~~~~~~~~~~~~~~~\n \n","prefixes":["libcamera-devel","v3","01/38"]}