Guest User

Untitled

a guest
Nov 4th, 2010
121
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. diff --git a/lib/skin_parser/skin_buffer.c b/lib/skin_parser/skin_buffer.c
  2. index ecfe04b..9aa43ab 100644
  3. --- a/lib/skin_parser/skin_buffer.c
  4. +++ b/lib/skin_parser/skin_buffer.c
  5. @@ -27,16 +27,50 @@
  6.  #include "skin_buffer.h"
  7.  
  8.  #ifdef ROCKBOX
  9. +# if (CONFIG_PLATFORM&PLATFORM_HOSTED)
  10. +#   define USE_HOST_MALLOC
  11. +# else
  12. +#   define USE_ROCKBOX_ALLOC
  13. +# endif
  14. +#endif
  15. +
  16. +#ifdef USE_ROCKBOX_ALLOC
  17.  static size_t buf_size;
  18.  static unsigned char *buffer_start = NULL;
  19.  static unsigned char *buffer_front = NULL;
  20.  #endif
  21.  
  22. +#ifdef USE_HOST_MALLOC
  23. +
  24. +struct malloc_object {
  25. +    void* object;
  26. +    struct malloc_object *next;
  27. +};
  28. +struct malloc_object *first = NULL, *last = NULL;
  29. +
  30. +void skin_free_malloced(void)
  31. +{
  32. +    struct malloc_object *obj = first, this;
  33. +    while (obj)
  34. +    {
  35. +        this = obj;
  36. +        obj = this->next;
  37. +        free(this->object);
  38. +        free(this->next);
  39. +    }
  40. +    first = NULL;
  41. +    last = NULL;
  42. +}
  43. +
  44. +#endif
  45. +
  46.  void skin_buffer_init(char* buffer, size_t size)
  47.  {
  48. -#if defined(ROCKBOX)
  49. +#ifdef USE_ROCKBOX_ALLOC
  50.      buffer_start = buffer_front = buffer;
  51.      buf_size = size;
  52. +#elif defined(USE_HOST_MALLOC)
  53. +    skin_free_malloced();    
  54.  #endif
  55.  }
  56.  
  57. @@ -44,13 +78,22 @@ void skin_buffer_init(char* buffer, size_t size)
  58.  void* skin_buffer_alloc(size_t size)
  59.  {
  60.      void *retval = NULL;
  61. -#ifdef ROCKBOX
  62. +#ifdef USE_ROCKBOX_ALLOC
  63.      /* 32-bit aligned */
  64.      size = (size + 3) & ~3;
  65.      if (size > skin_buffer_freespace())
  66.          return NULL;
  67.      retval = buffer_front;
  68.      buffer_front += size;
  69. +#elif defined(USE_HOST_MALLOC)
  70. +    struct malloc_object *obj = malloc(sizeof (struct malloc_object));
  71. +    obj->object = malloc(size);
  72. +    obj->next = NULL;
  73. +    if (last == NULL)
  74. +        first = last = obj;
  75. +    else
  76. +        last->next = obj;
  77. +    retval = obj->object;
  78.  #else
  79.      retval = malloc(size);
  80.  #endif
  81. @@ -58,7 +101,7 @@ void* skin_buffer_alloc(size_t size)
  82.  }
  83.  
  84.  
  85. -#ifdef ROCKBOX
  86. +#ifdef USE_ROCKBOX_ALLOC
  87.  /* get the number of bytes currently being used */
  88.  size_t skin_buffer_usage(void)
  89.  {
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×