SF1772783 Added VT_DECIMAL support -- raised compiler warnings to /W3. fixed some of those warnings in VT_DECIMAL code

This commit is contained in:
clay_shooter
2007-09-09 23:48:08 +00:00
parent cd3c0ed7f6
commit 51c900e485
4 changed files with 85 additions and 77 deletions

View File

@@ -280,7 +280,7 @@
<arg value="/MD"/> <arg value="/MD"/>
<!-- raise the warning level from the default --> <!-- raise the warning level from the default -->
<!-- <arg value="/Wp64"/> --> <!-- <arg value="/Wp64"/> -->
<arg value="/W2" /> <arg value="/W3" />
<!-- sets the exception model --> <!-- sets the exception model -->
<arg value="/EHsc" /> <arg value="/EHsc" />
<!-- /O2 and /RCT1 are incompatible --> <!-- /O2 and /RCT1 are incompatible -->
@@ -312,7 +312,7 @@
<arg value="/MD"/> <arg value="/MD"/>
<!-- raise the warning level from the default --> <!-- raise the warning level from the default -->
<!-- <arg value="/Wp64"/> --> <!-- <arg value="/Wp64"/> -->
<arg value="/W2" /> <arg value="/W3" />
<!-- sets the exception model --> <!-- sets the exception model -->
<arg value="/EHsc" /> <arg value="/EHsc" />
<!-- /O2 and /RCT1 are incompatible --> <!-- /O2 and /RCT1 are incompatible -->

View File

@@ -1069,7 +1069,7 @@ JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantVariant
* Added 1.13M4 * Added 1.13M4
* */ * */
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDecRef JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDecRef
(JNIEnv *env, jobject _this, jint signum, jint scale, jint lo, jint mid, jint hi) (JNIEnv *env, jobject _this, jint signum, jbyte scale, jint lo, jint mid, jint hi)
{ {
VARIANT *v = extractVariant(env, _this); VARIANT *v = extractVariant(env, _this);
if (v) { if (v) {
@@ -1091,7 +1091,7 @@ JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantVariant
* Added 1.13M4 * Added 1.13M4
* */ * */
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDec JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDec
(JNIEnv *env, jobject _this, jint signum, jint scale, jint lo, jint mid, jint hi) (JNIEnv *env, jobject _this, jint signum, jbyte scale, jint lo, jint mid, jint hi)
{ {
VARIANT *v = extractVariant(env, _this); VARIANT *v = extractVariant(env, _this);
DECIMAL *d; DECIMAL *d;
@@ -1151,18 +1151,18 @@ jobject extractDecimal
} }
/* Unfortunately the byte ordering is completely wrong, so we remap it into buffer */ /* Unfortunately the byte ordering is completely wrong, so we remap it into buffer */
buffer = (jbyte*)malloc(12); buffer = (jbyte*)malloc(12);
buffer[11] = d->Lo32 & 255; buffer[11] = (byte)(d->Lo32 & 255);
buffer[10] = (d->Lo32 >> 8) & 255; buffer[10] = (byte)((d->Lo32 >> 8) & 255);
buffer[9] = (d->Lo32 >> 16) & 255;; buffer[9] = (byte)((d->Lo32 >> 16) & 255);
buffer[8] = (d->Lo32 >> 24) & 255;; buffer[8] = (byte)((d->Lo32 >> 24) & 255);
buffer[7] = (d->Mid32) & 255;; buffer[7] = (byte)((d->Mid32) & 255);
buffer[6] = (d->Mid32 >> 8) & 255; buffer[6] = (byte)((d->Mid32 >> 8) & 255);
buffer[5] = (d->Mid32 >> 16) & 255; buffer[5] = (byte)((d->Mid32 >> 16) & 255);
buffer[4] = (d->Mid32 >> 24) & 255; buffer[4] = (byte)((d->Mid32 >> 24) & 255);
buffer[3] = (d->Hi32) & 255; buffer[3] = (byte)((d->Hi32) & 255);
buffer[2] = (d->Hi32 >> 8) & 255; buffer[2] = (byte)((d->Hi32 >> 8) & 255);
buffer[1] = (d->Hi32 >> 16) & 255; buffer[1] = (byte)((d->Hi32 >> 16) & 255);
buffer[0] = (d->Hi32 >> 24) & 255; buffer[0] = (byte)((d->Hi32 >> 24) & 255);
/* Load buffer into the actual array */ /* Load buffer into the actual array */
env->SetByteArrayRegion(bArray, 0, 12, buffer); env->SetByteArrayRegion(bArray, 0, 12, buffer);
/* then clean up the C array */ /* then clean up the C array */

View File

@@ -519,7 +519,7 @@ JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantVariant
* Signature: (Ljava.math.BigDecimal;)V * Signature: (Ljava.math.BigDecimal;)V
*/ */
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDecRef JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDecRef
(JNIEnv *env, jobject _this, jint signum, jint scale, jint lo, jint mid, jint hi); (JNIEnv *env, jobject _this, jint signum, jbyte scale, jint lo, jint mid, jint hi);
/* /*
@@ -528,7 +528,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDecRef
* Signature: (Ljava.math.BigDecimal;)V * Signature: (Ljava.math.BigDecimal;)V
*/ */
JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDec JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantDec
(JNIEnv *env, jobject _this, jint signum, jint scale, jint lo, jint mid, jint hi); (JNIEnv *env, jobject _this, jint signum, jbyte scale, jint lo, jint mid, jint hi);
/* /*

View File

@@ -308,36 +308,38 @@ public class Variant extends JacobObject {
* @param mid middle 32 bits * @param mid middle 32 bits
* @param hi high 32 bits * @param hi high 32 bits
*/ */
private native void putVariantDecRef(int signum, int scale, int lo, int mid, int hi); private native void putVariantDecRef(int signum, byte scale, int lo, int mid, int hi);
/** /**
* Set the content of this variant to an int (VT_DECIMAL|VT_BYREF) * Set the content of this variant to an decimal (VT_DECIMAL|VT_BYREF)
* This may throw exceptions more often than the caller expects because * This may throw exceptions more often than the caller expects because
* most callers don't manage the scale of their BigDecimal objects. * most callers don't manage the scale of their BigDecimal objects.
* @param in the BigDecimal that will be converted to VT_DECIMAL * @param in the BigDecimal that will be converted to VT_DECIMAL
* @throws IllegalArgumentException if the scale is > 28, the maximum for VT_DECIMAL * @throws IllegalArgumentException if the scale is > 28, the maximum for VT_DECIMAL
*/ */
public void putDecimalRef(BigDecimal in){ public void putDecimalRef(BigDecimal in) {
// verify we aren't released // verify we aren't released
getvt(); getvt();
int scale = in.scale(); if (in.scale() > 28) {
if (scale > 28) { // should this really cast to a string and call putStringRef()?
// should this really cast to a string and call putStringRef()? throw new IllegalArgumentException(
throw new IllegalArgumentException("VT_DECIMAL only supports a scale of 28 and the passed"+ "VT_DECIMAL only supports a scale of 28 and the passed"
" in value has a scale of "+scale); + " in value has a scale of " + in.scale());
} } else {
else { byte scale = (byte) in.scale();
BigInteger unscaled = in.unscaledValue(); BigInteger unscaled = in.unscaledValue();
BigInteger shifted = unscaled.shiftRight(32); BigInteger shifted = unscaled.shiftRight(32);
putVariantDecRef(in.signum(), scale, unscaled.intValue(), shifted.intValue(), shifted.shiftRight(32).intValue()); putVariantDecRef(in.signum(), scale, unscaled.intValue(), shifted
} .intValue(), shifted.shiftRight(32).intValue());
} }
}
/** /**
* set the content of this variant to a double (VT_R8|VT_BYREF) * set the content of this variant to a double (VT_R8|VT_BYREF)
* @param in *
*/ * @param in
*/
private native void putVariantDoubleRef(double in); private native void putVariantDoubleRef(double in);
/** /**
@@ -801,27 +803,31 @@ public class Variant extends JacobObject {
* @return BigDecimal * @return BigDecimal
* @throws IllegalStateException if variant is not of the requested type * @throws IllegalStateException if variant is not of the requested type
*/ */
public BigDecimal getDecimal(){ public BigDecimal getDecimal() {
if (this.getvt() == VariantDecimal){ if (this.getvt() == VariantDecimal) {
return (BigDecimal)(getVariantDec()); return (BigDecimal) (getVariantDec());
} else {
throw new IllegalStateException(
"getDecimal() only legal on Variants of type VariantDecimal, not "+this.getvt());
}
}
/**
* return the BigDecimal value held in this variant (fails on other types)
* @return BigDecimal
* @throws IllegalStateException if variant is not of the requested type
*/
public BigDecimal getDecimalRef(){
if ((this.getvt() & VariantDecimal) == VariantDecimal &&
(this.getvt() & VariantByref) == VariantByref) {
return (BigDecimal)(getVariantDecRef());
} else { } else {
throw new IllegalStateException( throw new IllegalStateException(
"getDecimalRef() only legal on byRef Variants of type VariantDecimal, not "+this.getvt()); "getDecimal() only legal on Variants of type VariantDecimal, not "
+ this.getvt());
}
}
/**
* return the BigDecimal value held in this variant (fails on other types)
*
* @return BigDecimal
* @throws IllegalStateException
* if variant is not of the requested type
*/
public BigDecimal getDecimalRef() {
if ((this.getvt() & VariantDecimal) == VariantDecimal
&& (this.getvt() & VariantByref) == VariantByref) {
return (BigDecimal) (getVariantDecRef());
} else {
throw new IllegalStateException(
"getDecimalRef() only legal on byRef Variants of type VariantDecimal, not "
+ this.getvt());
} }
} }
@@ -833,7 +839,7 @@ public class Variant extends JacobObject {
* @param mid middle 32 bits * @param mid middle 32 bits
* @param hi high 32 bits * @param hi high 32 bits
*/ */
private native void putVariantDec(int signum, int scale, int lo, int mid, int hi); private native void putVariantDec(int signum, byte scale, int lo, int mid, int hi);
/** /**
* Set the value of this variant and set the type. * Set the value of this variant and set the type.
@@ -842,26 +848,28 @@ public class Variant extends JacobObject {
* @param in the big decimal that will convert to the VT_DECIMAL type * @param in the big decimal that will convert to the VT_DECIMAL type
* @throws IllegalArgumentException if the scale is > 28, the maximum for VT_DECIMAL * @throws IllegalArgumentException if the scale is > 28, the maximum for VT_DECIMAL
*/ */
public void putDecimal(BigDecimal in){ public void putDecimal(BigDecimal in) {
// verify we aren't released yet // verify we aren't released yet
getvt(); getvt();
int scale = in.scale(); if (in.scale() > 28) {
if (scale > 28) { // should this really cast to a string and call putStringRef()?
// should this really cast to a string and call putStringRef()? throw new IllegalArgumentException(
throw new IllegalArgumentException("VT_DECIMAL only supports a scale of 28 and the passed"+ "VT_DECIMAL only supports a scale of 28 and the passed"
" in value has a scale of "+scale); + " in value has a scale of " + in.scale());
} } else {
else { byte scale = (byte) in.scale();
BigInteger unscaled = in.unscaledValue(); BigInteger unscaled = in.unscaledValue();
BigInteger shifted = unscaled.shiftRight(32); BigInteger shifted = unscaled.shiftRight(32);
putVariantDec(in.signum(), in.scale(), unscaled.intValue(), shifted.intValue(), shifted.shiftRight(32).intValue()); putVariantDec( in.signum(), scale, unscaled.intValue(), shifted
} .intValue(), shifted.shiftRight(32).intValue());
} }
}
/** /**
* set the value of this variant * set the value of this variant
* @param in *
*/ * @param in
*/
private native void putVariantDate(double in); private native void putVariantDate(double in);
/** /**