This is the mail archive of the newlib@sources.redhat.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] repost


Sorry for delay, got dragged into other stuff.

At Tue, 25 Jun 2002 17:40:13 -0400, J. Johnston wrote:
> > (3) the change you made even further muddies the water when config.h
> >     erroneously fails to set either of __IEEE_{BIG,LITTLE}_ENDIAN:
> >     now, you get a setting which causes the code to compile (probably)
> >     but may not be correct.
> > 
> 
> The check should actually be in <sys/config.h> like it is for <machine/ieeefp.h> so
> all code doesn't constantly have to be checking this.  This is minor change.

is it possible for sys/config.h to be overridden w/ a machine-specific
version like like the default sys/param.h is?

It's not currently done, but if it's possible the right place for a
check is in the place that uses it, i.e., param.h.  8-)

(Just like the right place to check that BYTE_ORDER has been defined
adequately _must_ be in the files which include param.h and need that
test.)

Anyway, assuming that sys/config.h will never be overridden by a
machine-dependent version, I've moved the test there (actually, copied
the test verbatim from ieeefp.h).


> Looks good Chris.  Repost when you have finished your testing.

So, I built mips-elf, mips64-elf, mipsisa32-elf, mipsisa64-elf and ran
them through their the normal set of compiler regression tests w/ the
changes, which is a bit of a test but not too much of one for newlib
AFAICT.  8-)

I also ran the hsearch code in newlib's 'searhc' dir through my
'hsearchtest' code (which, uh, kinda goes along w/ said hsearch code
8-), with some added diagnostic printfs, and it worked just fine...


the following is the patch as tested.


chris
===================================================================
2002-06-28  Chris Demetriou  <cgd@broadcom.com>

	* libc/include/sys/config.h (__IEEE_LITTLE_ENDIAN)
	(__IEEE_BIG_ENDIAN): Define appropriately for MIPS.
	Check that one of them is defined and error out if not.
	* libc/search/hash.h (DB_BYTE_ORDER, DB_BIG_ENDIAN)
	(DB_LITTLE_ENDIAN): New defines.
	* libc/search/hash.c: Replace all incorrect checks for
	_IEEE_LITTLE_ENDIAN with tests of BYTE_ORDER, and all uses of
	BYTE_ORDER, LITTLE_ENDIAN, and BIG_ENDIAN with DB_* versions.
	* libc/search/hash_page.c: Likewise.

Index: libc/include/sys/config.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/sys/config.h,v
retrieving revision 1.20
diff -u -p -r1.20 config.h
--- libc/include/sys/config.h	21 Jun 2002 18:40:48 -0000	1.20
+++ libc/include/sys/config.h	28 Jun 2002 19:30:15 -0000
@@ -82,6 +82,13 @@
 #define __IEEE_LITTLE_ENDIAN
 #endif
 
+#ifdef __MIPSEL__
+#define __IEEE_LITTLE_ENDIAN
+#endif
+#ifdef __MIPSEB__
+#define __IEEE_BIG_ENDIAN
+#endif
+
 #ifdef __MMIX__
 #define __IEEE_BIG_ENDIAN
 #endif
@@ -201,5 +208,11 @@
 #ifndef _READ_WRITE_RETURN_TYPE
 #define _READ_WRITE_RETURN_TYPE int
 #endif
+
+#ifndef __IEEE_BIG_ENDIAN
+#ifndef __IEEE_LITTLE_ENDIAN
+#error Endianess not declared!!
+#endif /* not __IEEE_LITTLE_ENDIAN */
+#endif /* not __IEEE_BIG_ENDIAN */
 
 #endif /* __SYS_CONFIG_H__ */
Index: libc/search/hash.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/search/hash.c,v
retrieving revision 1.2
diff -u -p -r1.2 hash.c
--- libc/search/hash.c	24 Jun 2002 23:05:08 -0000	1.2
+++ libc/search/hash.c	28 Jun 2002 19:30:16 -0000
@@ -72,7 +72,7 @@ static int   hash_sync(const DB *, __uin
 static int   hdestroy(HTAB *);
 static HTAB *init_hash(HTAB *, const char *, HASHINFO *);
 static int   init_htab(HTAB *, int);
-#ifdef _IEEE_LITTLE_ENDIAN
+#if (BYTE_ORDER == LITTLE_ENDIAN)
 static void  swap_header(HTAB *);
 static void  swap_header_copy(HASHHDR *, HASHHDR *);
 #endif
@@ -156,7 +156,7 @@ __hash_open(file, flags, mode, info, dfl
 			hashp->hash = __default_hash;
 
 		hdrsize = read(hashp->fp, &hashp->hdr, sizeof(HASHHDR));
-#ifdef _IEEE_LITTLE_ENDIAN
+#if (BYTE_ORDER == LITTLE_ENDIAN)
 		swap_header(hashp);
 #endif
 		if (hdrsize == -1)
@@ -299,7 +299,7 @@ init_hash(hashp, file, info)
 
 	nelem = 1;
 	hashp->NKEYS = 0;
-	hashp->LORDER = BYTE_ORDER;
+	hashp->LORDER = DB_BYTE_ORDER;
 	hashp->BSIZE = DEF_BUCKET_SIZE;
 	hashp->BSHIFT = DEF_BUCKET_SHIFT;
 	hashp->SGSIZE = DEF_SEGSIZE;
@@ -335,8 +335,8 @@ init_hash(hashp, file, info)
 		if (info->nelem)
 			nelem = info->nelem;
 		if (info->lorder) {
-			if (info->lorder != BIG_ENDIAN &&
-			    info->lorder != LITTLE_ENDIAN) {
+			if (info->lorder != DB_BIG_ENDIAN &&
+			    info->lorder != DB_LITTLE_ENDIAN) {
 				errno = EINVAL;
 				return (NULL);
 			}
@@ -495,7 +495,7 @@ flush_meta(hashp)
 	HTAB *hashp;
 {
 	HASHHDR *whdrp;
-#ifdef _IEEE_LITTLE_ENDIAN
+#if (BYTE_ORDER == LITTLE_ENDIAN)
 	HASHHDR whdr;
 #endif
 	int fp, i, wsize;
@@ -508,7 +508,7 @@ flush_meta(hashp)
 
 	fp = hashp->fp;
 	whdrp = &hashp->hdr;
-#ifdef _IEEE_LITTLE_ENDIAN
+#if (BYTE_ORDER == LITTLE_ENDIAN)
 	whdrp = &whdr;
 	swap_header_copy(&hashp->hdr, whdrp);
 #endif
@@ -941,7 +941,7 @@ alloc_segs(hashp, nsegs)
 	return (0);
 }
 
-#ifdef _IEEE_LITTLE_ENDIAN
+#if (BYTE_ORDER == LITTLE_ENDIAN)
 /*
  * Hashp->hdr needs to be byteswapped.
  */
Index: libc/search/hash.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/search/hash.h,v
retrieving revision 1.3
diff -u -p -r1.3 hash.h
--- libc/search/hash.h	21 Jun 2002 19:09:50 -0000	1.3
+++ libc/search/hash.h	28 Jun 2002 19:30:16 -0000
@@ -39,18 +39,18 @@
 
 #include <sys/param.h>
 
+/* Check that newlib understands the byte order of its target system.  */
 #ifndef BYTE_ORDER
-#ifndef LITTLE_ENDIAN
-#define LITTLE_ENDIAN 1234
+#error BYTE_ORDER not defined by sys/param.h
 #endif
-#ifndef BIG_ENDIAN
-#define BIG_ENDIAN 4321
-#endif
-#ifdef __IEEE_LITTLE_ENDIAN
-#define BYTE_ORDER LITTLE_ENDIAN
+
+/* Define DB endianness constants based on target endianness.  */
+#define DB_LITTLE_ENDIAN 1234
+#define DB_BIG_ENDIAN 4321
+#if (BYTE_ORDER == LITTLE_ENDIAN)
+#define DB_BYTE_ORDER DB_LITTLE_ENDIAN
 #else
-#define BYTE_ORDER BIG_ENDIAN
-#endif
+#define DB_BYTE_ORDER DB_BIG_ENDIAN
 #endif
 
 /* Operations */
Index: libc/search/hash_page.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/search/hash_page.c,v
retrieving revision 1.2
diff -u -p -r1.2 hash_page.c
--- libc/search/hash_page.c	24 Jun 2002 23:05:08 -0000	1.2
+++ libc/search/hash_page.c	28 Jun 2002 19:30:16 -0000
@@ -552,7 +552,7 @@ __get_page(hashp, p, bucket, is_bucket, 
 	if (!is_bitmap && !bp[0]) {
 		PAGE_INIT(p);
 	} else
-		if (hashp->LORDER != BYTE_ORDER) {
+		if (hashp->LORDER != DB_BYTE_ORDER) {
 			int i, max;
 
 			if (is_bitmap) {
@@ -591,7 +591,7 @@ __put_page(hashp, p, bucket, is_bucket, 
 		return (-1);
 	fd = hashp->fp;
 
-	if (hashp->LORDER != BYTE_ORDER) {
+	if (hashp->LORDER != DB_BYTE_ORDER) {
 		int i;
 		int max;
 


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]