Move xmalloc to the public side (libpolyp).

git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@908 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
Pierre Ossman 2006-05-17 16:34:18 +00:00
parent cdd3588f3a
commit d9cc2cfcb9
105 changed files with 193 additions and 109 deletions

View file

@ -22,7 +22,8 @@
#include <assert.h>
#include <string.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include <polypcore/props.h>
#include <polypcore/log.h>

View file

@ -27,8 +27,9 @@
#include <stdlib.h>
#include <string.h>
#include <polyp/xmalloc.h>
#include <polypcore/module.h>
#include <polypcore/xmalloc.h>
#include <polypcore/memchunk.h>
#include <polypcore/sound-file.h>
#include <polypcore/log.h>

View file

@ -29,6 +29,8 @@
#include <stdlib.h>
#include <errno.h>
#include <polyp/xmalloc.h>
#include <polypcore/module.h>
#include <polypcore/sink.h>
#include <polypcore/source.h>
@ -44,7 +46,6 @@
#include <polypcore/sound-file.h>
#include <polypcore/play-memchunk.h>
#include <polypcore/autoload.h>
#include <polypcore/xmalloc.h>
#include <polypcore/sound-file-stream.h>
#include <polypcore/props.h>
#include <polypcore/util.h>

View file

@ -27,6 +27,8 @@
#include <string.h>
#include <polyp/volume.h>
#include <polyp/xmalloc.h>
#include <polypcore/module.h>
#include <polypcore/client.h>
#include <polypcore/sink.h>
@ -37,7 +39,6 @@
#include <polypcore/sample-util.h>
#include <polypcore/core-scache.h>
#include <polypcore/autoload.h>
#include <polypcore/xmalloc.h>
#include "cli-text.h"

View file

@ -28,6 +28,8 @@
#include <assert.h>
#include <stdlib.h>
#include <polyp/xmalloc.h>
#include <polypcore/ioline.h>
#include <polypcore/module.h>
#include <polypcore/sink.h>
@ -40,7 +42,6 @@
#include <polypcore/namereg.h>
#include <polypcore/cli-text.h>
#include <polypcore/cli-command.h>
#include <polypcore/xmalloc.h>
#include <polypcore/log.h>
#include "cli.h"

View file

@ -28,7 +28,8 @@
#include <stdlib.h>
#include <string.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include <polypcore/core-subscribe.h>
#include <polypcore/log.h>

View file

@ -28,9 +28,10 @@
#include <stdio.h>
#include <errno.h>
#include <polyp/xmalloc.h>
#include <polypcore/log.h>
#include <polypcore/util.h>
#include <polypcore/xmalloc.h>
#include "conf-parser.h"

View file

@ -44,10 +44,11 @@
#include <polyp/mainloop.h>
#include <polyp/channelmap.h>
#include <polyp/volume.h>
#include <polyp/xmalloc.h>
#include <polypcore/sink-input.h>
#include <polypcore/sample-util.h>
#include <polypcore/play-memchunk.h>
#include <polypcore/xmalloc.h>
#include <polypcore/core-subscribe.h>
#include <polypcore/namereg.h>
#include <polypcore/sound-file.h>

View file

@ -26,8 +26,9 @@
#include <stdio.h>
#include <assert.h>
#include <polyp/xmalloc.h>
#include <polypcore/queue.h>
#include <polypcore/xmalloc.h>
#include <polypcore/log.h>
#include "core-subscribe.h"

View file

@ -28,6 +28,8 @@
#include <stdio.h>
#include <signal.h>
#include <polyp/xmalloc.h>
#include <polypcore/module.h>
#include <polypcore/sink.h>
#include <polypcore/source.h>
@ -35,7 +37,6 @@
#include <polypcore/util.h>
#include <polypcore/core-scache.h>
#include <polypcore/autoload.h>
#include <polypcore/xmalloc.h>
#include <polypcore/core-subscribe.h>
#include <polypcore/props.h>
#include <polypcore/random.h>

View file

@ -27,7 +27,7 @@
#include <assert.h>
#include <stdlib.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include "dynarray.h"

View file

@ -27,8 +27,9 @@
#include <assert.h>
#include <string.h>
#include <polyp/xmalloc.h>
#include <polypcore/idxset.h>
#include <polypcore/xmalloc.h>
#include <polypcore/log.h>
#include "hashmap.h"

View file

@ -28,7 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include "idxset.h"

View file

@ -38,9 +38,10 @@
#include "winsock.h"
#include <polyp/xmalloc.h>
#include <polypcore/util.h>
#include <polypcore/socket-util.h>
#include <polypcore/xmalloc.h>
#include <polypcore/log.h>
#include "iochannel.h"

View file

@ -29,7 +29,8 @@
#include <stdlib.h>
#include <string.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include <polypcore/log.h>
#include "ioline.h"

View file

@ -33,7 +33,8 @@
#include <syslog.h>
#endif
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include <polypcore/util.h>
#include "log.h"

View file

@ -28,7 +28,7 @@
#include <assert.h>
#include <string.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include "mcalign.h"

View file

@ -28,7 +28,7 @@
#include <assert.h>
#include <string.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include "memblock.h"

View file

@ -30,7 +30,8 @@
#include <stdlib.h>
#include <string.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include <polypcore/log.h>
#include <polypcore/mcalign.h>

View file

@ -28,7 +28,7 @@
#include <assert.h>
#include <string.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include "memchunk.h"

View file

@ -28,13 +28,14 @@
#include <stdlib.h>
#include <string.h>
#include <polyp/xmalloc.h>
#include <polypcore/hashmap.h>
#include <polypcore/idxset.h>
#include <polypcore/sample-util.h>
#include <polypcore/namereg.h>
#include <polypcore/sink.h>
#include <polypcore/source.h>
#include <polypcore/xmalloc.h>
#include <polypcore/util.h>
#include "modargs.h"

View file

@ -26,7 +26,8 @@
#include <ltdl.h>
#include <assert.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include <polypcore/util.h>
#include <polypcore/log.h>

View file

@ -30,7 +30,8 @@
#include <string.h>
#include <errno.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include <polypcore/core-subscribe.h>
#include <polypcore/log.h>
#include <polypcore/util.h>

View file

@ -29,10 +29,11 @@
#include <string.h>
#include <stdio.h>
#include <polyp/xmalloc.h>
#include <polypcore/autoload.h>
#include <polypcore/source.h>
#include <polypcore/sink.h>
#include <polypcore/xmalloc.h>
#include <polypcore/core-subscribe.h>
#include <polypcore/util.h>

View file

@ -26,7 +26,7 @@
#include <assert.h>
#include <stdlib.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include "packet.h"

View file

@ -27,7 +27,8 @@
#include <assert.h>
#include <stdlib.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include <polypcore/util.h>
#include "parseaddr.h"

View file

@ -27,8 +27,9 @@
#include <stdlib.h>
#include <assert.h>
#include <polyp/xmalloc.h>
#include <polypcore/native-common.h>
#include <polypcore/xmalloc.h>
#include <polypcore/llist.h>
#include <polypcore/log.h>
#include <polypcore/util.h>

View file

@ -39,9 +39,10 @@
#include <windows.h>
#endif
#include <polyp/xmalloc.h>
#include <polypcore/util.h>
#include <polypcore/log.h>
#include <polypcore/xmalloc.h>
#include "pid.h"

View file

@ -28,8 +28,9 @@
#include <stdio.h>
#include <string.h>
#include <polyp/xmalloc.h>
#include <polypcore/sink-input.h>
#include <polypcore/xmalloc.h>
#include <polypcore/gccmacro.h>
#include "play-memchunk.h"

View file

@ -21,7 +21,8 @@
#include <assert.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include <polypcore/log.h>
#include "props.h"

View file

@ -26,8 +26,9 @@
#include <assert.h>
#include <stdlib.h>
#include <polyp/xmalloc.h>
#include <polypcore/cli.h>
#include <polypcore/xmalloc.h>
#include <polypcore/log.h>
#include "protocol-cli.h"

View file

@ -31,6 +31,8 @@
#include <limits.h>
#include <polyp/sample.h>
#include <polyp/xmalloc.h>
#include <polypcore/esound.h>
#include <polypcore/memblock.h>
#include <polypcore/client.h>
@ -42,7 +44,6 @@
#include <polypcore/sample-util.h>
#include <polypcore/authkey.h>
#include <polypcore/namereg.h>
#include <polypcore/xmalloc.h>
#include <polypcore/log.h>
#include <polypcore/util.h>
#include <polypcore/utf8.h>

View file

@ -28,8 +28,9 @@
#include <stdio.h>
#include <string.h>
#include <polyp/xmalloc.h>
#include <polypcore/ioline.h>
#include <polypcore/xmalloc.h>
#include <polypcore/log.h>
#include <polypcore/namereg.h>
#include <polypcore/cli-text.h>

View file

@ -30,6 +30,7 @@
#include <unistd.h>
#include <polyp/version.h>
#include <polyp/xmalloc.h>
#include <polypcore/native-common.h>
#include <polypcore/packet.h>
@ -43,7 +44,6 @@
#include <polypcore/authkey.h>
#include <polypcore/namereg.h>
#include <polypcore/core-scache.h>
#include <polypcore/xmalloc.h>
#include <polypcore/util.h>
#include <polypcore/core-subscribe.h>
#include <polypcore/log.h>

View file

@ -30,12 +30,13 @@
#include <errno.h>
#include <string.h>
#include <polyp/xmalloc.h>
#include <polypcore/sink-input.h>
#include <polypcore/source-output.h>
#include <polypcore/client.h>
#include <polypcore/sample-util.h>
#include <polypcore/namereg.h>
#include <polypcore/xmalloc.h>
#include <polypcore/log.h>
#include "protocol-simple.h"

View file

@ -34,8 +34,9 @@
#include "winsock.h"
#include <polyp/xmalloc.h>
#include <polypcore/queue.h>
#include <polypcore/xmalloc.h>
#include <polypcore/log.h>
#include <polypcore/core-scache.h>

View file

@ -26,7 +26,7 @@
#include <assert.h>
#include <stdlib.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include "queue.h"

View file

@ -30,8 +30,9 @@
#include <liboil/liboilfuncs.h>
#include <liboil/liboil.h>
#include <polyp/xmalloc.h>
#include <polypcore/sconv.h>
#include <polypcore/xmalloc.h>
#include <polypcore/log.h>
#include "resampler.h"

View file

@ -28,8 +28,9 @@
#include <stdlib.h>
#include <string.h>
#include <polyp/xmalloc.h>
#include <polypcore/sample-util.h>
#include <polypcore/xmalloc.h>
#include <polypcore/core-subscribe.h>
#include <polypcore/log.h>
#include <polypcore/utf8.h>

View file

@ -29,12 +29,12 @@
#include <stdio.h>
#include <polyp/introspect.h>
#include <polyp/xmalloc.h>
#include <polypcore/sink-input.h>
#include <polypcore/namereg.h>
#include <polypcore/util.h>
#include <polypcore/sample-util.h>
#include <polypcore/xmalloc.h>
#include <polypcore/core-subscribe.h>
#include <polypcore/log.h>
#include <polypcore/utf8.h>

View file

@ -54,9 +54,10 @@
#include "winsock.h"
#include <polyp/xmalloc.h>
#include <polypcore/socket-util.h>
#include <polypcore/util.h>
#include <polypcore/xmalloc.h>
#include <polypcore/log.h>
#include <polypcore/parseaddr.h>

View file

@ -62,8 +62,9 @@
#include "winsock.h"
#include <polyp/xmalloc.h>
#include <polypcore/socket-util.h>
#include <polypcore/xmalloc.h>
#include <polypcore/util.h>
#include <polypcore/log.h>

View file

@ -59,8 +59,9 @@
#include "winsock.h"
#include <polyp/xmalloc.h>
#include <polypcore/util.h>
#include <polypcore/xmalloc.h>
#include <polypcore/log.h>
#include "socket-util.h"

View file

@ -30,8 +30,9 @@
#include <sndfile.h>
#include <polyp/xmalloc.h>
#include <polypcore/sink-input.h>
#include <polypcore/xmalloc.h>
#include <polypcore/log.h>
#include "sound-file-stream.h"

View file

@ -28,7 +28,8 @@
#include <stdlib.h>
#include <string.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include <polypcore/core-subscribe.h>
#include <polypcore/log.h>
#include <polypcore/utf8.h>

View file

@ -28,9 +28,10 @@
#include <stdlib.h>
#include <string.h>
#include <polyp/xmalloc.h>
#include <polypcore/source-output.h>
#include <polypcore/namereg.h>
#include <polypcore/xmalloc.h>
#include <polypcore/core-subscribe.h>
#include <polypcore/log.h>
#include <polypcore/sample-util.h>

View file

@ -30,7 +30,7 @@
#include <stdarg.h>
#include <stdio.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include "strbuf.h"

View file

@ -26,7 +26,8 @@
#include <string.h>
#include <assert.h>
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include <polypcore/strbuf.h>
#include <polypcore/util.h>

View file

@ -36,7 +36,7 @@
#include "winsock.h"
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include "tagstruct.h"

View file

@ -27,8 +27,9 @@
#include <assert.h>
#include <stdlib.h>
#include <polyp/xmalloc.h>
#include <polypcore/dynarray.h>
#include <polypcore/xmalloc.h>
#include <polypcore/gccmacro.h>
#include "tokenizer.h"

View file

@ -33,8 +33,9 @@
#include <inttypes.h>
#include <string.h>
#include <polyp/xmalloc.h>
#include "utf8.h"
#include "xmalloc.h"
#define FILTER_CHAR '_'

View file

@ -70,7 +70,8 @@
#include "winsock.h"
#include <polypcore/xmalloc.h>
#include <polyp/xmalloc.h>
#include <polypcore/log.h>
#include "util.h"

View file

@ -22,8 +22,9 @@
#include <assert.h>
#include <stdio.h>
#include <polyp/xmalloc.h>
#include <polypcore/llist.h>
#include <polypcore/xmalloc.h>
#include <polypcore/log.h>
#include <polypcore/props.h>

View file

@ -1,123 +0,0 @@
/* $Id$ */
/***
This file is part of polypaudio.
polypaudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 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.
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.
***/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <signal.h>
#include <assert.h>
#include <unistd.h>
#include <string.h>
#include <polypcore/util.h>
#include <polypcore/gccmacro.h>
#include "xmalloc.h"
/* Make sure not to allocate more than this much memory. */
#define MAX_ALLOC_SIZE (1024*1024*20) /* 20MB */
/* #undef malloc */
/* #undef free */
/* #undef realloc */
/* #undef strndup */
/* #undef strdup */
static void oom(void) PA_GCC_NORETURN;
/** called in case of an OOM situation. Prints an error message and
* exits */
static void oom(void) {
static const char e[] = "Not enough memory\n";
pa_loop_write(STDERR_FILENO, e, sizeof(e)-1);
#ifdef SIGQUIT
raise(SIGQUIT);
#endif
_exit(1);
}
void* pa_xmalloc(size_t size) {
void *p;
assert(size > 0);
assert(size < MAX_ALLOC_SIZE);
if (!(p = malloc(size)))
oom();
return p;
}
void* pa_xmalloc0(size_t size) {
void *p;
assert(size > 0);
assert(size < MAX_ALLOC_SIZE);
if (!(p = calloc(1, size)))
oom();
return p;
}
void *pa_xrealloc(void *ptr, size_t size) {
void *p;
assert(size > 0);
assert(size < MAX_ALLOC_SIZE);
if (!(p = realloc(ptr, size)))
oom();
return p;
}
void* pa_xmemdup(const void *p, size_t l) {
if (!p)
return NULL;
else {
char *r = pa_xmalloc(l);
memcpy(r, p, l);
return r;
}
}
char *pa_xstrdup(const char *s) {
if (!s)
return NULL;
return pa_xmemdup(s, strlen(s)+1);
}
char *pa_xstrndup(const char *s, size_t l) {
if (!s)
return NULL;
else {
char *r;
size_t t = strlen(s);
if (t > l)
t = l;
r = pa_xmemdup(s, t+1);
r[t] = 0;
return r;
}
}

View file

@ -1,58 +0,0 @@
#ifndef foomemoryhfoo
#define foomemoryhfoo
/* $Id$ */
/***
This file is part of polypaudio.
polypaudio is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published
by the Free Software Foundation; either version 2 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.
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 <sys/types.h>
#include <stdlib.h>
#include <limits.h>
#include <assert.h>
void* pa_xmalloc(size_t l);
void *pa_xmalloc0(size_t l);
void *pa_xrealloc(void *ptr, size_t size);
#define pa_xfree free
char *pa_xstrdup(const char *s);
char *pa_xstrndup(const char *s, size_t l);
void* pa_xmemdup(const void *p, size_t l);
/** Internal helper for pa_xnew() */
static inline void* pa_xnew_internal(unsigned n, size_t k) {
assert(n < INT_MAX/k);
return pa_xmalloc(n*k);
}
/** Allocate n new structures of the specified type. */
#define pa_xnew(type, n) ((type*) pa_xnew_internal((n), sizeof(type)))
/** Internal helper for pa_xnew0() */
static inline void* pa_xnew0_internal(unsigned n, size_t k) {
assert(n < INT_MAX/k);
return pa_xmalloc0(n*k);
}
/** Same as pa_xnew() but set the memory to zero */
#define pa_xnew0(type, n) ((type*) pa_xnew0_internal((n), sizeof(type)))
#endif