[pulseaudio-commits] r1535 - /branches/lennart/src/pulsecore/strbuf.c

svnmailer-noreply at 0pointer.de svnmailer-noreply at 0pointer.de
Wed Jul 25 09:33:58 PDT 2007


Author: lennart
Date: Wed Jul 25 18:33:56 2007
New Revision: 1535

URL: http://0pointer.de/cgi-bin/viewcvs.cgi?rev=3D1535&root=3Dpulseaudio&vi=
ew=3Drev
Log:
fix some alignment issues and modernize file a little bit

Modified:
    branches/lennart/src/pulsecore/strbuf.c

Modified: branches/lennart/src/pulsecore/strbuf.c
URL: http://0pointer.de/cgi-bin/viewcvs.cgi/branches/lennart/src/pulsecore/=
strbuf.c?rev=3D1535&root=3Dpulseaudio&r1=3D1534&r2=3D1535&view=3Ddiff
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- branches/lennart/src/pulsecore/strbuf.c (original)
+++ branches/lennart/src/pulsecore/strbuf.c Wed Jul 25 18:33:56 2007
@@ -27,12 +27,12 @@
 =

 #include <sys/types.h>
 #include <stdlib.h>
-#include <assert.h>
 #include <string.h>
 #include <stdarg.h>
 #include <stdio.h>
 =

 #include <pulse/xmalloc.h>
+#include <pulsecore/macro.h>
 =

 #include "strbuf.h"
 =

@@ -42,7 +42,7 @@
     size_t length;
 };
 =

-#define CHUNK_TO_TEXT(c) ((char*) (c) + sizeof(struct chunk))
+#define CHUNK_TO_TEXT(c) ((char*) (c) + PA_ALIGN(sizeof(struct chunk)))
 =

 struct pa_strbuf {
     size_t length;
@@ -50,14 +50,17 @@
 };
 =

 pa_strbuf *pa_strbuf_new(void) {
-    pa_strbuf *sb =3D pa_xmalloc(sizeof(pa_strbuf));
+    =

+    pa_strbuf *sb =3D pa_xnew(pa_strbuf, 1);
     sb->length =3D 0;
     sb->head =3D sb->tail =3D NULL;
+    =

     return sb;
 }
 =

 void pa_strbuf_free(pa_strbuf *sb) {
-    assert(sb);
+    pa_assert(sb);
+    =

     while (sb->head) {
         struct chunk *c =3D sb->head;
         sb->head =3D sb->head->next;
@@ -72,9 +75,10 @@
 char *pa_strbuf_tostring(pa_strbuf *sb) {
     char *t, *e;
     struct chunk *c;
-    assert(sb);
+    =

+    pa_assert(sb);
 =

-    e =3D t =3D pa_xmalloc(sb->length+1);
+    e =3D t =3D pa_xnew(char, sb->length+1);
 =

     for (c =3D sb->head; c; c =3D c->next) {
         assert((size_t) (e-t) <=3D sb->length);
@@ -93,27 +97,33 @@
 /* Combination of pa_strbuf_free() and pa_strbuf_tostring() */
 char *pa_strbuf_tostring_free(pa_strbuf *sb) {
     char *t;
-    assert(sb);
+    =

+    pa_assert(sb);
     t =3D pa_strbuf_tostring(sb);
     pa_strbuf_free(sb);
+    =

     return t;
 }
 =

 /* Append a string to the string buffer */
 void pa_strbuf_puts(pa_strbuf *sb, const char *t) {
-    assert(sb && t);
+    =

+    pa_assert(sb);
+    pa_assert(t);
+    =

     pa_strbuf_putsn(sb, t, strlen(t));
 }
 =

 /* Append a new chunk to the linked list */
 static void append(pa_strbuf *sb, struct chunk *c) {
-    assert(sb && c);
+    pa_assert(sb);
+    pa_assert(c);
 =

     if (sb->tail) {
-        assert(sb->head);
+        pa_assert(sb->head);
         sb->tail->next =3D c;
     } else {
-        assert(!sb->head);
+        pa_assert(!sb->head);
         sb->head =3D c;
     }
 =

@@ -125,12 +135,14 @@
 /* Append up to l bytes of a string to the string buffer */
 void pa_strbuf_putsn(pa_strbuf *sb, const char *t, size_t l) {
     struct chunk *c;
-    assert(sb && t);
+    =

+    pa_assert(sb);
+    pa_assert(t);
 =

     if (!l)
        return;
 =

-    c =3D pa_xmalloc(sizeof(struct chunk)+l);
+    c =3D pa_xmalloc(PA_ALIGN(sizeof(struct chunk)) + l);
     c->length =3D l;
     memcpy(CHUNK_TO_TEXT(c), t, l);
 =

@@ -143,13 +155,14 @@
     int size =3D 100;
     struct chunk *c =3D NULL;
 =

-    assert(sb);
+    pa_assert(sb);
+    pa_assert(format);
 =

     for(;;) {
         va_list ap;
         int r;
 =

-        c =3D pa_xrealloc(c, sizeof(struct chunk)+size);
+        c =3D pa_xrealloc(c, PA_ALIGN(sizeof(struct chunk)) + size);
 =

         va_start(ap, format);
         r =3D vsnprintf(CHUNK_TO_TEXT(c), size, format, ap);




More information about the pulseaudio-commits mailing list