mirror of
https://github.com/corda/corda.git
synced 2025-01-17 10:20:02 +00:00
Use custom initialization scheme to allow the java-nio library to be linked without
the stdc++ library, using a custom operator new
This commit is contained in:
parent
71e7a6d796
commit
782081d1ff
@ -402,7 +402,7 @@ class Pipe {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
~Pipe() {
|
void dispose() {
|
||||||
::close(pipe[0]);
|
::close(pipe[0]);
|
||||||
::close(pipe[1]);
|
::close(pipe[1]);
|
||||||
}
|
}
|
||||||
@ -434,17 +434,25 @@ struct SelectorState {
|
|||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
inline void* operator new(size_t, void* p) throw() { return p; }
|
||||||
|
|
||||||
extern "C" JNIEXPORT jlong JNICALL
|
extern "C" JNIEXPORT jlong JNICALL
|
||||||
Java_java_nio_channels_SocketSelector_natInit(JNIEnv* e, jclass)
|
Java_java_nio_channels_SocketSelector_natInit(JNIEnv* e, jclass)
|
||||||
{
|
{
|
||||||
SelectorState* s = new SelectorState(e);
|
void *mem = malloc(sizeof(SelectorState));
|
||||||
|
if (mem) {
|
||||||
|
SelectorState *s = new (mem) SelectorState(e);
|
||||||
|
|
||||||
if (s) {
|
if (s) {
|
||||||
FD_ZERO(&(s->read));
|
FD_ZERO(&(s->read));
|
||||||
FD_ZERO(&(s->write));
|
FD_ZERO(&(s->write));
|
||||||
FD_ZERO(&(s->except));
|
FD_ZERO(&(s->except));
|
||||||
}
|
|
||||||
return reinterpret_cast<jlong>(s);
|
return reinterpret_cast<jlong>(s);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
throwNew(e, "java/lang/OutOfMemoryError", 0);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" JNIEXPORT void JNICALL
|
extern "C" JNIEXPORT void JNICALL
|
||||||
Java_java_nio_channels_SocketSelector_natWakeup(JNIEnv *e, jclass, jlong state)
|
Java_java_nio_channels_SocketSelector_natWakeup(JNIEnv *e, jclass, jlong state)
|
||||||
@ -476,7 +484,8 @@ extern "C" JNIEXPORT void JNICALL
|
|||||||
Java_java_nio_channels_SocketSelector_natClose(JNIEnv *, jclass, jlong state)
|
Java_java_nio_channels_SocketSelector_natClose(JNIEnv *, jclass, jlong state)
|
||||||
{
|
{
|
||||||
SelectorState* s = reinterpret_cast<SelectorState*>(state);
|
SelectorState* s = reinterpret_cast<SelectorState*>(state);
|
||||||
delete s;
|
s->control.dispose();
|
||||||
|
free(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" JNIEXPORT void JNICALL
|
extern "C" JNIEXPORT void JNICALL
|
||||||
|
Loading…
Reference in New Issue
Block a user