qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Erik Rull <erik.rull@rdsoftware.de>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	qemu-devel@nongnu.org, Richard Henderson <rth@redhat.com>
Subject: Re: [Qemu-devel] [PULL for-1.7 v2 4/6] acpi-build: fix build on glib < 2.14
Date: Mon, 25 Nov 2013 23:01:54 +0200	[thread overview]
Message-ID: <20131125210154.GJ12689@redhat.com> (raw)
In-Reply-To: <5293AF9B.8030903@rdsoftware.de>

On Mon, Nov 25, 2013 at 09:14:19PM +0100, Erik Rull wrote:
> Michael S. Tsirkin wrote:
> >g_array_get_element_size was only added in glib 2.14,
> >there's no way to find element size in with an older glib.
> >
> >Fortunately we only use a single table (linker) where element size > 1.
> >Switch element size to 1 everywhere, then we can just look at len field
> >to get table size in bytes.
> >
> >Add an assert to make sure we catch any violations of this rule.
> >
> >Reviewed-by: Paolo Bonzini <pbonzini@redhat.com>
> >Reported-by: Richard Henderson <rth@redhat.com>
> >Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
> >---
> >  hw/i386/acpi-build.c         | 5 ++++-
> >  hw/i386/bios-linker-loader.c | 8 ++++----
> >  2 files changed, 8 insertions(+), 5 deletions(-)
> >
> >diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
> >index 59a17df..5f36e7e 100644
> >--- a/hw/i386/acpi-build.c
> >+++ b/hw/i386/acpi-build.c
> >@@ -425,7 +425,10 @@ static inline void *acpi_data_push(GArray *table_data, unsigned size)
> >
> >  static unsigned acpi_data_len(GArray *table)
> >  {
> >-    return table->len * g_array_get_element_size(table);
> >+#if GLIB_CHECK_VERSION(2, 14, 0)
> >+    assert(g_array_get_element_size(table) == 1);
> >+#endif
> >+    return table->len;
> >  }
> >
> >  static void acpi_align_size(GArray *blob, unsigned align)
> >diff --git a/hw/i386/bios-linker-loader.c b/hw/i386/bios-linker-loader.c
> >index 0833853..fd23611 100644
> >--- a/hw/i386/bios-linker-loader.c
> >+++ b/hw/i386/bios-linker-loader.c
> >@@ -90,7 +90,7 @@ enum {
> >
> >  GArray *bios_linker_loader_init(void)
> >  {
> >-    return g_array_new(false, true /* clear */, sizeof(BiosLinkerLoaderEntry));
> >+    return g_array_new(false, true /* clear */, 1);
> >  }
> >
> >  /* Free linker wrapper and return the linker array. */
> >@@ -115,7 +115,7 @@ void bios_linker_loader_alloc(GArray *linker,
> >                                      BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH);
> >
> >      /* Alloc entries must come first, so prepend them */
> >-    g_array_prepend_val(linker, entry);
> >+    g_array_prepend_vals(linker, &entry, sizeof entry);
> >  }
> >
> >  void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> >@@ -132,7 +132,7 @@ void bios_linker_loader_add_checksum(GArray *linker, const char *file,
> >      entry.cksum.start = cpu_to_le32((uint8_t *)start - (uint8_t *)table);
> >      entry.cksum.length = cpu_to_le32(size);
> >
> >-    g_array_append_val(linker, entry);
> >+    g_array_append_vals(linker, &entry, sizeof entry);
> >  }
> >
> >  void bios_linker_loader_add_pointer(GArray *linker,
> >@@ -154,5 +154,5 @@ void bios_linker_loader_add_pointer(GArray *linker,
> >      assert(pointer_size == 1 || pointer_size == 2 ||
> >             pointer_size == 4 || pointer_size == 8);
> >
> >-    g_array_append_val(linker, entry);
> >+    g_array_append_vals(linker, &entry, sizeof entry);
> >  }
> >
> 
> Hi all,
> 
> acpi-build.c has another occurence of g_array_get_element_size in
> acpi_align_size. Please put another ifdef for the older glib here,
> too.
> 
> Thanks.
> 
> Best regards,
> 
> Erik
> 


Can you confirm this works?


diff --git a/hw/i386/acpi-build.c b/hw/i386/acpi-build.c
index 5f36e7e..1f22fb6 100644
--- a/hw/i386/acpi-build.c
+++ b/hw/i386/acpi-build.c
@@ -425,7 +425,7 @@ static inline void *acpi_data_push(GArray *table_data, unsigned size)
 
 static unsigned acpi_data_len(GArray *table)
 {
-#if GLIB_CHECK_VERSION(2, 14, 0)
+#if GLIB_CHECK_VERSION(2, 22, 0)
     assert(g_array_get_element_size(table) == 1);
 #endif
     return table->len;
@@ -436,9 +436,7 @@ static void acpi_align_size(GArray *blob, unsigned align)
     /* Align size to multiple of given size. This reduces the chance
      * we need to change size in the future (breaking cross version migration).
      */
-    g_array_set_size(blob, (ROUND_UP(acpi_data_len(blob), align) +
-                            g_array_get_element_size(blob) - 1) /
-                             g_array_get_element_size(blob));
+    g_array_set_size(blob, ROUND_UP(acpi_data_len(blob), align));
 }
 
 /* Get pointer within table in a safe manner */

  parent reply	other threads:[~2013-11-25 20:58 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-25 11:48 [Qemu-devel] [PULL for-1.7 v2 0/5] pc very last minute fixes for 1.7 Michael S. Tsirkin
2013-11-25 11:48 ` [Qemu-devel] [PULL for-1.7 v2 1/6] s390x: fix flat file load on 32 bit systems Michael S. Tsirkin
2013-11-25 11:48 ` [Qemu-devel] [PULL for-1.7 v2 2/6] pci: unregister vmstate_pcibus on unplug Michael S. Tsirkin
2013-11-25 11:48 ` [Qemu-devel] [PULL for-1.7 v2 3/6] acpi-build: fix build on glib < 2.22 Michael S. Tsirkin
2013-11-25 20:24   ` Richard Henderson
2013-11-25 20:31     ` Michael S. Tsirkin
2013-11-25 20:37       ` Richard Henderson
2013-11-25 20:54         ` Michael S. Tsirkin
2013-11-25 21:15           ` Laszlo Ersek
2013-11-25 21:22             ` Eric Blake
2013-11-25 21:18           ` Richard Henderson
2013-11-25 21:26             ` Michael S. Tsirkin
2013-11-25 21:02         ` Michael S. Tsirkin
2013-11-25 21:21           ` Richard Henderson
2013-11-25 21:33             ` Michael S. Tsirkin
2013-11-25 21:57               ` Laszlo Ersek
2013-11-25 11:48 ` [Qemu-devel] [PULL for-1.7 v2 4/6] acpi-build: fix build on glib < 2.14 Michael S. Tsirkin
2013-11-25 20:14   ` Erik Rull
2013-11-25 20:59     ` Michael S. Tsirkin
2013-11-25 21:01     ` Michael S. Tsirkin [this message]
2013-11-25 21:47       ` Richard Henderson
2013-11-25 22:41         ` Erik Rull
2013-11-25 20:26   ` Richard Henderson
2013-11-25 11:48 ` [Qemu-devel] [PULL for-1.7 v2 5/6] Revert "e1000/rtl8139: update HMP NIC when every bit is written" Michael S. Tsirkin
2013-11-25 11:48 ` [Qemu-devel] [PULL for-1.7 v2 6/6] configure: make --iasl option actually work Michael S. Tsirkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131125210154.GJ12689@redhat.com \
    --to=mst@redhat.com \
    --cc=erik.rull@rdsoftware.de \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).