Fix Windows build errors in valgrind.h

valgrind.h is a verbatim copy taken from Valgrind project. Previously
that file had local changes that got dropped by last update. To avoid
regressing again, do not edit valgrind.h anymore and instead add a
gvalgrind.h wrapper that gets included instead.

This fix 2 errors:
- uintptr_t is not defined when including valgrind.h on mingw.
- MSVC compiler is not supported on amd64-Win64 platform.
This commit is contained in:
Xavier Claessens 2018-05-25 21:30:57 -04:00
parent f9dc091e37
commit 707106c7a5
5 changed files with 46 additions and 3 deletions

View File

@ -188,6 +188,7 @@ libglib_2_0_la_SOURCES = \
gurifuncs.c \
gutils.c \
guuid.c \
gvalgrind.h \
gvariant.h \
gvariant.c \
gvariant-core.h \

View File

@ -52,7 +52,7 @@
#include "glib_trace.h"
#include "gprintf.h"
#include "valgrind.h"
#include "gvalgrind.h"
/**
* SECTION:memory_slices
@ -389,8 +389,10 @@ slice_config_init (SliceConfig *config)
* This way it's possible to force gslice to be enabled under
* valgrind just by setting G_SLICE to the empty string.
*/
#ifdef ENABLE_VALGRIND
if (RUNNING_ON_VALGRIND)
config->always_malloc = TRUE;
#endif
}
}

32
glib/gvalgrind.h Normal file
View File

@ -0,0 +1,32 @@
/*
* Copyright 2018 Collabora ltd.
*
* This library 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.
*
* This library 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 this library; if not, see <http://www.gnu.org/licenses/>.
*
* Author: Xavier Claessens <xavier.claessens@collabora.com>
*/
#ifndef __G_VALGRIND_H__
#define __G_VALGRIND_H__
#if HAVE_STDINT_H
#include <stdint.h>
#endif
#ifndef _MSC_VER
#include "valgrind.h"
#define ENABLE_VALGRIND 1
#endif
#endif /* __G_VALGRIND_H__ */

View File

@ -22,7 +22,7 @@
#include "config.h"
#include "../glib/valgrind.h"
#include "../glib/gvalgrind.h"
#include <string.h>
#include <ffi.h>
@ -200,6 +200,7 @@ g_closure_new_simple (guint sizeof_closure,
private_size = sizeof (GRealClosure) - sizeof (GClosure);
#ifdef ENABLE_VALGRIND
/* See comments in gtype.c about what's going on here... */
if (RUNNING_ON_VALGRIND)
{
@ -213,6 +214,7 @@ g_closure_new_simple (guint sizeof_closure,
VALGRIND_MALLOCLIKE_BLOCK (allocated + sizeof (gpointer), private_size - sizeof (gpointer), 0, TRUE);
}
else
#endif
allocated = g_malloc0 (private_size + sizeof_closure);
closure = (GClosure *) (allocated + private_size);
@ -613,6 +615,7 @@ g_closure_unref (GClosure *closure)
closure_invoke_notifiers (closure, FNOTIFY);
g_free (closure->notifiers);
#ifdef ENABLE_VALGRIND
/* See comments in gtype.c about what's going on here... */
if (RUNNING_ON_VALGRIND)
{
@ -627,6 +630,7 @@ g_closure_unref (GClosure *closure)
VALGRIND_FREELIKE_BLOCK (closure, 0);
}
else
#endif
g_free (G_REAL_CLOSURE (closure));
}
}

View File

@ -21,7 +21,7 @@
#include "config.h"
#include "../glib/valgrind.h"
#include "../glib/gvalgrind.h"
#include <string.h>
#include "gtype.h"
@ -1831,6 +1831,7 @@ g_type_create_instance (GType type)
private_size = node->data->instance.private_size;
ivar_size = node->data->instance.instance_size;
#ifdef ENABLE_VALGRIND
if (private_size && RUNNING_ON_VALGRIND)
{
private_size += ALIGN_STRUCT (1);
@ -1845,6 +1846,7 @@ g_type_create_instance (GType type)
VALGRIND_MALLOCLIKE_BLOCK (allocated + ALIGN_STRUCT (1), private_size - ALIGN_STRUCT (1), 0, TRUE);
}
else
#endif
allocated = g_slice_alloc0 (private_size + ivar_size);
instance = (GTypeInstance *) (allocated + private_size);
@ -1923,6 +1925,7 @@ g_type_free_instance (GTypeInstance *instance)
memset (allocated, 0xaa, ivar_size + private_size);
#endif
#ifdef ENABLE_VALGRIND
/* See comment in g_type_create_instance() about what's going on here.
* We're basically unwinding what we put into motion there.
*/
@ -1940,6 +1943,7 @@ g_type_free_instance (GTypeInstance *instance)
VALGRIND_FREELIKE_BLOCK (instance, 0);
}
else
#endif
g_slice_free1 (private_size + ivar_size, allocated);
#ifdef G_ENABLE_DEBUG