From nobody Sun Feb 8 10:05:25 2026 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=libvir-list-bounces@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=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1600950561; cv=none; d=zohomail.com; s=zohoarc; b=n8omjURFi4AHDoDeQ9RJssuzKnDdYxMk93zEAAbJGxcI18gC92ZAnRe+e9cZr13mtoTMAY5MWPy5iuQJvKEZrCZWftiHttr+qESlU6H70axD46RxbLJnzHX3fDxNLb32zcmxVO8r3QzIBXDsboNATsQ0VHPjF+NLV29WxRIpZj4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1600950561; 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=ZK0VuKjj6Z/vrJbt6HFwpC8pQ3Y4ftj89+WF3XDPE1o=; b=gt2XHVz1w2KWBNyV4xBKWZonjRL1AIZZZju0D0GPm8wyoCpQeO1S3udldgRz+LjhSPaA5rO4uvW/UGo/Xr1Wbn3lwBkWK7Lalt1D549mqy1acZNlV7aIv2ViJ89vmB1ZihaeoZ0KZtYVTRkN7as/o3nVIPUfLnY1CsS7b+bzFL0= 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=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: 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 1600950561404933.7703575824447; Thu, 24 Sep 2020 05:29:21 -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-595-HWQ5vNOPNsujXAP9s9l3fg-1; Thu, 24 Sep 2020 08:29:18 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B6F761091062; Thu, 24 Sep 2020 12:29:11 +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 58B3373672; Thu, 24 Sep 2020 12:29:11 +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 24B4C181A050; Thu, 24 Sep 2020 12:29:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 08OCSlcd016086 for ; Thu, 24 Sep 2020 08:28:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6AEE173684; Thu, 24 Sep 2020 12:28:47 +0000 (UTC) Received: from lpt.redhat.com (unknown [10.40.208.52]) by smtp.corp.redhat.com (Postfix) with ESMTP id D313773682 for ; Thu, 24 Sep 2020 12:28:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1600950560; 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=ZK0VuKjj6Z/vrJbt6HFwpC8pQ3Y4ftj89+WF3XDPE1o=; b=ebrwNWi1jxo1bCN+IcaJWhhjZUDdMz3A4wJB/0Kq7zPD76mUt8NAXpCjN+91HD1xsaEKx+ 3RhX8EtDkR9IhB+BE5utbzZqm7xx3rmpArBf6YttIOrrQEJFp4sy/b/uSHJwjnTqXMTHlA lWQfuZifI+rlHR0hwSx5VCBYSPaOSLc= X-MC-Unique: HWQ5vNOPNsujXAP9s9l3fg-1 From: =?UTF-8?q?J=C3=A1n=20Tomko?= To: libvir-list@redhat.com Subject: [libvirt PATCH 1/6] Revert "docs: Drop glib-adoption.rst" Date: Thu, 24 Sep 2020 14:28:35 +0200 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com 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" Cleaning up after Andrea as he requested: https://www.redhat.com/archives/libvir-list/2020-May/msg00405.html This reverts commit 842d3712ed612f213b454e610cc7ff9db2321803 --- docs/glib-adoption.rst | 96 ++++++++++++++++++++++++++++++++++++++++++ docs/hacking.rst | 1 + 2 files changed, 97 insertions(+) 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 858dd2dfc1..cd009c4c73 100644 --- a/docs/hacking.rst +++ b/docs/hacking.rst @@ -74,4 +74,5 @@ you also take a look at the following documents: - `Programming languages `__ - `Developer tooling `__ - `Advanced test suite usage `__ +- `Adoption of GLib APIs `__ - `Committer guidelines `__ --=20 2.26.2