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

API Enhancements #18

Merged
merged 3 commits into from
Mar 15, 2021
Merged

API Enhancements #18

merged 3 commits into from
Mar 15, 2021

Conversation

rikner
Copy link
Collaborator

@rikner rikner commented Mar 12, 2021

Adds new public APIs:

  • JNI.GetDirectBufferAddress(buffer:)
  • JNI.GetField(fieldName: fieldJavaClassName: from:)
  • JNIObject.getField(fieldName: fieldJavaClassName:)

@rikner rikner force-pushed the api-enhancements branch from 77976f7 to ffa9bf7 Compare March 12, 2021 15:56
@rikner rikner requested a review from ephemer March 12, 2021 15:57
func GetField(_ fieldName: String, fieldJavaClassName: String, from javaObject: JavaObject) throws -> JavaObject {
let env = self._env
let javaClass = try GetObjectClass(obj: javaObject)
let fieldID = env.pointee.pointee.GetFieldID(env, javaClass, fieldName, "L\(fieldJavaClassName);")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure but I think we might need to delete the local ref to the class here after we use it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh yes, totally oversaw this. we do it also in the other methods above :+1

@@ -87,6 +87,10 @@ open class JNIObject {
return try jni.GetField(fieldName, from: self.instance)
}

public func getField(_ fieldName: String, fieldJavaClassName: String) throws -> JavaObject {
return try jni.GetField(fieldName, fieldJavaClassName: fieldJavaClassName, from: self.instance)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool looks good, ideally we'd add getters for primitive fields too (Int etc) but we can also do that later when/if we need it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what you mean is already covered by the generic methods above.


func GetDirectBufferAddress(buffer: JavaObject) -> UnsafeMutableRawPointer? {
let env = self._env
return env.pointee.pointee.GetDirectBufferAddress(env, buffer)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

@rikner rikner merged commit bf6249d into devel Mar 15, 2021
@rikner rikner deleted the api-enhancements branch March 15, 2021 11:22
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

Successfully merging this pull request may close these issues.

2 participants