From nobody Sat May 18 02:03:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1637247447; cv=none; d=zohomail.com; s=zohoarc; b=a171EpAmUyi2OHa6SpuwiLAu/GtorK5e1F/7ncBw3Zb3PHEZtpxD4jr5fPiv4uMjtsyXaDLmm7dKBRR68tZMo7SROeH1pTCMZBVzLgbSBhRaKqZLrzj1B8uXRX5bJaGj1Nvg41gTke6kbrp5aFCvZ0Wu+cnqTA9XSZpzMP6pCc8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637247447; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=/sBYOa2h22qqCaXNmWikjc24bg3qqY1FNjgkcCrf8RE=; b=iYg50tggjUgWO4ijW/J+EQSSzgjfNHmh/BxxTZ3kRm8s0VBEtzXUbEomE4cYzgiGb67ZWzICcVJUVsKNKx4fQ7urL+EYoVVtNTltPeUNlbJA+jxmCAPi/7yWQicdAv1/5J044DnCbDnDKcqnsYlyCncne7QSwca1QmdTA0vUonU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1637247447419746.8877429158861; Thu, 18 Nov 2021 06:57:27 -0800 (PST) Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-266-Cd8zA79WN7SyGy9GcAz-uw-1; Thu, 18 Nov 2021 09:57:24 -0500 Received: by mail-wm1-f69.google.com with SMTP id ay34-20020a05600c1e2200b00337fd217772so3241552wmb.4 for ; Thu, 18 Nov 2021 06:57:23 -0800 (PST) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id r8sm118850wrz.43.2021.11.18.06.57.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 06:57:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637247445; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/sBYOa2h22qqCaXNmWikjc24bg3qqY1FNjgkcCrf8RE=; b=RILYiTPbnr4yMxMhaKTr1ibSXtbXtlRZ6l3+anpsnx2dH1qsA5clG2RHYLcmWNGSVuo/zW ANaDuif5N3z8LV9qfeLRd54jIyFXMMdv/Mv/ryKEwxoX/+GSlZzC/t17RKG3Q13fKntyE1 2tygoTwlJBX9qzyxX1oBk3E/oNCLa7E= X-MC-Unique: Cd8zA79WN7SyGy9GcAz-uw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/sBYOa2h22qqCaXNmWikjc24bg3qqY1FNjgkcCrf8RE=; b=djzJS7mIBqJdWF5pZwcKAtcrE4eXBwsyp3ccbBHGeYSIzwi4Cz33RbnSKiwMVjVxsb UQaUP75tQtARQUmTrYzFfvFSJmLLVf/9KVT40Oq7Pv+4iOZQKykqCX/u/GubDtAnJ+k9 gSSopSlCC2QSNmoS8IRl4RIyOALcKCowOqf3Ew1Sro+J58JCRUho1B9GVYV10yNSj2GQ 5nk4JaUnTyxm6ZcaGTmz6tWPckYPp1w7YGHxAh0bkVsWfE/YnFTizzy8ziIYJK2pGsN+ CLOO1PiZIC+2MNNCC2OxAi8a4bWTlb67kdoA1/oHg+T2FH5vqgIOTrzR5ZLFlGyyeoFD VhMg== X-Gm-Message-State: AOAM5300TlqyqDoWxyBkqxM99uc0AM/uOd+cX9o3auPsqT3ls0NO5SaY 9cwbKpkWMHHIcZ5H4W0QMdx6uhA373I1A2kNAK85IbZwYSmkpmeRg4XmfN2RdHnG3/QbzPU9x83 Pweb6dizAxEznZA== X-Received: by 2002:a05:6000:181:: with SMTP id p1mr31961473wrx.292.1637247442326; Thu, 18 Nov 2021 06:57:22 -0800 (PST) X-Google-Smtp-Source: ABdhPJwbaWYbx+81L3A2uMQ7E+xXjuqJi+VdIcV7V1z1J9YNySN3KDUkR1Gyg1jOwtaldysuX7gw+Q== X-Received: by 2002:a05:6000:181:: with SMTP id p1mr31961425wrx.292.1637247442040; Thu, 18 Nov 2021 06:57:22 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Markus Armbruster , Peter Maydell , Darren Kenny , "Daniel P . Berrange" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH-for-6.2? v2 1/5] docs/devel/style: Render C types as monospaced text Date: Thu, 18 Nov 2021 15:57:12 +0100 Message-Id: <20211118145716.4116731-2-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211118145716.4116731-1-philmd@redhat.com> References: <20211118145716.4116731-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1637247448565100001 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Darren Kenny --- docs/devel/style.rst | 59 ++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/docs/devel/style.rst b/docs/devel/style.rst index e00af62e763..3e519dc6ade 100644 --- a/docs/devel/style.rst +++ b/docs/devel/style.rst @@ -111,7 +111,7 @@ Variables are lower_case_with_underscores; easy to type= and read. Structured type names are in CamelCase; harder to type but standing out. Enum type names and function type names should also be in CamelCase. Scalar type names are lower_case_with_underscores_ending_with_a_t, like the POSIX -uint64_t and family. Note that this last convention contradicts POSIX +``uint64_t`` and family. Note that this last convention contradicts POSIX and is therefore likely to be changed. =20 Variable Naming Conventions @@ -290,57 +290,57 @@ a few useful guidelines here. Scalars ------- =20 -If you're using "int" or "long", odds are good that there's a better type. -If a variable is counting something, it should be declared with an -unsigned type. +If you're using '``int``' or '``long``', odds are good that there's a bett= er +type. If a variable is counting something, it should be declared with an +*unsigned* type. =20 -If it's host memory-size related, size_t should be a good choice (use -ssize_t only if required). Guest RAM memory offsets must use ram_addr_t, +If it's host memory-size related, ``size_t`` should be a good choice (use +``ssize_t`` only if required). Guest RAM memory offsets must use ``ram_add= r_t``, but only for RAM, it may not cover whole guest address space. =20 -If it's file-size related, use off_t. -If it's file-offset related (i.e., signed), use off_t. -If it's just counting small numbers use "unsigned int"; +If it's file-size related, use ``off_t``. +If it's file-offset related (i.e., signed), use ``off_t``. +If it's just counting small numbers use '``unsigned int``'; (on all but oddball embedded systems, you can assume that that type is at least four bytes wide). =20 In the event that you require a specific width, use a standard type -like int32_t, uint32_t, uint64_t, etc. The specific types are +like ``int32_t``, ``uint32_t``, ``uint64_t``, etc. The specific types are mandatory for VMState fields. =20 -Don't use Linux kernel internal types like u32, __u32 or __le32. +Don't use Linux kernel internal types like ``u32``, ``__u32`` or ``__le32`= `. =20 -Use hwaddr for guest physical addresses except pcibus_t -for PCI addresses. In addition, ram_addr_t is a QEMU internal address +Use ``hwaddr`` for guest physical addresses except ``pcibus_t`` +for PCI addresses. In addition, ``ram_addr_t`` is a QEMU internal address space that maps guest RAM physical addresses into an intermediate address space that can map to host virtual address spaces. Generally -speaking, the size of guest memory can always fit into ram_addr_t but +speaking, the size of guest memory can always fit into ``ram_addr_t`` but it would not be correct to store an actual guest physical address in a -ram_addr_t. +``ram_addr_t``. =20 For CPU virtual addresses there are several possible types. -vaddr is the best type to use to hold a CPU virtual address in +``vaddr`` is the best type to use to hold a CPU virtual address in target-independent code. It is guaranteed to be large enough to hold a virtual address for any target, and it does not change size from target to target. It is always unsigned. -target_ulong is a type the size of a virtual address on the CPU; this means +``target_ulong`` is a type the size of a virtual address on the CPU; this = means it may be 32 or 64 bits depending on which target is being built. It should therefore be used only in target-specific code, and in some performance-critical built-per-target core code such as the TLB code. -There is also a signed version, target_long. -abi_ulong is for the ``*``-user targets, and represents a type the size of -'void ``*``' in that target's ABI. (This may not be the same as the size o= f a +There is also a signed version, ``target_long``. +``abi_ulong`` is for the ``*-user`` targets, and represents a type the siz= e of +'``void *``' in that target's ABI. (This may not be the same as the size o= f a full CPU virtual address in the case of target ABIs which use 32 bit point= ers -on 64 bit CPUs, like sparc32plus.) Definitions of structures that must mat= ch +on 64 bit CPUs, like *sparc32plus*.) Definitions of structures that must m= atch the target's ABI must use this type for anything that on the target is def= ined -to be an 'unsigned long' or a pointer type. -There is also a signed version, abi_long. +to be an '``unsigned long``' or a pointer type. +There is also a signed version, ``abi_long``. =20 Of course, take all of the above with a grain of salt. If you're about -to use some system interface that requires a type like size_t, pid_t or -off_t, use matching types for any corresponding variables. +to use some system interface that requires a type like ``size_t``, ``pid_t= `` or +``off_t``, use matching types for any corresponding variables. =20 -Also, if you try to use e.g., "unsigned int" as a type, and that +Also, if you try to use e.g., '``unsigned int``' as a type, and that conflicts with the signedness of a related variable, sometimes it's best just to use the *wrong* type, if "pulling the thread" and fixing all related variables would be too invasive. @@ -363,7 +363,7 @@ it points to, or it is aliased to another pointer that = is. Typedefs -------- =20 -Typedefs are used to eliminate the redundant 'struct' keyword, since type +Typedefs are used to eliminate the redundant '``struct``' keyword, since t= ype names have a different style than other identifiers ("CamelCase" versus "snake_case"). Each named struct type should have a CamelCase name and a corresponding typedef. @@ -418,8 +418,9 @@ Calling ``g_malloc`` with a zero size is valid and will= return NULL. Prefer ``g_new(T, n)`` instead of ``g_malloc(sizeof(T) * n)`` for the foll= owing reasons: =20 -* It catches multiplication overflowing size_t; -* It returns T ``*`` instead of void ``*``, letting compiler catch more ty= pe errors. +* It catches multiplication overflowing ``size_t``; +* It returns ``T *`` instead of ``void *``, letting compiler catch more ty= pe + errors. =20 Declarations like =20 --=20 2.31.1 From nobody Sat May 18 02:03:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1637247452; cv=none; d=zohomail.com; s=zohoarc; b=adSvmYQBFIIGQLPHECQKprkHI1a7rp9Vea8GEUCMK2YiupCs86mOIUXxS4iyznXOkEVX3t4+Vk4Wkji5v9TgeZG/bsU2jrn5bV6s1uYTxjcu2l4toIwLxaMjTm8pmyiyRfa0iYscKRgC1fzMYP0xnLF9Zxv698/FKWC/2f1a9Tg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637247452; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=/HpEathA5riapQobuv/wwQs6HF4NNRoprJj+KElllXM=; b=WqhTiXKhxAewSE2U0zrfse9GXoyeQX6rx4WGZ+I/AH+d/TiFZdsEeZxAb0ajD/9a8a1b5W406HqYm/hXLFl1qXqrtgTKSvjFY1szeFX6f4XrXIVcZg051+Q04OWJQwdM9cqxVTD2V5S8KBaeYjwrF3u+N08WdF4oeOM/wacS5s0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1637247452144286.69840722504125; Thu, 18 Nov 2021 06:57:32 -0800 (PST) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-61-5lrZ8SuPNn6TkKhRCXfw9w-1; Thu, 18 Nov 2021 09:57:28 -0500 Received: by mail-wm1-f72.google.com with SMTP id l6-20020a05600c4f0600b0033321934a39so3223878wmq.9 for ; Thu, 18 Nov 2021 06:57:27 -0800 (PST) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id 38sm119011wrc.1.2021.11.18.06.57.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 06:57:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637247451; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/HpEathA5riapQobuv/wwQs6HF4NNRoprJj+KElllXM=; b=TFpZuF8/iVSxO9iwMszKlDzVC5VDD3/jRvQyfXNJEywrwBHEoKBTjkeoYtgv4XbRbPjdqQ OpHdAZK2ERzdyyy9J/CTdCQjdUwcMtJRGI1/+rRWv4iCkrEkQLw0o6a2EC2fy/4YRZhbAj xpP2zZSDJMYd2y3ApF4a0pMd89+BTCY= X-MC-Unique: 5lrZ8SuPNn6TkKhRCXfw9w-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/HpEathA5riapQobuv/wwQs6HF4NNRoprJj+KElllXM=; b=ltOLA6MWrTyytEo8TyASV9SaTKmDS4NdqBoiBU7R16cE7cgMrOUPFaNOtGpk4EH4hH Z3MfcfXKjeG64l8/B/sJWtxxuo5aJwBtZFjbBr5TiwQiMqzvAnJiA87zvATWHF/8m3tO /i6Ifw0lrGeVyYHjNKngkEfuBijqDvlZuVF/nwMatnE6YQgfgiw1yGj+VKJBZHgUvNu7 OMBhfZ8nXVluIrfs/WB517YmeFlPZSWl3hr7Y4nZKENTxy3f/1NDdHxTWzJbeBGYWu/i rulg1aCykhPneeVNxo7g5h9TJLduIEEX2wv7iU06gLFYmvD1TCSmTVUg0XP/x1zF4H7k pnhQ== X-Gm-Message-State: AOAM533XGlYjMIi+DLcZAb81t+TPIAy3/WIS8jqZ0BfE1RbUxozsz+6F nvEfDscu50AlXnicmktUW/DQzcFvUOdvxVF37/mjnwNjtc40HYApZdWLZmKd5ZMepDFavWG4Axs C62XJtQBj/IY3Dg== X-Received: by 2002:adf:dd0a:: with SMTP id a10mr32197008wrm.60.1637247446618; Thu, 18 Nov 2021 06:57:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJy9540F1z7RYJ5+NhbiHpVspcg/n+EsQJDIPIvg6LAIdPON8lY1Ry++DNhW9b/FKJUIJYSG8Q== X-Received: by 2002:adf:dd0a:: with SMTP id a10mr32196978wrm.60.1637247446390; Thu, 18 Nov 2021 06:57:26 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Markus Armbruster , Peter Maydell , Darren Kenny , "Daniel P . Berrange" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH-for-6.2? v2 2/5] docs/devel/style: Improve Error** functions rST rendering Date: Thu, 18 Nov 2021 15:57:13 +0100 Message-Id: <20211118145716.4116731-3-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211118145716.4116731-1-philmd@redhat.com> References: <20211118145716.4116731-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1637247453488100001 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Darren Kenny --- docs/devel/style.rst | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/docs/devel/style.rst b/docs/devel/style.rst index 3e519dc6ade..1a23021bc3e 100644 --- a/docs/devel/style.rst +++ b/docs/devel/style.rst @@ -602,16 +602,16 @@ Error handling and reporting Reporting errors to the human user ---------------------------------- =20 -Do not use printf(), fprintf() or monitor_printf(). Instead, use -error_report() or error_vreport() from error-report.h. This ensures the -error is reported in the right place (current monitor or stderr), and in -a uniform format. +Do not use ``printf()``, ``fprintf()`` or ``monitor_printf()``. Instead, = use +``error_report()`` or ``error_vreport()`` from error-report.h. This ensur= es +the error is reported in the right place (current monitor or ``stderr``), = and +in a uniform format. =20 -Use error_printf() & friends to print additional information. +Use ``error_printf()`` & friends to print additional information. =20 -error_report() prints the current location. In certain common cases +``error_report()`` prints the current location. In certain common cases like command line parsing, the current location is tracked -automatically. To manipulate it manually, use the loc_``*``() from +automatically. To manipulate it manually, use the ``loc_*()`` from error-report.h. =20 Propagating errors @@ -621,7 +621,7 @@ An error can't always be reported to the user right whe= re it's detected, but often needs to be propagated up the call chain to a place that can handle it. This can be done in various ways. =20 -The most flexible one is Error objects. See error.h for usage +The most flexible one is ``Error`` objects. See error.h for usage information. =20 Use the simplest suitable method to communicate success / failure to @@ -631,10 +631,10 @@ error, non-negative / -errno, non-null / null, or Err= or objects. Example: when a function returns a non-null pointer on success, and it can fail only in one way (as far as the caller is concerned), returning null on failure is just fine, and certainly simpler and a lot easier on -the eyes than propagating an Error object through an Error ``*````*`` para= meter. +the eyes than propagating an Error object through an ``Error **`` paramete= r. =20 Example: when a function's callers need to report details on failure -only the function really knows, use Error ``*````*``, and set suitable err= ors. +only the function really knows, use ``Error **``, and set suitable errors. =20 Do not report an error to the user when you're also returning an error for somebody else to handle. Leave the reporting to the place that @@ -643,17 +643,17 @@ consumes the error returned. Handling errors --------------- =20 -Calling exit() is fine when handling configuration errors during +Calling ``exit()`` is fine when handling configuration errors during startup. It's problematic during normal operation. In particular, -monitor commands should never exit(). +monitor commands should never ``exit()``. =20 -Do not call exit() or abort() to handle an error that can be triggered +Do not call ``exit()`` or ``abort()`` to handle an error that can be trigg= ered by the guest (e.g., some unimplemented corner case in guest code translation or device emulation). Guests should not be able to terminate QEMU. =20 -Note that &error_fatal is just another way to exit(1), and &error_abort -is just another way to abort(). +Note that ``&error_fatal`` is just another way to ``exit(1)``, and +``&error_abort`` is just another way to ``abort()``. =20 =20 trace-events style --=20 2.31.1 From nobody Sat May 18 02:03:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1637247454; cv=none; d=zohomail.com; s=zohoarc; b=XHHqeH0aCKBGyGquc2eRmUL+UxQ/oZ92DUXOUrhrzFWD1IAYgwp7cTlS8wHOSM4K6s1s38qjXkaqs/EF0D9Y9x2dX2pIv6re1qtkUVEUfKLnh6jeQpr+KbE3SwEggrV0LNWcrdX8PvNG6/wEOOffRDGJmwOJ+VvaoO2AUjl3sGQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637247454; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=6DiSDv3PdVbuzBwVbsPBRsE403y5aRBjXVqhRXtzZwI=; b=PEjr/NiSFkNmW+j2kJxZ0tBc6Iy9Oiiy1LGrL/Y7aEXweCIUHc/ilhKL5JtIMPwRnfvIt/cK1fc4DkIiRzwli6t7aLaSQ480UT7waOgZcusCcTlaWd6QyaXP1LNSKxPejuIGVjOEcOtfReUI2HwPaJVoZ6mb2OsZhjHXcwQIsFE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1637247454286792.1612565099216; Thu, 18 Nov 2021 06:57:34 -0800 (PST) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-569-TtCbMAx-N8y2vKLnkMmDwg-1; Thu, 18 Nov 2021 09:57:32 -0500 Received: by mail-wm1-f71.google.com with SMTP id 144-20020a1c0496000000b003305ac0e03aso4446436wme.8 for ; Thu, 18 Nov 2021 06:57:31 -0800 (PST) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id b10sm81077wrt.36.2021.11.18.06.57.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 06:57:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637247453; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6DiSDv3PdVbuzBwVbsPBRsE403y5aRBjXVqhRXtzZwI=; b=CL1xe1rtwsDeCo3UIbKDgVZWXjX1VhB1cCeZIbdouJr2BUq6XguXaMGeZU8U4U+qpgAZ3r dkqi2Jd19GjfgG8QkOyUB8fqrczHamlbHiAh1vkRfGoZMl0AuaX+kZLYyLBRL+CMAvQQNv AsdYnr6oNNd/luux5gMxaSV55yXQhBs= X-MC-Unique: TtCbMAx-N8y2vKLnkMmDwg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6DiSDv3PdVbuzBwVbsPBRsE403y5aRBjXVqhRXtzZwI=; b=3UsH26K7oHJgdYFZSWuL7EWhdU9rTmxNkdc6uX73z9Pns/CM/bXZWbRv1gBE790eBz z4vYnY9Fo8pGorQZak0dO/x6ZCVCerMrq8ZS0jWnj9cLtfFAIEMTylrIEw/znhfMz/uB uuzNqCzi6zEU39GSrS6LEE3MaWy5R6p5HtP6u9rCwfKJMN0759Rp10TgZNve9KL/jMUg iq2mMPebZHQrX8A14yVwZEtSfzpvT+SeuYtyXBuJd/jZCIRwHkYFAGwbDG/kavrjZJo6 gzRYzHSShwfL4xrg/TVKrEWsajW5/35NYw1W20kkceuo0uVVN/bvRszFpwwQy231reJO Mg4w== X-Gm-Message-State: AOAM533UGdWIH501dUhboVK/7cvYJ5tqOfkU6BiUWqzbU8PSq4bX5VFW rEwRySxIiAWPWSr/G3GTuiF8FSDwkQ/vn+hhyEpt3y9TsaSh00YWp9a4YSZIzs5OeV9eK0gVGz1 5sOG87E9z26vefQ== X-Received: by 2002:a1c:a715:: with SMTP id q21mr10926048wme.23.1637247450896; Thu, 18 Nov 2021 06:57:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJwFehAPCodWGX22DYzque1Ork/YjeZDpJjpMHY+Bq8h0Rt0bxqYzveTzZqKA3MfHMEK+z02Mg== X-Received: by 2002:a1c:a715:: with SMTP id q21mr10926028wme.23.1637247450721; Thu, 18 Nov 2021 06:57:30 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Markus Armbruster , Peter Maydell , Darren Kenny , "Daniel P . Berrange" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH-for-6.2? v2 3/5] docs/devel/style: Improve string format rST rendering Date: Thu, 18 Nov 2021 15:57:14 +0100 Message-Id: <20211118145716.4116731-4-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211118145716.4116731-1-philmd@redhat.com> References: <20211118145716.4116731-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1637247455819100001 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Darren Kenny --- docs/devel/style.rst | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/docs/devel/style.rst b/docs/devel/style.rst index 1a23021bc3e..a7487d867e6 100644 --- a/docs/devel/style.rst +++ b/docs/devel/style.rst @@ -471,11 +471,11 @@ instead of plain strdup/strndup. Printf-style functions =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 -Whenever you add a new printf-style function, i.e., one with a format -string argument and following "..." in its prototype, be sure to use -gcc's printf attribute directive in the prototype. +Whenever you add a new ``printf()``-style function, i.e., one with a format +string argument and following '``...``' in its prototype, be sure to use +gcc's ``printf()`` attribute directive in the prototype. =20 -This makes it so gcc's -Wformat and -Wformat-security options can do +This makes it so gcc's ``-Wformat`` and ``-Wformat-security`` options can = do their jobs and cross-check format strings with the number and types of arguments. =20 @@ -659,10 +659,10 @@ Note that ``&error_fatal`` is just another way to ``e= xit(1)``, and trace-events style =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 -0x prefix ---------- +``0x`` prefix +------------- =20 -In trace-events files, use a '0x' prefix to specify hex numbers, as in: +In trace-events files, use a '``0x``' prefix to specify hex numbers, as in: =20 .. code-block:: c =20 @@ -676,27 +676,28 @@ PCI bus id): =20 another_trace(int cssid, int ssid, int dev_num) "bus id: %x.%x.%04x" =20 -However, you can use '0x' for such groups if you want. Anyway, be sure that +However, you can use '``0x``' for such groups if you want. Anyway, be sure= that it is obvious that numbers are in hex, ex.: =20 .. code-block:: c =20 data_dump(uint8_t c1, uint8_t c2, uint8_t c3) "bytes (in hex): %02x %0= 2x %02x" =20 -Rationale: hex numbers are hard to read in logs when there is no 0x prefix, -especially when (occasionally) the representation doesn't contain any lett= ers -and especially in one line with other decimal numbers. Number groups are a= llowed -to not use '0x' because for some things notations like %x.%x.%x are used n= ot -only in QEMU. Also dumping raw data bytes with '0x' is less readable. +Rationale: hex numbers are hard to read in logs when there is no '``0x``' +prefix, especially when (occasionally) the representation doesn't contain = any +letters and especially in one line with other decimal numbers. Number grou= ps +are allowed to not use '``0x``' because for some things notations like +'``%x.%x.%x``' are used not only in QEMU. Also dumping raw data bytes with +'``0x``' is less readable. =20 -'#' printf flag ---------------- +'``#``' printf flag +------------------- =20 -Do not use printf flag '#', like '%#x'. +Do not use printf flag '``#``', like '``%#x``'. =20 -Rationale: there are two ways to add a '0x' prefix to printed number: '0x%= ...' -and '%#...'. For consistency the only one way should be used. Arguments for -'0x%' are: +Rationale: there are two ways to add a '``0x``' prefix to printed number: +'``0x%...``' and '``%#...``'. For consistency the only one way should be u= sed. +Arguments for '``0x%``' are: =20 * it is more popular -* '%#' omits the 0x for the value 0 which makes output inconsistent +* '``%#``' omits the ``0x`` for the value ``0`` which makes output inconsi= stent --=20 2.31.1 From nobody Sat May 18 02:03:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1637247459; cv=none; d=zohomail.com; s=zohoarc; b=aabxJTMn5MOcfhU4ZA9Z7FSi//9Y1h3OPl9yhHyx+QEDweXEv1JAdNi/NIYYHYLgTkgpFNzGBiLN7yTYk8lhlvka88KFbMbVsoaYrK4OkzV/v01qFqODyTFFE7F6zDgY6p6skekdiZYhOJl5wBAW4QniFOWPrOTSLMOIQyNw2Gk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637247459; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=m3us/2QX6xHvSyMB3iMuIzPGz+T3xWB4txlMwAd+l0s=; b=LUIJ/ihnAy1H+q06jBwJ57eohddLQfORiwZgmjGL9UUDGdRUtRznU9Add84WZoQPtKqTWygMjuT8G2aql6k2pdYREAxdWnP7Bu0ii8bynCvwm3H3VVG0atlpuvq/ZPIzIVEuEX59nlSsZ2aQ/+qTSKz9IGErSgZdkn0PYHnPHrM= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1637247459613834.029389851954; Thu, 18 Nov 2021 06:57:39 -0800 (PST) Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-209-HKg60pfwNOCqCttYK-WFQA-1; Thu, 18 Nov 2021 09:57:36 -0500 Received: by mail-wm1-f71.google.com with SMTP id l187-20020a1c25c4000000b0030da46b76daso4435306wml.9 for ; Thu, 18 Nov 2021 06:57:36 -0800 (PST) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id g4sm89060wro.12.2021.11.18.06.57.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 06:57:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637247458; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=m3us/2QX6xHvSyMB3iMuIzPGz+T3xWB4txlMwAd+l0s=; b=V7bCA94Zebaz38TtRmAaPa0V/Mj8tEIEHXQp2rFipXRBgbOKIKMMgBeL7spfrmoWQPGI/d thvjm5l4HN3hkQXUvpVQxsoIWJbupBTcQcGg2dpWghEMURxALp2GIh9LSkCsSHULoKwGhe NKaIqzEBR2jJNDvXETVHkj63IFIk1No= X-MC-Unique: HKg60pfwNOCqCttYK-WFQA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=m3us/2QX6xHvSyMB3iMuIzPGz+T3xWB4txlMwAd+l0s=; b=KrrOSRCkrzVBbQp6dUIZGf5ze9xDY3oVPVlSqbVFRQvsZaWMjS2+mi28vZ9WBss5QN wB7YUoYkdVmdlJYNeDzFiBmdcO7g7nwMDf+Ste9nwkRda9/Ya15qUkAVY+Dp2pUyhNZz nvnJFJPrG3id5bigqVsc5MaCAl1O4e2WMQ/mOEAcpDb0Jnu8qNYAxXLcJTfOUlzuraHV yJgrMfpvuTHz9Z8EY0yKsNsxrhKRftbAJrzrijX7mwy9SidGRV4Ra/3wn3Q7Bz/s+b1i z5Xz5Q+OcRSY7MUEMUh6PmtO0D0qOQUfIyCy2W5jBZrhgpwOViBdXeli3mSdFJXDzsmN WD6w== X-Gm-Message-State: AOAM531uFw6W7St2HhJ1rh6mxG5ocsI+6KgmMEIP+S7nL9gsEXCuWBNv 6wU9XBr/YIloorEqjSCIFqt+qD6+UnFkRM+Wxw+qdRMYWnZ00amURg3kTWZxp1Geo4uXgu6pA4c ogHFMrD4rSF6UUQ== X-Received: by 2002:a05:6000:2c7:: with SMTP id o7mr32215627wry.62.1637247455261; Thu, 18 Nov 2021 06:57:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJy7Vy50/RRoqMbMb1vlB+RFIURa8dhPXf4Q0RGgcJkntxcEMZnyS4mQdt/plnR2/jpo47Cvow== X-Received: by 2002:a05:6000:2c7:: with SMTP id o7mr32215590wry.62.1637247454975; Thu, 18 Nov 2021 06:57:34 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Markus Armbruster , Peter Maydell , Darren Kenny , "Daniel P . Berrange" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH-for-6.2? v2 4/5] docs/devel/style: Render C function names as monospaced text Date: Thu, 18 Nov 2021 15:57:15 +0100 Message-Id: <20211118145716.4116731-5-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211118145716.4116731-1-philmd@redhat.com> References: <20211118145716.4116731-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1637247461136100001 Add trailing parenthesis to functions and render them as monospaced text. Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Darren Kenny --- docs/devel/style.rst | 66 +++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/docs/devel/style.rst b/docs/devel/style.rst index a7487d867e6..0397971e528 100644 --- a/docs/devel/style.rst +++ b/docs/devel/style.rst @@ -130,13 +130,13 @@ Function Naming Conventions =20 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 +example ``qemu_strtol()`` or ``qemu_mutex_lock()``. Other utility functio= ns 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``. +prefix, for example ``pstrcpy()`` or bit manipulation functions such as +``find_first_bit()``. =20 The ``qemu_`` prefix is also used for functions that modify global -emulator state, for example ``qemu_add_vm_change_state_handler``. +emulator state, for example ``qemu_add_vm_change_state_handler()``. However, if there is an obvious subsystem-specific prefix it should be used instead. =20 @@ -385,15 +385,16 @@ avoided. Low level memory management =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D =20 -Use of the ``malloc/free/realloc/calloc/valloc/memalign/posix_memalign`` +Use of the +``malloc()/free()/realloc()/calloc()/valloc()/memalign()/posix_memalign()`` APIs is not allowed in the QEMU codebase. Instead of these routines, use the GLib memory allocation routines -``g_malloc/g_malloc0/g_new/g_new0/g_realloc/g_free`` -or QEMU's ``qemu_memalign/qemu_blockalign/qemu_vfree`` APIs. +``g_malloc()/g_malloc0()/g_new()/g_new0()/g_realloc()/g_free()`` +or QEMU's ``qemu_memalign()/qemu_blockalign()/qemu_vfree()`` APIs. =20 -Please note that ``g_malloc`` will exit on allocation failure, so +Please note that ``g_malloc()`` will exit on allocation failure, so there is no need to test for failure (as you would have to with -``malloc``). Generally using ``g_malloc`` on start-up is fine as the +``malloc()``). Generally using ``g_malloc()`` on start-up is fine as the result of a failure to allocate memory is going to be a fatal exit anyway. There may be some start-up cases where failing is unreasonable (for example speculatively loading a large debug symbol table). @@ -401,11 +402,11 @@ anyway. There may be some start-up cases where failin= g is unreasonable Care should be taken to avoid introducing places where the guest could trigger an exit by causing a large allocation. For small allocations, of the order of 4k, a failure to allocate is likely indicative of an -overloaded host and allowing ``g_malloc`` to ``exit`` is a reasonable +overloaded host and allowing ``g_malloc()`` to ``exit()`` is a reasonable approach. However for larger allocations where we could realistically fall-back to a smaller one if need be we should use functions like -``g_try_new`` and check the result. For example this is valid approach -for a time/space trade-off like ``tlb_mmu_resize_locked`` in the +``g_try_new()`` and check the result. For example this is valid approach +for a time/space trade-off like ``tlb_mmu_resize_locked()`` in the SoftMMU TLB code. =20 If the lifetime of the allocation is within the function and there are @@ -413,7 +414,7 @@ multiple exist paths you can also improve the readabili= ty of the code by using ``g_autofree`` and related annotations. See :ref:`autofree-ref` for more details. =20 -Calling ``g_malloc`` with a zero size is valid and will return NULL. +Calling ``g_malloc()`` with a zero size is valid and will return ``NULL``. =20 Prefer ``g_new(T, n)`` instead of ``g_malloc(sizeof(T) * n)`` for the foll= owing reasons: @@ -430,14 +431,15 @@ Declarations like =20 are acceptable, though. =20 -Memory allocated by ``qemu_memalign`` or ``qemu_blockalign`` must be freed= with -``qemu_vfree``, since breaking this will cause problems on Win32. +Memory allocated by ``qemu_memalign()`` or ``qemu_blockalign()`` must be f= reed +with ``qemu_vfree()``, since breaking this will cause problems on Win32. =20 String manipulation =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 -Do not use the strncpy function. As mentioned in the man page, it does *n= ot* -guarantee a NULL-terminated buffer, which makes it extremely dangerous to = use. +Do not use the ``strncpy()`` function. As mentioned in the man page, it d= oes +*not* guarantee a ``NULL``-terminated buffer, which makes it extremely +dangerous to use. It also zeros trailing destination bytes out to the specified length. Ins= tead, use this similar function when possible, but note its different signature: =20 @@ -445,14 +447,14 @@ use this similar function when possible, but note its= different signature: =20 void pstrcpy(char *dest, int dest_buf_size, const char *src) =20 -Don't use strcat because it can't check for buffer overflows, but: +Don't use ``strcat()`` because it can't check for buffer overflows, but: =20 .. code-block:: c =20 char *pstrcat(char *buf, int buf_size, const char *s) =20 -The same limitation exists with sprintf and vsprintf, so use snprintf and -vsnprintf. +The same limitation exists with ``sprintf()`` and ``vsprintf()``, so use +``snprintf()`` and ``vsnprintf()``. =20 QEMU provides other useful string functions: =20 @@ -462,11 +464,11 @@ QEMU provides other useful string functions: int stristart(const char *str, const char *val, const char **ptr) int qemu_strnlen(const char *s, int max_len) =20 -There are also replacement character processing macros for isxyz and toxyz, -so instead of e.g. isalnum you should use qemu_isalnum. +There are also replacement character processing macros for ``isxyz()`` and +``toxyz()``, so instead of e.g. ``isalnum()`` you should use ``qemu_isalnu= m()``. =20 -Because of the memory management rules, you must use g_strdup/g_strndup -instead of plain strdup/strndup. +Because of the memory management rules, you must use ``g_strdup()/g_strndu= p()`` +instead of plain ``strdup()/strndup()``. =20 Printf-style functions =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D @@ -525,10 +527,10 @@ automatic cleanup: =20 Most notably: =20 -* g_autofree - will invoke g_free() on the variable going out of scope +* ``g_autofree`` - will invoke ``g_free()`` on the variable going out of s= cope =20 -* g_autoptr - for structs / objects, will invoke the cleanup func created - by a previous use of G_DEFINE_AUTOPTR_CLEANUP_FUNC. This is +* ``g_autoptr`` - for structs / objects, will invoke the cleanup func crea= ted + by a previous use of ``G_DEFINE_AUTOPTR_CLEANUP_FUNC``. This is supported for most GLib data types and GObjects =20 For example, instead of @@ -552,7 +554,7 @@ For example, instead of return ret; } =20 -Using g_autofree/g_autoptr enables the code to be written as: +Using ``g_autofree/g_autoptr`` enables the code to be written as: =20 .. code-block:: c =20 @@ -570,13 +572,13 @@ Using g_autofree/g_autoptr enables the code to be wri= tten as: While this generally results in simpler, less leak-prone code, there are still some caveats to beware of =20 -* Variables declared with g_auto* MUST always be initialized, +* Variables declared with ``g_auto*`` MUST always be initialized, otherwise the cleanup function will use uninitialized stack memory =20 -* If a variable declared with g_auto* holds a value which must +* If a variable declared with ``g_auto*`` holds a value which must live beyond the life of the function, that value must be saved - and the original variable NULL'd out. This can be simpler using - g_steal_pointer + and the original variable ``NULL``'d out. This can be simpler using + ``g_steal_pointer``. =20 =20 .. code-block:: c --=20 2.31.1 From nobody Sat May 18 02:03:43 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=philmd@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1637247464; cv=none; d=zohomail.com; s=zohoarc; b=Pt4zoXQRvus+KrgvicWsDr5XFRwQ/IA52vHqxMdKjruma9ANK0IBnohdncl+U0b4kSFOLcK/Y2WB1NiWsEFDj3Q4hfTrOkVmQu+M/X/ITRdKOWyjowjEwL0Kgy+nkYrWZvrOeYnLD43Bmuc9qY64+0LagWYVhKiV9VkRzKh6qB8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1637247464; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:To; bh=995klPDX33rmzvSoWGVJ6V1EGfWuQDmUmdzVzSbmtDc=; b=LjJXfpYtlglzcEFO4CKfKMNyFn+Al9anAOY1fQ6bSVD51Snajaj9MDgbz58VInwb+lK+LzhAU2iRwAm2O/77LF1LSjWnmTlYmjR5x5RsjW3x8OygG9wiRykzJgMtWXn9mvjuv2GXV+t3v3fx0AzqtZkmcqZhhvYkK/9p/FVW2UY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=philmd@redhat.com; dmarc=pass header.from= (p=none dis=none) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 1637247464521856.4706760222874; Thu, 18 Nov 2021 06:57:44 -0800 (PST) Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-540-d-tvIO6hOgKFAQay9Jx4Jg-1; Thu, 18 Nov 2021 09:57:40 -0500 Received: by mail-wm1-f72.google.com with SMTP id j193-20020a1c23ca000000b003306ae8bfb7so2691608wmj.7 for ; Thu, 18 Nov 2021 06:57:40 -0800 (PST) Return-Path: Return-Path: Received: from x1w.. (62.red-83-57-168.dynamicip.rima-tde.net. [83.57.168.62]) by smtp.gmail.com with ESMTPSA id q123sm9051755wma.30.2021.11.18.06.57.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Nov 2021 06:57:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1637247463; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=995klPDX33rmzvSoWGVJ6V1EGfWuQDmUmdzVzSbmtDc=; b=OA5rWNVVqGYNzy8W6XMXi9QRTl1evtFNQizwJBsGJScJCtsJhnXQ/XLRCHbb+QL3aWFGhS Hid4NM2BVMhIsir+ZP2MftUBaWh+zzvTwmaiPq746tYN1YKMts/QLiAXdCoNZrclTohfv5 QcjeBR95RntmS+E9BcuYMIGj3IM+u+g= X-MC-Unique: d-tvIO6hOgKFAQay9Jx4Jg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=995klPDX33rmzvSoWGVJ6V1EGfWuQDmUmdzVzSbmtDc=; b=kd392eA1z70QKASFSJmEZ/Xkc43cspPDssapg9vK4cI0ZB24UXf4PL33navA9HwoJ0 L/+fwC8bYPacsZnpbyJyV27tvjxYmN0KBwtkgeBA4tM290NUBnFfi4cEN2ZN/+0HimR0 B1OC4MMi2ZrOGCz2suUj9Lk+7zMfrhd1SOyRcxalVO+H0tbmZKcMjpTukUYhCv0dXjGL Nte4aXcquvIK+c3bIOsxhGNxyBfw4oitFi2yzIH78BTb+8zS/Dnnt0a0CU+OE49xUUXE Og51bINGRV9OfRubHqM0GbmJeYAePYWt2nShh2BvhyeGFqV+Ojn8rJ1/3PMn4nm7L7p7 G6JA== X-Gm-Message-State: AOAM530sPk3cxFegUL3qcN99YD6u6ehfzZbq/yEkUo3FObifK3OHoTQU AUU3qx5VrxaudWNYAaGPtFsuYEAGpLlqBJ068gilDNoWaIxWXAnoIM1A4zNIylPLC6GQuQNSVxr FsKqIoDt0CQ1Ixg== X-Received: by 2002:adf:ce0e:: with SMTP id p14mr31229414wrn.423.1637247459394; Thu, 18 Nov 2021 06:57:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJyzA9z6QrKZQxNpKCdTMNZz5Kdu7G0oiAbK9lXyLgLEfb7M5V6ubx7stOrU/w/u2ubttfOFqQ== X-Received: by 2002:adf:ce0e:: with SMTP id p14mr31229388wrn.423.1637247459149; Thu, 18 Nov 2021 06:57:39 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Markus Armbruster , Peter Maydell , Darren Kenny , "Daniel P . Berrange" , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Subject: [PATCH-for-6.2? v2 5/5] docs/devel/style: Misc rST rendering improvements Date: Thu, 18 Nov 2021 15:57:16 +0100 Message-Id: <20211118145716.4116731-6-philmd@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211118145716.4116731-1-philmd@redhat.com> References: <20211118145716.4116731-1-philmd@redhat.com> MIME-Version: 1.0 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=philmd@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1637247465747100001 Signed-off-by: Philippe Mathieu-Daud=C3=A9 Reviewed-by: Alex Benn=C3=A9e Reviewed-by: Darren Kenny --- docs/devel/style.rst | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/devel/style.rst b/docs/devel/style.rst index 0397971e528..1db50b70544 100644 --- a/docs/devel/style.rst +++ b/docs/devel/style.rst @@ -4,7 +4,7 @@ QEMU Coding Style =20 .. contents:: Table of Contents =20 -Please use the script checkpatch.pl in the scripts directory to check +Please use the script ``checkpatch.pl`` in the scripts directory to check patches before submitting. =20 Formatting and style @@ -195,9 +195,9 @@ blocks) are generally not allowed; declarations should = be at the beginning of blocks. =20 Every now and then, an exception is made for declarations inside a -#ifdef or #ifndef block: if the code looks nicer, such declarations can +``#ifdef`` or ``#ifndef`` block: if the code looks nicer, such declaration= s can be placed at the top of the block even if there are statements above. -On the other hand, however, it's often best to move that #ifdef/#ifndef +On the other hand, however, it's often best to move that ``#ifdef/#ifndef`` block to a separate function altogether. =20 Conditional statements @@ -220,13 +220,13 @@ even when the constant is on the right. Comment style =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 -We use traditional C-style /``*`` ``*``/ comments and avoid // comments. +We use traditional C-style ``/* */`` comments and avoid ``//`` comments. =20 -Rationale: The // form is valid in C99, so this is purely a matter of +Rationale: The ``//`` form is valid in C99, so this is purely a matter of consistency of style. The checkpatch script will warn you about this. =20 Multiline comment blocks should have a row of stars on the left, -and the initial /``*`` and terminating ``*``/ both on their own lines: +and the initial ``/*`` and terminating ``*/`` both on their own lines: =20 .. code-block:: c =20 @@ -274,11 +274,11 @@ Order include directives as follows: #include "..." /* and finally QEMU headers. */ =20 The "qemu/osdep.h" header contains preprocessor macros that affect the beh= avior -of core system headers like . It must be the first include so t= hat -core system headers included by external libraries get the preprocessor ma= cros -that QEMU depends on. +of core system headers like ````. It must be the first include = so +that core system headers included by external libraries get the preprocess= or +macros that QEMU depends on. =20 -Do not include "qemu/osdep.h" from header files since the .c file will have +Do not include ``"qemu/osdep.h"`` from header files since the .c file will= have already included it. =20 C types @@ -352,9 +352,9 @@ casts, then reconsider or ask for help. Pointers -------- =20 -Ensure that all of your pointers are "const-correct". +Ensure that all of your pointers are "``const``-correct". Unless a pointer is used to modify the pointed-to storage, -give it the "const" attribute. That way, the reader knows +give it the '``const``' attribute. That way, the reader knows up-front that this is a read-only pointer. Perhaps more importantly, if we're diligent about this, when you see a non-const pointer, you're guaranteed that it is used to modify the storage @@ -505,7 +505,7 @@ painful. These are: the sign bit (ie it is an arithmetic shift, not a logical shift) =20 In addition, QEMU assumes that the compiler does not use the latitude -given in C99 and C11 to treat aspects of signed '<<' as undefined, as +given in C99 and C11 to treat aspects of signed '``<<``' as undefined, as documented in the GNU Compiler Collection manual starting at version 4.0. =20 .. _autofree-ref: --=20 2.31.1