From patchwork Thu Sep 10 13:14:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 249608 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ecf:0:0:0:0 with SMTP id i15csp720930ilk; Thu, 10 Sep 2020 06:16:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzoQa9vLFPvoJapZaJoGSofgLKEhCcbtWcPwWBK8EQdL5eXBlSAntJhfHDU7QUxqL1f/Xxw X-Received: by 2002:ab0:26d0:: with SMTP id b16mr3346951uap.1.1599743777594; Thu, 10 Sep 2020 06:16:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599743777; cv=none; d=google.com; s=arc-20160816; b=L6oEVV7be4rVTUvfsp98Mnrr8mThUbaniNbYq/wjaOVUi/Wf+gjLszH7+sFFiTHn4i OFVe/3nfruAMmTY5Wbsh0gpB1lQ2CmoMwAg1V1VhXCNOJc3nO5bbsM+1nh/XExzbu/la prFd1kL49A6CimcF6lBejgffjBzwBcX5CnWvZYtooHnxzOtXsdl3Su+oS+eLbeE1Xjc1 ec2etO9GUJNuXNlUrCi6jmoqcWFsm+1Dhyr3nRv2Vu2Pry6S+yinB8uxhhxwT0c1x1I0 85hrt6QCRPN4ozUoQoeA2ai+D9NkP4+3zOogBkIGt+4GoLbyjkZJQmbvlQ9n8HdBD/WK bMkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=1IVujaGcl6Gaeb44XvH6utm7tpVyG1R70wAp2OwcHKE=; b=C6KBTYteRg6GVMVkDiz0YV9yMF0HJDh2D0Cfob41stWdsBRtLADFmy728uf1jhjzAE mWQJ5LzgladVhAOqhIY92swACcXIMQcpeLndcBZ4vuLb5KfT7OzsWqugFlXufsFjRa5/ K/bBBQIb9X3Lh1siSSAHwMnlvek3BCIzJiVxMNuOJYhQP88GOIHa7EkPhaziXl9MLtsC atNhNmA7fD/zCm4R+IPepvkL5a4ZM9z7Dq/e9ommA/e13XIyB8u0Xd22VUA+1IOazQmY dOyPORIk4xEq2i5NBeTL+g7OS+rCgblPm7wmAfDkCTFSp8L3K9eWoBWObQ9c+E7vUNzW ieXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QWasbVzq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id t23si775824vsq.269.2020.09.10.06.16.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Sep 2020 06:16:17 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=QWasbVzq; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54436 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kGMQy-0003xC-JZ for patch@linaro.org; Thu, 10 Sep 2020 09:16:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:33136) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kGMPu-0003vy-5z for qemu-devel@nongnu.org; Thu, 10 Sep 2020 09:15:10 -0400 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]:56040) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kGMPs-00064g-E6 for qemu-devel@nongnu.org; Thu, 10 Sep 2020 09:15:09 -0400 Received: by mail-wm1-x334.google.com with SMTP id a65so5589184wme.5 for ; Thu, 10 Sep 2020 06:15:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1IVujaGcl6Gaeb44XvH6utm7tpVyG1R70wAp2OwcHKE=; b=QWasbVzqGjmIb6mcq+bDGufK48YF9mzK9gFFvYiuOwKW3ujXXBOxSjepx841Qn0ERZ /NGAAdiT9EehL8SBgR2liB8AV52gnqC3/b0Vv+VfzbECCV2Lo/ofYQloJ8m6vcQI+U9Y ofxnEZpU8pazgX1neTq+rl94WBAPCd0UKmVAeXO7/EgPhQINzsRmKBgdE8ge+vIfAQFb k5r8Ht59wagjlSEeHMrvmuvhSWcCz8BU2W7hrjbC4fDIIBPulkD7GtNlVwQ5mlQkrgCi YZeh+u59VRRmX2zC1bA83NsVvgp0LfVt8AS3pT125u9KFeArja8YDXvNzC8pxSA+YTqS NTpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1IVujaGcl6Gaeb44XvH6utm7tpVyG1R70wAp2OwcHKE=; b=r/1sRu4DnLp+TLRfwwaLuKpzAnqf5EEuaaISpAfyZ2of5ZoakCsiCbm4WtwPtU44GN 0uzNFxdJk6L2MGbW0q+/KWDCZaDyFgclSkGNDeymPzqPu8m9BYXk9AJi+6FzjAnntmDy IpEut5VmMl5nMADxRMm14QDa53rDyKGo5urG7iBslqg5JS7gDbX3HTRx6rRk82RQGrwD CEuxVHWn6l1CXQl6/36PdqEkbfs9wI/annnqy/H3cdc6pfe8w4llJeVCMVBAbTz4BInA BjP0uX7eN7t6Mp/17Lijdg5JuZEatp1aOedeAnQ9n9yyeKcdhuwjQOI2aOFKwp3/w8+S XZjA== X-Gm-Message-State: AOAM533nmJypdCnqmd9pIFcjhxb6fXdGKdsg/t5qNfcHwo5I61p28RaW An1yOd+/DA8vf0vcHONJ3j82pw== X-Received: by 2002:a1c:9a8d:: with SMTP id c135mr63339wme.58.1599743706263; Thu, 10 Sep 2020 06:15:06 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id f1sm9030393wrt.20.2020.09.10.06.15.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 06:15:04 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 77C6B1FF87; Thu, 10 Sep 2020 14:15:04 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: peter.maydell@linaro.org Subject: [PULL 01/10] CODING_STYLE.rst: flesh out our naming conventions. Date: Thu, 10 Sep 2020 14:14:55 +0100 Message-Id: <20200910131504.11341-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200910131504.11341-1-alex.bennee@linaro.org> References: <20200910131504.11341-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::334; envelope-from=alex.bennee@linaro.org; helo=mail-wm1-x334.google.com X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , =?utf-8?q?Alex_Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Mention a few of the more common naming conventions we follow in the code base including common variable names and function prefix and suffix examples. Signed-off-by: Alex Bennée Reviewed-by: Thomas Huth Message-Id: <20200909112742.25730-2-alex.bennee@linaro.org> -- 2.20.1 diff --git a/CODING_STYLE.rst b/CODING_STYLE.rst index 427699e0e42..8b13ef0669e 100644 --- a/CODING_STYLE.rst +++ b/CODING_STYLE.rst @@ -109,8 +109,41 @@ names are lower_case_with_underscores_ending_with_a_t, like the POSIX uint64_t and family. Note that this last convention contradicts POSIX and is therefore likely to be changed. -When wrapping standard library functions, use the prefix ``qemu_`` to alert -readers that they are seeing a wrapped version; otherwise avoid this prefix. +Variable Naming Conventions +--------------------------- + +A number of short naming conventions exist for variables that use +common QEMU types. For example, the architecture independent CPUState +is often held as a ``cs`` pointer variable, whereas the concrete +CPUArchState is usually held in a pointer called ``env``. + +Likewise, in device emulation code the common DeviceState is usually +called ``dev``. + +Function Naming Conventions +--------------------------- + +Wrapped version of standard library or GLib functions use a ``qemu_`` +prefix to alert readers that they are seeing a wrapped version, for +example ``qemu_strtol`` or ``qemu_mutex_lock``. Other utility functions +that are widely called from across the codebase should not have any +prefix, for example ``pstrcpy`` or bit manipulation functions such as +``find_first_bit``. + +The ``qemu_`` prefix is also used for functions that modify global +emulator state, for example ``qemu_add_vm_change_state_handler``. +However, if there is an obvious subsystem-specific prefix it should be +used instead. + +Public functions from a file or subsystem (declared in headers) tend +to have a consistent prefix to show where they came from. For example, +``tlb_`` for functions from ``cputlb.c`` or ``cpu_`` for functions +from cpus.c. + +If there are two versions of a function to be called with or without a +lock held, the function that expects the lock to be already held +usually uses the suffix ``_locked``. + Block structure ===============