[Julian, you might like to check these changes]

Fixed demangler bug -- it was relying on glibc for some functions.  This
triggered an incredibly obscure bug in my experimental skin -- memcpy() was
called within the demangler at (about?) the same time as the dynamic linker was
fiddling with the memcpy() entry, which caused one word of memory (probably
some counter in the dynamic linker) to be incremented, which my skin didn't
like.

So I removed all (AFAICT) of the demangler's dependencies on glibc.  This
required adding macros for memset, memcpy, strlen, strcmp..., to replace them
with their VG_(...) version.  The only #includes now are to .h files that are
part of Valgrind.

Also required #defining "size_t" as "Int".

Also required adding VG_(memcmp)() to vg_mylibc.c.

Also removed the "-1 == EOF" part of the compile-time test in safe-ctype.h
that checks the character set is ASCII.  This was to remove the dependency
on stdio.h.  Slightly dodgy, but should be ok I think/hope.


git-svn-id: svn://svn.valgrind.org/valgrind/trunk@1436
This commit is contained in:
Nicholas Nethercote 2003-02-24 10:49:08 +00:00
parent 3d8b6976f0
commit b8faaa5488
6 changed files with 46 additions and 15 deletions

View File

@ -26,19 +26,19 @@
executable (functionally similar to c++filt, but includes this
demangler only). */
#include <sys/types.h>
/*#include <sys/types.h>*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_STDLIB_H
/*#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#endif*/
#ifdef HAVE_STRING_H
/*#ifdef HAVE_STRING_H
#include <string.h>
#endif
#endif*/
#include "vg_include.h"
#include "ansidecl.h"
@ -46,6 +46,8 @@
#include "demangle.h"
#ifndef STANDALONE
#define size_t Int
#define malloc(s) VG_(arena_malloc) (VG_AR_DEMANGLE, s)
#define free(p) VG_(arena_free) (VG_AR_DEMANGLE, p)
#define realloc(p,s) VG_(arena_realloc)(VG_AR_DEMANGLE, p, /*alignment*/4, s)

View File

@ -39,16 +39,16 @@ Boston, MA 02111-1307, USA. */
#include "safe-ctype.h"
#include "vg_include.h"
#include <sys/types.h>
/*#include <sys/types.h>
#include <string.h>
#include <stdio.h>
#include <stdio.h>*/
#ifdef HAVE_STDLIB_H
/*#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#else
char * malloc ();
char * realloc ();
#endif
#endif*/
#include <demangle.h>
#include "dyn-string.h"
@ -70,6 +70,8 @@ static char *ada_demangle PARAMS ((const char *, int));
#endif
#ifndef STANDALONE
#define size_t Int
#define xstrdup(ptr) VG_(arena_strdup) (VG_AR_DEMANGLE, ptr)
#define free(ptr) VG_(arena_free) (VG_AR_DEMANGLE, ptr)
#define xmalloc(size) VG_(arena_malloc) (VG_AR_DEMANGLE, size)
@ -79,10 +81,17 @@ static char *ada_demangle PARAMS ((const char *, int));
#undef strstr
#define strstr VG_(strstr)
#define sprintf VG_(sprintf)
#define strcpy VG_(strcpy)
#define strncpy VG_(strncpy)
#define strncat VG_(strncat)
#define strchr VG_(strchr)
#define strpbrk VG_(strpbrk)
#define strlen VG_(strlen)
#define strcmp VG_(strcmp)
#define strncmp VG_(strncmp)
#define memcpy VG_(memcpy)
#define memset VG_(memset)
#define memcmp VG_(memcmp)
#endif
extern void fancy_abort PARAMS ((void)) ATTRIBUTE_NORETURN;

View File

@ -23,13 +23,13 @@ Boston, MA 02111-1307, USA. */
#include "config.h"
#endif
#ifdef HAVE_STRING_H
/*#ifdef HAVE_STRING_H
#include <string.h>
#endif
#endif*/
#ifdef HAVE_STDLIB_H
/*#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#endif*/
#include "vg_include.h"
#include "ansidecl.h"

View File

@ -31,7 +31,7 @@ Boston, MA 02111-1307, USA. */
#include "ansidecl.h"
#include <safe-ctype.h>
#include <stdio.h> /* for EOF */
/*#include <stdio.h>*/ /* for EOF */
/* Shorthand */
#define bl _sch_isblank
@ -66,7 +66,7 @@ Boston, MA 02111-1307, USA. */
/* Are we ASCII? */
#if '\n' == 0x0A && ' ' == 0x20 && '0' == 0x30 \
&& 'A' == 0x41 && 'a' == 0x61 && '!' == 0x21 \
&& EOF == -1
/* && EOF == -1*/
const unsigned short _sch_istable[256] =
{

View File

@ -964,6 +964,25 @@ void* VG_(memset) ( void *dest, Int c, Int sz )
return dest;
}
Int VG_(memcmp) ( const void* s1, const void* s2, Int n )
{
Int res;
Char a0;
Char b0;
vg_assert(n >= 0);
while (n != 0) {
a0 = ((Char *) s1)[0];
b0 = ((Char *) s2)[0];
s1 += 1;
s2 += 1;
res = a0 - b0;
if (res != 0)
return res;
n -= 1;
}
return 0;
}
Char VG_(toupper) ( Char c )
{

View File

@ -365,6 +365,7 @@ extern Char* VG_(strchr) ( const Char* s, Char c );
extern Char* VG_(strdup) ( const Char* s);
extern void* VG_(memcpy) ( void *d, const void *s, Int sz );
extern void* VG_(memset) ( void *s, Int c, Int sz );
extern Int VG_(memcmp) ( const void* s1, const void* s2, Int n );
/* Like strcmp() and strncmp(), but stop comparing at any whitespace. */
extern Int VG_(strcmp_ws) ( const Char* s1, const Char* s2 );