Skip to content

Commit

Permalink
#41 Fix for SafeArray(String) constructor
Browse files Browse the repository at this point in the history
#111 m_pDispatch is not 0 if not attached
Should really be mixing two fixes in the same commit but that's the way it goes
  • Loading branch information
clay_shooter committed Jul 24, 2013
1 parent db89245 commit eeefefd
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 12 deletions.
13 changes: 10 additions & 3 deletions jacob/docs/ReleaseNotes.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ <h3>Tracked Changes</h3>
<td width="87%" valign="top">(M1)Fix memory pointer that was 32 bit. Causes defects in 64 bit systems above 2GB</td>
</tr>
<tr>
<td width="13%" valign="top">115 (new system numbering)</td>
<td width="87%" valign="top">(M3)#115 Release problem if you've got two threads with the same name</td>
<td width="13%" valign="top">115 (new numbers)</td>
<td width="87%" valign="top">(M3)Release problem if you've got two threads with the same name</td>
</tr>
<tr>
<td width="13%" valign="top">111 (new numbers)</td>
<td width="87%" valign="top">(M3)m_pDispatch is not 0 if not attached</td>
</tr>
<tr>
<td width="13%" valign="top">&nbsp;</td>
Expand All @@ -33,7 +37,10 @@ <h3>Tracked Changes</h3>
<tr>
<td colspan="2"><b>Patches</b></td>
</tr>
<tr>
<tr>
<td width="13%" valign="top">41 (new numbers)</td>
<td width="87%" valign="top">(M3)Fix for SafeArray(String) constructor</td>
</tr> <tr>
<td width="13%" valign="top">&nbsp;</td>
<td width="87%" valign="top">&nbsp;</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion jacob/jni/Dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_release
IDispatch *disp = (IDispatch *)num;
if (disp) {
disp->Release();
env->SetIntField(_this, jf, 0ll);
env->SetLongField(_this, jf, 0ll);
}
}

Expand Down
24 changes: 17 additions & 7 deletions jacob/src/com/jacob/com/SafeArray.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,38 @@ public SafeArray(int vt, int lbounds[], int celems[]) {
}

/**
* convert a string to a VT_UI1 array
* Convert a string to a VT_UI1 array.
*
* @param s
* source string
*/
public SafeArray(String s) {
char[] ca = s.toCharArray();
init(Variant.VariantByte, new int[] { 0 }, new int[] { ca.length });
fromCharArray(ca);
// https://sourceforge.net/p/jacob-project/patches/41/
/*
* char[] ca = s.toCharArray(); init(Variant.VariantByte, new int[] { 0
* }, new int[] { ca.length }); fromCharArray(ca);
*/
byte[] ba = s.getBytes();
init(Variant.VariantByte, new int[] { 0 }, new int[] { ba.length });
fromByteArray(ba);

}

/**
* convert a VT_UI1 array to string
* Convert a VT_UI1 array to string. Is this broken for unicode?
*
* @return variant byte as a string
*/
public String asString() {
if (getvt() != Variant.VariantByte) {
return null;
}
char ja[] = toCharArray();
return new String(ja);
// https://sourceforge.net/p/jacob-project/patches/41/
/*
* char ja[] = toCharArray(); return new String(ja);
*/
byte ba[] = toByteArray();
return new String(ba);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion jacob/src/com/jacob/com/Variant.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public class Variant extends JacobObject {

// VT_I1 = 16

/** variant's type is byte VT_UI1 */
/** variant's type is byte VT_UI1 This is an UNSIGNED byte */
public static final short VariantByte = 17;

// VT_UI2 = 18
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.jacob.test.safearray;

import com.jacob.com.SafeArray;
import com.jacob.test.BaseTestCase;

/**
* Test case provided #41 Fix for SafeArray(String) constructor
*
* In the current release of Jacob, SafeArray.java contains a constructor which
* takes a string as a single argument. The documentation claims that this
* method converts a string to a VT_UI1 array. Using this method as written
* always causes a ComFailException, because it attempts to create a SafeArray
* from Java chars, which are 16-bit unsigned integers (which would be VT_UI2).
*/
public class SafeArrayStringConstructorTest extends BaseTestCase {
public void testStringConstructor() {
// The line below will throw ComFailException using jacob 1.17-M2
// without the patch.
SafeArray safeArrayFromString = new SafeArray("This is a string.");
String convertBack = safeArrayFromString.asString();
assertEquals("This is a string.", convertBack);
}

}

0 comments on commit eeefefd

Please sign in to comment.