qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] Remove osdep.c/qemu-img code duplication


From: Aurelien Jarno
Subject: Re: [Qemu-devel] [PATCH] Remove osdep.c/qemu-img code duplication
Date: Tue, 8 Apr 2008 20:49:36 +0200
User-agent: Mutt/1.5.17+20080114 (2008-01-14)

On Wed, Apr 02, 2008 at 07:40:24PM +0200, Kevin Wolf wrote:
> 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.

After applying this patch, some files in tcg/ starts to emit warning
about undefined function.

The patch is a good idea though.


> 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;


-- 
  .''`.  Aurelien Jarno             | GPG: 1024D/F1BCDB73
 : :' :  Debian developer           | Electrical Engineer
 `. `'   address@hidden         | address@hidden
   `-    people.debian.org/~aurel32 | www.aurel32.net




reply via email to

[Prev in Thread] Current Thread [Next in Thread]