[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 09/11] acpi_table_add(): extract acpi_tables realloc
From: |
Eduardo Habkost |
Subject: |
[Qemu-devel] [PATCH 09/11] acpi_table_add(): extract acpi_tables reallocation code to a separate function |
Date: |
Wed, 27 Jun 2012 17:23:05 -0300 |
This was the maint point of most of the previous variable renames and
calculation-method changes: to isolate the g_realloc() call to avoid
doing pointer math with acpi_tables everywhere.
No behavior change, just code movement.
Signed-off-by: Eduardo Habkost <address@hidden>
---
hw/acpi.c | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/hw/acpi.c b/hw/acpi.c
index 251c770..cbc2ba7 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -81,6 +81,18 @@ static void init_acpi_tables(void)
}
}
+/* Resize acpi_tables to fit a new (under construction) table of size 'newlen'
+ *
+ * acpi_tables_len is _not_ changed, as the table is still incomplete.
+ *
+ * Returns a pointer to the reallocated _new_ table at end of acpi_tables.
+ */
+static char *acpi_newtable_resize(size_t newlen)
+{
+ acpi_tables = g_realloc(acpi_tables, acpi_tables_len + newlen);
+ return acpi_tables + acpi_tables_len;
+}
+
static int acpi_make_table_header(const char *t, bool has_header, char *f,
size_t qemu_len)
{
@@ -213,7 +225,7 @@ int acpi_table_add(const char *t)
init_acpi_tables();
- acpi_tables = g_realloc(acpi_tables, acpi_tables_len +
ACPI_TABLE_HDR_SIZE);
+ acpi_newtable_resize(ACPI_TABLE_HDR_SIZE);
newlen = has_header ? ACPI_TABLE_PFX_SIZE : ACPI_TABLE_HDR_SIZE;
/* now read in the data files, reallocating buffer as needed */
@@ -232,8 +244,7 @@ int acpi_table_add(const char *t)
if (r == 0) {
break;
} else if (r > 0) {
- acpi_tables = g_realloc(acpi_tables, acpi_tables_len + newlen
- + r);
+ acpi_newtable_resize(newlen + r);
memcpy(acpi_tables + acpi_tables_len + newlen, data, r);
newlen += r;
} else if (errno != EINTR) {
--
1.7.10.4
- [Qemu-devel] [PATCH 00/11] acpi_table_add() code cleanup, Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 03/11] acpi_table_add(): rename 'len' to 'acpi_len', Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 04/11] acpi_table_add(): introduce 'qemu_len' variable, Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 09/11] acpi_table_add(): extract acpi_tables reallocation code to a separate function,
Eduardo Habkost <=
- [Qemu-devel] [PATCH 05/11] acpi_table_add(): extract ACPI header creation to separate function, Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 10/11] acpi_table_add(): use acpi_newtable_resize() return value, Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 01/11] acpi_table_add(): simplify acpi_tables on-demand initialization, Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 06/11] acpi_table_add(): rename 'qemu_len' to 'newlen', Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 02/11] acpi_table_add(): extract acpi_tables init to separate function, Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 07/11] acpi_table_add(): eliminate 'allen' variable, Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 08/11] acpi_table_add(): eliminate 'start' variable, Eduardo Habkost, 2012/06/27
- [Qemu-devel] [PATCH 11/11] acpi_table_add(): extract acpi_tables count update code to separate function, Eduardo Habkost, 2012/06/27