From nobody Sat Feb 7 11:38:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1629580390; cv=none; d=zohomail.com; s=zohoarc; b=Bq9nOorTkT/PEXGaoDC7af/CN78VSu76AmpL9kd+//vLBiF6VbQmSh0bcJeXoOlkokHE47O5lT/9vSxuPLC5Uevd1+qFk3fxxX63Cy3acfFuy16H6Oow6RXIi3OMoLlO06WzQZyge6eWeOfuCQybkCAiD8qO/SF4BcFOSDKZwl4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629580390; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=Ihfx/i5DNU+G4x66QNtBztFtNjftz3znLfp5inBsl2c=; b=Ha2XeJP8s6qViUdEeWZiqJPt1KtOzPFoIcjc9zEpwm9GJsqSL1aCHb/o/X6ZK1/vGUnOK498fvxhT1aX0Y7TIZXX+B8Yl/0Mv3Rh50NE6r3G+oYH5QCLHTiUZzP2Jwo5GYVwqmKtNzo38IEJvFMS+K27YYFSfvWhO/RGDTU9H1M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1629580390264297.74252552940186; Sat, 21 Aug 2021 14:13:10 -0700 (PDT) Received: from localhost ([::1]:58552 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mHYIf-0002AI-7g for importer@patchew.org; Sat, 21 Aug 2021 17:13:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57432) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mHYHG-00007H-Eh for qemu-devel@nongnu.org; Sat, 21 Aug 2021 17:11:42 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:43873) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mHYHC-0001WJ-6e for qemu-devel@nongnu.org; Sat, 21 Aug 2021 17:11:42 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=Ihfx/i5DNU+G4x66QNtBztFtNjftz3znLfp5inBsl2c=; b=XH5Oz LhB+4tiX0w5g+MfP7h1502rt6GzM1ecxyGrj3tpwIHxLt0UYF2kw17qEfUWqH/phA+nzNFQljROa6 KD8/I54KKd08lUaxXIBEFbhCuOMtFkWZoUY5VgWrT1tt8S7OCDxdqnkLOnX4UbBsRTAetdb8bWlEH M5O/Efh2+zCr9oPmo+IJqgFlCOXDwRpMpS+LP1tqZUNE5B9iLDtPen4Wbdc1uVd7oWgeJ4J9x9VLt yUdfzd/wWr9L4z2E3q5RK896a9PWhNQ5icSQoOEguWJJbq0it0sjZMUb9pK9t4oKak5BUltmVuSyT /cnEfUSLRfU68vpBuhkIXyXbFLQqQ==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Sat, 21 Aug 2021 22:18:18 +0200 Subject: [PATCH 1/5] qemu/qarray.h: introduce QArray To: qemu-devel@nongnu.org Cc: Greg Kurz Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=91.194.90.13; envelope-from=a1925f3bb2560f2f19558dbc6d4309d3bb17529d@lizzy.crudebyte.com; helo=lizzy.crudebyte.com 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, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1629581295156100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Implements deep auto free of arrays while retaining common C-style squared bracket access. Signed-off-by: Christian Schoenebeck --- include/qemu/qarray.h | 148 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 include/qemu/qarray.h diff --git a/include/qemu/qarray.h b/include/qemu/qarray.h new file mode 100644 index 0000000000..230a556e81 --- /dev/null +++ b/include/qemu/qarray.h @@ -0,0 +1,148 @@ +/* + * QArray - deep auto free C-array + * + * Copyright (c) 2021 Crudebyte + * + * Authors: + * Christian Schoenebeck + * + * Permission is hereby granted, free of charge, to any person obtaining a= copy + * of this software and associated documentation files (the "Software"), t= o deal + * in the Software without restriction, including without limitation the r= ights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or se= ll + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included= in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS= OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OT= HER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING= FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS = IN + * THE SOFTWARE. + */ +#ifndef QEMU_QARRAY_H +#define QEMU_QARRAY_H + +/** + * QArray provides a mechanism to access arrays in common C-style (e.g. by + * square bracket [] operator) in conjunction with reference variables that + * perform deep auto free of the array when leaving the scope of the auto + * reference variable. That means not only is the array itself automatical= ly + * freed, but also memory dynamically allocated by the individual array + * elements. + * + * Example: + * + * Consider the following user struct @c Foo which shall be used as scalar + * (element) type of an array: + * @code + * typedef struct Foo { + * int i; + * char *s; + * } Foo; + * @endcode + * and assume it has the following function to free memory allocated by @c= Foo + * instances: + * @code + * void free_foo(Foo *foo) { + * free(foo->s); + * } + * @endcode + * Add the following to a shared header file: + * @code + * DECLARE_QARRAY_TYPE(Foo); + * @endcode + * and the following to a C unit file: + * @code + * DEFINE_QARRAY_TYPE(Foo, free_foo); + * @endcode + * Finally the array may then be used like this: + * @code + * void doSomething(int n) { + * QArrayRef(Foo) foos =3D NULL; + * QARRAY_CREATE(Foo, foos, n); + * for (size_t i =3D 0; i < n; ++i) { + * foos[i].i =3D i; + * foos[i].s =3D calloc(4096, 1); + * snprintf(foos[i].s, 4096, "foo %d", i); + * } + * } + * @endcode + */ + +/** + * Declares an array for the passed @a scalar_type. + * + * This is typically used from a shared header file. + * + * @param scalar_type - type of the individual array elements + */ +#define DECLARE_QARRAY_TYPE(scalar_type) \ + typedef struct QArray##scalar_type { \ + size_t len; \ + scalar_type first[]; \ + } QArray##scalar_type; \ + \ + void qarray_create_##scalar_type(scalar_type **auto_var, size_t len); \ + void qarray_auto_free_##scalar_type(scalar_type **auto_var); \ + +/** + * Defines an array for the passed @a scalar_type and appropriate + * @a scalar_cleanup_func. + * + * @param scalar_type - type of the individual array elements + * @param scalar_cleanup_func - appropriate function to free memory dynami= cally + * allocated by individual array elements bef= ore + */ +#define DEFINE_QARRAY_TYPE(scalar_type, scalar_cleanup_func) \ + void qarray_create_##scalar_type(scalar_type **auto_var, size_t len) \ + { \ + qarray_auto_free_##scalar_type(auto_var); \ + QArray##scalar_type *arr =3D g_malloc0(sizeof(QArray##scalar_type)= + \ + len * sizeof(scalar_type)); \ + arr->len =3D len; \ + *auto_var =3D &arr->first[0]; \ + } \ + \ + void qarray_auto_free_##scalar_type(scalar_type **auto_var) \ + { \ + scalar_type *first =3D (*auto_var); \ + if (!first) { \ + return; \ + } \ + QArray##scalar_type *arr =3D (QArray##scalar_type *) ( \ + ((char *)first) - offsetof(QArray##scalar_type, first) \ + ); \ + for (size_t i =3D 0; i < arr->len; ++i) { \ + scalar_cleanup_func(&arr->first[i]); \ + } \ + g_free(arr); \ + } \ + +/** + * Used to declare a reference variable (unique pointer) for an array. Aft= er + * leaving the scope of the reference variable, the associated array is + * automatically freed. + * + * @param scalar_type - type of the individual array elements + */ +#define QArrayRef(scalar_type) \ + __attribute((__cleanup__(qarray_auto_free_##scalar_type))) scalar_type* + +/** + * Allocates a new array of passed @a scalar_type with @a len number of ar= ray + * elements and assigns the created array to the reference variable + * @a auto_var. + * + * @param scalar_type - type of the individual array elements + * @param auto_var - destination reference variable + * @param len - amount of array elements to be allocated immediately + */ +#define QARRAY_CREATE(scalar_type, auto_var, len) \ + qarray_create_##scalar_type((&auto_var), len) + +#endif /* QEMU_QARRAY_H */ --=20 2.20.1 From nobody Sat Feb 7 11:38:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1629580390; cv=none; d=zohomail.com; s=zohoarc; b=XbwKmU0IOWIcqNapyxllk08vgpM5/3w+EYyF643IXstabIdh8D6yfuAOhwPH2f5T33ZlD1ZLIL23bvN2cYdNKLZznOW4FaPo3NkJsSgc4tYnoalov1efARQyIXR5SwrBLDz2dY2J56Z1jaiZrF0cdvNdMpoY/2syKJ3b7AjbukA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629580390; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=5ZVZyj3YzMwTNDGFgyv9k2EPVfxtHmOdwi1p8mZRfZ0=; b=AQLI94zfbO+wL3HqIGhYnBOqtakfe0VWID3at/bS+v/rMBdPoHy3lz5FcqU4GFTQcbcpM3KjvUcqKr7ceOl0kEBJU529Bn4TAUnkkvU6YbodTySi/6nAbkAjEnKZ8nqRDdGeqpKyAY9GJGi8idQo5lcmouwqLprR6V0MBxKIxlw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1629580390460907.9795050631832; Sat, 21 Aug 2021 14:13:10 -0700 (PDT) Received: from localhost ([::1]:58616 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mHYIf-0002CW-Eq for importer@patchew.org; Sat, 21 Aug 2021 17:13:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57456) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mHYHN-0000B2-Ha for qemu-devel@nongnu.org; Sat, 21 Aug 2021 17:11:49 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:52949) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mHYHJ-0001b8-7n for qemu-devel@nongnu.org; Sat, 21 Aug 2021 17:11:49 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=5ZVZyj3YzMwTNDGFgyv9k2EPVfxtHmOdwi1p8mZRfZ0=; b=SF/Ks Pnmj08oJmdChuHRSKvqiqWlzWTwoDx06Is2aSeWV293HghprW4IG4Md1Z2Zz8/c0BvAp3pMsu+bwW 0UTwRqJmyCr8bJ21ppcF0A6ZCEx/HK1A7Jvi1h5W9Lxuv5n4kU3sFhaXFBMNrqmm5q3udLgSqE5Ad 2xErHHTW++2bhE31yI6nlcOGzemjSKhdegXTZuZK+CpIGqW8cVOxocjPAiKpMDxHwlpDg+uzWxC27 f5k9hPJAL55YTyQXcqDjB9g9R8KzmWFGl/i5054HMchfsIYbAdb3iZfw7slOJSIFNkUkhY8gk7nBx rhzpqa0RHjV7dI2D8yzilteMVmzmw==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Sat, 21 Aug 2021 22:30:49 +0200 Subject: [PATCH 2/5] qemu/qarray.h: weak scalar type check in QARRAY_CREATE() To: qemu-devel@nongnu.org Cc: Greg Kurz Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=91.194.90.13; envelope-from=a3f07198ba9e12b45ef38b45fa543e9b597ee70f@lizzy.crudebyte.com; helo=lizzy.crudebyte.com 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, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1629580392975100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Unfortunately something like _Static_assert(typeof(a) =3D=3D typeof(b), "type mismatch"); is currently not suported by C. So for the time being at least check that the size of the scalar types match at compile time. Signed-off-by: Christian Schoenebeck --- include/qemu/qarray.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/qemu/qarray.h b/include/qemu/qarray.h index 230a556e81..2cb8656c5d 100644 --- a/include/qemu/qarray.h +++ b/include/qemu/qarray.h @@ -27,6 +27,8 @@ #ifndef QEMU_QARRAY_H #define QEMU_QARRAY_H =20 +#include "qemu/compiler.h" + /** * QArray provides a mechanism to access arrays in common C-style (e.g. by * square bracket [] operator) in conjunction with reference variables that @@ -143,6 +145,10 @@ * @param len - amount of array elements to be allocated immediately */ #define QARRAY_CREATE(scalar_type, auto_var, len) \ + QEMU_BUILD_BUG_MSG( \ + sizeof(scalar_type) !=3D sizeof(*auto_var), \ + "QArray scalar type mismatch" \ + ); \ qarray_create_##scalar_type((&auto_var), len) =20 #endif /* QEMU_QARRAY_H */ --=20 2.20.1 From nobody Sat Feb 7 11:38:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1629580458; cv=none; d=zohomail.com; s=zohoarc; b=OGy5k2L8Ej+JTgAJlewI2TQfa6CSlnfaSo9kTqUA2QRIH06gEF0XT3riW3aAAo8uz8rjoiLNaEofLHsUCVJL1m3RTytz/aOn7B2eqbD3/T8g4kbRiDSLLvNAp7PudtW5o7n2Wr0dvqVCR2Cuq65MUuKN8DsK+tWT131IaSGYjE8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629580458; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=7V7AtSA/GGpLfVhFDdKh0FTfh0YNxsRShVikFoZsWHQ=; b=Mo2lWi4sJmXNBVFrLA2A4FSVBlpf0fhqLr57QrkFiQsil2RkB5NNqy6F6NsGtbWBNe2CU7wA2TEXc/vvEYGeEolXbP/WzPH2v2hYj+i741emj9dKFJEQBzllotTYH6JwsriwmdT9Y1tyGfP0T0j73nTX09/wMouMFC9r5DLcF2g= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1629580458744326.49854621003067; Sat, 21 Aug 2021 14:14:18 -0700 (PDT) Received: from localhost ([::1]:35656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mHYJl-0005j0-OQ for importer@patchew.org; Sat, 21 Aug 2021 17:14:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57472) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <2f252cef960127f76b29b5159d5155d470d1feba@lizzy.crudebyte.com>) id 1mHYHV-0000Ev-SD for qemu-devel@nongnu.org; Sat, 21 Aug 2021 17:11:57 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:34929) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <2f252cef960127f76b29b5159d5155d470d1feba@lizzy.crudebyte.com>) id 1mHYHQ-0001gg-SC for qemu-devel@nongnu.org; Sat, 21 Aug 2021 17:11:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=7V7AtSA/GGpLfVhFDdKh0FTfh0YNxsRShVikFoZsWHQ=; b=D3ZR1 jroaLH/C2VORPxeeF7TlnTev9B4McLbNzoQ8eKRqFkoF/zLCs9ne7OxI77D9+Yp51TUf82SQdSQPX 9I6E9hpwGVoNaKx2qQqdnTBsO+4RREgEhboPh0SKtjO1sgLJ7Fn+wmzUVLdzTa58YnZH56+VC78JQ 5yVtDgSflRZSbRe+6/GdOelCWYHQBAXYltwCv00DwCtaYqcFIuYkn4ASLgLZ+vlO7vYWgKoWAqlLL Ta5B7vcvaEnrzG1UDsavaGyrDrV57S6Iv+POW4u5Ut3n2wEBeUOZXWrEHIWjx/u2dNQAcyeg0fpG7 Az5XHCEdDqWX/TZC4v4tFSbHh6m2w==; Message-Id: <2f252cef960127f76b29b5159d5155d470d1feba.1629578875.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Sat, 21 Aug 2021 22:35:48 +0200 Subject: [PATCH 3/5] 9pfs: make V9fsString usable via QArray API To: qemu-devel@nongnu.org Cc: Greg Kurz Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=91.194.90.13; envelope-from=2f252cef960127f76b29b5159d5155d470d1feba@lizzy.crudebyte.com; helo=lizzy.crudebyte.com 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, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1629580460138100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Christian Schoenebeck --- fsdev/9p-marshal.c | 2 ++ fsdev/9p-marshal.h | 3 +++ 2 files changed, 5 insertions(+) diff --git a/fsdev/9p-marshal.c b/fsdev/9p-marshal.c index a01bba6908..fbfc2a62cd 100644 --- a/fsdev/9p-marshal.c +++ b/fsdev/9p-marshal.c @@ -18,6 +18,8 @@ =20 #include "9p-marshal.h" =20 +DEFINE_QARRAY_TYPE(V9fsString, v9fs_string_free); + void v9fs_string_free(V9fsString *str) { g_free(str->data); diff --git a/fsdev/9p-marshal.h b/fsdev/9p-marshal.h index ceaf2f521e..7229e4e617 100644 --- a/fsdev/9p-marshal.h +++ b/fsdev/9p-marshal.h @@ -1,10 +1,13 @@ #ifndef QEMU_9P_MARSHAL_H #define QEMU_9P_MARSHAL_H =20 +#include "qemu/qarray.h" + typedef struct V9fsString { uint16_t size; char *data; } V9fsString; +DECLARE_QARRAY_TYPE(V9fsString); =20 typedef struct V9fsQID { uint8_t type; --=20 2.20.1 From nobody Sat Feb 7 11:38:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1629580461; cv=none; d=zohomail.com; s=zohoarc; b=EDLk2UHfFcbSyTJvoRDuTmR+fTjAuetpo95XV+6SNrJUp4dTkyU4IqSlqt7gDlJ1e0ovJqvr7QKh/RUL+Lvh3EVPjj4OX7Xud+OLZ/7YoumWQNWvZMSufFLYnMkL4fI9ZuTjpkHCCTjXzArbyAE/nkT+YbaEd38ZTb/zwPMTB80= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629580461; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=vQaRlv4ehwFofDzfKsbV8n12CLuEweQkA+Zqbl7DPSM=; b=YlwNhk//NdJW2EZDnFMCwAqsK8o/a7ZZNf84KjIOtyzHgqL64dOZ/ca94wLgZ2ugEnTh9cQDiM7Pn+Mf+cryX9h5nGF/SyMk7tTqYHN+Dddx9+JMwFt3QbPaDIlMFSNk62pMd8z2gZJ2qqbtL2Yb197zVL8xJQFjsQKiKR0C8/0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1629580461111405.3097237403582; Sat, 21 Aug 2021 14:14:21 -0700 (PDT) Received: from localhost ([::1]:35854 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mHYJo-0005qn-6F for importer@patchew.org; Sat, 21 Aug 2021 17:14:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <0c7d0f5a413ce9e27950baa1a41570565f0703a4@lizzy.crudebyte.com>) id 1mHYHc-0000Kz-Lx for qemu-devel@nongnu.org; Sat, 21 Aug 2021 17:12:05 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:40753) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <0c7d0f5a413ce9e27950baa1a41570565f0703a4@lizzy.crudebyte.com>) id 1mHYHY-0001lS-0S for qemu-devel@nongnu.org; Sat, 21 Aug 2021 17:12:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=vQaRlv4ehwFofDzfKsbV8n12CLuEweQkA+Zqbl7DPSM=; b=joZln nXrlBkOs5g1jlMZ9i6j0+hFNEgTx8LBwdikXcUPZNe0wg+PYnfYgbiN7rkhJ5oKAsurnB3l8ltidJ UkOspLoK05IvPwLgoQT7PlaRrmPAxBLRoIG0hN6IcsjK9r2RB+f5NEGTgiTTHKnnbFpIpL6OzOPhy +3CT6ml1N86/Qwvz6FLlUKsKF/OSJydsZ+F17OnolKpYj8OdmWEw/mv2gSUA1GgUxervP52uXPOR9 jCJUSeuIvegrjXZTZ9+GK7b7fH+Hq53SLFvM0hQ+X74h+Ahs+SKlnYIKR5CWHkfuy1c+MO4qrY2ge apRFv3nQL6/+D09tlUxtUSQkfOE2A==; Message-Id: <0c7d0f5a413ce9e27950baa1a41570565f0703a4.1629578875.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Sat, 21 Aug 2021 22:37:10 +0200 Subject: [PATCH 4/5] 9pfs: make V9fsPath usable via QArray API To: qemu-devel@nongnu.org Cc: Greg Kurz Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=91.194.90.13; envelope-from=0c7d0f5a413ce9e27950baa1a41570565f0703a4@lizzy.crudebyte.com; helo=lizzy.crudebyte.com 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, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1629580462193100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Christian Schoenebeck --- fsdev/file-op-9p.h | 2 ++ hw/9pfs/9p.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/fsdev/file-op-9p.h b/fsdev/file-op-9p.h index 42f677cf38..7630f0e538 100644 --- a/fsdev/file-op-9p.h +++ b/fsdev/file-op-9p.h @@ -18,6 +18,7 @@ #include #include #include "qemu-fsdev-throttle.h" +#include "qemu/qarray.h" =20 #define SM_LOCAL_MODE_BITS 0600 #define SM_LOCAL_DIR_MODE_BITS 0700 @@ -105,6 +106,7 @@ struct V9fsPath { uint16_t size; char *data; }; +DECLARE_QARRAY_TYPE(V9fsPath); =20 typedef union V9fsFidOpenState V9fsFidOpenState; =20 diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index c857b31321..b59572fa79 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -50,6 +50,8 @@ enum { Oappend =3D 0x80, }; =20 +DEFINE_QARRAY_TYPE(V9fsPath, v9fs_path_free); + static ssize_t pdu_marshal(V9fsPDU *pdu, size_t offset, const char *fmt, .= ..) { ssize_t ret; --=20 2.20.1 From nobody Sat Feb 7 11:38:19 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=crudebyte.com ARC-Seal: i=1; a=rsa-sha256; t=1629580567; cv=none; d=zohomail.com; s=zohoarc; b=TuWcEq9d5dr/4c6q3BVRF3nUin33BEH0y2Lzd3w3FH5uLnay5twRI1CUQNDSMCZQCpu0r82Em+j4CHubmL3Kes44Ofw1id8WhwyKCgNKcn5S11sZ8KRBhh5fdXWT3OkFA7adwukRXea0+H0i83ZY1ciINT7yBYOE0RRziwObMNE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1629580567; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To; bh=5jKfd6sVikDt3oYLoGttLhQ8l3eB72EFDlpIpChG4sE=; b=AD+PnTu8sPcPW/pjBb46DrD49OjY6uj6IGb42l6AZacqEr03nk24AvFjWJ8NqqFPFxUFGHNsXKhp2Vhmo4Vsxkj3mWK7/VuYRJ3bzSaNJ1uSMCHP8KaAh0oEwJ4kADfBCQMwSR4y1FgSTpPOQr/VWfg4yZsiacv8zShrSrpCqrA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1629580567887301.20278442564336; Sat, 21 Aug 2021 14:16:07 -0700 (PDT) Received: from localhost ([::1]:39132 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mHYLW-00088F-Uy for importer@patchew.org; Sat, 21 Aug 2021 17:16:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57512) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mHYHj-0000Ti-FG for qemu-devel@nongnu.org; Sat, 21 Aug 2021 17:12:11 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:38417) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mHYHf-0001oz-4v for qemu-devel@nongnu.org; Sat, 21 Aug 2021 17:12:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=5jKfd6sVikDt3oYLoGttLhQ8l3eB72EFDlpIpChG4sE=; b=Ewdc8 Ket+aEQvohUKi26/4QuNAfiAQd9OEfvuwwmFcNzwZLm929t+vg/SQpLSf9ZpTE16LBCYz0+h6VAlu tObRetsO25cWXM7/3xXO0tsxRgOaj+zxyyeO6fS/bVx0TV6mE5MuF5Ri8C/uQyd0Qxy3s3dqyGlTr DiqbEtCyZHWbBeYqtL0hB/xDP1nQY4uLrGvo2jUzAWHZOrP0ZW/YuhUPV5hsfG0z/0Xx1SAQ0KbiO V47WlWJZiaQ8FkeFh32qfQt05/6RVpTBtWc692NYsB3T7/L4pWkVvNfTJVxKdrWUZ3Zhp823esmv7 qXI7AVShrqnrK4BjRTvoM26frcdcg==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Sat, 21 Aug 2021 22:39:25 +0200 Subject: [PATCH 5/5] 9pfs: use QArray in v9fs_walk() To: qemu-devel@nongnu.org Cc: Greg Kurz Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: none client-ip=91.194.90.13; envelope-from=c34a1d230748f5a0996a60d7f2b7b3e95342ef4f@lizzy.crudebyte.com; helo=lizzy.crudebyte.com 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, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @crudebyte.com) X-ZM-MESSAGEID: 1629580569500100001 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Christian Schoenebeck --- hw/9pfs/9p.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/hw/9pfs/9p.c b/hw/9pfs/9p.c index b59572fa79..91062ee4d6 100644 --- a/hw/9pfs/9p.c +++ b/hw/9pfs/9p.c @@ -1707,13 +1707,14 @@ static void coroutine_fn v9fs_walk(void *opaque) int name_idx; g_autofree V9fsQID *qids =3D NULL; int i, err =3D 0; - V9fsPath dpath, path, *pathes =3D NULL; + V9fsPath dpath, path; + QArrayRef(V9fsPath) pathes =3D NULL; uint16_t nwnames; struct stat stbuf, fidst; g_autofree struct stat *stbufs =3D NULL; size_t offset =3D 7; int32_t fid, newfid; - V9fsString *wnames =3D NULL; + QArrayRef(V9fsString) wnames =3D NULL; V9fsFidState *fidp; V9fsFidState *newfidp =3D NULL; V9fsPDU *pdu =3D opaque; @@ -1734,10 +1735,10 @@ static void coroutine_fn v9fs_walk(void *opaque) goto out_nofid; } if (nwnames) { - wnames =3D g_new0(V9fsString, nwnames); + QARRAY_CREATE(V9fsString, wnames, nwnames); qids =3D g_new0(V9fsQID, nwnames); stbufs =3D g_new0(struct stat, nwnames); - pathes =3D g_new0(V9fsPath, nwnames); + QARRAY_CREATE(V9fsPath, pathes, nwnames); for (i =3D 0; i < nwnames; i++) { err =3D pdu_unmarshal(pdu, offset, "s", &wnames[i]); if (err < 0) { @@ -1869,14 +1870,6 @@ out: v9fs_path_free(&path); out_nofid: pdu_complete(pdu, err); - if (nwnames && nwnames <=3D P9_MAXWELEM) { - for (name_idx =3D 0; name_idx < nwnames; name_idx++) { - v9fs_string_free(&wnames[name_idx]); - v9fs_path_free(&pathes[name_idx]); - } - g_free(wnames); - g_free(pathes); - } } =20 static int32_t coroutine_fn get_iounit(V9fsPDU *pdu, V9fsPath *path) --=20 2.20.1