From patchwork Mon Aug 10 10:51:47 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: 247580 Delivered-To: patch@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp4746202ilo; Mon, 10 Aug 2020 03:53:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSpcgSp8endqEDJ1P1oaObQtgv/f1E5PptyMhYVAokXVW/qFu7e5TUA52R01YRKLd1I3y1 X-Received: by 2002:a25:cf8a:: with SMTP id f132mr38262008ybg.139.1597056795496; Mon, 10 Aug 2020 03:53:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597056795; cv=none; d=google.com; s=arc-20160816; b=OjxInerdYamkH09wNhX87hLQH2xDQ1Al8N3iodbkWY9IOT2ZgDO1yWgCvqQvWvfeiq QmQp1/xVgbiE58W0WKTxJE9YU9ZKOuImujA7bgATW5UtjU7Z5WDX/iybzd5prVgCX07o Wxg1uK9k0xZQ7SRhlYl1CfwTZ5gNdvTG7C80aX8IS37Jffr6cf6v8UACNE6Nsmb/FI+I QzbvARKKH7mlnZ4f7Ej1hv4WRNYuiAdXb7HqisnTCUsBrwO30mb2GPGlaX8Ef8cTBiqh kxDM+ad+SnobNLoQywG+deQXuVjvQUK37SNaPXB37IgMmdFfxYAFf8s8Q88QXSUnabGL 103g== 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:message-id:date:subject:to:from:dkim-signature; bh=ZFMHqgtK4joNIT/9rWbW+hlBCF9dx6g0E6pjSUq3iHE=; b=xlxlPtTFH7l45X+AuA2HhZLcWTnvzjtG4OjvnpoZLSmuUqWJXSXLTd0GkVTrswXHbV Td4JL0VG1jK428yPMOFHL+qx+POvSAQcjdR6oaZ7/SFA83PaKov/uEFywZZ34+HyJmSf GAY4PBHGCpUC0UD0S7kE4V6Lo5kgkqz6Yc86vVzL7Gm4o/6KWXYRFiaYOyvXOYiHY5nu 62EW4QdnmdlvzUeSYcbgYN+GdOZyGxJKtZNuDq7DYw5ezvmgPSC8HreWMfskO71bLOXI 8KAvBtILSfMgzD6M6c6yVCyWDjjeJQVJYEAwcE3cHU25xxyZfQLqdguVSWFPcDjiW69W BR1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ko1WLEpY; 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=pass (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 k9si3343924ybp.269.2020.08.10.03.53.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 10 Aug 2020 03:53:15 -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=pass header.i=@linaro.org header.s=google header.b=Ko1WLEpY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56202 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k55QZ-0003Ox-05 for patch@linaro.org; Mon, 10 Aug 2020 06:53:15 -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) 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-Received: by 2002:a5d:5641:: with SMTP id j1mr24495239wrw.399.1597056716293; Mon, 10 Aug 2020 03:51:56 -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) From: =?utf-8?q?Alex_Benn=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 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_Benn=C3=A9e?= 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 --- 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(-) -- 2.20.1 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. -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 +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. Block structure ===============