From c65a1c3ad8225b68165d0c751466dea1b9eccc4f Mon Sep 17 00:00:00 2001 From: ddennedy Date: Wed, 30 May 2007 05:11:30 +0000 Subject: [PATCH] Apply patch from Jon Schewe to make valgrind happy. Adds --with-valgrind configure option. git-svn-id: svn://svn.linux1394.org/libraw1394/trunk@172 53a565d1-3bb7-0310-b661-cf11e63c67ab --- configure.ac | 5 +++++ src/readwrite.c | 30 ++++++++++++++++++++++++++---- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index fe23ca8..fe9ffcd 100644 --- a/configure.ac +++ b/configure.ac @@ -24,6 +24,11 @@ AC_SUBST(lt_major) AC_SUBST(lt_revision) AC_SUBST(lt_age) +dnl Check to see if valgrind is available +AC_ARG_WITH(valgrind, AC_HELP_STRING([--with-valgrind],[compile with valgrind support])) +if test x$with_valgrind = xyes ; then + AC_CHECK_HEADERS(valgrind/valgrind.h) +fi #CFLAGS=${CFLAGS:-"-Wall"} AC_OUTPUT([ diff --git a/src/readwrite.c b/src/readwrite.c index 8f5948d..2ad147c 100644 --- a/src/readwrite.c +++ b/src/readwrite.c @@ -30,6 +30,15 @@ #include "kernel-raw1394.h" #include "raw1394_private.h" +#if HAVE_VALGRIND_VALGRIND_H +# include +# ifndef VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE +#  define VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(m, n) do {} while(0) +# endif +#else +# define VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(m, n) do {} while(0) +#endif + int raw1394_start_read(struct raw1394_handle *handle, nodeid_t node, nodeaddr_t addr, size_t length, quadlet_t *buffer, @@ -218,13 +227,16 @@ int raw1394_start_async_send(struct raw1394_handle *handle, &sd }; \ int err = 0 -#define SYNCFUNC_BODY \ +#define SYNCFUNC_BODY_WO_RETURN \ while (!sd.done) { \ if (err < 0) return err; \ err = raw1394_loop_iterate(handle); \ } \ handle->err = sd.errcode; \ - errno = raw1394_errcode_to_errno(sd.errcode); \ + errno = raw1394_errcode_to_errno(sd.errcode); + +#define SYNCFUNC_BODY \ + SYNCFUNC_BODY_WO_RETURN \ return (errno ? -1 : 0) int raw1394_read(struct raw1394_handle *handle, nodeid_t node, nodeaddr_t addr, @@ -235,7 +247,12 @@ int raw1394_read(struct raw1394_handle *handle, nodeid_t node, nodeaddr_t addr, err = raw1394_start_read(handle, node, addr, length, buffer, (unsigned long)&rh); - SYNCFUNC_BODY; + SYNCFUNC_BODY_WO_RETURN; + if(!errno) { + VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(buffer, length); + } + + return (errno ? -1 : 0); } int raw1394_write(struct raw1394_handle *handle, nodeid_t node, nodeaddr_t addr, @@ -258,7 +275,12 @@ int raw1394_lock(struct raw1394_handle *handle, nodeid_t node, nodeaddr_t addr, err = raw1394_start_lock(handle, node, addr, extcode, data, arg, result, (unsigned long)&rh); - SYNCFUNC_BODY; + SYNCFUNC_BODY_WO_RETURN; + if(!errno) { + VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(result, sizeof(quadlet_t)); + } + + return (errno ? -1 : 0); } int raw1394_lock64(struct raw1394_handle *handle, nodeid_t node, nodeaddr_t addr,