Skip to content

Commit 73f645a

Browse files
author
clay_shooter
committed
SF 1650134 - preliminary VT_Variant support VariantVariant
1 parent e640d9d commit 73f645a

File tree

3 files changed

+15
-18
lines changed

3 files changed

+15
-18
lines changed

jacob/jni/Variant.cpp

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantVariant
10401040
* Added 1.12 pre 6
10411041
*
10421042
* */
1043-
JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_getVariantVariant
1043+
JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantVariant
10441044
(JNIEnv *env, jobject _this)
10451045
{
10461046

@@ -1051,24 +1051,14 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_getVariantVariant
10511051
return NULL;
10521052
}
10531053

1054-
//Construct a new Variant
1055-
jclass variantClass = env->FindClass("com/jacob/com/Variant");
1056-
jmethodID defaultCon = env->GetMethodID(variantClass, "<init>", "()V");
1057-
jobject newVariant = env->NewObject(variantClass, defaultCon);
1058-
10591054
VARIANT *refVar = V_VARIANTREF(v);
1060-
VARIANT *newV = extractVariant(env, newVariant);
10611055

10621056
// we could have made a copy of refV here but we aren't every going to free
10631057
// it outside of the scope of the enclosing context so we will just used the
10641058
// enclosed. This relies on the java layer to zero out its ref to this
10651059
// enclosed variant before the gc can come along and free the memory out from
10661060
// under this enclosing variant.
1067-
1068-
jfieldID jf = env->GetFieldID( variantClass, VARIANT_FLD, "I");
1069-
env->SetIntField(newVariant, jf, (unsigned int)refVar);
1070-
1071-
return newVariant;
1061+
return (unsigned int)refVar;
10721062
}
10731063

10741064
return NULL;

jacob/jni/Variant.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,9 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantVariant
508508
/*
509509
* Class: com_jacob_com_Variant
510510
* Method: getVariantVariant
511-
* Signature: ()Lcom/jacob/com/Variant;
511+
* Signature: ()I
512512
*/
513-
JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_getVariantVariant
513+
JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantVariant
514514
(JNIEnv *, jobject);
515515

516516
/*

jacob/src/com/jacob/com/Variant.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ public void putStringRef(String in){
360360
* Added 1.12 pre 6
361361
*
362362
* @throws IllegalArgumentException
363-
* if inVariant = null
363+
* if inVariant = null or if inVariant is a Varint
364364
* @param objectToBeWrapped A object that is to be referenced by this variant.
365365
* If objectToBeWrapped is already of type Variant, then it is used.
366366
* If objectToBeWrapped is not Variant then <code>new Variant(objectToBeWrapped)</code>
@@ -370,10 +370,15 @@ public void putVariant(Object objectToBeWrapped) {
370370
if (objectToBeWrapped == null) {
371371
throw new IllegalArgumentException("Cannot put null in as a variant");
372372
} else if (objectToBeWrapped instanceof Variant){
373-
putVariantVariant((Variant)objectToBeWrapped);
373+
throw new IllegalArgumentException("Cannot putVariant() only accepts non jacob objects.");
374374
} else {
375375
Variant inVariant = new Variant(objectToBeWrapped);
376376
putVariantVariant(inVariant);
377+
// This could be done in Variant.cpp
378+
if (JacobObject.isDebugEnabled()){
379+
JacobObject.debug("Zeroing out enclosed Variant's ref to windows memory");
380+
}
381+
inVariant.m_pVariant = 0;
377382
}
378383
}
379384

@@ -400,7 +405,9 @@ public Object getVariant() {
400405
if (JacobObject.isDebugEnabled()){
401406
JacobObject.debug("About to call getVariantVariant()");
402407
}
403-
Variant enclosedVariant = getVariantVariant();
408+
Variant enclosedVariant = new Variant();
409+
int enclosedVariantMemory = getVariantVariant();
410+
enclosedVariant.m_pVariant = enclosedVariantMemory;
404411
Object enclosedVariantAsJava = enclosedVariant.toJavaObject();
405412
// zero out the reference to the underlying windows memory so that
406413
// it is still only owned in one place by one java object
@@ -423,7 +430,7 @@ public Object getVariant() {
423430
* Added 1.12 pre 6 - VT_VARIANT support is at an alpha level
424431
* @return Variant one of the VT_Variant types
425432
*/
426-
private native Variant getVariantVariant();
433+
private native int getVariantVariant();
427434

428435
/**
429436
* get the content of this variant as a short

0 commit comments

Comments
 (0)