[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-trivial] [PATCH 02/88] cocci: add more g_new() transformations
From: |
Philippe Mathieu-Daudé |
Subject: |
[Qemu-trivial] [PATCH 02/88] cocci: add more g_new() transformations |
Date: |
Fri, 6 Oct 2017 20:48:57 -0300 |
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
scripts/coccinelle/g_new.cocci | 73 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 73 insertions(+)
diff --git a/scripts/coccinelle/g_new.cocci b/scripts/coccinelle/g_new.cocci
index 1e57685a6b..c767325a21 100644
--- a/scripts/coccinelle/g_new.cocci
+++ b/scripts/coccinelle/g_new.cocci
@@ -80,6 +80,49 @@ expression p, n;
-g_try_realloc(p, sizeof(T) * (n))
+g_try_renew(T, p, n)
+@@
+type T;
+expression n;
+@@
+(
+-g_malloc_n(n, sizeof(T))
++g_new(T, n)
+|
+-g_malloc0_n(n, sizeof(T))
++g_new0(T, n)
+|
+-g_try_malloc_n(n, sizeof(T))
++g_try_new(T, n)
+|
+-g_try_malloc0_n(n, sizeof(T))
++g_try_new0(T, n)
+)
+
+@@
+type T;
+identifier m;
+@@
+T *m;
+...
+(
+-m = g_malloc(sizeof(*m));
++m = g_new(T, 1);
+|
+-m = g_malloc0(sizeof(*m));
++m = g_new0(T, 1);
+|
+-m = g_try_malloc(sizeof(*m));
++m = g_try_new(T, 1);
+|
+-m = g_try_malloc0(sizeof(*m));
++m = g_try_new0(T, 1);
+)
+
+////////////////////////////////////////
+//
+// last transformations: cleanups
+//
+
// drop superfluous cast
@@
type T;
@@ -99,3 +142,33 @@ expression p, n;
@@
-(T *)g_renew(T, p, n)
+g_renew(T, p, n)
+@@
+type T;
+expression n;
+@@
+(
+-(T *)g_try_new(T, n)
++g_try_new(T, n)
+|
+-(T *)g_try_new0(T, n)
++g_try_new0(T, n)
+)
+
+// drop superfluous parenthesis
+@@
+type T;
+expression c;
+@@
+(
+-g_new(T, (c))
++g_new(T, c)
+|
+-g_try_new(T, (c))
++g_try_new(T, c)
+|
+-g_new0(T, (c))
++g_new0(T, c)
+|
+-g_try_new0(T, (c))
++g_try_new0(T, c)
+)
--
2.14.2
- [Qemu-trivial] [PATCH 00/88] use g_new() family of functions, Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-trivial] [PATCH 01/88] cocci: script to use g_new() & friends, Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-trivial] [PATCH 02/88] cocci: add more g_new() transformations,
Philippe Mathieu-Daudé <=
- [Qemu-trivial] [PATCH 03/88] cocci: extract typeof() from g_new(), Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-trivial] [PATCH 04/88] cocci: avoid use of g_new0(), Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-trivial] [PATCH 05/88] cocci: use g_strfreev(), Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-trivial] [PATCH 07/88] Audio: use g_new() family of functions, Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-trivial] [PATCH 06/88] ARM: use g_new() family of functions, Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-trivial] [PATCH 08/88] BT: use g_new() family of functions, Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-trivial] [PATCH 09/88] Bootdevice: use g_new() family of functions, Philippe Mathieu-Daudé, 2017/10/06
- [Qemu-trivial] [PATCH 10/88] Character devices: use g_new() family of functions, Philippe Mathieu-Daudé, 2017/10/06