am 2708f19b: Merge "Update API level 9 sysroot to allow static C++ destructors to be called on dlclose()." into gingerbread
Merge commit '2708f19ba33163b1ac0c5ea2758d0c09d97e8cc0' into gingerbread-plus-aosp * commit '2708f19ba33163b1ac0c5ea2758d0c09d97e8cc0': Update API level 9 sysroot to allow static C++ destructors to be called on dlclose().
This commit is contained in:
committed by
Android Git Automerger
commit
ac243e049f
4
ndk/.gitignore
vendored
4
ndk/.gitignore
vendored
@@ -2,5 +2,9 @@ samples/*/libs/
|
||||
samples/*/obj/
|
||||
samples/*/bin/
|
||||
samples/*/gen/
|
||||
tests/*/libs
|
||||
tests/*/obj/
|
||||
tests/*/bin/
|
||||
tests/*/gen/
|
||||
local.properties
|
||||
build.xml
|
||||
|
||||
Binary file not shown.
BIN
ndk/platforms/android-9/arch-arm/usr/lib/crtbegin_so.o
Normal file
BIN
ndk/platforms/android-9/arch-arm/usr/lib/crtbegin_so.o
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
ndk/platforms/android-9/arch-arm/usr/lib/crtend_so.o
Normal file
BIN
ndk/platforms/android-9/arch-arm/usr/lib/crtend_so.o
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
12
ndk/tests/dlclose-destruction/jni/Android.mk
Normal file
12
ndk/tests/dlclose-destruction/jni/Android.mk
Normal file
@@ -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)
|
||||
1
ndk/tests/dlclose-destruction/jni/Application.mk
Normal file
1
ndk/tests/dlclose-destruction/jni/Application.mk
Normal file
@@ -0,0 +1 @@
|
||||
APP_PLATFORM := android-9
|
||||
31
ndk/tests/dlclose-destruction/jni/libtest1.cpp
Normal file
31
ndk/tests/dlclose-destruction/jni/libtest1.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <stddef.h>
|
||||
#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);
|
||||
}
|
||||
21
ndk/tests/dlclose-destruction/jni/libtest1.h
Normal file
21
ndk/tests/dlclose-destruction/jni/libtest1.h
Normal file
@@ -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 */
|
||||
48
ndk/tests/dlclose-destruction/jni/main.c
Normal file
48
ndk/tests/dlclose-destruction/jni/main.c
Normal file
@@ -0,0 +1,48 @@
|
||||
#include <stdio.h>
|
||||
#include <dlfcn.h>
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user