Skip to content

Commit

Permalink
Rename Argument -> Arg
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Mar 19, 2024
1 parent dbe5f22 commit 3f86d70
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions java-spaghetti/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ pub use ::std;

mod refs {

mod argument;
mod arg;
mod global;
mod local;
mod ref_;

pub use argument::*;
pub use arg::*;
pub use global::*;
pub use local::*;
pub use ref_::*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ use jni_sys::*;

use crate::{Env, Global, Local, Ref, ReferenceType};

/// FFI: Use **Argument\<java::lang::Object\>** instead of jobject. This represents a (null?) function argument.
/// FFI: Use **Arg\<java::lang::Object\>** instead of jobject. This represents a (null?) function argument.
///
/// Unlike most Java reference types from this library, this *can* be null.
///
/// FFI safe where a jobject is safe, assuming you match your types correctly. Using the wrong type may result in
/// soundness issues, but at least on Android mostly seems to just result in JNI aborting execution for the current
/// process when calling methods on an instance of the wrong type.
#[repr(transparent)]
pub struct Argument<T: ReferenceType> {
pub struct Arg<T: ReferenceType> {
object: jobject,
_class: PhantomData<T>,
}

impl<T: ReferenceType> Argument<T> {
impl<T: ReferenceType> Arg<T> {
/// **unsafe**: There's no guarantee the jobject being passed is valid or null, nor any means of checking it.
pub unsafe fn from_raw(object: jobject) -> Self {
Self {
Expand All @@ -31,7 +31,7 @@ impl<T: ReferenceType> Argument<T> {
}

/// **unsafe**: This assumes the argument belongs to the given Env/VM, which is technically unsound. However, the
/// intended use case of immediately converting any Argument s into ArgumentRef s at the start of a JNI callback,
/// intended use case of immediately converting any Arg s into ArgRef s at the start of a JNI callback,
/// where Java directly invoked your function with an Env + arguments, is sound.
pub unsafe fn into_ref<'env>(self, env: Env<'env>) -> Option<Ref<'env, T>> {
if self.object.is_null() {
Expand All @@ -42,7 +42,7 @@ impl<T: ReferenceType> Argument<T> {
}

/// **unsafe**: This assumes the argument belongs to the given Env/VM, which is technically unsound. However, the
/// intended use case of immediately converting any Argument s into ArgumentRef s at the start of a JNI callback,
/// intended use case of immediately converting any Arg s into ArgRef s at the start of a JNI callback,
/// where Java directly invoked your function with an Env + arguments, is sound.
pub unsafe fn into_local<'env>(self, env: Env<'env>) -> Option<Local<'env, T>> {
if self.object.is_null() {
Expand All @@ -53,7 +53,7 @@ impl<T: ReferenceType> Argument<T> {
}

/// **unsafe**: This assumes the argument belongs to the given Env/VM, which is technically unsound. However, the
/// intended use case of immediately converting any Argument s into ArgumentRef s at the start of a JNI callback,
/// intended use case of immediately converting any Arg s into ArgRef s at the start of a JNI callback,
/// where Java directly invoked your function with an Env + arguments, is sound.
pub unsafe fn into_global(self, env: Env) -> Option<Global<T>> {
if self.object.is_null() {
Expand Down
2 changes: 1 addition & 1 deletion java-spaghetti/src/refs/ref_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use jni_sys::jobject;
use crate::{Env, Global, Local, ObjectAndEnv, ReferenceType};

/// A non-null, [reference](https://www.ibm.com/support/knowledgecenter/en/SSYKE2_8.0.0/com.ibm.java.vm.80.doc/docs/jni_refs.html)
/// to a Java object (+ [Env]). This may refer to a [Local](crate::Local), [Global](crate::Global), local [Argument](crate::Argument), etc.
/// to a Java object (+ [Env]). This may refer to a [Local](crate::Local), [Global](crate::Global), local [Arg](crate::Arg), etc.
///
/// **Not FFI Safe:** #\[repr(rust)\], and exact layout is likely to change - depending on exact features used - in the
/// future. Specifically, on Android, since we're guaranteed to only have a single ambient VM, we can likely store the
Expand Down

0 comments on commit 3f86d70

Please sign in to comment.