From nobody Tue Feb 10 01:19:12 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1586190051; cv=none; d=zohomail.com; s=zohoarc; b=F+uCnOtuTJo/+phfVbWytkJ9dHp2J1jtmUAAA5rdu4/sd30/KSq1Oan00isudI1hVmlqQmwFVz2tsboTLnXxY2JoHqLC3H7wihM6+Jn2b3+iN/KtNBz0v82XLty2THILEwAV7KpIlm+6ScwZFejx1+ssJM2AdB+B7As7ss3uD7s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586190051; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ndinM7GHL/eSj+Lt+pzNO1z2PGMU4lTjCDhMdobweUo=; b=hebmZOFWDVhTSF/gIkWl/F+OW9LeFV3O9GmDVCOrXvoKLxNub8NduP3Z5gRAn6CaZ34jozs8WpvNH9mIy/Kex4RVGP3ncv9zBhC2ahLRVJAKLRIRZUAa2GypWl2GdcO5yPbnZJrO1GhFmrPMK/Irn2trKJNllNaCDQRd1Sh63w4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1586190051141685.0894565627316; Mon, 6 Apr 2020 09:20:51 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-290-q_Yi1nBmNy2EHxmQFtj11Q-1; Mon, 06 Apr 2020 12:20:47 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B02A3100550D; Mon, 6 Apr 2020 16:20:41 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 83FBC5C1B5; Mon, 6 Apr 2020 16:20:41 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 426C618089D6; Mon, 6 Apr 2020 16:20:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 036GKNAM027888 for ; Mon, 6 Apr 2020 12:20:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 38CC45417F; Mon, 6 Apr 2020 16:20:23 +0000 (UTC) Received: from kinshicho.usersys.redhat.com (unknown [10.40.196.71]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 62C69B19CB for ; Mon, 6 Apr 2020 16:20:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1586190049; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=ndinM7GHL/eSj+Lt+pzNO1z2PGMU4lTjCDhMdobweUo=; b=RULhNgda1hYAicANNxaWOlXePltUMBcJ5T1iYh8ab+mWC03/khru/6c8QNBSzBhgL0R3PF xqe8irelfzjl0HFqKNxBpquX5ZlpS4/NRD9BCxiwfNGxwZHiqag0Nc2RaKLfWWzeB9nFV0 4X85pA9ijAvyvXzM3B+GrFqCkr48JiM= X-MC-Unique: q_Yi1nBmNy2EHxmQFtj11Q-1 From: Andrea Bolognani To: libvir-list@redhat.com Subject: [libvirt PATCH 02/10] docs: Add glib-adoption.rst Date: Mon, 6 Apr 2020 18:20:02 +0200 Message-Id: <20200406162010.332813-3-abologna@redhat.com> In-Reply-To: <20200406162010.332813-1-abologna@redhat.com> References: <20200406162010.332813-1-abologna@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) Content-Type: text/plain; charset="utf-8" This part is very specific and doesn't quite fit into the "coding style" section, so let's move it to its own page. Signed-off-by: Andrea Bolognani --- docs/glib-adoption.rst | 96 ++++++++++++++++++++++++++++++++++++++++++ docs/hacking.rst | 96 ------------------------------------------ 2 files changed, 96 insertions(+), 96 deletions(-) create mode 100644 docs/glib-adoption.rst diff --git a/docs/glib-adoption.rst b/docs/glib-adoption.rst new file mode 100644 index 0000000000..62ddd7c61d --- /dev/null +++ b/docs/glib-adoption.rst @@ -0,0 +1,96 @@ +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D +Adoption of GLib APIs +=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +Libvirt has adopted use of the `GLib +library `__. Due to +libvirt's long history of development, there are many APIs in +libvirt, for which GLib provides an alternative solution. The +general rule to follow is that the standard GLib solution will be +preferred over historical libvirt APIs. Existing code will be +ported over to use GLib APIs over time, but new code should use +the GLib APIs straight away where possible. + +The following is a list of libvirt APIs that should no longer be +used in new code, and their suggested GLib replacements: + +``VIR_ALLOC``, ``VIR_REALLOC``, ``VIR_RESIZE_N``, ``VIR_EXPAND_N``, ``VIR_= SHRINK_N``, ``VIR_FREE``, ``VIR_APPEND_ELEMENT``, ``VIR_INSERT_ELEMENT``, `= `VIR_DELETE_ELEMENT`` + Prefer the GLib APIs ``g_new0``/``g_renew``/ ``g_free`` in most + cases. There should rarely be a need to use + ``g_malloc``/``g_realloc``. Instead of using plain C arrays, it + is preferrable to use one of the GLib types, ``GArray``, + ``GPtrArray`` or ``GByteArray``. These all use a struct to + track the array memory and size together and efficiently + resize. **NEVER MIX** use of the classic libvirt memory + allocation APIs and GLib APIs within a single method. Keep the + style consistent, converting existing code to GLib style in a + separate, prior commit. +``virStrerror`` + The GLib ``g_strerror()`` function should be used instead, + which has a simpler calling convention as an added benefit. + +The following libvirt APIs have been deleted already: + +``VIR_AUTOPTR``, ``VIR_AUTOCLEAN``, ``VIR_AUTOFREE`` + The GLib macros ``g_autoptr``, ``g_auto`` and ``g_autofree`` + must be used instead in all new code. In existing code, the + GLib macros must never be mixed with libvirt macros within a + method, nor should they be mixed with ``VIR_FREE``. If + introducing GLib macros to an existing method, any use of + libvirt macros must be converted in an independent commit. +``VIR_DEFINE_AUTOPTR_FUNC``, ``VIR_DEFINE_AUTOCLEAN_FUNC`` + The GLib macros ``G_DEFINE_AUTOPTR_CLEANUP_FUNC`` and + ``G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC`` must be used in all new + code. Existing code should be converted to the new macros where + relevant. It is permissible to use ``g_autoptr``, ``g_auto`` on + an object whose cleanup function is declared with the libvirt + macros and vice-versa. +``VIR_AUTOUNREF`` + The GLib macros ``g_autoptr`` and + ``G_DEFINE_AUTOPTR_CLEANUP_FUNC`` should be used to manage + autoclean of virObject classes. This matches usage with GObject + classes. +``VIR_STRDUP``, ``VIR_STRNDUP`` + Prefer the GLib APIs ``g_strdup`` and ``g_strndup``. + ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| deleted version | GLib version | N= otes | ++=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=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=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=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=3D=3D=3D=3D+ +| ``VIR_AUTOPTR`` | ``g_autoptr`` | = | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``VIR_AUTOCLEAN`` | ``g_auto`` | = | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``VIR_AUTOFREE`` | ``g_autofree`` | T= he GLib version does not use parentheses | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``VIR_AUTOUNREF`` | ``g_autoptr`` | T= he cleanup function needs to be defined | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``VIR_DEFINE_AUTOPTR_FUNC`` | ``G_DEFINE_AUTOPTR_CLEANUP_FUNC`` | = | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``VIR_DEFINE_AUTOCLEAN_FUNC`` | ``G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC`` | = | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``VIR_STEAL_PTR`` | ``g_steal_pointer`` | `= `a =3D f(&b)`` instead of ``f(a, b)`` | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``VIR_RETURN_PTR`` | ``return g_steal_pointer`` | = | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``ARRAY_CARDINALITY`` | ``G_N_ELEMENTS`` | = | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``ATTRIBUTE_FALLTHROUGH`` | ``G_GNUC_FALLTHROUGH`` | = | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``ATTRIBUTE_FMT_PRINTF`` | ``G_GNUC_PRINTF`` | = | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``ATTRIBUTE_NOINLINE`` | ``G_GNUC_NO_INLINE`` | = | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``ATTRIBUTE_NORETURN`` | ``G_GNUC_NORETURN`` | = | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``ATTRIBUTE_RETURN_CHECK`` | ``G_GNUC_WARN_UNUSED_RESULT`` | = | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``ATTRIBUTE_SENTINEL`` | ``G_GNUC_NULL_TERMINATED`` | = | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``ATTRIBUTE_UNUSED`` | ``G_GNUC_UNUSED`` | = | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``VIR_STRDUP`` | ``g_strdup`` | = | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``VIR_STRNDUP`` | ``g_strndup`` | = | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ +| ``virStrerror`` | ``g_strerror`` | = | ++-------------------------------+--------------------------------------+--= -----------------------------------------+ diff --git a/docs/hacking.rst b/docs/hacking.rst index ac02e9ab73..4067b282a3 100644 --- a/docs/hacking.rst +++ b/docs/hacking.rst @@ -921,102 +921,6 @@ analysis tools understand the code better: | ``G_GNUC_WARN_UNUSED_RESULT`` | the return value must be checked = | +-------------------------------+-----------------------------------------= -------------------+ =20 -Adoption of GLib APIs ---------------------- - -Libvirt has adopted use of the `GLib -library `__. Due to -libvirt's long history of development, there are many APIs in -libvirt, for which GLib provides an alternative solution. The -general rule to follow is that the standard GLib solution will be -preferred over historical libvirt APIs. Existing code will be -ported over to use GLib APIs over time, but new code should use -the GLib APIs straight away where possible. - -The following is a list of libvirt APIs that should no longer be -used in new code, and their suggested GLib replacements: - -``VIR_ALLOC``, ``VIR_REALLOC``, ``VIR_RESIZE_N``, ``VIR_EXPAND_N``, ``VIR_= SHRINK_N``, ``VIR_FREE``, ``VIR_APPEND_ELEMENT``, ``VIR_INSERT_ELEMENT``, `= `VIR_DELETE_ELEMENT`` - Prefer the GLib APIs ``g_new0``/``g_renew``/ ``g_free`` in most - cases. There should rarely be a need to use - ``g_malloc``/``g_realloc``. Instead of using plain C arrays, it - is preferrable to use one of the GLib types, ``GArray``, - ``GPtrArray`` or ``GByteArray``. These all use a struct to - track the array memory and size together and efficiently - resize. **NEVER MIX** use of the classic libvirt memory - allocation APIs and GLib APIs within a single method. Keep the - style consistent, converting existing code to GLib style in a - separate, prior commit. -``virStrerror`` - The GLib ``g_strerror()`` function should be used instead, - which has a simpler calling convention as an added benefit. - -The following libvirt APIs have been deleted already: - -``VIR_AUTOPTR``, ``VIR_AUTOCLEAN``, ``VIR_AUTOFREE`` - The GLib macros ``g_autoptr``, ``g_auto`` and ``g_autofree`` - must be used instead in all new code. In existing code, the - GLib macros must never be mixed with libvirt macros within a - method, nor should they be mixed with ``VIR_FREE``. If - introducing GLib macros to an existing method, any use of - libvirt macros must be converted in an independent commit. -``VIR_DEFINE_AUTOPTR_FUNC``, ``VIR_DEFINE_AUTOCLEAN_FUNC`` - The GLib macros ``G_DEFINE_AUTOPTR_CLEANUP_FUNC`` and - ``G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC`` must be used in all new - code. Existing code should be converted to the new macros where - relevant. It is permissible to use ``g_autoptr``, ``g_auto`` on - an object whose cleanup function is declared with the libvirt - macros and vice-versa. -``VIR_AUTOUNREF`` - The GLib macros ``g_autoptr`` and - ``G_DEFINE_AUTOPTR_CLEANUP_FUNC`` should be used to manage - autoclean of virObject classes. This matches usage with GObject - classes. -``VIR_STRDUP``, ``VIR_STRNDUP`` - Prefer the GLib APIs ``g_strdup`` and ``g_strndup``. - -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| deleted version | GLib version | N= otes | -+=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=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=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=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=3D=3D=3D=3D+ -| ``VIR_AUTOPTR`` | ``g_autoptr`` | = | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``VIR_AUTOCLEAN`` | ``g_auto`` | = | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``VIR_AUTOFREE`` | ``g_autofree`` | T= he GLib version does not use parentheses | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``VIR_AUTOUNREF`` | ``g_autoptr`` | T= he cleanup function needs to be defined | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``VIR_DEFINE_AUTOPTR_FUNC`` | ``G_DEFINE_AUTOPTR_CLEANUP_FUNC`` | = | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``VIR_DEFINE_AUTOCLEAN_FUNC`` | ``G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC`` | = | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``VIR_STEAL_PTR`` | ``g_steal_pointer`` | `= `a =3D f(&b)`` instead of ``f(a, b)`` | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``VIR_RETURN_PTR`` | ``return g_steal_pointer`` | = | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``ARRAY_CARDINALITY`` | ``G_N_ELEMENTS`` | = | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``ATTRIBUTE_FALLTHROUGH`` | ``G_GNUC_FALLTHROUGH`` | = | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``ATTRIBUTE_FMT_PRINTF`` | ``G_GNUC_PRINTF`` | = | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``ATTRIBUTE_NOINLINE`` | ``G_GNUC_NO_INLINE`` | = | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``ATTRIBUTE_NORETURN`` | ``G_GNUC_NORETURN`` | = | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``ATTRIBUTE_RETURN_CHECK`` | ``G_GNUC_WARN_UNUSED_RESULT`` | = | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``ATTRIBUTE_SENTINEL`` | ``G_GNUC_NULL_TERMINATED`` | = | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``ATTRIBUTE_UNUSED`` | ``G_GNUC_UNUSED`` | = | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``VIR_STRDUP`` | ``g_strdup`` | = | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``VIR_STRNDUP`` | ``g_strndup`` | = | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ -| ``virStrerror`` | ``g_strerror`` | = | -+-------------------------------+--------------------------------------+--= -----------------------------------------+ - File handling ------------- =20 --=20 2.25.1