diff options
Diffstat (limited to 'avahi-common')
-rw-r--r-- | avahi-common/Makefile.am | 2 | ||||
-rw-r--r-- | avahi-common/address.c | 16 | ||||
-rw-r--r-- | avahi-common/gccmacro.h | 9 | ||||
-rw-r--r-- | avahi-common/malloc.h | 20 | ||||
-rw-r--r-- | avahi-common/thread-watch.c | 26 |
5 files changed, 42 insertions, 31 deletions
diff --git a/avahi-common/Makefile.am b/avahi-common/Makefile.am index b00cd78..b4bc917 100644 --- a/avahi-common/Makefile.am +++ b/avahi-common/Makefile.am @@ -71,7 +71,7 @@ libavahi_common_la_SOURCES = \ i18n.c i18n.h libavahi_common_la_CFLAGS = $(AM_CFLAGS) $(PTHREAD_CFLAGS) -DAVAHI_LOCALEDIR=\"$(avahilocaledir)\" -libavahi_common_la_LIBADD = $(AM_LDADD) $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) +libavahi_common_la_LIBADD = $(AM_LDADD) $(PTHREAD_CFLAGS) $(PTHREAD_LIBS) $(LIBINTL) libavahi_common_la_LDFLAGS = $(AM_LDFLAGS) -version-info $(LIBAVAHI_COMMON_VERSION_INFO) strlst_test_SOURCES = \ diff --git a/avahi-common/address.c b/avahi-common/address.c index c8ddf7f..270292c 100644 --- a/avahi-common/address.c +++ b/avahi-common/address.c @@ -2,17 +2,17 @@ /*** This file is part of avahi. - + avahi 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.1 of the License, or (at your option) any later version. - + avahi 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 Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -48,7 +48,7 @@ static size_t address_get_size(const AvahiAddress *a) { int avahi_address_cmp(const AvahiAddress *a, const AvahiAddress *b) { assert(a); assert(b); - + if (a->proto != b->proto) return -1; @@ -59,10 +59,10 @@ char *avahi_address_snprint(char *s, size_t length, const AvahiAddress *a) { assert(s); assert(length); assert(a); - + if (!(inet_ntop(avahi_proto_to_af(a->proto), a->data.data, s, length))) return NULL; - + return s; } @@ -119,10 +119,10 @@ AvahiAddress *avahi_address_parse(const char *s, AvahiProtocol proto, AvahiAddre } else { if (inet_pton(avahi_proto_to_af(proto), s, ret_addr->data.data) <= 0) return NULL; - + ret_addr->proto = proto; } - + return ret_addr; } diff --git a/avahi-common/gccmacro.h b/avahi-common/gccmacro.h index 78a09a7..dd49502 100644 --- a/avahi-common/gccmacro.h +++ b/avahi-common/gccmacro.h @@ -28,6 +28,15 @@ AVAHI_C_DECL_BEGIN +#if defined(__GNUC__) && (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 3) +#define AVAHI_GCC_ALLOC_SIZE(x) __attribute__ ((__alloc_size__(x))) +#define AVAHI_GCC_ALLOC_SIZE2(x,y) __attribute__ ((__alloc_size__(x,y))) +#else +/** Macro for usage of GCC's alloc_size attribute */ +#define AVAHI_GCC_ALLOC_SIZE(x) +#define AVAHI_GCC_ALLOC_SIZE2(x,y) +#endif + #if defined(__GNUC__) && (__GNUC__ >= 4) #define AVAHI_GCC_SENTINEL __attribute__ ((sentinel)) #else diff --git a/avahi-common/malloc.h b/avahi-common/malloc.h index 2430199..511b51c 100644 --- a/avahi-common/malloc.h +++ b/avahi-common/malloc.h @@ -35,19 +35,19 @@ AVAHI_C_DECL_BEGIN /** Allocate some memory, just like the libc malloc() */ -void *avahi_malloc(size_t size); +void *avahi_malloc(size_t size) AVAHI_GCC_ALLOC_SIZE(1); /** Similar to avahi_malloc() but set the memory to zero */ -void *avahi_malloc0(size_t size); +void *avahi_malloc0(size_t size) AVAHI_GCC_ALLOC_SIZE(1); /** Free some memory */ void avahi_free(void *p); /** Similar to libc's realloc() */ -void *avahi_realloc(void *p, size_t size); +void *avahi_realloc(void *p, size_t size) AVAHI_GCC_ALLOC_SIZE(2); /** Internal helper for avahi_new() */ -static inline void* avahi_new_internal(unsigned n, size_t k) { +static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new_internal(unsigned n, size_t k) { assert(n < INT_MAX/k); return avahi_malloc(n*k); } @@ -56,7 +56,7 @@ static inline void* avahi_new_internal(unsigned n, size_t k) { #define avahi_new(type, n) ((type*) avahi_new_internal((n), sizeof(type))) /** Internal helper for avahi_new0() */ -static inline void* avahi_new0_internal(unsigned n, size_t k) { +static inline void* AVAHI_GCC_ALLOC_SIZE2(1,2) avahi_new0_internal(unsigned n, size_t k) { assert(n < INT_MAX/k); return avahi_malloc0(n*k); } @@ -71,14 +71,14 @@ char *avahi_strdup(const char *s); char *avahi_strndup(const char *s, size_t l); /** Duplicate the given memory block into a new one allocated with avahi_malloc() */ -void *avahi_memdup(const void *s, size_t l); +void *avahi_memdup(const void *s, size_t l) AVAHI_GCC_ALLOC_SIZE(2); /** Wraps allocator functions */ typedef struct AvahiAllocator { - void* (*malloc)(size_t size); - void (*free)(void *p); - void* (*realloc)(void *p, size_t size); - void* (*calloc)(size_t nmemb, size_t size); /**< May be NULL */ + void* (*malloc)(size_t size) AVAHI_GCC_ALLOC_SIZE(1); + void (*free)(void *p); + void* (*realloc)(void *p, size_t size) AVAHI_GCC_ALLOC_SIZE(2); + void* (*calloc)(size_t nmemb, size_t size) AVAHI_GCC_ALLOC_SIZE2(1,2); /**< May be NULL */ } AvahiAllocator; /** Change the allocator. May be NULL to return to default (libc) diff --git a/avahi-common/thread-watch.c b/avahi-common/thread-watch.c index 1a5d9d2..4f23608 100644 --- a/avahi-common/thread-watch.c +++ b/avahi-common/thread-watch.c @@ -2,17 +2,17 @@ /*** This file is part of avahi. - + avahi 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.1 of the License, or (at your option) any later version. - + avahi 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 Lesser General Public License for more details. - + You should have received a copy of the GNU Lesser General Public License along with avahi; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 @@ -53,7 +53,7 @@ static int poll_func(struct pollfd *ufds, unsigned int nfds, int timeout, void * /* Before entering poll() we unlock the mutex, so that * avahi_simple_poll_quit() can succeed from another thread. */ - + pthread_mutex_unlock(mutex); r = poll(ufds, nfds, timeout); pthread_mutex_lock(mutex); @@ -68,11 +68,11 @@ static void* thread(void *userdata){ /* Make sure that signals are delivered to the main thread */ sigfillset(&mask); pthread_sigmask(SIG_BLOCK, &mask, NULL); - + pthread_mutex_lock(&p->mutex); p->retval = avahi_simple_poll_loop(p->simple_poll); pthread_mutex_unlock(&p->mutex); - + return NULL; } @@ -81,14 +81,14 @@ AvahiThreadedPoll *avahi_threaded_poll_new(void) { if (!(p = avahi_new(AvahiThreadedPoll, 1))) goto fail; /* OOM */ - + if (!(p->simple_poll = avahi_simple_poll_new())) goto fail; - + pthread_mutex_init(&p->mutex, NULL); avahi_simple_poll_set_func(p->simple_poll, poll_func, &p->mutex); - + p->thread_running = 0; return p; @@ -136,6 +136,8 @@ int avahi_threaded_poll_start(AvahiThreadedPoll *p) { if (pthread_create(&p->thread_id, NULL, thread, p) < 0) return -1; + p->thread_running = 1; + return 0; } @@ -151,7 +153,7 @@ int avahi_threaded_poll_stop(AvahiThreadedPoll *p) { pthread_mutex_lock(&p->mutex); avahi_simple_poll_quit(p->simple_poll); pthread_mutex_unlock(&p->mutex); - + pthread_join(p->thread_id, NULL); p->thread_running = 0; @@ -172,7 +174,7 @@ void avahi_threaded_poll_lock(AvahiThreadedPoll *p) { /* Make sure that this function is not called from the helper thread */ assert(!p->thread_running || !pthread_equal(pthread_self(), p->thread_id)); - + pthread_mutex_lock(&p->mutex); } @@ -181,6 +183,6 @@ void avahi_threaded_poll_unlock(AvahiThreadedPoll *p) { /* Make sure that this function is not called from the helper thread */ assert(!p->thread_running || !pthread_equal(pthread_self(), p->thread_id)); - + pthread_mutex_unlock(&p->mutex); } |