Skip to content

Commit

Permalink
Safearray init0 #45
Browse files Browse the repository at this point in the history
  • Loading branch information
freemansoft committed Mar 19, 2024
1 parent 768a6ff commit c7b0ecc
Show file tree
Hide file tree
Showing 3 changed files with 853 additions and 917 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ See [ReleaseNotes](docs/ReleaseNotes.md) for a full history
| https://github.com/freemansoft/jacob-project/issues/40 | Incorrect delete in Dispatch JNI Invoke() |
| https://github.com/freemansoft/jacob-project/issues/42 | ArrayIndexOutOfBounds SafeArray |
| https://github.com/freemansoft/jacob-project/issues/43 | Memory Leaks in DispatchEvents.cpp |
| https://github.com/freemansoft/jacob-project/issues/45 | SaveArray init0 |
| https://github.com/freemansoft/jacob-project/issues/48 | Incorrect multi dimensional array element count |
| | none |
| **Patches** | |
Expand Down
42 changes: 42 additions & 0 deletions src/jni/SafeArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,48 @@ extern "C"
// what to do here?
}

/*
* Class: SafeArray
* Method: reinit0
* Signature: (LSafeArray;)V
*/
JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_reinit0(JNIEnv *env, jobject _this, jobject sa)
{
// EJP 1/12/2023 implemented this.
/*
* The MS documentation is clear that it is the SafeArray supplied as a parameter
* that is reinitialized.
* It is assumed here that this means destroying all its data
* but leaving its type and dimensions alone.
* Otherwise there would be no further way to use that SafeArray.
*
* This method is implemented by calling SafeArrayDestroyData() and then SafeArrayAllocData().
*
* Note on locking.
*
* 1. SafeArrayDestroyData() gives an error if the array is locked.
* 2. SafeArrayAllocData() gives an error if the array could not be locked.
*
* This implies that both methods lock the array internally.
* This in turn that it can't be locked out here, which would otherwise be desirable for atomicity.
*/
SAFEARRAY *psa = extractSA(env, sa);
if (!psa)
{
ThrowComFail(env, "safearray not initialized or corrupted", -1);
return;
}
HRESULT hr = SafeArrayDestroyData(psa);
if (SUCCEEDED(hr))
{
hr = SafeArrayAllocData(psa);
}
if (!SUCCEEDED(hr))
{
ThrowComFail(env, "safearray destroy or alloc failed", hr);
}
}

/*
* Class: SafeArray
* Method: reinterpretType
Expand Down
Loading

0 comments on commit c7b0ecc

Please sign in to comment.