Skip to contentSkip to conversation

acpi: Clean up some GLib compatibility cruft

PATCH In review Markus Armbruster 3 participants 7 messages May 27, 2015 – Jun 8, 2015

lore
Share & tools
lore
#0 lore raw

cover acpi: Clean up some GLib compatibility cruft

Markus Armbruster (3):
Revert "aml-build: fix build for glib < 2.22"
acpi: Drop superfluous GLIB_CHECK_VERSION()
acpi: Simplify printing to dynamic string

 hw/acpi/aml-build.c | 34 +++++++---------------------------
 1 file changed, 7 insertions(+), 27 deletions(-)
Signature · 1 line
1.9.3
#1 lore raw

PATCH 1/3 Revert "aml-build: fix build for glib < 2.22"

Since we now require GLib 2.22+ (commit f40685c), we don't have to work around lack of g_ptr_array_new_with_free_func() anymore.

This reverts commit 2e5feadbf8133b9b108919a2f576943b448a1a06.

---
 hw/acpi/aml-build.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
hw/acpi/aml-build.c +2 -3
index 77ce00b..65c9d00 100644
@@ -301,7 +301,7 @@ static Aml *aml_bundle(uint8_t op, AmlBlockFlags flags)
     return var;
 }
 
-static void aml_free(gpointer data, gpointer user_data)
+static void aml_free(gpointer data)
 {
     Aml *var = data;
     build_free_array(var->buf);
@@ -312,14 +312,13 @@ Aml *init_aml_allocator(void)
     Aml *var;
 
     assert(!alloc_list);
-    alloc_list = g_ptr_array_new();
+    alloc_list = g_ptr_array_new_with_free_func(aml_free);
     var = aml_alloc();
     return var;
 }
 
 void free_aml_allocator(void)
 {
-    g_ptr_array_foreach(alloc_list, aml_free, NULL);
     g_ptr_array_free(alloc_list, true);
     alloc_list = 0;
 }
Signature · 1 line
1.9.3
#2 lore raw

PATCH 2/3 acpi: Drop superfluous GLIB_CHECK_VERSION()

In reply to Markus Armbruster

The version check is always true since we require GLib 2.22+ (commit f40685c). It dates back to commit 8b9c3b8 "acpi-build: fix build on glib < 2.22", amended in commit fd8f5e3 "acpi-build: fix build on glib < 2.14". I guess we could revert both of them now, but I'm not sure it's worth the churn, so just drop the superfluous check instead.

---
 hw/acpi/aml-build.c | 2 --
 1 file changed, 2 deletions(-)
hw/acpi/aml-build.c +0 -2
index 65c9d00..9efbb37 100644
@@ -922,9 +922,7 @@ void *acpi_data_push(GArray *table_data, unsigned size)
 
 unsigned acpi_data_len(GArray *table)
 {
-#if GLIB_CHECK_VERSION(2, 22, 0)
     assert(g_array_get_element_size(table) == 1);
-#endif
     return table->len;
 }
 
Signature · 1 line
1.9.3
#3 lore raw

PATCH 3/3 acpi: Simplify printing to dynamic string

In reply to Markus Armbruster

build_append_namestringv() and aml_string() first calculate the resulting string's length with vsnprintf(NULL, ...), then allocate, then print for real. Simply use g_strdup_vprintf() or g_vasprintf() instead.

---
 hw/acpi/aml-build.c | 27 +++++----------------------
 1 file changed, 5 insertions(+), 22 deletions(-)
hw/acpi/aml-build.c +5 -22
index 9efbb37..5be8a9d 100644
@@ -19,6 +19,7 @@
  * with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+#include <glib/gprintf.h>
 #include <stdio.h>
 #include <stdarg.h>
 #include <assert.h>
@@ -58,7 +59,6 @@ static void build_append_array(GArray *array, GArray *val)
 static void
 build_append_nameseg(GArray *array, const char *seg)
 {
-    /* It would be nicer to use g_string_vprintf but it's only there in 2.22 */
     int len;
 
     len = strlen(seg);
@@ -72,22 +72,12 @@ build_append_nameseg(GArray *array, const char *seg)
 static void GCC_FMT_ATTR(2, 0)
 build_append_namestringv(GArray *array, const char *format, va_list ap)
 {
-    /* It would be nicer to use g_string_vprintf but it's only there in 2.22 */
     char *s;
-    int len;
-    va_list va_len;
     char **segs;
     char **segs_iter;
     int seg_count = 0;
 
-    va_copy(va_len, ap);
-    len = vsnprintf(NULL, 0, format, va_len);
-    va_end(va_len);
-    len += 1;
-    s = g_new(typeof(*s), len);
-
-    len = vsnprintf(s, len, format, ap);
-
+    s = g_strdup_vprintf(format, ap);
     segs = g_strsplit(s, ".", 0);
     g_free(s);
 
@@ -649,22 +639,15 @@ Aml *aml_field(const char *name, AmlAccessType type, AmlUpdateRule rule)
 Aml *aml_string(const char *name_format, ...)
 {
     Aml *var = aml_opcode(0x0D /* StringPrefix */);
-    va_list ap, va_len;
+    va_list ap;
     char *s;
     int len;
 
     va_start(ap, name_format);
-    va_copy(va_len, ap);
-    len = vsnprintf(NULL, 0, name_format, va_len);
-    va_end(va_len);
-    len += 1;
-    s = g_new0(typeof(*s), len);
-
-    len = vsnprintf(s, len, name_format, ap);
+    len = g_vasprintf(&s, name_format, ap);
     va_end(ap);
 
-    g_array_append_vals(var->buf, s, len);
-    build_append_byte(var->buf, 0x0); /* NullChar */
+    g_array_append_vals(var->buf, s, len + 1);
     g_free(s);
 
     return var;
Signature · 1 line
1.9.3
Reviewed-by on the v1 series
#4 lore raw
In reply to Markus Armbruster
Quoted 8 lines · Markus Armbruster

Markus Armbruster (3):
Revert "aml-build: fix build for glib < 2.22"
acpi: Drop superfluous GLIB_CHECK_VERSION()
acpi: Simplify printing to dynamic string

 hw/acpi/aml-build.c | 34 +++++++---------------------------
 1 file changed, 7 insertions(+), 27 deletions(-)

ありがとう

Reviewed-by on the v1 series
#5 lore raw
In reply to Markus Armbruster
Quoted 8 lines · On Wed, 27 May 2015 19:55:52 +0200 Markus Armbruster <[email protected]> wrote:

Markus Armbruster (3):
Revert "aml-build: fix build for glib < 2.22"
acpi: Drop superfluous GLIB_CHECK_VERSION()
acpi: Simplify printing to dynamic string

 hw/acpi/aml-build.c | 34 +++++++---------------------------
 1 file changed, 7 insertions(+), 27 deletions(-)
#6 lore raw
In reply to Markus Armbruster
Quoted 4 lines · Markus Armbruster

Markus Armbruster (3):
Revert "aml-build: fix build for glib < 2.22"
acpi: Drop superfluous GLIB_CHECK_VERSION()
acpi: Simplify printing to dynamic string

3/3 got in (commit c3bdc56, thanks), but what about the other two? They still apply cleanly.