public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
From: cagney@sourceware.org
To: frysk-cvs@sourceware.org
Subject: [SCM]  master: Add word-sized and word-indexed indexed byte-buffer get/put methods.
Date: Thu, 05 Jun 2008 14:36:00 -0000	[thread overview]
Message-ID: <20080605143625.28519.qmail@sourceware.org> (raw)

The branch, master has been updated
       via  a6241011ef6b3209bcd45876deb53d62baae19dc (commit)
      from  0fe10ca241a02a853f4882c9d68431b6957d384b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit a6241011ef6b3209bcd45876deb53d62baae19dc
Author: Andrew Cagney <cagney@redhat.com>
Date:   Thu Jun 5 10:32:32 2008 -0400

    Add word-sized and word-indexed indexed byte-buffer get/put methods.
    
    frysk-sys/inua/ChangeLog
    2008-06-05  Andrew Cagney  <cagney@redhat.com>
    
    	* eio/ByteBuffer.java: Add missing indexed word get/put methods.
    	* eio/TestWordSize.java: Test.
    	* eio/WordSized.java: Ditto.
    
    frysk-sys/lib/dwfl/ChangeLog
    2008-06-05  Andrew Cagney  <cagney@redhat.com>
    
    	* TestElf.java (checkAuxv): Use indexed word accessors.

-----------------------------------------------------------------------

Summary of changes:
 frysk-sys/frysk/junit/TestCase.java     |   10 ++
 frysk-sys/inua/ChangeLog                |    6 +
 frysk-sys/inua/eio/ArrayByteBuffer.java |    7 +
 frysk-sys/inua/eio/ByteBuffer.java      |  110 +++++++++++++-----
 frysk-sys/inua/eio/TestLib.java         |    2 +-
 frysk-sys/inua/eio/TestWordSize.java    |  167 ++++++++++++++++++--------
 frysk-sys/inua/eio/WordSized.java       |  195 +++++++++++++++++--------------
 frysk-sys/lib/dwfl/ChangeLog            |    4 +
 frysk-sys/lib/dwfl/TestElf.java         |    7 +-
 9 files changed, 332 insertions(+), 176 deletions(-)

First 500 lines of diff:
diff --git a/frysk-sys/frysk/junit/TestCase.java b/frysk-sys/frysk/junit/TestCase.java
index 39d665d..a484dc5 100644
--- a/frysk-sys/frysk/junit/TestCase.java
+++ b/frysk-sys/frysk/junit/TestCase.java
@@ -277,4 +277,14 @@ public class TestCase
 	    }
 	}
     }
+    
+    /**
+     * Override JUnit's long == with one that prints failing values in hex.
+     */
+    public static void assertEquals(String what, long correct, long test) {
+	if (correct != test) {
+	    fail(what + " expected:<0x" + Long.toHexString(correct)
+		 + "> but was:<0x" + Long.toHexString(test) + ">");
+	}
+    }
 }
diff --git a/frysk-sys/inua/ChangeLog b/frysk-sys/inua/ChangeLog
index a606daa..1827bf2 100644
--- a/frysk-sys/inua/ChangeLog
+++ b/frysk-sys/inua/ChangeLog
@@ -1,3 +1,9 @@
+2008-06-05  Andrew Cagney  <cagney@redhat.com>
+
+	* eio/ByteBuffer.java: Add missing indexed word get/put methods.
+	* eio/TestWordSize.java: Test.
+	* eio/WordSized.java: Ditto.
+
 2008-04-11  Andrew Cagney  <cagney@redhat.com>
 
 	* eio/TestMmap.java: Delete.
diff --git a/frysk-sys/inua/eio/ArrayByteBuffer.java b/frysk-sys/inua/eio/ArrayByteBuffer.java
index 9e3b7ab..fe4c752 100644
--- a/frysk-sys/inua/eio/ArrayByteBuffer.java
+++ b/frysk-sys/inua/eio/ArrayByteBuffer.java
@@ -68,6 +68,13 @@ public class ArrayByteBuffer
 	this (bytes, 0, bytes.length);
     }
 
+    /**
+     * Return the byte array backing the byte buffer.
+     */
+    public byte[] toArray() {
+	return array;
+    }
+
     protected ByteBuffer subBuffer (ByteBuffer parent, long lowerExtreem,
 				    long upperExtreem)
     {
diff --git a/frysk-sys/inua/eio/ByteBuffer.java b/frysk-sys/inua/eio/ByteBuffer.java
index 67140fa..6549a58 100644
--- a/frysk-sys/inua/eio/ByteBuffer.java
+++ b/frysk-sys/inua/eio/ByteBuffer.java
@@ -751,38 +751,90 @@ public abstract class ByteBuffer
     byteOrdered.pokeDouble(this, lowWater + index, v);
   }
   
-  public final long getWord ()
-  {
-    return wordSized.getWord(this);
-  }
-
-  public final long getUWord ()
-  {
-    return wordSized.getUWord(this);
-  }
-
-  public final void putWord (long w)
-  {
-    wordSized.putWord(this, w);
-  }
-
-  public final void putUWord (long w)
-  {
-    wordSized.putUWord(this, w);
-  }
+    public final long getWord() {
+	return wordSized.getWord(this);
+    }
+    public final long getUWord() {
+	return wordSized.getUWord(this);
+    }
+
+    public final void putWord(long w) {
+	wordSized.putWord(this, w);
+    }
+    public final void putUWord(long w) {
+	wordSized.putUWord(this, w);
+    }
+
+    /**
+     * Get word at word at byte offset INDEX.
+     */
+    public final long getWord(long index) {
+	return wordSized.getWord(this, index);
+    }
+    /**
+     * Get unsigned word at byte offset INDEX.
+     */
+    public final long getUWord(long index) {
+	return wordSized.getUWord(this, index);
+    }
+    /**
+     * Put WORD at byte offset INDEX.
+     */
+    public final void putWord(long index, long w) {
+	wordSized.putWord(this, index, w);
+    }
+    /**
+     * Put the unsigned WORD at byte offset INDEX.
+     */
+    public final void putUWord(long index, long w) {
+	wordSized.putUWord(this, index, w);
+    }
+
+    /**
+     * Get word at word (and not byte) offset INDEX.  Arguably this
+     * should be provided with a separate WordBuffer class.
+     */
+    public final long getWordSized(long index) {
+	return wordSized.getWord(this, index * wordSize());
+    }
+    /**
+     * Get unsigned word at word (and not byte) offset INDEX.
+     * Arguably this should be provided with a separate WordBuffer
+     * class.
+     */
+    public final long getUWordSized(long index) {
+	return wordSized.getUWord(this, index * wordSize());
+    }
+    /**
+     * Put WORD at word (and not byte) offset INDEX.  Arguably this
+     * should be provided with a separate WordBuffer class.
+     */
+    public final void putWordSized(long index, long w) {
+	wordSized.putWord(this, index * wordSize(), w);
+    }
+    /**
+     * Put WORD at unsigned word (and not byte) offset INDEX.  Arguably
+     * this should be provided with a separate WordBuffer class.
+     */
+    public final void putUWordSized(long index, long w) {
+	wordSized.putUWord(this, index * wordSize(), w);
+    }
 
   protected WordSized wordSized;
 
-  public ByteBuffer wordSize (int w)
-  {
-    wordSized = WordSized.wordSize(w);
-    return this;
-  }
-
-  public int wordSize ()
-  {
-    return wordSized.wordSize;
-  }
+    public ByteBuffer wordSize(int w) {
+	wordSized = WordSized.wordSize(w);
+	return this;
+    }
+    public int wordSize() {
+	return wordSized.wordSize;
+    }
+    /**
+     * Return the length of the ByteBuffer as words.
+     */
+    public long wordLength() {
+	return capacity() / wordSize();
+    }
 
   public ByteBuffer get (StringBuffer string)
   {
diff --git a/frysk-sys/inua/eio/TestLib.java b/frysk-sys/inua/eio/TestLib.java
index d669bd5..9f74105 100644
--- a/frysk-sys/inua/eio/TestLib.java
+++ b/frysk-sys/inua/eio/TestLib.java
@@ -36,7 +36,7 @@
 // exception.
 package inua.eio;
 
-import junit.framework.TestCase;
+import frysk.junit.TestCase;
 
 public class TestLib
     extends TestCase
diff --git a/frysk-sys/inua/eio/TestWordSize.java b/frysk-sys/inua/eio/TestWordSize.java
index 5597dac..982d80f 100644
--- a/frysk-sys/inua/eio/TestWordSize.java
+++ b/frysk-sys/inua/eio/TestWordSize.java
@@ -34,115 +34,178 @@
 // modification, you must delete this exception statement from your
 // version and license this file solely under the GPL without
 // exception.
+
 package inua.eio;
 
-public class TestWordSize
-    extends TestLib
-{
-    static ByteOrder[] byteOrders = new ByteOrder[] {
+public class TestWordSize extends TestLib {
+    private static ByteOrder[] byteOrders = new ByteOrder[] {
 	ByteOrder.BIG_ENDIAN, ByteOrder.LITTLE_ENDIAN
     };
 
-    static int[] wordSizes = new int[] { 2, 4, 8 };
+    private static int[] wordSizes = new int[] { 2, 4, 8 };
 
-    static long[] getWordVals = new long[] {
+    private static long[] getWordVals = new long[] {
 	0x0102L, 0x0403L,
 	0x05060708L, 0x0c0b0a09L,
 	0x0d0e0f1011121314L, 0x1c1b1a1918171615L
     };
 
-    static long[] getUWordVals = new long[] {
+    private static long[] getUWordVals = new long[] {
 	0x898aL, 0x8c8bL,
 	0x8d8e8f90L, 0x94939291L,
 	0x95969798999a9b9cL, 0xa4a3a2a1a09f9e9dL
     };
 
-    public void testGetWord ()
-    {
+    public void testGetWord() {
 	int idx;
 	
-	byte[] array = orderedArray ();
-	ByteBuffer b = new ArrayByteBuffer (array);
+	byte[] array = orderedArray();
+	ByteBuffer b = new ArrayByteBuffer(array);
 
 	idx = 0;
 	for (int w = 0; w < wordSizes.length; w++) {
 	    int wordSize = wordSizes[w];
-	    b.wordSize (wordSize);
+	    b.wordSize(wordSize);
 	    for (int o = 0; o < byteOrders.length; o++) {
 		ByteOrder byteOrder = byteOrders[o];
-		b.order (byteOrder);
-		assertEquals ("getWord() wordsize=" + wordSize + " " + byteOrder,
-			      b.getWord (), getWordVals[idx]);
+		b.order(byteOrder);
+		assertEquals("getWord() wordsize=" + wordSize + " " + byteOrder,
+			     b.getWord(), getWordVals[idx]);
 		idx++;
 	    }
 	}
 
     }
 
-    public void testRest ()
-    {
+    private void checkIndexedWord(int wordSize, ByteOrder order,
+				  long[] words, long[] uwords) {
+	byte[] array = orderedArray();
+	ByteBuffer b = new ArrayByteBuffer(array);
+	b.wordSize(wordSize);
+	b.order(order);
+	for (int i = 0; i < words.length; i++) {
+	    assertEquals("word " + i, words[i], b.getWordSized(i));
+	    assertEquals("uword " + i, uwords[i], b.getUWordSized(i));
+	}
+    }
+    public void testGetIndexedBigWord2() {
+	checkIndexedWord(2, ByteOrder.BIG_ENDIAN,
+			 new long[] {
+			     0x0102L, 0x0304L,
+			 },
+			 new long[] {
+			     0x0102L, 0x0304L,
+			 });
+    }
+    public void testGetIndexedBigWord4() {
+	checkIndexedWord(4, ByteOrder.BIG_ENDIAN,
+			 new long[] {
+			     0x01020304L, 0x05060708L,
+			 },
+			 new long[] {
+			     0x01020304L, 0x05060708L,
+			 });
+    }
+    public void testGetIndexedBigWord8() {
+	checkIndexedWord(8, ByteOrder.BIG_ENDIAN,
+			 new long[] {
+			     0x0102030405060708L, 0x090a0b0c0d0e0f10L,
+			 },
+			 new long[] {
+			     0x0102030405060708L, 0x090a0b0c0d0e0f10L,
+			 });
+    }
+    public void testGetIndexedLittleWord2() {
+	checkIndexedWord(2, ByteOrder.LITTLE_ENDIAN,
+			 new long[] {
+			     0x0201L, 0x0403L,
+			 },
+			 new long[] {
+			     0x0201L, 0x0403L,
+			 });
+    }
+    public void testGetIndexedLittleWord4() {
+	checkIndexedWord(4, ByteOrder.LITTLE_ENDIAN,
+			 new long[] {
+			     0x04030201L, 0x08070605L,
+			 },
+			 new long[] {
+			     0x04030201L, 0x08070605L,
+			 });
+    }
+    public void testGetIndexedLittleWord8() {
+	checkIndexedWord(8, ByteOrder.LITTLE_ENDIAN,
+			 new long[] {
+			     0x0807060504030201L, 0x100f0e0d0c0b0a09L,
+			 },
+			 new long[] {
+			     0x0807060504030201L, 0x100f0e0d0c0b0a09L,
+			 });
+    }
+
+    public void testRest() {
 	int idx;
 
-	byte[] array = orderedArray ();
-	ByteBuffer b = new ArrayByteBuffer (array);
+	byte[] array = orderedArray();
+	ByteBuffer b = new ArrayByteBuffer(array);
 	idx = 0;
-	b.position (0x88);
+	b.position(0x88);
 	for (int w = 0; w < wordSizes.length; w++) {
 	    int wordSize = wordSizes[w];
-	    b.wordSize (wordSize);
+	    b.wordSize(wordSize);
 	    for (int o = 0; o < byteOrders.length; o++) {
 		ByteOrder byteOrder = byteOrders[o];
-		b.order (byteOrder);
-		assertEquals ("getWord() wordsize=" + wordSize + " " + byteOrder,
-			      b.getUWord (), getUWordVals[idx]);
+		b.order(byteOrder);
+		assertEquals("getWord() wordsize=" + wordSize + " " + byteOrder,
+			     b.getUWord(), getUWordVals[idx]);
 		idx++;
 	    }
 	}
 
-	clearArray (array);
+	clearArray(array);
 	idx = 0;
-	b.position (35);
+	b.position(35);
 	for (int w = 0; w < wordSizes.length; w++) {
 	    int wordSize = wordSizes[w];
-	    b.wordSize (wordSize);
+	    b.wordSize(wordSize);
 	    for (int o = 0; o < byteOrders.length; o++) {
 		ByteOrder byteOrder = byteOrders[o];
-		b.order (byteOrder);
-		b.putWord (getWordVals[idx]);
+		b.order(byteOrder);
+		b.putWord(getWordVals[idx]);
 		idx++;
 	    }
 	}
-	check ("putWord()", array, 35,
-	       new int[] {
-		   0x01, 0x02,
-		   0x03, 0x04,
-		   0x05, 0x06, 0x07, 0x08,
-		   0x09, 0x0a, 0x0b, 0x0c,
-		   0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
-		   0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c
-	       });
+	check("putWord()", array, 35,
+	      new int[] {
+		  0x01, 0x02,
+		  0x03, 0x04,
+		  0x05, 0x06, 0x07, 0x08,
+		  0x09, 0x0a, 0x0b, 0x0c,
+		  0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
+		  0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c
+	      });
 
-	clearArray (array);
+	clearArray(array);
 	idx = 0;
-	b.position (0x88);
+	b.position(0x88);
 	for (int w = 0; w < wordSizes.length; w++) {
 	    int wordSize = wordSizes[w];
-	    b.wordSize (wordSize);
+	    b.wordSize(wordSize);
 	    for (int o = 0; o < byteOrders.length; o++) {
 		ByteOrder byteOrder = byteOrders[o];
-		b.order (byteOrder);
-		b.putUWord (getUWordVals[idx]);
+		b.order(byteOrder);
+		b.putUWord(getUWordVals[idx]);
 		idx++;
 	    }
 	}
-	check ("putUWord()", array, 0x88,
-	       new int[] {
-		   0x89, 0x8a,
-		   0x8b, 0x8c,
-		   0x8d, 0x8e, 0x8f, 0x90,
-		   0x91, 0x92, 0x93, 0x94,
-		   0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c,
-		   0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4
-	       });
+	check("putUWord()", array, 0x88,
+	      new int[] {
+		  0x89, 0x8a,
+		  0x8b, 0x8c,
+		  0x8d, 0x8e, 0x8f, 0x90,
+		  0x91, 0x92, 0x93, 0x94,
+		  0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c,
+		  0x9d, 0x9e, 0x9f, 0xa0, 0xa1, 0xa2, 0xa3, 0xa4
+	      });
     }
 }
diff --git a/frysk-sys/inua/eio/WordSized.java b/frysk-sys/inua/eio/WordSized.java
index a7e6e54..f709643 100644
--- a/frysk-sys/inua/eio/WordSized.java
+++ b/frysk-sys/inua/eio/WordSized.java
@@ -38,98 +38,113 @@
 
 package inua.eio;
 
-abstract class WordSized
-{
-  WordSized (int wordSize)
-  {
-    this.wordSize = wordSize;
-  }
-
-  int wordSize;
-
-  abstract long getWord (ByteBuffer b);
-
-  abstract long getUWord (ByteBuffer b);
-
-  abstract void putWord (ByteBuffer b, long w);
-
-  abstract void putUWord (ByteBuffer b, long w);
-
-  private static final WordSized[] wordSizes = { new WordSized(2)
-  {
-    long getWord (ByteBuffer b)
-    {
-      return b.getShort();
-    }
-
-    long getUWord (ByteBuffer b)
-    {
-      return b.getUShort();
-    }
-
-    void putWord (ByteBuffer b, long w)
-    {
-      b.putShort((short) w);
-    }
-
-    void putUWord (ByteBuffer b, long w)
-    {
-      b.putUShort((int) w);
-    }
-  }, new WordSized(4)
-  {
-    long getWord (ByteBuffer b)
-    {
-      return b.getInt();
+abstract class WordSized{
+    WordSized(int wordSize) {
+	this.wordSize = wordSize;
     }
 
-    long getUWord (ByteBuffer b)
-    {
-      return b.getUInt();
+    int wordSize;
+
+    abstract long getWord(ByteBuffer b);
+    abstract long getUWord(ByteBuffer b);
+
+    abstract long getWord(ByteBuffer b, long index);
+    abstract long getUWord(ByteBuffer b, long index);
+
+    abstract void putWord(ByteBuffer b, long w);
+    abstract void putUWord(ByteBuffer b, long w);
+
+    abstract void putWord(ByteBuffer b, long index, long w);
+    abstract void putUWord(ByteBuffer b, long index, long w);
+
+    private static final WordSized[] wordSizes = {
+	new WordSized(2) {
+	    long getWord(ByteBuffer b) {
+		return b.getShort();


hooks/post-receive
--
frysk system monitor/debugger


                 reply	other threads:[~2008-06-05 14:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20080605143625.28519.qmail@sourceware.org \
    --to=cagney@sourceware.org \
    --cc=frysk-cvs@sourceware.org \
    --cc=frysk@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).