Skip to content

Commit

Permalink
Java: rename delete function to _delete and make private.
Browse files Browse the repository at this point in the history
At the moment, Java classes are created with a special `delete`
function that is in charge of clearing the Rust object, e.g.:

```
public synchronized void delete() {
    if (mNativeObj != 0) {
        do_delete(mNativeObj);
        mNativeObj = 0;
   }
}
```

Delete is quite a useful name to have (I use it in my API) and
this function being called this way is confusing, but also
needlessly limits the API.

Fixes Dushistov#350
  • Loading branch information
tasn committed Aug 26, 2020
1 parent cd5f502 commit 5ce81ec
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions macroslib/src/java_jni/fclass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,22 +442,22 @@ May be you need to use `private constructor = empty;` syntax?",
writeln!(
file,
r#"
public synchronized void delete() {{
private synchronized void _delete() {{
if ({rust_self_name} != 0) {{
do_delete({rust_self_name});
do__delete({rust_self_name});
{rust_self_name} = 0;
}}
}}
@Override
protected void finalize() throws Throwable {{
try {{
delete();
_delete();
}}
finally {{
super.finalize();
}}
}}
private static native void do_delete(long me);
private static native void do__delete(long me);
/*package*/ {class_name}({internal_ptr_marker} marker, long ptr) {{
assert marker == {internal_ptr_marker}.RAW_PTR;
this.{rust_self_name} = ptr;
Expand Down Expand Up @@ -707,7 +707,7 @@ May be you need to use `private constructor = empty;` syntax?",
ctx,
&class.name.to_string(),
(class.src_id, class.span()),
"do_delete",
"do__delete",
MethodVariant::StaticMethod,
&JniForeignMethodSignature {
output: ForeignTypeInfo {
Expand Down

0 comments on commit 5ce81ec

Please sign in to comment.