From: Kevin Wolf <kwolf@suse.de>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Remove osdep.c/qemu-img code duplication
Date: Wed, 02 Apr 2008 19:40:24 +0200 [thread overview]
Message-ID: <47F3C508.8040002@suse.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 382 bytes --]
There are few helper functions (e.g. qemu_malloc) in osdep.c which are
not OS dependent at all. Even the first CVS commit comment for osdep.c
says "most functions are generic in fact". They are duplicated in
qemu-img because osdep.c isn't used there.
This patch moves those functions to cutils.c and removes the duplicates
from qemu-img.
Signed-off-by: Kevin Wolf <kwolf@suse.de>
[-- Attachment #2: qemu-remove-duplication.patch --]
[-- Type: text/x-patch, Size: 3900 bytes --]
Index: Makefile.target
===================================================================
--- Makefile.target (Revision 4156)
+++ Makefile.target (Arbeitskopie)
@@ -430,6 +430,7 @@
endif
OBJS+= libqemu.a
+OBJS+= ../libqemu_common.a
# Note: this is a workaround. The real fix is to avoid compiling
# cpu_signal_handler() in cpu-exec.c.
Index: osdep.c
===================================================================
--- osdep.c (Revision 4156)
+++ osdep.c (Arbeitskopie)
@@ -45,21 +45,6 @@
#include <malloc.h>
#endif
-void *get_mmap_addr(unsigned long size)
-{
- return NULL;
-}
-
-void qemu_free(void *ptr)
-{
- free(ptr);
-}
-
-void *qemu_malloc(size_t size)
-{
- return malloc(size);
-}
-
#if defined(_WIN32)
void *qemu_memalign(size_t alignment, size_t size)
{
@@ -217,26 +202,6 @@
#endif
-void *qemu_mallocz(size_t size)
-{
- void *ptr;
- ptr = qemu_malloc(size);
- if (!ptr)
- return NULL;
- memset(ptr, 0, size);
- return ptr;
-}
-
-char *qemu_strdup(const char *str)
-{
- char *ptr;
- ptr = qemu_malloc(strlen(str) + 1);
- if (!ptr)
- return NULL;
- strcpy(ptr, str);
- return ptr;
-}
-
int qemu_create_pidfile(const char *filename)
{
char buffer[128];
Index: osdep.h
===================================================================
--- osdep.h (Revision 4156)
+++ osdep.h (Arbeitskopie)
@@ -47,17 +47,10 @@
#define qemu_printf printf
-void *qemu_malloc(size_t size);
-void *qemu_mallocz(size_t size);
-void qemu_free(void *ptr);
-char *qemu_strdup(const char *str);
-
void *qemu_memalign(size_t alignment, size_t size);
void *qemu_vmalloc(size_t size);
void qemu_vfree(void *ptr);
-void *get_mmap_addr(unsigned long size);
-
int qemu_create_pidfile(const char *filename);
#ifdef _WIN32
Index: cutils.c
===================================================================
--- cutils.c (Revision 4156)
+++ cutils.c (Arbeitskopie)
@@ -95,3 +95,38 @@
t += 3600 * tm->tm_hour + 60 * tm->tm_min + tm->tm_sec;
return t;
}
+
+void *get_mmap_addr(unsigned long size)
+{
+ return NULL;
+}
+
+void qemu_free(void *ptr)
+{
+ free(ptr);
+}
+
+void *qemu_malloc(size_t size)
+{
+ return malloc(size);
+}
+
+void *qemu_mallocz(size_t size)
+{
+ void *ptr;
+ ptr = qemu_malloc(size);
+ if (!ptr)
+ return NULL;
+ memset(ptr, 0, size);
+ return ptr;
+}
+
+char *qemu_strdup(const char *str)
+{
+ char *ptr;
+ ptr = qemu_malloc(strlen(str) + 1);
+ if (!ptr)
+ return NULL;
+ strcpy(ptr, str);
+ return ptr;
+}
Index: qemu-common.h
===================================================================
--- qemu-common.h (Revision 4156)
+++ qemu-common.h (Arbeitskopie)
@@ -86,6 +86,14 @@
int stristart(const char *str, const char *val, const char **ptr);
time_t mktimegm(struct tm *tm);
+void *qemu_malloc(size_t size);
+void *qemu_mallocz(size_t size);
+void qemu_free(void *ptr);
+char *qemu_strdup(const char *str);
+
+void *get_mmap_addr(unsigned long size);
+
+
/* Error handling. */
void hw_error(const char *fmt, ...)
Index: qemu-img.c
===================================================================
--- qemu-img.c (Revision 4156)
+++ qemu-img.c (Arbeitskopie)
@@ -30,41 +30,6 @@
#include <windows.h>
#endif
-void *get_mmap_addr(unsigned long size)
-{
- return NULL;
-}
-
-void qemu_free(void *ptr)
-{
- free(ptr);
-}
-
-void *qemu_malloc(size_t size)
-{
- return malloc(size);
-}
-
-void *qemu_mallocz(size_t size)
-{
- void *ptr;
- ptr = qemu_malloc(size);
- if (!ptr)
- return NULL;
- memset(ptr, 0, size);
- return ptr;
-}
-
-char *qemu_strdup(const char *str)
-{
- char *ptr;
- ptr = qemu_malloc(strlen(str) + 1);
- if (!ptr)
- return NULL;
- strcpy(ptr, str);
- return ptr;
-}
-
static void __attribute__((noreturn)) error(const char *fmt, ...)
{
va_list ap;
next reply other threads:[~2008-04-02 17:45 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-02 17:40 Kevin Wolf [this message]
2008-04-08 18:49 ` [Qemu-devel] [PATCH] Remove osdep.c/qemu-img code duplication Aurelien Jarno
2008-04-09 11:15 ` Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=47F3C508.8040002@suse.de \
--to=kwolf@suse.de \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.