diff --git a/ndk/.gitignore b/ndk/.gitignore index 48a8878a1..923cc4049 100644 --- a/ndk/.gitignore +++ b/ndk/.gitignore @@ -2,5 +2,9 @@ samples/*/libs/ samples/*/obj/ samples/*/bin/ samples/*/gen/ +tests/*/libs +tests/*/obj/ +tests/*/bin/ +tests/*/gen/ local.properties build.xml diff --git a/ndk/platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o b/ndk/platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o index 63d4efae4..f34cba84e 100644 Binary files a/ndk/platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o and b/ndk/platforms/android-9/arch-arm/usr/lib/crtbegin_dynamic.o differ diff --git a/ndk/platforms/android-9/arch-arm/usr/lib/crtbegin_so.o b/ndk/platforms/android-9/arch-arm/usr/lib/crtbegin_so.o new file mode 100644 index 000000000..523017896 Binary files /dev/null and b/ndk/platforms/android-9/arch-arm/usr/lib/crtbegin_so.o differ diff --git a/ndk/platforms/android-9/arch-arm/usr/lib/crtbegin_static.o b/ndk/platforms/android-9/arch-arm/usr/lib/crtbegin_static.o index d11c79ebe..f34cba84e 100644 Binary files a/ndk/platforms/android-9/arch-arm/usr/lib/crtbegin_static.o and b/ndk/platforms/android-9/arch-arm/usr/lib/crtbegin_static.o differ diff --git a/ndk/platforms/android-9/arch-arm/usr/lib/crtend_android.o b/ndk/platforms/android-9/arch-arm/usr/lib/crtend_android.o index 5b76af8da..c57149e5d 100644 Binary files a/ndk/platforms/android-9/arch-arm/usr/lib/crtend_android.o and b/ndk/platforms/android-9/arch-arm/usr/lib/crtend_android.o differ diff --git a/ndk/platforms/android-9/arch-arm/usr/lib/crtend_so.o b/ndk/platforms/android-9/arch-arm/usr/lib/crtend_so.o new file mode 100644 index 000000000..c54db97fd Binary files /dev/null and b/ndk/platforms/android-9/arch-arm/usr/lib/crtend_so.o differ diff --git a/ndk/platforms/android-9/arch-arm/usr/lib/libc.a b/ndk/platforms/android-9/arch-arm/usr/lib/libc.a index 4fdcafc41..bebfe791e 100644 Binary files a/ndk/platforms/android-9/arch-arm/usr/lib/libc.a and b/ndk/platforms/android-9/arch-arm/usr/lib/libc.a differ diff --git a/ndk/platforms/android-9/arch-arm/usr/lib/libc.so b/ndk/platforms/android-9/arch-arm/usr/lib/libc.so index 9714e97e3..2e076b5ae 100644 Binary files a/ndk/platforms/android-9/arch-arm/usr/lib/libc.so and b/ndk/platforms/android-9/arch-arm/usr/lib/libc.so differ diff --git a/ndk/tests/dlclose-destruction/jni/Android.mk b/ndk/tests/dlclose-destruction/jni/Android.mk new file mode 100644 index 000000000..09226c794 --- /dev/null +++ b/ndk/tests/dlclose-destruction/jni/Android.mk @@ -0,0 +1,12 @@ +# A small sample used to demonstrate static C++ destructors +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +LOCAL_MODULE := libtest1 +LOCAL_SRC_FILES := libtest1.cpp +include $(BUILD_SHARED_LIBRARY) + +include $(CLEAR_VARS) +LOCAL_MODULE := test_dlclose_destruction +LOCAL_SRC_FILES := main.c +include $(BUILD_EXECUTABLE) diff --git a/ndk/tests/dlclose-destruction/jni/Application.mk b/ndk/tests/dlclose-destruction/jni/Application.mk new file mode 100644 index 000000000..22d188e59 --- /dev/null +++ b/ndk/tests/dlclose-destruction/jni/Application.mk @@ -0,0 +1 @@ +APP_PLATFORM := android-9 diff --git a/ndk/tests/dlclose-destruction/jni/libtest1.cpp b/ndk/tests/dlclose-destruction/jni/libtest1.cpp new file mode 100644 index 000000000..0544b2bf1 --- /dev/null +++ b/ndk/tests/dlclose-destruction/jni/libtest1.cpp @@ -0,0 +1,31 @@ +#include +#include "libtest1.h" + +class Foo +{ +public: + Foo() { mAddress = NULL; } + void setAddress(int *px); + ~Foo(); +private: + int *mAddress; +}; + +void Foo::setAddress(int *px) +{ + mAddress = px; + *mAddress = 1; +} + +Foo::~Foo() +{ + if (mAddress) + *mAddress = 2; +} + +static Foo foo; + +extern "C" void test1_set(int *px) +{ + foo.setAddress(px); +} diff --git a/ndk/tests/dlclose-destruction/jni/libtest1.h b/ndk/tests/dlclose-destruction/jni/libtest1.h new file mode 100644 index 000000000..6471332e9 --- /dev/null +++ b/ndk/tests/dlclose-destruction/jni/libtest1.h @@ -0,0 +1,21 @@ +#ifndef LIBTEST1_H +#define LIBTEST1_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* define in libtest1, will be called dynamically through dlsym() + * by main.c. This function receives the address of an integer + * and sets its value to 1. + * + * when the library is unloaded, the value is set to 2 automatically + * by the destructor there. + */ +extern void test1_set(int *px); + +#ifdef __cplusplus +} +#endif + +#endif /* LIBTEST1_H */ diff --git a/ndk/tests/dlclose-destruction/jni/main.c b/ndk/tests/dlclose-destruction/jni/main.c new file mode 100644 index 000000000..63c0a6524 --- /dev/null +++ b/ndk/tests/dlclose-destruction/jni/main.c @@ -0,0 +1,48 @@ +#include +#include + +typedef void (*test_func_t)(int *px); +int x; + +int main(void) +{ + void* lib = dlopen("libtest1.so", RTLD_NOW); + test_func_t test_func; + + if (lib == NULL) { + fprintf(stderr, "Can't load library: %s\n", dlerror()); + return 1; + } + + printf("Loaded !\n"); + + test_func = dlsym(lib, "test1_set"); + if (test_func == NULL) { + fprintf(stderr, "Can't find test function\n"); + return 2; + } + + x = 0; + test_func(&x); + + if (x == 1) { + printf("Test function called !\n"); + } else { + fprintf(stderr, "Test function failed to set variable !\n"); + return 3; + } + + dlclose(lib); + printf("Unloaded !\n"); + + if (x == 2) { + printf("Test destructor called !\n"); + } else if (x == 1) { + fprintf(stderr, "Test destructor was *not* called !\n"); + return 4; + } else { + fprintf(stderr, "Test destructor called but returned invalid value (%d)\n", x); + return 5; + } + return 0; +}