]> code.delx.au - pulseaudio/blobdiff - polyp/memchunk.c
Make the whole stuff LGPL only
[pulseaudio] / polyp / memchunk.c
index d27ca61aa12a943e7644217ead31e83871703882..a8aeb881ea070add4e34b85428a2efda835a2d9c 100644 (file)
@@ -4,17 +4,17 @@
   This file is part of polypaudio.
  
   polypaudio is free software; you can redistribute it and/or modify
-  it under the terms of the GNU General Public License as published
-  by the Free Software Foundation; either version 2 of the License,
-  or (at your option) any later version.
+  it under the terms of the GNU Lesser General Public License as
+  published by the Free Software Foundation; either version 2.1 of the
+  License, or (at your option) any later version.
  
   polypaudio is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  General Public License for more details.
+  Lesser General Public License for more details.
  
-  You should have received a copy of the GNU General Public License
-  along with polypaudio; if not, write to the Free Software
+  You should have received a copy of the GNU Lesser General Public
+  License along with polypaudio; if not, write to the Free Software
   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
   USA.
 ***/
 #include <string.h>
 
 #include "memchunk.h"
+#include "xmalloc.h"
 
-void pa_memchunk_make_writable(struct pa_memchunk *c) {
+void pa_memchunk_make_writable(struct pa_memchunk *c, struct pa_memblock_stat *s) {
     struct pa_memblock *n;
     assert(c && c->memblock && c->memblock->ref >= 1);
 
     if (c->memblock->ref == 1)
         return;
     
-    n = pa_memblock_new(c->length);
+    n = pa_memblock_new(c->length, s);
     assert(n);
-    memcpy(n->data, c->memblock->data+c->index, c->length);
+    memcpy(n->data, (uint8_t*) c->memblock->data+c->index, c->length);
     pa_memblock_unref(c->memblock);
     c->memblock = n;
     c->index = 0;
@@ -51,31 +52,32 @@ struct pa_mcalign {
     struct pa_memchunk chunk;
     uint8_t *buffer;
     size_t buffer_fill;
+    struct pa_memblock_stat *memblock_stat;
 };
 
-struct pa_mcalign *pa_mcalign_new(size_t base) {
+struct pa_mcalign *pa_mcalign_new(size_t base, struct pa_memblock_stat *s) {
     struct pa_mcalign *m;
     assert(base);
 
-    m = malloc(sizeof(struct pa_mcalign));
-    assert(m);
+    m = pa_xmalloc(sizeof(struct pa_mcalign));
     m->base = base;
     m->chunk.memblock = NULL;
     m->chunk.length = m->chunk.index = 0;
     m->buffer = NULL;
     m->buffer_fill = 0;
+    m->memblock_stat = s;
     return m;
 }
 
 void pa_mcalign_free(struct pa_mcalign *m) {
     assert(m);
 
-    free(m->buffer);
+    pa_xfree(m->buffer);
     
     if (m->chunk.memblock)
         pa_memblock_unref(m->chunk.memblock);
     
-    free(m);
+    pa_xfree(m);
 }
 
 void pa_mcalign_push(struct pa_mcalign *m, const struct pa_memchunk *c) {
@@ -86,8 +88,8 @@ void pa_mcalign_push(struct pa_mcalign *m, const struct pa_memchunk *c) {
 }
 
 int pa_mcalign_pop(struct pa_mcalign *m, struct pa_memchunk *c) {
-    assert(m && c && m->base > m->buffer_fill);
     int ret;
+    assert(m && c && m->base > m->buffer_fill);
 
     if (!m->chunk.memblock)
         return -1;
@@ -98,7 +100,7 @@ int pa_mcalign_pop(struct pa_mcalign *m, struct pa_memchunk *c) {
             l = m->chunk.length;
         assert(m->buffer && l);
 
-        memcpy(m->buffer + m->buffer_fill, m->chunk.memblock->data + m->chunk.index, l);
+        memcpy((uint8_t*) m->buffer + m->buffer_fill, (uint8_t*) m->chunk.memblock->data + m->chunk.index, l);
         m->buffer_fill += l;
         m->chunk.index += l;
         m->chunk.length -= l;
@@ -111,7 +113,7 @@ int pa_mcalign_pop(struct pa_mcalign *m, struct pa_memchunk *c) {
 
         assert(m->buffer_fill <= m->base);
         if (m->buffer_fill == m->base) {
-            c->memblock = pa_memblock_new_dynamic(m->buffer, m->base);
+            c->memblock = pa_memblock_new_dynamic(m->buffer, m->base, m->memblock_stat);
             assert(c->memblock);
             c->index = 0;
             c->length = m->base;
@@ -128,10 +130,9 @@ int pa_mcalign_pop(struct pa_mcalign *m, struct pa_memchunk *c) {
 
     if (m->buffer_fill) {
         assert(!m->buffer);
-        m->buffer = malloc(m->base);
-        assert(m->buffer);
+        m->buffer = pa_xmalloc(m->base);
         m->chunk.length -= m->buffer_fill;
-        memcpy(m->buffer, m->chunk.memblock->data + m->chunk.index + m->chunk.length, m->buffer_fill);
+        memcpy(m->buffer, (uint8_t*) m->chunk.memblock->data + m->chunk.index + m->chunk.length, m->buffer_fill);
     }
 
     if (m->chunk.length) {