Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SafeArray.reinit() #45

Closed
EJP286CRSKW opened this issue Oct 18, 2023 · 8 comments
Closed

Implement SafeArray.reinit() #45

EJP286CRSKW opened this issue Oct 18, 2023 · 8 comments

Comments

@EJP286CRSKW
Copy link

EJP286CRSKW commented Oct 18, 2023

This is implementable as SafeArrayDestroyData() followed by SafeArrayAllocData(), with suitable error-checking.

@freemansoft
Copy link
Owner

Where?

@EJP286CRSKW
Copy link
Author

In SafeArray.cpp, as follows (modulo typos):


/*
 * 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);
        }
}

@freemansoft
Copy link
Owner

freemansoft commented Mar 19, 2024

Why did you call this reinit0? We have a signature that is not implemented that seems like it would align. Does this replace reinit?

  JNIEXPORT void JNICALL Java_com_jacob_com_SafeArray_reinit(JNIEnv *env, jobject _this, jobject sa)

freemansoft added a commit that referenced this issue Mar 19, 2024
@freemansoft
Copy link
Owner

Implemented in c7b0ecc as coded with init0

@EJP286CRSKW
Copy link
Author

EJP286CRSKW commented Mar 19, 2024

I did that in association with:

public void reinit()
{
    reinit0();
}

private native void reinit0();

in SafeArray.java. Previously the method was public native, which is frowned on. The pattern above is used throughout the JDK and all my Java code for 27 years.

@freemansoft
Copy link
Owner

Does this sound right

  1. Replace reinit() with renit0() in SafeArray.cpp from the first post in this thread
  2. Rename reinit() with reinit0() in SafeArray.h to align with the SafeArray.cpp name
  3. Replace the public native void reinit() with the block in your previous response that makes the native private and creates a java wrapper method reinit() for the reinit0() private

And then sometime, maybe, in the future the other privates should be updated to follow the same pattern

@EJP286CRSKW
Copy link
Author

Correct. Sorry if I wasn't clear. I am so used to doing it this way ...

freemansoft added a commit that referenced this issue Mar 20, 2024
@freemansoft
Copy link
Owner

Change pushed ea09033

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants