From patchwork Mon Oct 19 18:42:52 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 36398 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id EFED0B7B74 for ; Tue, 20 Oct 2009 05:56:10 +1100 (EST) Received: from localhost ([127.0.0.1]:38832 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MzxOp-0002tw-FY for incoming@patchwork.ozlabs.org; Mon, 19 Oct 2009 14:56:07 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MzxD2-00066V-R0 for qemu-devel@nongnu.org; Mon, 19 Oct 2009 14:43:56 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MzxCw-000627-Fq for qemu-devel@nongnu.org; Mon, 19 Oct 2009 14:43:54 -0400 Received: from [199.232.76.173] (port=49040 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MzxCw-00061w-Ab for qemu-devel@nongnu.org; Mon, 19 Oct 2009 14:43:50 -0400 Received: from mx1.redhat.com ([209.132.183.28]:6917) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MzxCv-0006J5-MK for qemu-devel@nongnu.org; Mon, 19 Oct 2009 14:43:50 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9JIhmxK025210 for ; Mon, 19 Oct 2009 14:43:49 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n9JIhcC0012656; Mon, 19 Oct 2009 14:43:47 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Mon, 19 Oct 2009 20:42:52 +0200 Message-Id: In-Reply-To: References: In-Reply-To: References: X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 07/25] vmstate: factor vmstate_offset_value X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Juan Quintela --- hw/hw.h | 31 +++++++++++++------------------ 1 files changed, 13 insertions(+), 18 deletions(-) diff --git a/hw/hw.h b/hw/hw.h index cd42f74..d1395e9 100644 --- a/hw/hw.h +++ b/hw/hw.h @@ -338,14 +338,17 @@ extern const VMStateInfo vmstate_info_buffer; #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0) #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0) +#define vmstate_offset_value(_state, _field, _type) \ + (offsetof(_state, _field) + \ + type_check(_type, typeof_field(_state, _field))) + #define VMSTATE_SINGLE(_field, _state, _version, _info, _type) { \ .name = (stringify(_field)), \ .version_id = (_version), \ .size = sizeof(_type), \ .info = &(_info), \ .flags = VMS_SINGLE, \ - .offset = offsetof(_state, _field) \ - + type_check(_type,typeof_field(_state, _field)) \ + .offset = vmstate_offset_value(_state, _field, _type), \ } #define VMSTATE_SINGLE_TEST(_field, _state, _test, _info, _type) { \ @@ -354,8 +357,7 @@ extern const VMStateInfo vmstate_info_buffer; .size = sizeof(_type), \ .info = &(_info), \ .flags = VMS_SINGLE, \ - .offset = offsetof(_state, _field) \ - + type_check(_type,typeof_field(_state, _field)) \ + .offset = vmstate_offset_value(_state, _field, _type), \ } #define VMSTATE_POINTER(_field, _state, _version, _info, _type) { \ @@ -364,8 +366,7 @@ extern const VMStateInfo vmstate_info_buffer; .info = &(_info), \ .size = sizeof(_type), \ .flags = VMS_SINGLE|VMS_POINTER, \ - .offset = offsetof(_state, _field) \ - + type_check(_type,typeof_field(_state, _field)) \ + .offset = vmstate_offset_value(_state, _field, _type), \ } #define VMSTATE_ARRAY(_field, _state, _num, _version, _info, _type) {\ @@ -393,8 +394,7 @@ extern const VMStateInfo vmstate_info_buffer; #define VMSTATE_VARRAY_INT32(_field, _state, _field_num, _version, _info, _type) {\ .name = (stringify(_field)), \ .version_id = (_version), \ - .num_offset = offsetof(_state, _field_num) \ - + type_check(int32_t,typeof_field(_state, _field_num)), \ + .num_offset = vmstate_offset_value(_state, _field_num, int32_t), \ .info = &(_info), \ .size = sizeof(_type), \ .flags = VMS_VARRAY_INT32|VMS_POINTER, \ @@ -408,8 +408,7 @@ extern const VMStateInfo vmstate_info_buffer; .vmsd = &(_vmsd), \ .size = sizeof(_type), \ .flags = VMS_STRUCT, \ - .offset = offsetof(_state, _field) \ - + type_check(_type,typeof_field(_state, _field)) \ + .offset = vmstate_offset_value(_state, _field, _type), \ } #define VMSTATE_STRUCT_POINTER(_field, _state, _vmsd, _type) { \ @@ -417,8 +416,7 @@ extern const VMStateInfo vmstate_info_buffer; .vmsd = &(_vmsd), \ .size = sizeof(_type), \ .flags = VMS_STRUCT|VMS_POINTER, \ - .offset = offsetof(_state, _field) \ - + type_check(_type,typeof_field(_state, _field)) \ + .offset = vmstate_offset_value(_state, _field, _type), \ } #define VMSTATE_ARRAY_OF_POINTER(_field, _state, _num, _version, _info, _type) {\ @@ -445,8 +443,7 @@ extern const VMStateInfo vmstate_info_buffer; #define VMSTATE_STRUCT_ARRAY_SIZE_UINT8(_field, _state, _field__num, _version, _vmsd, _type) { \ .name = (stringify(_field)), \ - .num_offset = offsetof(_state, _field_num) \ - + type_check(uint8_t,typeof_field(_state, _field_num)), \ + .num_offset = vmstate_offset_value(_state, _field_num, uint8_t), \ .version_id = (_version), \ .vmsd = &(_vmsd), \ .size = sizeof(_type), \ @@ -490,8 +487,7 @@ extern const VMStateDescription vmstate_pci_device; .size = sizeof(PCIDevice), \ .vmsd = &vmstate_pci_device, \ .flags = VMS_STRUCT, \ - .offset = offsetof(_state, _field) \ - + type_check(PCIDevice,typeof_field(_state, _field)) \ + .offset = vmstate_offset_value(_state, _field, PCIDevice), \ } extern const VMStateDescription vmstate_i2c_slave; @@ -501,8 +497,7 @@ extern const VMStateDescription vmstate_i2c_slave; .size = sizeof(i2c_slave), \ .vmsd = &vmstate_i2c_slave, \ .flags = VMS_STRUCT, \ - .offset = offsetof(_state, _field) \ - + type_check(i2c_slave,typeof_field(_state, _field)) \ + .offset = vmstate_offset_value(_state, _field, i2c_slave), \ } /* _f : field name