From nobody Fri May 17 15:48:47 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1597056813; cv=none; d=zohomail.com; s=zohoarc; b=AcmYufqv74IT5UUDNxT5WQNrkCuFcIrJkTnBcp8SEZJ24MB/TBK7FRCM5dpbfFT7j+U+cNtBOKWp+mzCLLXtnnW/K7acFJafDrwmJNBcQCGPJYzaS0bRqS0CWn4YTF+ZgB85uiH0g4Lrsk+PZpXnSvz00YcDVakNBRGn7zvvTuE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1597056813; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=ZFMHqgtK4joNIT/9rWbW+hlBCF9dx6g0E6pjSUq3iHE=; b=PsonIJMeKHpE0Go08RkgTOxOm0Q8BAvOXsXcErjZZsAAgu83kCVLEFWfZ3GRuhPKkbN2iUlsIjrB3ngwAWoUTO5xIV57EQLh9NDIYh2MLxJ/QVEwOdbfflpcbn+EqnjkG81+eLIupg5odK8ltDxjHe2c9jjd0k+8JJjuojLhy2g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1597056813714849.2303027198171; Mon, 10 Aug 2020 03:53:33 -0700 (PDT) Received: from localhost ([::1]:57578 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k55Qq-00041N-F2 for importer@patchew.org; Mon, 10 Aug 2020 06:53:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35034) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k55PM-0002Gu-BQ for qemu-devel@nongnu.org; Mon, 10 Aug 2020 06:52:00 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:37786) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k55PK-000558-BO for qemu-devel@nongnu.org; Mon, 10 Aug 2020 06:51:59 -0400 Received: by mail-wr1-x441.google.com with SMTP id y3so7706060wrl.4 for ; Mon, 10 Aug 2020 03:51:57 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id 6sm6268969wmf.4.2020.08.10.03.51.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Aug 2020 03:51:54 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 4868D1FF7E; Mon, 10 Aug 2020 11:51:54 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ZFMHqgtK4joNIT/9rWbW+hlBCF9dx6g0E6pjSUq3iHE=; b=Ko1WLEpYrwDjUycTAUFZMegY7nQxEYL9f0JsubwIRKfIazXcXXtVWHCZw1oX1XqMLy mMHFO9caAiXj4znMm5G1AiNxARwTdiGnDPG87xA+/kUA1DfZRgvxPPcS9hSseX5FqKzg H+W4MsptHyS5FAHgSE7BJwLNwxSJUu9AswDJKjVgEBgF3rCc236cNN6Z0AV9GyYvYOjx Yab3SZ8M6zobDB9A9zH9qhvEA15wDhNgnm0rcGgiXdmw/2JstBjiqgL6ASXUAVl6x76K fFplc3Zio34QSwBySK89haCb0wj2tVPxeSWtu2T5CAkFgZvJR/nBEvZ7ehnfXB/9F3Dz OieA== 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:mime-version :content-transfer-encoding; bh=ZFMHqgtK4joNIT/9rWbW+hlBCF9dx6g0E6pjSUq3iHE=; b=QCohaUTlmrMGseb1dPVfHXjPH2/L7ampsI5T8fCc6kSGUs6nJZSw1C9ptdzJRkzbbA q45210DbmgiTjSN3cGdIKJnaRdii+0GIySBQX3P1p36IKqWp+YacDymk2MDaX6RI4Xb7 2tcy8aKjSDHcX9eFoAa2iUIrzIcMKYtqNSHZ2UItxlp74Y0if2AZWAoTHW6rKvX9fO67 BEUFHIxTVVii/0XiPmmPs0MiE1gy1Kx3ZNTF0jyy86pIC/vfSNJBACm8RR5rcLTsfEE+ GnhpQllnZqzUoNGE6xVhAQ0u0mboxeWoer83oy3TRbdqSeSE7gHr03gruAFCGS2aohKK Af6w== X-Gm-Message-State: AOAM532FGtmqsUaAh6l6XQbJirFkSvfpuNBqU/WMziuex/Xwn7ZR10+K //o0gmopvMumF35ey2Vs2jSdEw== X-Google-Smtp-Source: ABdhPJy96PgPtawk91ylSNsPU63ReomYSEc+oN93a24khDnUOFo/wLxSkEsnXckQJBhrz5bAOSM9EA== X-Received: by 2002:a5d:5641:: with SMTP id j1mr24495239wrw.399.1597056716293; Mon, 10 Aug 2020 03:51:56 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [PATCH v2] CODING_STYLE.rst: flesh out our naming conventions. Date: Mon, 10 Aug 2020 11:51:47 +0100 Message-Id: <20200810105147.10670-1-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::441; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x441.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: =?UTF-8?q?Alex=20Benn=C3=A9e?= Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) 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=C3=A9e --- v2 - punctuation fixes suggested by Cornelia - re-worded section on qemu_ prefix - expanded on _locked suffix --- CODING_STYLE.rst | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/CODING_STYLE.rst b/CODING_STYLE.rst index 427699e0e42..e7ae44aed7f 100644 --- a/CODING_STYLE.rst +++ b/CODING_STYLE.rst @@ -109,8 +109,34 @@ 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. =20 -When wrapping standard library functions, use the prefix ``qemu_`` to alert -readers that they are seeing a wrapped version; otherwise avoid this prefi= x. +Variable Naming Conventions +--------------------------- + +A number of short naming conventions exist for variables that use +common QEMU types. For example, the architecture independent CPUState +this is often held as a ``cs`` pointer variable, whereas the concrete +CPUArchState us usually held in a pointer called ``env``. + +Likewise, in device emulation code the common DeviceState is usually +called ``dev`` with the actual status structure often uses the terse +``s`` or maybe ``foodev``. + +Function Naming Conventions +--------------------------- + +The ``qemu_`` prefix is used for utility functions that are widely +called from across the code-base. This includes wrapped versions of +standard library functions (e.g. qemu_strtol) where the prefix is +added to the function name to alert readers that they are seeing a +wrapped version; otherwise avoid this prefix. + +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``. + +Public functions (i.e. declared in public headers) tend to be prefixed +with the subsystem or file they came from. For example, ``tlb_`` for +functions from ``cputlb.c`` or ``cpu_`` for functions from cpus.c. =20 Block structure =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --=20 2.20.1