summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changes7
-rw-r--r--ev.c19
-rw-r--r--ev.pod15
3 files changed, 31 insertions, 10 deletions
diff --git a/Changes b/Changes
index eb03147..7ae2943 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
Revision history for libev, a high-performance and full-featured event loop.
+ - event_base_loopexit should return 0 on success
+ (W.C.A. Wijngaards).
- added linux eventfd support.
- try to autodetect epoll and inotify support
by libc header version if not using autoconf.
@@ -7,8 +9,9 @@ Revision history for libev, a high-performance and full-featured event loop.
- declare functions defined in ev.h as inline if
C99 or gcc are available.
- enable inlining with gcc versions 2 and 3.
- - event_base_loopexit should return 0 on success
- (W.C.A. Wijngaards).
+ - work around a bug in realloc on openbsd and darwin,
+ also makes the errornous valgrind complaints
+ go away (noted by various people).
3.2 Wed Apr 2 17:11:19 CEST 2008
- fix a 64 bit overflow issue in the select backend,
diff --git a/ev.c b/ev.c
index 68adb7e..51a070e 100644
--- a/ev.c
+++ b/ev.c
@@ -362,7 +362,22 @@ syserr (const char *msg)
}
}
-static void *(*alloc)(void *ptr, long size);
+static void *
+ev_realloc_emul (void *ptr, long size)
+{
+ /* some systems, notably openbsd and darwin, fail to properly
+ * implement realloc (x, 0) (as required by both ansi c-98 and
+ * the single unix specification, so work around them here.
+ */
+
+ if (size)
+ return realloc (ptr, size);
+
+ free (ptr);
+ return 0;
+}
+
+static void *(*alloc)(void *ptr, long size) = ev_realloc_emul;
void
ev_set_allocator (void *(*cb)(void *ptr, long size))
@@ -373,7 +388,7 @@ ev_set_allocator (void *(*cb)(void *ptr, long size))
inline_speed void *
ev_realloc (void *ptr, long size)
{
- ptr = alloc ? alloc (ptr, size) : realloc (ptr, size);
+ ptr = alloc (ptr, size);
if (!ptr && size)
{
diff --git a/ev.pod b/ev.pod
index fb837c0..2d60895 100644
--- a/ev.pod
+++ b/ev.pod
@@ -198,18 +198,21 @@ See the description of C<ev_embed> watchers for more info.
=item ev_set_allocator (void *(*cb)(void *ptr, long size))
Sets the allocation function to use (the prototype is similar - the
-semantics is identical - to the realloc C function). It is used to
-allocate and free memory (no surprises here). If it returns zero when
-memory needs to be allocated, the library might abort or take some
-potentially destructive action. The default is your system realloc
-function.
+semantics are identical to the C<realloc> C89/SuS/POSIX function). It is
+used to allocate and free memory (no surprises here). If it returns zero
+when memory needs to be allocated (C<size != 0>), the library might abort
+or take some potentially destructive action.
+
+Since some systems (at least OpenBSD and Darwin) fail to implement
+correct C<realloc> semantics, libev will use a wrapper around the system
+C<realloc> and C<free> functions by default.
You could override this function in high-availability programs to, say,
free some memory if it cannot allocate memory, to use a special allocator,
or even to sleep a while and retry until some memory is available.
Example: Replace the libev allocator with one that waits a bit and then
-retries).
+retries (example requires a standards-compliant C<realloc>).
static void *
persistent_realloc (void *ptr, size_t size)