gtk.cfg: Add support for g_new() and similar macros. (#1760)

Also add / improve corresponding function configurations and some tests.
This commit is contained in:
Sebastian 2019-03-26 10:45:06 +01:00 committed by GitHub
parent 5b72e1f568
commit 6976d5c6e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 114 additions and 3 deletions

View File

@ -64,6 +64,18 @@
<define name="G_TYPE_INSTANCE_GET_PRIVATE(instance, g_type, c_type)" value="((c_type*) g_type_instance_get_private ((GTypeInstance*) (instance), (g_type)))"/>
<define name="G_OBJECT(obj)" value="(GObject*)(obj)"/>
<define name="G_OBJECT_CLASS(class)" value="(G_TYPE_CHECK_CLASS_CAST ((class), G_TYPE_OBJECT, GObjectClass))"/>
<!-- TODO #9047: use this define instead of the one without the cast as soon as memleaks are detected also with the cast
<define name="_G_NEW(struct_type, n_structs, func)" value="((struct_type *) g_##func##_n ((n_structs), sizeof (struct_type)))"/> -->
<define name="_G_NEW(struct_type, n_structs, func)" value="(g_##func##_n ((n_structs), sizeof (struct_type)))"/>
<!-- TODO #9047: use this define instead of the one without the cast as soon as memleaks are detected also with the cast
<define name="_G_RENEW(struct_type, mem, n_structs, func)" value="((struct_type *) g_##func##_n (mem, (n_structs), sizeof (struct_type)))"/> -->
<define name="_G_RENEW(struct_type, mem, n_structs, func)" value="(g_##func##_n (mem, (n_structs), sizeof (struct_type)))"/>
<define name="g_new(struct_type, n_structs)" value="_G_NEW (struct_type, n_structs, malloc)"/>
<define name="g_new0(struct_type, n_structs)" value="_G_NEW (struct_type, n_structs, malloc0)"/>
<define name="g_renew(struct_type, mem, n_structs)" value="_G_RENEW (struct_type, mem, n_structs, realloc)"/>
<define name="g_try_new(struct_type, n_structs)" value="_G_NEW (struct_type, n_structs, try_malloc)"/>
<define name="g_try_new0(struct_type, n_structs)" value="_G_NEW (struct_type, n_structs, try_malloc0)"/>
<define name="g_try_renew(struct_type, mem, n_structs)" value="_G_RENEW (struct_type, mem, n_structs, try_realloc)"/>
<define name="GTK_BOX(obj)" value="((GtkBox*)(obj))"/>
<define name="GTK_CONTAINER(obj)" value="((GtkContainer*)(obj))"/>
<define name="GTK_ENTRY(obj)" value="((GtkEntry*)(obj))"/>
@ -2496,13 +2508,33 @@
<leak-ignore/>
<noreturn>false</noreturn>
</function>
<!-- gpointer g_realloc (gpointer mem, gsize n_bytes); -->
<function name="g_realloc">
<leak-ignore/>
<noreturn>false</noreturn>
<returnValue type="gpointer"/>
<use-retval/>
<arg nr="1"/>
<arg nr="2" direction="in">
<not-uninit/>
<not-bool/>
<valid>0:</valid>
</arg>
</function>
<!-- gpointer g_realloc_n (gpointer mem, gsize n_blocks, gsize n_block_bytes); -->
<function name="g_realloc_n">
<leak-ignore/>
<noreturn>false</noreturn>
<returnValue type="gpointer"/>
<use-retval/>
<arg nr="1"/>
<arg nr="2" direction="in">
<not-uninit/>
<valid>0:</valid>
</arg>
<arg nr="3" direction="in">
<not-uninit/>
<not-bool/>
<valid>0:</valid>
</arg>
</function>
<function name="g_regex_check_replacement">
<leak-ignore/>
@ -2983,6 +3015,32 @@
<leak-ignore/>
<noreturn>false</noreturn>
</function>
<!-- gpointer g_try_malloc (gsize n_bytes); -->
<!-- gpointer g_try_malloc0 (gsize n_bytes); -->
<function name="g_try_malloc,g_try_malloc0">
<noreturn>false</noreturn>
<returnValue type="gpointer"/>
<arg nr="1" direction="in">
<not-uninit/>
<not-bool/>
<valid>0:</valid>
</arg>
</function>
<!-- gpointer g_try_malloc_n (gsize n_blocks, gsize n_block_bytes); -->
<!-- gpointer g_try_malloc0_n (gsize n_blocks, gsize n_block_bytes); -->
<function name="g_try_malloc_n,g_try_malloc0_n">
<noreturn>false</noreturn>
<returnValue type="gpointer"/>
<arg nr="1" direction="in">
<not-uninit/>
<valid>0:</valid>
</arg>
<arg nr="2" direction="in">
<not-uninit/>
<not-bool/>
<valid>0:</valid>
</arg>
</function>
<function name="g_try_realloc">
<leak-ignore/>
<noreturn>false</noreturn>
@ -4151,12 +4209,29 @@
<leak-ignore/>
<noreturn>false</noreturn>
</function>
<!-- https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html#g-malloc -->
<!-- gpointer g_malloc(gsize n_bytes); -->
<!-- gpointer g_malloc0(gsize n_bytes); -->
<function name="g_malloc,g_malloc0">
<noreturn>false</noreturn>
<returnValue type="gpointer"/>
<arg nr="1">
<arg nr="1" direction="in">
<not-uninit/>
<not-bool/>
<valid>0:</valid>
</arg>
</function>
<!-- https://developer.gnome.org/glib/stable/glib-Memory-Allocation.html#g-malloc-n -->
<!-- gpointer g_malloc_n (gsize n_blocks, gsize n_block_bytes); -->
<!-- gpointer g_malloc0_n (gsize n_blocks, gsize n_block_bytes); -->
<function name="g_malloc_n,g_malloc0_n">
<noreturn>false</noreturn>
<returnValue type="gpointer"/>
<arg nr="1" direction="in">
<not-uninit/>
<valid>0:</valid>
</arg>
<arg nr="2" direction="in">
<not-uninit/>
<not-bool/>
<valid>0:</valid>

View File

@ -77,3 +77,39 @@ void g_alloca_test()
char * pBuf1 = g_alloca(5);
pBuf1[0] = '\0';
}
void g_new_test()
{
struct a {
int b;
};
// valid
struct a * pNew1 = g_new(struct a, 5);
printf("%p", pNew1);
g_free(pNew1);
// cppcheck-suppress leakReturnValNotUsed
g_new(struct a, 1);
struct a * pNew2 = g_new(struct a, 2);
printf("%p", pNew2);
// cppcheck-suppress memleak
}
void g_try_new0_test()
{
struct a {
int b;
};
// valid
struct a * pNew1 = g_try_new0(struct a, 5);
printf("%p", pNew1);
g_free(pNew1);
// cppcheck-suppress leakReturnValNotUsed
g_try_new0(struct a, 1);
struct a * pNew2 = g_try_new0(struct a, 2);
printf("%p", pNew2);
// cppcheck-suppress memleak
}