diff options
| author | android-build-team Robot <android-build-team-robot@google.com> | 2019-11-11 21:24:56 +0000 |
|---|---|---|
| committer | android-build-team Robot <android-build-team-robot@google.com> | 2019-11-11 21:24:56 +0000 |
| commit | 5b211f8cd277b2797ccadb2d3b94fddb35b9f155 (patch) | |
| tree | 0e1feaa1d877c9f624d1dea63127295f53b34e8a /include | |
| parent | 721695a8babcce4bdad0fd7134a3f6ab0c059ada (diff) | |
| parent | fcb38946a79ccfde12654834e936f0dee2c73350 (diff) | |
| download | platform_libnativehelper-android10-mainline-resolv-release.tar.gz platform_libnativehelper-android10-mainline-resolv-release.tar.bz2 platform_libnativehelper-android10-mainline-resolv-release.zip | |
Snap for 6001391 from fcb38946a79ccfde12654834e936f0dee2c73350 to qt-aml-resolv-releaseandroid-mainline-10.0.0_r8android10-mainline-resolv-release
Change-Id: Idb91a554fc5dda37e4d1bab3c8e6ed1bd87f86db
Diffstat (limited to 'include')
| -rw-r--r-- | include/nativehelper/JNIHelp.h | 163 | ||||
| -rw-r--r-- | include/nativehelper/JniInvocation.h | 16 | ||||
| -rw-r--r-- | include/nativehelper/ScopedBytes.h | 6 | ||||
| -rw-r--r-- | include/nativehelper/ScopedLocalFrame.h | 6 | ||||
| -rw-r--r-- | include/nativehelper/ScopedLocalRef.h | 6 | ||||
| -rw-r--r-- | include/nativehelper/ScopedPrimitiveArray.h | 6 | ||||
| -rw-r--r-- | include/nativehelper/ScopedStringChars.h | 6 | ||||
| -rw-r--r-- | include/nativehelper/ScopedUtfChars.h | 6 | ||||
| -rw-r--r-- | include/nativehelper/libnativehelper_api.h | 263 | ||||
| -rw-r--r-- | include/nativehelper/module_api.h | 23 | ||||
| -rw-r--r-- | include/nativehelper/toStringArray.h | 15 |
11 files changed, 294 insertions, 222 deletions
diff --git a/include/nativehelper/JNIHelp.h b/include/nativehelper/JNIHelp.h index 92a3882..858d625 100644 --- a/include/nativehelper/JNIHelp.h +++ b/include/nativehelper/JNIHelp.h @@ -20,172 +20,19 @@ * This file may be included by C or C++ code, which is trouble because jni.h * uses different typedefs for JNIEnv in each language. */ -#ifndef NATIVEHELPER_JNIHELP_H_ -#define NATIVEHELPER_JNIHELP_H_ +#ifndef LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_JNIHELP_H_ +#define LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_JNIHELP_H_ #include <errno.h> #include <unistd.h> -#include <jni.h> -#include "module_api.h" +#include "libnativehelper_api.h" #ifndef NELEM -# define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) +#define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) #endif /* - * Register one or more native methods with a particular class. - * "className" looks like "java/lang/String". Aborts on failure. - * TODO: fix all callers and change the return type to void. - */ -MODULE_API int jniRegisterNativeMethods(C_JNIEnv* env, - const char* className, - const JNINativeMethod* gMethods, - int numMethods); - -/* - * Throw an exception with the specified class and an optional message. - * - * The "className" argument will be passed directly to FindClass, which - * takes strings with slashes (e.g. "java/lang/Object"). - * - * If an exception is currently pending, we log a warning message and - * clear it. - * - * Returns 0 on success, nonzero if something failed (e.g. the exception - * class couldn't be found, so *an* exception will still be pending). - * - * Currently aborts the VM if it can't throw the exception. - */ -MODULE_API int jniThrowException(C_JNIEnv* env, const char* className, const char* msg); - -/* - * Throw an exception with the specified class and formatted error message. - * - * The "className" argument will be passed directly to FindClass, which - * takes strings with slashes (e.g. "java/lang/Object"). - * - * If an exception is currently pending, we log a warning message and - * clear it. - * - * Returns 0 on success, nonzero if something failed (e.g. the exception - * class couldn't be found, so *an* exception will still be pending). - * - * Currently aborts the VM if it can't throw the exception. - */ -MODULE_API int jniThrowExceptionFmt(C_JNIEnv* env, const char* className, const char* fmt, va_list args); - -/* - * Throw a java.lang.NullPointerException, with an optional message. - */ -MODULE_API int jniThrowNullPointerException(C_JNIEnv* env, const char* msg); - -/* - * Throw a java.lang.RuntimeException, with an optional message. - */ -MODULE_API int jniThrowRuntimeException(C_JNIEnv* env, const char* msg); - -/* - * Throw a java.io.IOException, generating the message from errno. - */ -MODULE_API int jniThrowIOException(C_JNIEnv* env, int errnum); - -/* - * Return a pointer to a locale-dependent error string explaining errno - * value 'errnum'. The returned pointer may or may not be equal to 'buf'. - * This function is thread-safe (unlike strerror) and portable (unlike - * strerror_r). - */ -MODULE_API const char* jniStrError(int errnum, char* buf, size_t buflen); - -/* - * Returns a new java.io.FileDescriptor for the given int fd. - */ -MODULE_API jobject jniCreateFileDescriptor(C_JNIEnv* env, int fd); - -/* - * Returns the int fd from a java.io.FileDescriptor. - */ -MODULE_API int jniGetFDFromFileDescriptor(C_JNIEnv* env, jobject fileDescriptor); - -/* - * Sets the int fd in a java.io.FileDescriptor. Throws java.lang.NullPointerException - * if fileDescriptor is null. - */ -MODULE_API void jniSetFileDescriptorOfFD(C_JNIEnv* env, - jobject fileDescriptor, - int value); - -/* - * Returns the long ownerId from a java.io.FileDescriptor. - */ -MODULE_API jlong jniGetOwnerIdFromFileDescriptor(C_JNIEnv* env, jobject fileDescriptor); - -/* - * Gets the managed heap array backing a java.nio.Buffer instance. - * - * Returns nullptr if there is no array backing. - * - * This method performs a JNI call to java.nio.NIOAccess.getBaseArray(). - */ -MODULE_API jarray jniGetNioBufferBaseArray(C_JNIEnv* env, jobject nioBuffer); - -/* - * Gets the offset in bytes from the start of the managed heap array backing the buffer. - * - * Returns 0 if there is no array backing. - * - * This method performs a JNI call to java.nio.NIOAccess.getBaseArrayOffset(). - */ -MODULE_API jint jniGetNioBufferBaseArrayOffset(C_JNIEnv* env, jobject nioBuffer); - -/* - * Gets field information from a java.nio.Buffer instance. - * - * Reads the |position|, |limit|, and |elementSizeShift| fields from the buffer instance. - * - * Returns the |address| field of the java.nio.Buffer instance which is only valid (non-zero) when - * the buffer is backed by a direct buffer. - */ -MODULE_API jlong jniGetNioBufferFields(C_JNIEnv* env, - jobject nioBuffer, - /*out*/jint* position, - /*out*/jint* limit, - /*out*/jint* elementSizeShift); - -/* - * Gets the current position from a java.nio.Buffer as a pointer to memory in a fixed buffer. - * - * Returns 0 if |nioBuffer| is not backed by a direct buffer. - * - * This method reads the |address|, |position|, and |elementSizeShift| fields from the - * java.nio.Buffer instance to calculate the pointer address for the current position. - */ -MODULE_API jlong jniGetNioBufferPointer(C_JNIEnv* env, jobject nioBuffer); - -/* - * Returns the reference from a java.lang.ref.Reference. - */ -MODULE_API jobject jniGetReferent(C_JNIEnv* env, jobject ref); - -/* - * Returns a Java String object created from UTF-16 data either from jchar or, - * if called from C++11, char16_t (a bitwise identical distinct type). - */ -MODULE_API jstring jniCreateString(C_JNIEnv* env, const jchar* unicodeChars, jsize len); - -/* - * Log a message and an exception. - * If exception is NULL, logs the current exception in the JNI environment. - */ -MODULE_API void jniLogException(C_JNIEnv* env, int priority, const char* tag, jthrowable exception); - -/* - * Clear the cache of constants libnativehelper is using. - */ -MODULE_API void jniUninitializeConstants(); - -/* * For C++ code, we provide inlines that map to the C functions. g++ always * inlines these, even on non-optimized builds. */ @@ -274,4 +121,4 @@ inline void jniLogException(JNIEnv* env, int priority, const char* tag, jthrowab #endif // defined(__cplusplus) -#endif /* NATIVEHELPER_JNIHELP_H_ */ +#endif // LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_JNIHELP_H_ diff --git a/include/nativehelper/JniInvocation.h b/include/nativehelper/JniInvocation.h index 0d87aa9..9b7d510 100644 --- a/include/nativehelper/JniInvocation.h +++ b/include/nativehelper/JniInvocation.h @@ -14,18 +14,10 @@ * limitations under the License. */ -#ifndef JNI_INVOCATION_H_included -#define JNI_INVOCATION_H_included +#ifndef LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_JNIINVOCATION_H_ +#define LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_JNIINVOCATION_H_ -#include <jni.h> -#include "module_api.h" - -struct JniInvocationImpl; - -MODULE_API struct JniInvocationImpl* JniInvocationCreate(); -MODULE_API void JniInvocationDestroy(struct JniInvocationImpl* instance); -MODULE_API int JniInvocationInit(struct JniInvocationImpl* instance, const char* library); -MODULE_API const char* JniInvocationGetLibrary(const char* library, char* buffer); +#include "libnativehelper_api.h" #ifdef __cplusplus @@ -77,4 +69,4 @@ class JniInvocation final { #endif // __cplusplus -#endif // JNI_INVOCATION_H_included +#endif // LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_JNIINVOCATION_H_ diff --git a/include/nativehelper/ScopedBytes.h b/include/nativehelper/ScopedBytes.h index 7cb2ad0..371b1bb 100644 --- a/include/nativehelper/ScopedBytes.h +++ b/include/nativehelper/ScopedBytes.h @@ -14,10 +14,10 @@ * limitations under the License. */ -#ifndef SCOPED_BYTES_H_included -#define SCOPED_BYTES_H_included +#ifndef LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDBYTES_H_ +#define LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDBYTES_H_ #include "JNIHelp.h" #include <nativehelper/scoped_bytes.h> -#endif // SCOPED_BYTES_H_included +#endif // LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDBYTES_H_ diff --git a/include/nativehelper/ScopedLocalFrame.h b/include/nativehelper/ScopedLocalFrame.h index 57873f2..4cb3d23 100644 --- a/include/nativehelper/ScopedLocalFrame.h +++ b/include/nativehelper/ScopedLocalFrame.h @@ -14,9 +14,9 @@ * limitations under the License. */ -#ifndef SCOPED_LOCAL_FRAME_H_included -#define SCOPED_LOCAL_FRAME_H_included +#ifndef LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDLOCALFRAME_H_ +#define LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDLOCALFRAME_H_ #include <nativehelper/scoped_local_frame.h> -#endif // SCOPED_LOCAL_FRAME_H_included +#endif // LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDLOCALFRAME_H_ diff --git a/include/nativehelper/ScopedLocalRef.h b/include/nativehelper/ScopedLocalRef.h index 0fb03d7..9960922 100644 --- a/include/nativehelper/ScopedLocalRef.h +++ b/include/nativehelper/ScopedLocalRef.h @@ -14,10 +14,10 @@ * limitations under the License. */ -#ifndef SCOPED_LOCAL_REF_H_included -#define SCOPED_LOCAL_REF_H_included +#ifndef LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDLOCALREF_H_ +#define LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDLOCALREF_H_ #include "JNIHelp.h" #include <nativehelper/scoped_local_ref.h> -#endif // SCOPED_LOCAL_REF_H_included +#endif // LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDLOCALREF_H_ diff --git a/include/nativehelper/ScopedPrimitiveArray.h b/include/nativehelper/ScopedPrimitiveArray.h index 626b64f..830a712 100644 --- a/include/nativehelper/ScopedPrimitiveArray.h +++ b/include/nativehelper/ScopedPrimitiveArray.h @@ -14,10 +14,10 @@ * limitations under the License. */ -#ifndef SCOPED_PRIMITIVE_ARRAY_H_included -#define SCOPED_PRIMITIVE_ARRAY_H_included +#ifndef LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDPRIMITIVEARRAY_H_ +#define LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDPRIMITIVEARRAY_H_ #include "JNIHelp.h" #include <nativehelper/scoped_primitive_array.h> -#endif // SCOPED_PRIMITIVE_ARRAY_H_included +#endif // LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDPRIMITIVEARRAY_H_ diff --git a/include/nativehelper/ScopedStringChars.h b/include/nativehelper/ScopedStringChars.h index 59c405c..f37d05c 100644 --- a/include/nativehelper/ScopedStringChars.h +++ b/include/nativehelper/ScopedStringChars.h @@ -14,10 +14,10 @@ * limitations under the License. */ -#ifndef SCOPED_STRING_CHARS_H_included -#define SCOPED_STRING_CHARS_H_included +#ifndef LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDSTRINGCHARS_H_ +#define LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDSTRINGCHARS_H_ #include "JNIHelp.h" #include <nativehelper/scoped_string_chars.h> -#endif // SCOPED_STRING_CHARS_H_included +#endif // LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDSTRINGCHARS_H_ diff --git a/include/nativehelper/ScopedUtfChars.h b/include/nativehelper/ScopedUtfChars.h index f123115..b782a4e 100644 --- a/include/nativehelper/ScopedUtfChars.h +++ b/include/nativehelper/ScopedUtfChars.h @@ -14,10 +14,10 @@ * limitations under the License. */ -#ifndef SCOPED_UTF_CHARS_H_included -#define SCOPED_UTF_CHARS_H_included +#ifndef LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDUTFCHARS_H_ +#define LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDUTFCHARS_H_ #include "JNIHelp.h" #include <nativehelper/scoped_utf_chars.h> -#endif // SCOPED_UTF_CHARS_H_included +#endif // LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_SCOPEDUTFCHARS_H_ diff --git a/include/nativehelper/libnativehelper_api.h b/include/nativehelper/libnativehelper_api.h new file mode 100644 index 0000000..b9e3570 --- /dev/null +++ b/include/nativehelper/libnativehelper_api.h @@ -0,0 +1,263 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_LIBNATIVEHELPER_API_H_ +#define LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_LIBNATIVEHELPER_API_H_ + +#include <stddef.h> + +#include "jni.h" + +// This is the stable C API exported by libnativehelper. + +#ifdef __cplusplus +extern "C" { +#endif // __cplusplus + +/* ------------------------------------ C API for JNIHelp.h ------------------------------------- */ + +/* + * Register one or more native methods with a particular class. "className" looks like + * "java/lang/String". Aborts on failure, returns 0 on success. + */ +int jniRegisterNativeMethods(C_JNIEnv* env, + const char* className, + const JNINativeMethod* gMethods, + int numMethods); + +/* + * Throw an exception with the specified class and an optional message. + * + * The "className" argument will be passed directly to FindClass, which + * takes strings with slashes (e.g. "java/lang/Object"). + * + * If an exception is currently pending, we log a warning message and + * clear it. + * + * Returns 0 on success, nonzero if something failed (e.g. the exception + * class couldn't be found, so *an* exception will still be pending). + * + * Currently aborts the VM if it can't throw the exception. + */ +int jniThrowException(C_JNIEnv* env, const char* className, const char* msg); + +/* + * Throw an exception with the specified class and formatted error message. + * + * The "className" argument will be passed directly to FindClass, which + * takes strings with slashes (e.g. "java/lang/Object"). + * + * If an exception is currently pending, we log a warning message and + * clear it. + * + * Returns 0 on success, nonzero if something failed (e.g. the exception + * class couldn't be found, so *an* exception will still be pending). + * + * Currently aborts the VM if it can't throw the exception. + */ +int jniThrowExceptionFmt(C_JNIEnv* env, const char* className, const char* fmt, va_list args); + +/* + * Throw a java.lang.NullPointerException, with an optional message. + */ +int jniThrowNullPointerException(C_JNIEnv* env, const char* msg); + +/* + * Throw a java.lang.RuntimeException, with an optional message. + */ +int jniThrowRuntimeException(C_JNIEnv* env, const char* msg); + +/* + * Throw a java.io.IOException, generating the message from errno. + */ +int jniThrowIOException(C_JNIEnv* env, int errnum); + +/* + * Return a pointer to a locale-dependent error string explaining errno + * value 'errnum'. The returned pointer may or may not be equal to 'buf'. + * This function is thread-safe (unlike strerror) and portable (unlike + * strerror_r). + */ +const char* jniStrError(int errnum, char* buf, size_t buflen); + +/* + * Returns a new java.io.FileDescriptor for the given int fd. + */ +jobject jniCreateFileDescriptor(C_JNIEnv* env, int fd); + +/* + * Returns the int fd from a java.io.FileDescriptor. + */ +int jniGetFDFromFileDescriptor(C_JNIEnv* env, jobject fileDescriptor); + +/* + * Sets the int fd in a java.io.FileDescriptor. Throws java.lang.NullPointerException + * if fileDescriptor is null. + */ +void jniSetFileDescriptorOfFD(C_JNIEnv* env, jobject fileDescriptor, int value); + +/* + * Returns the long ownerId from a java.io.FileDescriptor. + */ +jlong jniGetOwnerIdFromFileDescriptor(C_JNIEnv* env, jobject fileDescriptor); + +/* + * Gets the managed heap array backing a java.nio.Buffer instance. + * + * Returns nullptr if there is no array backing. + * + * This method performs a JNI call to java.nio.NIOAccess.getBaseArray(). + */ +jarray jniGetNioBufferBaseArray(C_JNIEnv* env, jobject nioBuffer); + +/* + * Gets the offset in bytes from the start of the managed heap array backing the buffer. + * + * Returns 0 if there is no array backing. + * + * This method performs a JNI call to java.nio.NIOAccess.getBaseArrayOffset(). + */ +jint jniGetNioBufferBaseArrayOffset(C_JNIEnv* env, jobject nioBuffer); + +/* + * Gets field information from a java.nio.Buffer instance. + * + * Reads the |position|, |limit|, and |elementSizeShift| fields from the buffer instance. + * + * Returns the |address| field of the java.nio.Buffer instance which is only valid (non-zero) when + * the buffer is backed by a direct buffer. + */ +jlong jniGetNioBufferFields(C_JNIEnv* env, + jobject nioBuffer, + /*out*/jint* position, + /*out*/jint* limit, + /*out*/jint* elementSizeShift); + +/* + * Gets the current position from a java.nio.Buffer as a pointer to memory in a fixed buffer. + * + * Returns 0 if |nioBuffer| is not backed by a direct buffer. + * + * This method reads the |address|, |position|, and |elementSizeShift| fields from the + * java.nio.Buffer instance to calculate the pointer address for the current position. + */ +jlong jniGetNioBufferPointer(C_JNIEnv* env, jobject nioBuffer); + +/* + * Returns the reference from a java.lang.ref.Reference. + */ +jobject jniGetReferent(C_JNIEnv* env, jobject ref); + +/* + * Returns a Java String object created from UTF-16 data either from jchar or, + * if called from C++11, char16_t (a bitwise identical distinct type). + */ +jstring jniCreateString(C_JNIEnv* env, const jchar* unicodeChars, jsize len); + +/* + * Log a message and an exception. + * If exception is NULL, logs the current exception in the JNI environment. + */ +void jniLogException(C_JNIEnv* env, int priority, const char* tag, jthrowable exception); + +/* + * Clear the cache of constants libnativehelper is using. + */ +void jniUninitializeConstants(); + +/* ---------------------------------- C API for JniInvocation.h --------------------------------- */ + +/* + * The JNI invocation API exists to allow a choice of library responsible for managing virtual + * machines. + */ + +/* + * Opaque structure used to hold JNI invocation internal state. + */ +struct JniInvocationImpl; + +/* + * Creates an instance of a JniInvocationImpl. + */ +struct JniInvocationImpl* JniInvocationCreate(); + +/* + * Associates a library with a JniInvocationImpl instance. The library should export C symbols for + * JNI_GetDefaultJavaVMInitArgs, JNI_CreateJavaVM and JNI_GetDefaultJavaVMInitArgs. + * + * The specified |library| should be the filename of a shared library. The |library| is opened with + * dlopen(3). + * + * If there is an error opening the specified |library|, then function will fallback to the + * default library "libart.so". If the fallback library is successfully used then a warning is + * written to the Android log buffer. Use of the fallback library is not considered an error. + * + * If the fallback library cannot be opened or the expected symbols are not found in the library + * opened, then an error message is written to the Android log buffer and the function returns 0. + * + * Returns 1 on success, 0 otherwise. + */ +int JniInvocationInit(struct JniInvocationImpl* instance, const char* library); + +/* + * Release resources associated with JniInvocationImpl instance. + */ +void JniInvocationDestroy(struct JniInvocationImpl* instance); + +/* + * Gets the default library for JNI invocation. The default library is "libart.so". This value may + * be overridden for debuggable builds using the persist.sys.dalvik.vm.lib.2 system property. + * + * The |library| argument is the preferred library to use on debuggable builds (when + * ro.debuggable=1). If the |library| argument is nullptr, then the system preferred value will be + * queried from persist.sys.dalvik.vm.lib.2 if the caller has provided |buffer| argument. + * + * The |buffer| argument is used for reading system properties in debuggable builds. It is + * optional, but should be provisioned to be PROP_VALUE_MAX bytes if provided to ensure it is + * large enough to hold a system property. + * + * Returns the filename of the invocation library determined from the inputs and system + * properties. The returned value may be |library|, |buffer|, or a pointer to a string constant + * "libart.so". + */ +const char* JniInvocationGetLibrary(const char* library, char* buffer); + +/* ---------------------------------- C API for toStringArray.h --------------------------------- */ + +/* + * Allocates a new array for java/lang/String instances with space for |count| elements. Elements + * are initially null. + * + * Returns a new array on success or nullptr in case of failure. This method raises an + * OutOfMemoryError exception if allocation fails. + */ +jobjectArray newStringArray(JNIEnv* env, size_t count); + +/* + * Converts an array of C strings into a managed array of Java strings. The size of the C array is + * determined by the presence of a final element containing a nullptr. + * + * Returns a new array on success or nullptr in case of failure. This method raises an + * OutOfMemoryError exception if allocation fails. + */ +jobjectArray toStringArray(JNIEnv* env, const char* const* strings); + +#ifdef __cplusplus +} +#endif // __cplusplus + +#endif // LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_LIBNATIVEHELPER_API_H_ diff --git a/include/nativehelper/module_api.h b/include/nativehelper/module_api.h deleted file mode 100644 index 8b109e3..0000000 --- a/include/nativehelper/module_api.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2019 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#ifdef __cplusplus -#define MODULE_API extern "C" -#else -#define MODULE_API -#endif // __cplusplus diff --git a/include/nativehelper/toStringArray.h b/include/nativehelper/toStringArray.h index 1965d6a..02072b0 100644 --- a/include/nativehelper/toStringArray.h +++ b/include/nativehelper/toStringArray.h @@ -14,17 +14,10 @@ * limitations under the License. */ -#ifndef TO_STRING_ARRAY_H_included -#define TO_STRING_ARRAY_H_included +#ifndef LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_TOSTRINGARRAY_H_ +#define LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_TOSTRINGARRAY_H_ -#include <stddef.h> - -#include <jni.h> -#include "module_api.h" - -// Public API for libnativehelper library. -MODULE_API jobjectArray newStringArray(JNIEnv* env, size_t count); -MODULE_API jobjectArray toStringArray(JNIEnv* env, const char* const* strings); +#include "libnativehelper_api.h" #ifdef __cplusplus @@ -75,4 +68,4 @@ inline jobjectArray toStringArray(JNIEnv* env, const std::vector<std::string>& s #endif // __cplusplus -#endif // TO_STRING_ARRAY_H_included +#endif // LIBNATIVEHELPER_INCLUDE_NATIVEHELPER_TOSTRINGARRAY_H_ |
