X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=HACKING;h=471cf1d1970959e95ba18aa8abd798bb5240d95b;hb=233ffa1653b49755e841efdccbd2ac63272ce0c8;hp=6ba9d7e7402718d3a042e0026fd7b275e8dd6b1c;hpb=876f256bde4ff5263b435412d698ed15cad584d9;p=qemu.git diff --git a/HACKING b/HACKING index 6ba9d7e74..471cf1d19 100644 --- a/HACKING +++ b/HACKING @@ -77,11 +77,13 @@ avoided. Use of the malloc/free/realloc/calloc/valloc/memalign/posix_memalign APIs is not allowed in the QEMU codebase. Instead of these routines, -use the replacement qemu_malloc/qemu_mallocz/qemu_realloc/qemu_free or -qemu_vmalloc/qemu_memalign/qemu_vfree APIs. +use the GLib memory allocation routines g_malloc/g_malloc0/g_new/ +g_new0/g_realloc/g_free or QEMU's qemu_vmalloc/qemu_memalign/qemu_vfree +APIs. -Please note that NULL check for the qemu_malloc result is redundant and -that qemu_malloc() call with zero size is not allowed. +Please note that g_malloc will exit on allocation failure, so there +is no need to test for failure (as you would have to with malloc). +Calling g_malloc with a zero size is valid and will return NULL. Memory allocated by qemu_vmalloc or qemu_memalign must be freed with qemu_vfree, since breaking this will cause problems on Win32 and user @@ -108,7 +110,7 @@ int qemu_strnlen(const char *s, int max_len) There are also replacement character processing macros for isxyz and toxyz, so instead of e.g. isalnum you should use qemu_isalnum. -Because of the memory management rules, you must use qemu_strdup/qemu_strndup +Because of the memory management rules, you must use g_strdup/g_strndup instead of plain strdup/strndup. 5. Printf-style functions @@ -120,6 +122,3 @@ gcc's printf attribute directive in the prototype. This makes it so gcc's -Wformat and -Wformat-security options can do their jobs and cross-check format strings with the number and types of arguments. - -Currently many functions in QEMU are not following this rule but -patches to add the attribute would be very much appreciated.