Skip to content

Commit

Permalink
SF 1650134 - preliminary VT_Variant support VariantVariant
Browse files Browse the repository at this point in the history
  • Loading branch information
clay_shooter committed Apr 22, 2007
1 parent e640d9d commit 73f645a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 18 deletions.
14 changes: 2 additions & 12 deletions jacob/jni/Variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,7 +1040,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantVariant
* Added 1.12 pre 6
*
* */
JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_getVariantVariant
JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantVariant
(JNIEnv *env, jobject _this)
{

Expand All @@ -1051,24 +1051,14 @@ JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_getVariantVariant
return NULL;
}

//Construct a new Variant
jclass variantClass = env->FindClass("com/jacob/com/Variant");
jmethodID defaultCon = env->GetMethodID(variantClass, "<init>", "()V");
jobject newVariant = env->NewObject(variantClass, defaultCon);

VARIANT *refVar = V_VARIANTREF(v);
VARIANT *newV = extractVariant(env, newVariant);

// we could have made a copy of refV here but we aren't every going to free
// it outside of the scope of the enclosing context so we will just used the
// enclosed. This relies on the java layer to zero out its ref to this
// enclosed variant before the gc can come along and free the memory out from
// under this enclosing variant.

jfieldID jf = env->GetFieldID( variantClass, VARIANT_FLD, "I");
env->SetIntField(newVariant, jf, (unsigned int)refVar);

return newVariant;
return (unsigned int)refVar;
}

return NULL;
Expand Down
4 changes: 2 additions & 2 deletions jacob/jni/Variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,9 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Variant_putVariantVariant
/*
* Class: com_jacob_com_Variant
* Method: getVariantVariant
* Signature: ()Lcom/jacob/com/Variant;
* Signature: ()I
*/
JNIEXPORT jobject JNICALL Java_com_jacob_com_Variant_getVariantVariant
JNIEXPORT jint JNICALL Java_com_jacob_com_Variant_getVariantVariant
(JNIEnv *, jobject);

/*
Expand Down
15 changes: 11 additions & 4 deletions jacob/src/com/jacob/com/Variant.java
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public void putStringRef(String in){
* Added 1.12 pre 6
*
* @throws IllegalArgumentException
* if inVariant = null
* if inVariant = null or if inVariant is a Varint
* @param objectToBeWrapped A object that is to be referenced by this variant.
* If objectToBeWrapped is already of type Variant, then it is used.
* If objectToBeWrapped is not Variant then <code>new Variant(objectToBeWrapped)</code>
Expand All @@ -370,10 +370,15 @@ public void putVariant(Object objectToBeWrapped) {
if (objectToBeWrapped == null) {
throw new IllegalArgumentException("Cannot put null in as a variant");
} else if (objectToBeWrapped instanceof Variant){
putVariantVariant((Variant)objectToBeWrapped);
throw new IllegalArgumentException("Cannot putVariant() only accepts non jacob objects.");
} else {
Variant inVariant = new Variant(objectToBeWrapped);
putVariantVariant(inVariant);
// This could be done in Variant.cpp
if (JacobObject.isDebugEnabled()){
JacobObject.debug("Zeroing out enclosed Variant's ref to windows memory");
}
inVariant.m_pVariant = 0;
}
}

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

/**
* get the content of this variant as a short
Expand Down

0 comments on commit 73f645a

Please sign in to comment.