From patchwork Wed Sep 9 11:27:32 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: 249450 Delivered-To: patch@linaro.org Received: by 2002:a92:5b9c:0:0:0:0:0 with SMTP id c28csp308731ilg; Wed, 9 Sep 2020 04:30:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwK8R9t84EChAO6KLWBfI7HqeF/FZmWjcpiSltcLTEpaJjjqZDk8st/vdRV0lG4/D4sx/kq X-Received: by 2002:a25:b3c5:: with SMTP id x5mr910950ybf.207.1599651027769; Wed, 09 Sep 2020 04:30:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599651027; cv=none; d=google.com; s=arc-20160816; b=PX9G4mBAqYGKEkGfOal7L2PlIT65TOgwpMQNVMtzni7YEuBFIdgISozAU8jjUBLcOU KQ98HofFpTDpMlxQt1YrL0TXshRdE5XSMZbUbVp/mCHoQjesJjZzgEkg8uVpiuvyjwvJ LEFi5hc7BDYplcV8IbXYDQYhODPnjvI+II1rqdfhNIJdqNfDGPbfrciX/wGybo2sCt0M 7CNTF9sSaSHVt117YuDcJHTdSi/nyOnlNHCXSf4BSO0fgDr244DjbouKla59tRyj7VBS sJt4S5pDgzpIjP3TpClh83Vh6rAxItpGncV3DT3FAULu40+VFPMbxR+XsZhknLItAh0I oPlw== 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=Hb9hv73EPp1tw1ahzPI1+7OENb7hPI7UQgxNVfWg2Cw=; b=RZSwQQKZjuBJG/VaezACLgnxTwzvlZ3i3RsaETFMAJ95l7/vDSOzgqUOUWa9jxDWSN 7XyMpKnOOh+hlZyS9sRFMi+ASutMkNEAGoPCMd38z/Lr1bsOHdapzhAk1cYXnvrRpg0I ATcSqGPzpVii86aO2F1eITTeQopVLUQqOGu4C0PSlttWlAfpJ1J9Ej1lUsaB6AfrnckX zl9gfjSj1Zrh0YPY9XzzbepfBTb9oPZ71tfgywnz1JxShczLz6H+g10zI4/gbXrzeA/J GT7pmZHc/1WppSoNuZJvVtdSeBQ4HbKmcXvfDD8+WKLWrSvOk5y5ngMJZV/SvmyYS1Az kikw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=shQ5SKsx; 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 s12si2485463ybm.342.2020.09.09.04.30.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 09 Sep 2020 04:30:27 -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=shQ5SKsx; 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]:54430 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kFyJ1-0003F2-4f for patch@linaro.org; Wed, 09 Sep 2020 07:30:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:60310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kFyGS-0008OV-6K for qemu-devel@nongnu.org; Wed, 09 Sep 2020 07:27:48 -0400 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]:44720) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kFyGQ-0006WS-Ft for qemu-devel@nongnu.org; Wed, 09 Sep 2020 07:27:47 -0400 Received: by mail-wr1-x42a.google.com with SMTP id s12so2517347wrw.11 for ; Wed, 09 Sep 2020 04:27:46 -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=Hb9hv73EPp1tw1ahzPI1+7OENb7hPI7UQgxNVfWg2Cw=; b=shQ5SKsxA+gPp+yUihGIKLTX9NO38Y7B8ADOH9TV9AEr6rIIRQo78El1e6Ii20I8/4 a12Ik3OZQUkRnf9blRE9t3QNHUVY1/2IPx51ZDnbyXfw3+QoXkg+KFyCFRPuINU8YVbX vxjw+k7ZtQdgWFk6pFvD4C0dhdHPZWX5LY9OdZsZQ1dBN4uuJxcZJzMfe+KMyek4j5Ug CdWyndDIhgXaa8lQjHMSyaotj1S2WExxBXwOAvwfhCXZs9zgSYF2BdEhIQsNc6pCdS/y tIdaJuj3XHw4RV/h2JNUVkHZgmBeaF5b6SBOCC1OaO3870v1NU4uKacAaipKtAcUx+Bw z81w== 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=Hb9hv73EPp1tw1ahzPI1+7OENb7hPI7UQgxNVfWg2Cw=; b=DDIhfM2uQSnQTG/rBTZuHHGfUn1KqjN2JrNKt/vQYnX1WS1kieOIpEVWLNMs+I15Yk 9hF3Sl2k7XqAWL1ryJ9dqLlTBVJg/Din4zSuQh6fdWJ2BE5f4Ba8Fq0n3N+IBtrv+EX7 AQQqG1gif33n1OGONEiuXUnJJsiEq8RZ/ZxJbIg+tsFHIyKKnlUr8QYqC27Fp+E3S2Ba 24a8348Yuw3C73YwwnnmHI3KgjjgxN/5aVIySfcFNaB1EoDl7H/haENUqXtmnGUaIgsd RHQGWOKVOeSJ2xvEii0XY4qu0Smw/sa1rw7NhF2QBBIXXjuAPGc31fIpeGvfa+shnsQ0 fgyQ== X-Gm-Message-State: AOAM531CRJh0PAaYaetPBCUYValp0f2P+CNO5X2SqC97jWbrH+qA9E6H V/vJf0XpWZ/rRKYibmDjPojH6g== X-Received: by 2002:adf:f04c:: with SMTP id t12mr3461663wro.121.1599650864956; Wed, 09 Sep 2020 04:27:44 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id f6sm3809411wro.5.2020.09.09.04.27.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Sep 2020 04:27:42 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 2318B1FF87; Wed, 9 Sep 2020 12:27:42 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2 01/10] CODING_STYLE.rst: flesh out our naming conventions. Date: Wed, 9 Sep 2020 12:27:32 +0100 Message-Id: <20200909112742.25730-2-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200909112742.25730-1-alex.bennee@linaro.org> References: <20200909112742.25730-1-alex.bennee@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::42a; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x42a.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: fam@euphon.net, berrange@redhat.com, =?utf-8?q?Alex_Benn=C3=A9e?= , richard.henderson@linaro.org, f4bug@amsat.org, cota@braap.org, aurelien@aurel32.net 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 Message-Id: <20200903112107.27367-2-alex.bennee@linaro.org> --- v4 - Incorporated Paolo's suggested paragraph --- CODING_STYLE.rst | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) -- 2.20.1 Reviewed-by: Thomas Huth 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 ===============