mirror of
https://github.com/corda/corda.git
synced 2025-01-22 12:28:11 +00:00
Merge branch 'master' of oss.readytalk.com:/var/local/git/avian
This commit is contained in:
commit
abe6ada0c2
@ -16,6 +16,17 @@ public class InputStreamReader extends Reader {
|
|||||||
public InputStreamReader(InputStream in) {
|
public InputStreamReader(InputStream in) {
|
||||||
this.in = in;
|
this.in = in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public InputStreamReader(InputStream in, String encoding)
|
||||||
|
throws UnsupportedEncodingException
|
||||||
|
{
|
||||||
|
this(in);
|
||||||
|
|
||||||
|
if (! encoding.equals("UTF-8")) {
|
||||||
|
throw new UnsupportedEncodingException(encoding);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public int read(char[] b, int offset, int length) throws IOException {
|
public int read(char[] b, int offset, int length) throws IOException {
|
||||||
byte[] buffer = new byte[length];
|
byte[] buffer = new byte[length];
|
||||||
|
@ -32,6 +32,13 @@ public final class String implements Comparable<String>, CharSequence {
|
|||||||
this(data, 0, data.length);
|
this(data, 0, data.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String(byte bytes[], int offset, int length, String charsetName) throws UnsupportedEncodingException {
|
||||||
|
this(bytes, offset, length);
|
||||||
|
if (!charsetName.equals("UTF-8")) {
|
||||||
|
throw new UnsupportedEncodingException(charsetName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public String(byte[] data, int offset, int length, boolean copy) {
|
public String(byte[] data, int offset, int length, boolean copy) {
|
||||||
this((Object) data, offset, length, copy);
|
this((Object) data, offset, length, copy);
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,8 @@ public class SocketChannel extends SelectableChannel
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int doConnect(String host, int port) throws Exception {
|
private int doConnect(String host, int port) throws Exception {
|
||||||
|
if (host == null) throw new NullPointerException();
|
||||||
|
|
||||||
boolean b[] = new boolean[1];
|
boolean b[] = new boolean[1];
|
||||||
int s = natDoConnect(host, port, b);
|
int s = natDoConnect(host, port, b);
|
||||||
connected = b[0];
|
connected = b[0];
|
||||||
@ -66,7 +68,11 @@ public class SocketChannel extends SelectableChannel
|
|||||||
public int read(ByteBuffer b) throws IOException {
|
public int read(ByteBuffer b) throws IOException {
|
||||||
if (! isOpen()) return -1;
|
if (! isOpen()) return -1;
|
||||||
if (b.remaining() == 0) return 0;
|
if (b.remaining() == 0) return 0;
|
||||||
int r = natRead(socket, b.array(), b.arrayOffset() + b.position(), b.remaining());
|
|
||||||
|
byte[] array = b.array();
|
||||||
|
if (array == null) throw new NullPointerException();
|
||||||
|
|
||||||
|
int r = natRead(socket, array, b.arrayOffset() + b.position(), b.remaining());
|
||||||
if (r > 0) {
|
if (r > 0) {
|
||||||
b.position(b.position() + r);
|
b.position(b.position() + r);
|
||||||
}
|
}
|
||||||
@ -78,7 +84,11 @@ public class SocketChannel extends SelectableChannel
|
|||||||
natThrowWriteError(socket);
|
natThrowWriteError(socket);
|
||||||
}
|
}
|
||||||
if (b.remaining() == 0) return 0;
|
if (b.remaining() == 0) return 0;
|
||||||
int w = natWrite(socket, b.array(), b.arrayOffset() + b.position(), b.remaining());
|
|
||||||
|
byte[] array = b.array();
|
||||||
|
if (array == null) throw new NullPointerException();
|
||||||
|
|
||||||
|
int w = natWrite(socket, array, b.arrayOffset() + b.position(), b.remaining());
|
||||||
if (w > 0) {
|
if (w > 0) {
|
||||||
b.position(b.position() + w);
|
b.position(b.position() + w);
|
||||||
}
|
}
|
||||||
|
@ -45,16 +45,20 @@ public class BitSet implements Serializable, Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void and(BitSet otherBits) {
|
public void and(BitSet otherBits) {
|
||||||
int max = Math.max(bits.length, otherBits.bits.length);
|
int min = Math.min(bits.length, otherBits.bits.length);
|
||||||
for (int i = 0; i < max; i++) {
|
for (int i = 0; i < min; i++) {
|
||||||
bits[i] &= otherBits.bits[i];
|
bits[i] &= otherBits.bits[i];
|
||||||
}
|
}
|
||||||
|
for (int i = min; i < bits.length; i++) {
|
||||||
|
bits[i] = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void andNot(BitSet otherBits) {
|
public void andNot(BitSet otherBits) {
|
||||||
int max = Math.max(bits.length, otherBits.bits.length);
|
int max = Math.max(bits.length, otherBits.bits.length);
|
||||||
enlarge(max);
|
enlarge(max);
|
||||||
for (int i = 0; i < max; i++) {
|
int min = Math.min(bits.length, otherBits.bits.length);
|
||||||
|
for (int i = 0; i < min; i++) {
|
||||||
bits[i] &= ~otherBits.bits[i];
|
bits[i] &= ~otherBits.bits[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -62,7 +66,8 @@ public class BitSet implements Serializable, Cloneable {
|
|||||||
public void or(BitSet otherBits) {
|
public void or(BitSet otherBits) {
|
||||||
int max = Math.max(bits.length, otherBits.bits.length);
|
int max = Math.max(bits.length, otherBits.bits.length);
|
||||||
enlarge(max);
|
enlarge(max);
|
||||||
for (int i = 0; i < max; i++) {
|
int min = Math.min(bits.length, otherBits.bits.length);
|
||||||
|
for (int i = 0; i < min; i++) {
|
||||||
bits[i] |= otherBits.bits[i];
|
bits[i] |= otherBits.bits[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,13 +75,14 @@ public class BitSet implements Serializable, Cloneable {
|
|||||||
public void xor(BitSet otherBits) {
|
public void xor(BitSet otherBits) {
|
||||||
int max = Math.max(bits.length, otherBits.bits.length);
|
int max = Math.max(bits.length, otherBits.bits.length);
|
||||||
enlarge(max);
|
enlarge(max);
|
||||||
for (int i = 0; i < max; i++) {
|
int min = Math.min(bits.length, otherBits.bits.length);
|
||||||
|
for (int i = 0; i < min; i++) {
|
||||||
bits[i] ^= otherBits.bits[i];
|
bits[i] ^= otherBits.bits[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enlarge(int newSize) {
|
private void enlarge(int newSize) {
|
||||||
if (bits == null || bits.length <= newSize) {
|
if (bits == null || bits.length < newSize) {
|
||||||
long[] newBits = new long[newSize + 1];
|
long[] newBits = new long[newSize + 1];
|
||||||
if (bits != null) {
|
if (bits != null) {
|
||||||
System.arraycopy(bits, 0, newBits, 0, bits.length);
|
System.arraycopy(bits, 0, newBits, 0, bits.length);
|
||||||
|
@ -13,6 +13,25 @@ package java.util;
|
|||||||
public class Collections {
|
public class Collections {
|
||||||
private Collections() { }
|
private Collections() { }
|
||||||
|
|
||||||
|
public static void shuffle(List list, Random random) {
|
||||||
|
Object[] array = toArray(list, new Object[list.size()]);
|
||||||
|
for (int i = 0; i < array.length; ++i) {
|
||||||
|
int j = random.nextInt(array.length);
|
||||||
|
Object tmp = array[i];
|
||||||
|
array[i] = array[j];
|
||||||
|
array[j] = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
list.clear();
|
||||||
|
for (int i = 0; i < array.length; ++i) {
|
||||||
|
list.add(array[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void shuffle(List list) {
|
||||||
|
shuffle(list, new Random());
|
||||||
|
}
|
||||||
|
|
||||||
static <T> T[] toArray(Collection collection, T[] array) {
|
static <T> T[] toArray(Collection collection, T[] array) {
|
||||||
Class c = array.getClass().getComponentType();
|
Class c = array.getClass().getComponentType();
|
||||||
|
|
||||||
@ -106,6 +125,63 @@ public class Collections {
|
|||||||
return new SynchronizedIterator(lock, collection.iterator());
|
return new SynchronizedIterator(lock, collection.iterator());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static class SynchronizedMap<K,V> implements Map<K,V> {
|
||||||
|
protected final Object lock;
|
||||||
|
protected final Map<K,V> map;
|
||||||
|
|
||||||
|
SynchronizedMap(Map<K,V> map) {
|
||||||
|
this.map = map;
|
||||||
|
this.lock = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
SynchronizedMap(Object lock, Map<K,V> map) {
|
||||||
|
this.lock = lock;
|
||||||
|
this.map = map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
synchronized (lock) { map.clear(); }
|
||||||
|
}
|
||||||
|
public boolean containsKey(K key) {
|
||||||
|
synchronized (lock) { return map.containsKey(key); }
|
||||||
|
}
|
||||||
|
public boolean containsValue(V value) {
|
||||||
|
synchronized (lock) { return map.containsValue(value); }
|
||||||
|
}
|
||||||
|
public Set<java.util.Map.Entry<K, V>> entrySet() {
|
||||||
|
synchronized (lock) { return new SynchronizedSet<java.util.Map.Entry<K, V>>(lock, map.entrySet()); }
|
||||||
|
}
|
||||||
|
public V get(K key) {
|
||||||
|
synchronized (lock) { return map.get(key); }
|
||||||
|
}
|
||||||
|
public boolean isEmpty() {
|
||||||
|
synchronized (lock) { return map.isEmpty(); }
|
||||||
|
}
|
||||||
|
public Set<K> keySet() {
|
||||||
|
synchronized (lock) { return new SynchronizedSet<K>(lock, map.keySet()); }
|
||||||
|
}
|
||||||
|
public V put(K key, V value) {
|
||||||
|
synchronized (lock) { return map.put(key, value); }
|
||||||
|
}
|
||||||
|
public void putAll(Map<? extends K, ? extends V> elts) {
|
||||||
|
synchronized (lock) { map.putAll(elts); }
|
||||||
|
}
|
||||||
|
public V remove(K key) {
|
||||||
|
synchronized (lock) { return map.remove(key); }
|
||||||
|
}
|
||||||
|
public int size() {
|
||||||
|
synchronized (lock) { return map.size(); }
|
||||||
|
}
|
||||||
|
public Collection<V> values() {
|
||||||
|
synchronized (lock) { return new SynchronizedCollection<V>(lock, map.values()); }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <K,V> Map<K,V> synchronizedMap(Map<K,V> map) {
|
||||||
|
return new SynchronizedMap<K, V> (map);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static class SynchronizedSet<T>
|
static class SynchronizedSet<T>
|
||||||
extends SynchronizedCollection<T>
|
extends SynchronizedCollection<T>
|
||||||
|
@ -16,14 +16,23 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Logger {
|
public class Logger {
|
||||||
private final String name;
|
private final String name;
|
||||||
|
private Level levelValue = null;
|
||||||
private static final ArrayList<Handler> handlers;
|
private static final ArrayList<Handler> handlers;
|
||||||
|
private static Logger rootLogger;
|
||||||
|
private Logger parent;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
rootLogger = new Logger("");
|
||||||
|
rootLogger.setLevel(Level.INFO);
|
||||||
handlers = new ArrayList<Handler>();
|
handlers = new ArrayList<Handler>();
|
||||||
handlers.add(new DefaultHandler());
|
handlers.add(new DefaultHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Logger getLogger(String name) {
|
public static Logger getLogger(String name) {
|
||||||
return new Logger(name);
|
if (name.equals("")) return rootLogger;
|
||||||
|
Logger logger = new Logger(name);
|
||||||
|
logger.parent = rootLogger;
|
||||||
|
return logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Logger(String name) {
|
private Logger(String name) {
|
||||||
@ -42,6 +51,10 @@ public class Logger {
|
|||||||
handlers.remove(handler);
|
handlers.remove(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Logger getParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
public void fine(String message) {
|
public void fine(String message) {
|
||||||
log(Level.FINE, Method.getCaller(), message, null);
|
log(Level.FINE, Method.getCaller(), message, null);
|
||||||
}
|
}
|
||||||
@ -66,19 +79,59 @@ public class Logger {
|
|||||||
log(level, Method.getCaller(), message, exception);
|
log(level, Method.getCaller(), message, exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void logp(Level level, String sourceClass, String sourceMethod, String msg) {
|
||||||
|
if (!isLoggable(level)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
publish(new LogRecord(name, sourceMethod, level, msg, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void logp(Level level, String sourceClass, String sourceMethod,
|
||||||
|
String msg, Throwable thrown) {
|
||||||
|
if (!isLoggable(level)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
publish(new LogRecord(name, sourceMethod, level, msg, thrown));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Level getLevel() {
|
||||||
|
return levelValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Level getEffectiveLevel() {
|
||||||
|
Logger logger = this;
|
||||||
|
|
||||||
|
while (logger.levelValue == null) {
|
||||||
|
logger = logger.getParent();
|
||||||
|
}
|
||||||
|
return logger.getLevel();
|
||||||
|
}
|
||||||
|
|
||||||
private void log(Level level, Method caller, String message,
|
private void log(Level level, Method caller, String message,
|
||||||
Throwable exception) {
|
Throwable exception) {
|
||||||
|
|
||||||
|
if (level.intValue() < getEffectiveLevel().intValue()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
LogRecord r = new LogRecord(name, caller.getName(), level, message,
|
LogRecord r = new LogRecord(name, caller.getName(), level, message,
|
||||||
exception);
|
exception);
|
||||||
|
publish(r);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void publish(LogRecord logRecord) {
|
||||||
for (Handler h : handlers) {
|
for (Handler h : handlers) {
|
||||||
h.publish(r);
|
h.publish(logRecord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLevel(Level level) {
|
public void setLevel(Level level) {
|
||||||
// Currently ignored
|
levelValue = level;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isLoggable(Level level) {
|
||||||
|
return level.intValue() >= levelValue.intValue();
|
||||||
|
}
|
||||||
|
|
||||||
private static class DefaultHandler extends Handler {
|
private static class DefaultHandler extends Handler {
|
||||||
private static final int NAME_WIDTH = 14;
|
private static final int NAME_WIDTH = 14;
|
||||||
private static final int METHOD_WIDTH = 15;
|
private static final int METHOD_WIDTH = 15;
|
||||||
|
2
makefile
2
makefile
@ -125,7 +125,7 @@ ifeq ($(platform),windows)
|
|||||||
exe-suffix = .exe
|
exe-suffix = .exe
|
||||||
|
|
||||||
lflags = -L$(lib) $(common-lflags) -lws2_32 -mwindows -mconsole
|
lflags = -L$(lib) $(common-lflags) -lws2_32 -mwindows -mconsole
|
||||||
cflags = $(common-cflags) -I$(inc)
|
cflags = -I$(inc) $(common-cflags)
|
||||||
|
|
||||||
ifeq (,$(filter mingw32 cygwin,$(build-platform)))
|
ifeq (,$(filter mingw32 cygwin,$(build-platform)))
|
||||||
cxx = i586-mingw32msvc-g++
|
cxx = i586-mingw32msvc-g++
|
||||||
|
@ -238,9 +238,11 @@ class MySystem: public System {
|
|||||||
assert(s, t);
|
assert(s, t);
|
||||||
|
|
||||||
if (owner_ == t) {
|
if (owner_ == t) {
|
||||||
bool interrupted;
|
// Initialized here to make gcc 4.2 a happy compiler
|
||||||
bool notified;
|
bool interrupted = false;
|
||||||
unsigned depth;
|
bool notified = false;
|
||||||
|
unsigned depth = 0;
|
||||||
|
|
||||||
int r UNUSED;
|
int r UNUSED;
|
||||||
|
|
||||||
{ ACQUIRE(s, t->mutex);
|
{ ACQUIRE(s, t->mutex);
|
||||||
@ -837,11 +839,18 @@ LONG CALLBACK
|
|||||||
handleException(LPEXCEPTION_POINTERS e)
|
handleException(LPEXCEPTION_POINTERS e)
|
||||||
{
|
{
|
||||||
if (e->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) {
|
if (e->ExceptionRecord->ExceptionCode == EXCEPTION_ACCESS_VIOLATION) {
|
||||||
|
void* ip = reinterpret_cast<void*>(e->ContextRecord->Eip);
|
||||||
|
void* base = reinterpret_cast<void*>(e->ContextRecord->Ebp);
|
||||||
|
void* stack = reinterpret_cast<void*>(e->ContextRecord->Esp);
|
||||||
|
void* thread = reinterpret_cast<void*>(e->ContextRecord->Ebx);
|
||||||
|
|
||||||
bool jump = system->segFaultHandler->handleSignal
|
bool jump = system->segFaultHandler->handleSignal
|
||||||
(reinterpret_cast<void**>(&(e->ContextRecord->Eip)),
|
(&ip, &base, &stack, &thread);
|
||||||
reinterpret_cast<void**>(&(e->ContextRecord->Ebp)),
|
|
||||||
reinterpret_cast<void**>(&(e->ContextRecord->Esp)),
|
e->ContextRecord->Eip = reinterpret_cast<DWORD>(ip);
|
||||||
reinterpret_cast<void**>(&(e->ContextRecord->Ebx)));
|
e->ContextRecord->Ebp = reinterpret_cast<DWORD>(base);
|
||||||
|
e->ContextRecord->Esp = reinterpret_cast<DWORD>(stack);
|
||||||
|
e->ContextRecord->Ebx = reinterpret_cast<DWORD>(thread);
|
||||||
|
|
||||||
if (jump) {
|
if (jump) {
|
||||||
return EXCEPTION_CONTINUE_EXECUTION;
|
return EXCEPTION_CONTINUE_EXECUTION;
|
||||||
|
Loading…
Reference in New Issue
Block a user