Skip to content
Snippets Groups Projects
Commit 6243aa2e authored by brinn's avatar brinn
Browse files

fix: bug in NativeData.copyXXXToByte() methods when using a non-native byte...

fix: bug in NativeData.copyXXXToByte() methods when using a non-native byte order and only overwriting a part of the outArray
change: for Sparc V8 do not use -fast to avoid using UltraSparcIII instruction set commands

SVN: 15645
parent b4e4089d
No related branches found
No related tags found
No related merge requests found
#! /bin/bash
cc -G -KPIC -fast -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -I/usr/java/include -I/usr/java/include/solaris unix.c -o libunix.so
cc -G -KPIC -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -I/usr/java/include -I/usr/java/include/solaris unix.c -o libunix.so
# MACHINE_BYTE_ORDER=2 corresponds to 'big endian'
cc -G -KPIC -fast -DMACHINE_BYTE_ORDER=2 copy*.c -I/usr/java/include -I/usr/java/include/solaris -o libnativedata.so
cc -G -KPIC -DMACHINE_BYTE_ORDER=2 copy*.c -I/usr/java/include -I/usr/java/include/solaris -o libnativedata.so
......@@ -129,9 +129,9 @@ JNIEXPORT void JNICALL FUNCTIONNAMETB
if (byteOrder > 0 && byteOrder != MACHINE_BYTE_ORDER)
{
jbyte *buf = outArray;
jbyte *buf = outArray + outStart;
int nelmts;
for(nelmts=len; nelmts >= 0; --nelmts)
for(nelmts = 0; nelmts < len; ++nelmts)
{
CHANGE_BYTE_ORDER(buf);
buf += sizeof(TARGET);
......@@ -217,9 +217,9 @@ JNIEXPORT void JNICALL FUNCTIONNAMEBT
if (byteOrder > 0 && byteOrder != MACHINE_BYTE_ORDER)
{
jbyte *buf = (jbyte*) outArray;
jbyte *buf = (jbyte*) outArray + outStart;
int nelmts;
for(nelmts=len; nelmts >= 0; --nelmts)
for(nelmts = 0; nelmts < len; ++nelmts)
{
CHANGE_BYTE_ORDER(buf);
buf += sizeof(TARGET);
......
......@@ -24,6 +24,7 @@ import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import org.apache.commons.lang.ArrayUtils;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
......@@ -99,7 +100,7 @@ public class NativeDataTests
@Test(dataProvider = "getOfs")
public void testShortToByteToShort(int sourceOfs, int targetOfs)
{
final int sizeOfTarget = 8;
final int sizeOfTarget = 2;
final short[] orignalArr = new short[]
{ -1, 17, 20000, (short) -50000 };
final short[] iarr = new short[sourceOfs + orignalArr.length];
......@@ -116,7 +117,7 @@ public class NativeDataTests
@Test(dataProvider = "getOfs")
public void testFloatToByteToFloat(int sourceOfs, int targetOfs)
{
final int sizeOfTarget = 8;
final int sizeOfTarget = 4;
final float[] orignalArr = new float[]
{ -1, 17, 3.14159f, -1e6f };
final float[] iarr = new float[sourceOfs + orignalArr.length];
......@@ -272,6 +273,34 @@ public class NativeDataTests
}
}
@Test
public void testFloatToByteNonNativeByteOrderPartialOutputArray()
{
final int sizeOfTarget = 4;
final ByteOrder nonNativeByteOrder =
(NativeData.getNativeByteOrder() == ByteOrder.LITTLE_ENDIAN) ? ByteOrder.BIG_ENDIAN
: ByteOrder.LITTLE_ENDIAN;
final float[] iarr = new float[]
{ -1, 17, 3.14159f, -1e6f };
final byte[] headerArray = new byte[]
{ 1, 2, 3, 4 };
final byte[] trailerArray = new byte[]
{ 5, 6, 7, 8 };
final byte[] barr =
new byte[iarr.length * sizeOfTarget + headerArray.length + trailerArray.length];
System.arraycopy(headerArray, 0, barr, 0, headerArray.length);
System.arraycopy(trailerArray, 0, barr, headerArray.length + iarr.length * sizeOfTarget,
trailerArray.length);
NativeData.copyFloatToByte(iarr, 0, barr, headerArray.length, iarr.length,
nonNativeByteOrder);
final byte[] headerArray2 = ArrayUtils.subarray(barr, 0, headerArray.length);
final byte[] trailerArray2 =
ArrayUtils.subarray(barr, headerArray.length + iarr.length * sizeOfTarget,
barr.length);
assertTrue(Arrays.equals(headerArray, headerArray2));
assertTrue(Arrays.equals(trailerArray, trailerArray2));
}
private void afterClass()
{
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment