Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1uKF81-0005dK-32 for mharc-qemu-rust@gnu.org; Wed, 28 May 2025 07:39:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uKF7h-0005aL-JA for qemu-rust@nongnu.org; Wed, 28 May 2025 07:39:08 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1uKF7e-000654-QC for qemu-rust@nongnu.org; Wed, 28 May 2025 07:39:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748432340; 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:autocrypt:autocrypt; bh=5UlRWtxLGJx/TX+OrJuXUEzFWoVMQDNFtOeubM3y86c=; b=PvG/mnePVD7/oB+I3UIiwLe6WjLQMkPv5RWg0qLBIfH/2+BdGJUMi3lHpf0ivYcN+lm0rZ pzpEa4IXb956R+mzyqdgwUzgn12YGU8f2Rs0vdH+z+7aLfZOQFEJoDtO8u6cqxxKaAXVmY zFqABNEYU5igR4BColoj0Js8uUu9J1w= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-468-u6qehWG8NVyB7-sS086jgg-1; Wed, 28 May 2025 07:38:58 -0400 X-MC-Unique: u6qehWG8NVyB7-sS086jgg-1 X-Mimecast-MFC-AGG-ID: u6qehWG8NVyB7-sS086jgg_1748432338 Received: by mail-ed1-f72.google.com with SMTP id 4fb4d7f45d1cf-6047edc5cebso3751865a12.1 for ; Wed, 28 May 2025 04:38:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1748432338; x=1749037138; h=content-transfer-encoding:in-reply-to:autocrypt:content-language :from:references:cc:to:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5UlRWtxLGJx/TX+OrJuXUEzFWoVMQDNFtOeubM3y86c=; b=lhM/ZxxWcMEzkFwN4aIKuAGl4xof1Ta4d/3/QSJ3ssl34BmoaWbAnUc4pMRPlFPESs 2cpTSq7MxY81+uqBB4ZwWL7oCE4IhdQ4LlyxqaKmW9mhf0jwCxFgybpE3N2HyXEyBLpO GAjm8hmrvw5LlYXeyUWrcdwvknt8qgWUx4t6Oqmv7m/GVcJsY7eo3G6XVroCvBbBOJuL jo36nM87X7CsqdRwevcQzHzJTYiFB1J9gBbC+XSUt7u5Z7yT8V9Nkv9m0GkrQ4MrUO0D LrLP/d9SB4XtIeEBqhXwBCEmT2BmK9X/BUL9m+S4vlK1AoGzdY4nqL40RoJ8Cp1Sm0vr SDdA== X-Forwarded-Encrypted: i=1; AJvYcCWv5rhMCu+FWv6fPejG/08JWf/Umx8g+6vmgcdl9IP9FyWg+5HWrre8QhufwoLZ3MCJaxC84qiMtoI=@nongnu.org X-Gm-Message-State: AOJu0YzcHBJStTrAQUTmW+K3eQWZiPPjqpbEAPS1mYytDPbNErsQgzDJ AXcMVABgaXtJj4fUmdDLyyF2mtW5w5wSeuPKMd892RoGbUqOHep+7Ht1yGCGHb6pyeke6MgYw2G /apssoUuILiDpQ7O7j0gYGlpQid/bV6Ta5pxjQUKiykgiuY+RETkotic= X-Gm-Gg: ASbGncuhmWkNgs+OfZFK86ydTBl4dbfD2J55ZjB+G2UfXHpXqnkuzrxgHh0KF+Ky6Ct Ene81in8FUlZoGP6cDRdirREQZslffovK0NIbwdhNSmXvfaovFwLPbpLLFSI0S04jlwGoWvuxsR V7TY06HN3pnX17J6RZkUNZEw6nZQxIvPM2GbOjB+TM2yTARPi54URQ3JGnmkAY6J6ofWlG5IZva ZDnBZc4vSo8dYTxCTJc7IyXpygBIPJMuoLAAQVUVqQ/pCTWQ/dcKsKVSmvsojvL68sV+/0UVSGr au++IuH50lm5UA== X-Received: by 2002:a05:6402:26c4:b0:5f3:f04b:5663 with SMTP id 4fb4d7f45d1cf-6051c4ef709mr1483210a12.24.1748432337726; Wed, 28 May 2025 04:38:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IESJvlpBRArNWYINsAp1wlOil5rxUtaO4UWcnPmvgfi0cr6ppM8gUtHlEo/di4OT/4clqnXOg== X-Received: by 2002:a05:6402:26c4:b0:5f3:f04b:5663 with SMTP id 4fb4d7f45d1cf-6051c4ef709mr1483188a12.24.1748432337317; Wed, 28 May 2025 04:38:57 -0700 (PDT) Received: from [192.168.10.48] ([151.95.46.79]) by smtp.googlemail.com with ESMTPSA id 4fb4d7f45d1cf-6051d7a0013sm659319a12.80.2025.05.28.04.38.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 May 2025 04:38:56 -0700 (PDT) Message-ID: <0c5f3e95-3aab-448d-9713-97413cb5c2df@redhat.com> Date: Wed, 28 May 2025 13:38:55 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH WIP RFC] rust: add qdev DeviceProperties derive macro To: Manos Pitsidianakis Cc: qemu-devel , qemu-rust@nongnu.org, =?UTF-8?Q?Alex_Benn=C3=A9e?= , Zhao Liu References: <20250522-rust-qdev-properties-v1-1-5b18b218bad1@linaro.org> From: Paolo Bonzini Autocrypt: addr=pbonzini@redhat.com; keydata= xsEhBFRCcBIBDqDGsz4K0zZun3jh+U6Z9wNGLKQ0kSFyjN38gMqU1SfP+TUNQepFHb/Gc0E2 CxXPkIBTvYY+ZPkoTh5xF9oS1jqI8iRLzouzF8yXs3QjQIZ2SfuCxSVwlV65jotcj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PSRqYFm4NMP dRsn0/7oymhneL8RthIvjDDQ5ktUjMe8LtHr70OZE/TT88qvEdhiIVUogHdo4qBrk41+gGQh b906Dudw5YhTJFU3nC6bbF2nrLlB4C/XSiH76ZvqzV0Z/cAMBo5NF/w= In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: lINcBrKE-d-aiD71145xZnLJf41DyMoZdOU2nhmih4M_1748432338 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Received-SPF: pass client-ip=170.10.133.124; envelope-from=pbonzini@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -49 X-Spam_score: -5.0 X-Spam_bar: ----- X-Spam_report: (-5.0 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-2.904, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=0.001, RCVD_IN_MSPIKE_WL=0.001, RCVD_IN_VALIDITY_CERTIFIED_BLOCKED=0.001, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-rust@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: QEMU Rust-related patches and discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 May 2025 11:39:14 -0000 On 5/28/25 12:49, Manos Pitsidianakis wrote: >> It's not too large, overall. >> >>> #[repr(C)] >>> -#[derive(qemu_api_macros::Object)] >>> +#[derive(qemu_api_macros::Object, qemu_api_macros::DeviceProperties)] >> >> >> Is there more to be derived that is useful for Devices? Maybe the >> macro can be DeviceState or Device. > > VMStateDescription and the realize callback, I think. Ok, pick the name that you prefer. >> Can you change the name to be a "normal" string and change it to a C literal in the macro? > > That'd be neat, it should be possible to create a cstr literal token > and error out if the input str literal cannot be represented as a > cstr. Yes, shouldn't be hard. If it is hard, you could resurrect the c_str module and use ::qemu_api::c_str!(#string). >> I would also merge the files at this point, but no hurry. >> >>> +#[derive(Debug)] >>> +struct DeviceProperty { >>> + name: Option, >>> + qdev_prop: Option, >>> + assert_type: Option, >>> + bitnr: Option, >>> + defval: Option, >>> +} >>> + >>> +impl Parse for DeviceProperty { >> >> Can you look into using https://docs.rs/crate/attrs/latest for parsing? >> >> (attrs doesn't support LitCStr btw) > > I think we can do without it for now, even if this patch is not > cleaned up (for example it has unwraps instead of proper panic > messages or error handling) it does not end up very complex as far as > attribute parsing is concerned. > > I'm fine with either approach though. Ok, I'm fine with the manual parsing as well; just use Result<> instead of panicking. >>> +#[proc_macro_derive(DeviceProperties, attributes(property, bool_property))] >>> +pub fn derive_device_properties(input: TokenStream) -> TokenStream { >> >> >> Do you need to handle errors in the parsing of attributes?... >> >>> + _other => unreachable!(), > > This should be literally unreachable IIUC, because only property names > declared in the attributes part of `#[proc_macro_derive(... > attributes(__))]` would get accepted by the compiler and passed to the > derive macro. You're referring to + other => unreachable!("Got unexpected DeviceProperty attribute `{}`", other), and indeed this one is good as is. The "_other => unreachable!()" line above, instead, comes from matching on input.data and it can be replaced with the existing function get_fields(). Paolo