From patchwork Thu Aug 6 11:40:36 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: 247482 Delivered-To: patch@linaro.org Received: by 2002:a92:cc90:0:0:0:0:0 with SMTP id x16csp1392738ilo; Thu, 6 Aug 2020 04:41:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJygS/mjidwLKHf+YA3ZklzYWoqoqXwmKp3o965DFoXyluimVvQItEPKqfab+3ENY1SjVkp5 X-Received: by 2002:a25:9186:: with SMTP id w6mr10939369ybl.401.1596714062886; Thu, 06 Aug 2020 04:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596714062; cv=none; d=google.com; s=arc-20160816; b=Uk6GIPra7Zpkl/DqvtjyCNnML6/ySDbPxiQLabotbeu7CtDtTEljghKf90kIrehrZM JxIhIJWuE76I3qk62t0LBW7KNpRDJfy9jpRvXekUgbL9SgZ4LbViagmKMDwhwgNerHpl 5a17cPJ0qqsbTRlsZ95osw2lXjeASBTrEkeNTsm2V6tCgwwhmAUWpE4608nz779WRqKs Z863K98eLMl+tRm+MSDwXK7zlSAjFvwG4y5abihOuTsSy7LKgESycCDQghkFEwtHx6XN SFzxGHwZfdT1Ns2j02lUGHr3mrx0m4UKS8nD8WgqFobXe4M/Zv+Z72g0ytFz6w4O9Mtp dwFA== 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=chlYlmg1y+jGFcu7MLZcX9cVTv/UER0aYzDkRYc+PeE=; b=jMes9bc4SX6B1P1NKMXietzNt7VaFPGGdPRUSPRvg75nxNOql3sbE43btdDr4NmmYk 8T6+VrzGhQW/LxUN5YepAkTtKt7bWRkoJ5xVxrxSUgDVgqxkNXC1lb0+1CVqE2esWbXc ZUkIfk/d2xEsCqMGhvaRpOt60fOZG7xHodRxZqmS0rEIPryhoOvjMFLuS1sven/LL4RB m0ZlIY3jx9SHvqaSIoo93l2inxcwtVTYfLYxH0litvfyR3sIloeZqHJotTVzr6Ivq4S7 cLi2Yyh186yKWy5lsvdPb32wVEJ8RnR6oB/M8K9ymNr04I5KfVfLMl5Kw9lyQVMg3Z8A syew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y5v1vZUU; 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 w6si4676786ybp.85.2020.08.06.04.41.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Aug 2020 04:41:02 -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=Y5v1vZUU; 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]:56300 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1k3eGb-0002ud-Ny for patch@linaro.org; Thu, 06 Aug 2020 07:41:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54546) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1k3eGQ-0002uU-Tk for qemu-devel@nongnu.org; Thu, 06 Aug 2020 07:40:50 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:39560) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1k3eGP-0006Jc-1h for qemu-devel@nongnu.org; Thu, 06 Aug 2020 07:40:50 -0400 Received: by mail-wr1-x444.google.com with SMTP id a5so33714747wrm.6 for ; Thu, 06 Aug 2020 04:40:48 -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=chlYlmg1y+jGFcu7MLZcX9cVTv/UER0aYzDkRYc+PeE=; b=Y5v1vZUUrc8/KOdqlge8PXwotvagrVhI7iaBDtXclP0LmcgNqA8ivtKElr4Yyaxq8A jRy+W5IvwLJmt1QLnJBq8zpQgokhBeqzBvPpKpX6F+CnImniycP7+AbkHWDU/qrMrPhe gJqFs9vLsQsAQV3QQrCeIESOaTVP3YPrAosxkZZCRBf8EI5XaLA1DFp+3sH/3az4Uijc TQS6SHg5nEyc7Z0Yw06TBNYDvp18AyRUWXx9VCXHdyZtF0t0FTdlkyJBi2yx3miYEQc8 gJEJ7oTOnXCvGTvoNELpN/0fhXEYMsVceJnZ40Bd5AOLw1B049F+fXcvS56GlqmdbzMh uG9w== 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=chlYlmg1y+jGFcu7MLZcX9cVTv/UER0aYzDkRYc+PeE=; b=rFzQFRgW8jXVCxjmNrPqeIH6oQWtPqG+NiyrX4fyQwea150vN4ad5l2Vp2xO2DBq1i Wx+uON5KHQZbctsW5N0iDGw7XXYngU210V5ZaRFlIvtBAoNm61mALP3NcP4Azrcrnqp2 xJHBgvcG5/ZExkK/GIkakL+GOx0BNOAKqc55MQAmS3xlQkEacUey2A3ZwwXu0tN4ZKkc rUxvQuJF6dYqK16qGTJZsQnsLU8H4V2kGK69WHvamhFzNItvSltTKURZrkqLBidE7S1N T4JcFZ8U+rO2kV3/fWRzjf4/pmQN8RUjcA8UD8rq4ZougF2GKPJKgUPxTcAZPyuDHH1v xzMQ== X-Gm-Message-State: AOAM5333z/fwjP+C92RrPAaR7/kiQIholJPFwG6tmpf5ILYaXXggnNE0 S3okzY3EScMu/Fd8oi5zgjV9tw== X-Received: by 2002:a5d:464e:: with SMTP id j14mr7172286wrs.361.1596714046952; Thu, 06 Aug 2020 04:40:46 -0700 (PDT) Received: from zen.linaroharston ([51.148.130.216]) by smtp.gmail.com with ESMTPSA id g145sm8881929wmg.23.2020.08.06.04.40.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Aug 2020 04:40:45 -0700 (PDT) Received: from zen.lan (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id D35991FF7E; Thu, 6 Aug 2020 12:40:44 +0100 (BST) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Subject: [RFC PATCH] CODING_STYLE.rst: flesh out our naming conventions. Date: Thu, 6 Aug 2020 12:40:36 +0100 Message-Id: <20200806114036.10646-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::444; envelope-from=alex.bennee@linaro.org; helo=mail-wr1-x444.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 --- CODING_STYLE.rst | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) -- 2.20.1 diff --git a/CODING_STYLE.rst b/CODING_STYLE.rst index 427699e0e42..17cb42ba761 100644 --- a/CODING_STYLE.rst +++ b/CODING_STYLE.rst @@ -109,9 +109,32 @@ 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. +Variable Naming Conventions +--------------------------- + +A number of common short naming conventions exist for variables that use +common QEMU types. For example when dealing with the architecture +independent CPUState this is often in 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 state structure often the very terse +``s`` or maybe ``foodev``. + +Function Naming Conventions +--------------------------- + When wrapping standard library functions, use the prefix ``qemu_`` to alert readers that they are seeing a wrapped version; otherwise avoid this prefix. +Functions that are expected to be called with some sort of lock held +usually have the suffix ``_locked``. + +Public functions (i.e. declared in public headers) tend to be prefixes +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 ===============