#41 Fix for SafeArray(String) constructor
#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
This commit is contained in:
@@ -23,8 +23,12 @@
|
|||||||
<td width="87%" valign="top">(M1)Fix memory pointer that was 32 bit. Causes defects in 64 bit systems above 2GB</td>
|
<td width="87%" valign="top">(M1)Fix memory pointer that was 32 bit. Causes defects in 64 bit systems above 2GB</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td width="13%" valign="top">115 (new system numbering)</td>
|
<td width="13%" valign="top">115 (new numbers)</td>
|
||||||
<td width="87%" valign="top">(M3)#115 Release problem if you've got two threads with the same name</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>
|
||||||
<tr>
|
<tr>
|
||||||
<td width="13%" valign="top"> </td>
|
<td width="13%" valign="top"> </td>
|
||||||
@@ -33,7 +37,10 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td colspan="2"><b>Patches</b></td>
|
<td colspan="2"><b>Patches</b></td>
|
||||||
</tr>
|
</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"> </td>
|
<td width="13%" valign="top"> </td>
|
||||||
<td width="87%" valign="top"> </td>
|
<td width="87%" valign="top"> </td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@@ -251,7 +251,7 @@ JNIEXPORT void JNICALL Java_com_jacob_com_Dispatch_release
|
|||||||
IDispatch *disp = (IDispatch *)num;
|
IDispatch *disp = (IDispatch *)num;
|
||||||
if (disp) {
|
if (disp) {
|
||||||
disp->Release();
|
disp->Release();
|
||||||
env->SetIntField(_this, jf, 0ll);
|
env->SetLongField(_this, jf, 0ll);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -90,19 +90,25 @@ public class SafeArray extends JacobObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* convert a string to a VT_UI1 array
|
* Convert a string to a VT_UI1 array.
|
||||||
*
|
*
|
||||||
* @param s
|
* @param s
|
||||||
* source string
|
* source string
|
||||||
*/
|
*/
|
||||||
public SafeArray(String s) {
|
public SafeArray(String s) {
|
||||||
char[] ca = s.toCharArray();
|
// https://sourceforge.net/p/jacob-project/patches/41/
|
||||||
init(Variant.VariantByte, new int[] { 0 }, new int[] { ca.length });
|
/*
|
||||||
fromCharArray(ca);
|
* 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
|
* @return variant byte as a string
|
||||||
*/
|
*/
|
||||||
@@ -110,8 +116,12 @@ public class SafeArray extends JacobObject {
|
|||||||
if (getvt() != Variant.VariantByte) {
|
if (getvt() != Variant.VariantByte) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
char ja[] = toCharArray();
|
// https://sourceforge.net/p/jacob-project/patches/41/
|
||||||
return new String(ja);
|
/*
|
||||||
|
* char ja[] = toCharArray(); return new String(ja);
|
||||||
|
*/
|
||||||
|
byte ba[] = toByteArray();
|
||||||
|
return new String(ba);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ public class Variant extends JacobObject {
|
|||||||
|
|
||||||
// VT_I1 = 16
|
// 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;
|
public static final short VariantByte = 17;
|
||||||
|
|
||||||
// VT_UI2 = 18
|
// VT_UI2 = 18
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user