This repository has been archived by the owner on Apr 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* attach finalizable to close the port for interfaces * add missing JCharacter boxed type * add .implement method completed for interfaces * fix descriptor issues * temporarily do not check the ffigen bindings until ffigen#555 is solved * remove duplicated java source in jni + sort ffigen.yaml inline functions * add the interface implementation under an experiment flag + docs
- Loading branch information
1 parent
c7fbb15
commit c951f23
Showing
81 changed files
with
2,774 additions
and
340 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-keep class com.github.dart_lang.jni.** { *; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 0 additions & 42 deletions
42
jni/android/src/main/java/com/github/dart_lang/jni/PortContinuation.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
<build> | ||
<finalName>jni</finalName> | ||
<directory>${target}</directory> | ||
</build> | ||
|
||
<dependencies> | ||
|
82 changes: 82 additions & 0 deletions
82
jni/java/src/main/java/com/github/dart_lang/jni/PortProxy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
package com.github.dart_lang.jni; | ||
|
||
import java.lang.reflect.*; | ||
|
||
public class PortProxy implements InvocationHandler { | ||
static { | ||
System.loadLibrary("dartjni"); | ||
} | ||
|
||
private final long port; | ||
private final long threadId; | ||
private final long functionPtr; | ||
|
||
private PortProxy(long port, long threadId, long functionPtr) { | ||
this.port = port; | ||
this.threadId = threadId; | ||
this.functionPtr = functionPtr; | ||
} | ||
|
||
private static String getDescriptor(Method method) { | ||
StringBuilder descriptor = new StringBuilder(); | ||
descriptor.append(method.getName()).append("("); | ||
Class<?>[] parameterTypes = method.getParameterTypes(); | ||
for (Class<?> paramType : parameterTypes) { | ||
appendType(descriptor, paramType); | ||
} | ||
descriptor.append(")"); | ||
appendType(descriptor, method.getReturnType()); | ||
return descriptor.toString(); | ||
} | ||
|
||
private static void appendType(StringBuilder descriptor, Class<?> type) { | ||
if (type == void.class) { | ||
descriptor.append("V"); | ||
} else if (type == boolean.class) { | ||
descriptor.append("Z"); | ||
} else if (type == byte.class) { | ||
descriptor.append("B"); | ||
} else if (type == char.class) { | ||
descriptor.append("C"); | ||
} else if (type == short.class) { | ||
descriptor.append("S"); | ||
} else if (type == int.class) { | ||
descriptor.append("I"); | ||
} else if (type == long.class) { | ||
descriptor.append("J"); | ||
} else if (type == float.class) { | ||
descriptor.append("F"); | ||
} else if (type == double.class) { | ||
descriptor.append("D"); | ||
} else if (type.isArray()) { | ||
descriptor.append('['); | ||
appendType(descriptor, type.getComponentType()); | ||
} else { | ||
descriptor.append("L").append(type.getName().replace('.', '/')).append(";"); | ||
} | ||
} | ||
|
||
public static Object newInstance(String binaryName, long port, long threadId, long functionPtr) | ||
throws ClassNotFoundException { | ||
Class clazz = Class.forName(binaryName); | ||
return Proxy.newProxyInstance( | ||
clazz.getClassLoader(), new Class[] {clazz}, new PortProxy(port, threadId, functionPtr)); | ||
} | ||
|
||
@Override | ||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | ||
return _invoke(port, threadId, functionPtr, proxy, getDescriptor(method), args); | ||
} | ||
|
||
private native Object _invoke( | ||
long port, | ||
long threadId, | ||
long functionPtr, | ||
Object proxy, | ||
String methodDescriptor, | ||
Object[] args); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.