Ticket #157: mhl.from001-to002.diff

File mhl.from001-to002.diff, 3.6 KB (added by slavazanko, 15 years ago)

Changes from rev001 to rev002 between patches for better review

  • configure.ac

    diff --git a/configure.ac b/configure.ac
    index 0066dbf..957e958 100644
    a b dnl Keep this check close to the beginning, so that the users 
    2525dnl without any glib won't have their time wasted by other checks. 
    2626dnl 
    2727 
     28AC_DEFINE(WITH_GLIB, 1, [Use Glib functions]) 
     29 
     30dnl TODO: make option --with-glib like this: 
     31dnl  
     32dnl AC_ARG_WITH(glib,  
     33dnl     [AS_HELP_STRING([--with-glib], [Use glib (default is yes)])], 
     34dnl     [with_glib=$enableval], 
     35dnl     [with_glib=yes]) 
     36dnl  
     37dnl if test x${with_glib} = xyes; then 
     38dnl dnl some checking stuff 
     39dnl     AC_DEFINE(WITH_GLIB, 1, [Use Glib functions]) 
     40dnl fi 
     41 
     42 
    2843AC_ARG_WITH(glib12,  
    2944        [  --with-glib12            Force using glib 1.2.x [[no]]]) 
    3045 
  • mhl/memory.h

    diff --git a/mhl/memory.h b/mhl/memory.h
    index b006177..20db6c0 100644
    a b  
    11#ifndef __MHL_MEM 
    22#define __MHL_MEM 
    33 
     4#if defined _AIX && !defined REGEX_MALLOC 
     5  #pragma alloca 
     6#endif 
     7 
     8#include <config.h> 
    49#include <memory.h> 
    510#include <stdlib.h> 
    611 
    7 /* allocate a chunk of stack memory, uninitialized */ 
    8 #define         mhl_mem_alloc_u(sz)     (malloc(sz)) 
     12#ifdef __GNUC__ 
     13#    define alloca __builtin_alloca 
     14#else 
     15#    ifdef _MSC_VER 
     16#        include <malloc.h> 
     17#        define alloca _alloca 
     18#    else 
     19#        if HAVE_ALLOCA_H 
     20#            include <alloca.h> 
     21#        else 
     22#            ifdef _AIX 
     23#pragma alloca 
     24#            else 
     25#                ifndef alloca /* predefined by HP cc +Olibcalls */ 
     26char *alloca (); 
     27#                endif 
     28#            endif 
     29#        endif 
     30#    endif 
     31#endif 
     32 
     33#ifndef HAVE_ALLOCA 
     34#    include <stdlib.h> 
     35#    if !defined(STDC_HEADERS) && defined(HAVE_MALLOC_H) 
     36#        include <malloc.h> 
     37#    endif 
     38#    define alloca malloc 
     39#endif 
     40 
     41#ifdef WITH_GLIB 
     42#       include <glib.h> 
     43 
     44#       if GLIB_MAJOR_VERSION >= 2 
     45                /* allocate a chunk of stack memory, uninitialized */ 
     46#               define  mhl_mem_alloc_u(sz)     (g_try_malloc(sz)) 
     47 
     48                /* allocate a chunk of stack memory, zeroed */ 
     49#               define          mhl_mem_alloc_z(sz)     (g_try_malloc0(sz)) 
     50 
     51                /* re-alloc memory chunk */ 
     52#               define          mhl_mem_realloc(ptr,sz) (g_try_realloc(ptr,sz)) 
     53 
     54#       else 
     55 
     56                /* allocate a chunk of stack memory, uninitialized */ 
     57#               define  mhl_mem_alloc_u(sz)     (g_malloc(sz)) 
     58 
     59                /* allocate a chunk of stack memory, zeroed */ 
     60#               define          mhl_mem_alloc_z(sz)     (g_malloc0(sz)) 
    961 
    10 /* allocate a chunk of stack memory, zeroed */ 
    11 #define         mhl_mem_alloc_z(sz)     (calloc(1,sz)) 
     62                /* re-alloc memory chunk */ 
     63#               define          mhl_mem_realloc(ptr,sz) (g_realloc(ptr,sz)) 
     64 
     65#       endif 
     66 
     67        /* allocate a chunk on stack - automatically free'd on function exit */ 
     68#       define          mhl_stack_alloc(sz)     (g_alloca(sz)) 
     69 
     70#else 
     71 
     72        /* allocate a chunk of stack memory, uninitialized */ 
     73#       define  mhl_mem_alloc_u(sz)     (malloc(sz)) 
     74 
     75        /* allocate a chunk of stack memory, zeroed */ 
     76#       define          mhl_mem_alloc_z(sz)     (calloc(1,sz)) 
     77 
     78        /* re-alloc memory chunk */ 
     79#       define          mhl_mem_realloc(ptr,sz) (realloc(ptr,sz)) 
     80 
     81        /* allocate a chunk on stack - automatically free'd on function exit */ 
     82#       define          mhl_stack_alloc(sz)     (alloca(sz)) 
     83 
     84#endif 
    1285 
    1386/* free a chunk of memory from stack, passing NULL does no harm */ 
    1487static inline void mhl_mem_free(void* ptr) 
    1588{ 
    16     if (ptr) free(ptr); 
     89    if (ptr) 
     90#ifdef WITH_GLIB 
     91        g_free(ptr); 
     92#else 
     93        free(ptr); 
     94#endif 
    1795} 
    1896 
    1997/* free an ptr and NULL it */ 
    2098#define         MHL_PTR_FREE(ptr)       do { mhl_mem_free(ptr); (ptr) = NULL; } while (0);  
    2199 
    22 /* allocate a chunk on stack - automatically free'd on function exit */ 
    23 #define         mhl_stack_alloc(sz)     (alloca(sz)) 
    24  
    25 /* re-alloc memory chunk */ 
    26 #define         mhl_mem_realloc(ptr,sz) (realloc(ptr,sz)) 
    27  
    28100#endif