ensure StructBuilders and StructLists maintain capTable context
This commit is contained in:
parent
f74ad80dea
commit
196b82515c
5 changed files with 19 additions and 17 deletions
|
@ -1,6 +1,6 @@
|
||||||
package org.capnproto;
|
package org.capnproto;
|
||||||
|
|
||||||
interface CapTableBuilder extends CapTableReader {
|
public interface CapTableBuilder extends CapTableReader {
|
||||||
int injectCap(ClientHook cap);
|
int injectCap(ClientHook cap);
|
||||||
|
|
||||||
void dropCap(int index);
|
void dropCap(int index);
|
||||||
|
|
|
@ -10,12 +10,12 @@ public final class Capability {
|
||||||
static final Object NULL_CAPABILITY_BRAND = new Object();
|
static final Object NULL_CAPABILITY_BRAND = new Object();
|
||||||
static final Object BROKEN_CAPABILITY_BRAND = new Object();
|
static final Object BROKEN_CAPABILITY_BRAND = new Object();
|
||||||
|
|
||||||
static class BuilderContext {
|
public static class BuilderContext {
|
||||||
CapTableBuilder capTable;
|
public CapTableBuilder capTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ReaderContext {
|
public static class ReaderContext {
|
||||||
CapTableReader capTable;
|
public CapTableReader capTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static abstract class Factory<T extends ClientBase>
|
public static abstract class Factory<T extends ClientBase>
|
||||||
|
|
|
@ -44,11 +44,17 @@ public class StructBuilder extends Capability.BuilderContext {
|
||||||
|
|
||||||
public StructBuilder(SegmentBuilder segment, int data,
|
public StructBuilder(SegmentBuilder segment, int data,
|
||||||
int pointers, int dataSize, short pointerCount) {
|
int pointers, int dataSize, short pointerCount) {
|
||||||
|
this(segment, null, data, pointers, dataSize, pointerCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StructBuilder(SegmentBuilder segment, CapTableBuilder capTable, int data,
|
||||||
|
int pointers, int dataSize, short pointerCount) {
|
||||||
this.segment = segment;
|
this.segment = segment;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
this.pointers = pointers;
|
this.pointers = pointers;
|
||||||
this.dataSize = dataSize;
|
this.dataSize = dataSize;
|
||||||
this.pointerCount = pointerCount;
|
this.pointerCount = pointerCount;
|
||||||
|
this.capTable = capTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final boolean _getBooleanField(int offset) {
|
protected final boolean _getBooleanField(int offset) {
|
||||||
|
|
|
@ -51,17 +51,13 @@ public class StructReader extends Capability.ReaderContext {
|
||||||
this.dataSize = 0;
|
this.dataSize = 0;
|
||||||
this.pointerCount = 0;
|
this.pointerCount = 0;
|
||||||
this.nestingLimit = 0x7fffffff;
|
this.nestingLimit = 0x7fffffff;
|
||||||
|
this.capTable = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public StructReader(SegmentReader segment, int data,
|
public StructReader(SegmentReader segment, int data,
|
||||||
int pointers, int dataSize, short pointerCount,
|
int pointers, int dataSize, short pointerCount,
|
||||||
int nestingLimit) {
|
int nestingLimit) {
|
||||||
this.segment = segment;
|
this(segment, null, data, pointers, dataSize, pointerCount, nestingLimit);
|
||||||
this.data = data;
|
|
||||||
this.pointers = pointers;
|
|
||||||
this.dataSize = dataSize;
|
|
||||||
this.pointerCount = pointerCount;
|
|
||||||
this.nestingLimit = nestingLimit;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public StructReader(SegmentReader segment, CapTableReader capTable,
|
public StructReader(SegmentReader segment, CapTableReader capTable,
|
||||||
|
|
|
@ -503,7 +503,7 @@ final class WireHelpers {
|
||||||
|
|
||||||
ListPointer.set(allocation.segment.buffer, allocation.refOffset, elementSize, elementCount);
|
ListPointer.set(allocation.segment.buffer, allocation.refOffset, elementSize, elementCount);
|
||||||
|
|
||||||
return factory.constructBuilder(allocation.segment,
|
return factory.constructBuilder(allocation.segment, capTable,
|
||||||
allocation.ptr * Constants.BYTES_PER_WORD,
|
allocation.ptr * Constants.BYTES_PER_WORD,
|
||||||
elementCount, step, dataSize, (short)pointerCount);
|
elementCount, step, dataSize, (short)pointerCount);
|
||||||
}
|
}
|
||||||
|
@ -527,7 +527,7 @@ final class WireHelpers {
|
||||||
WirePointer.STRUCT, elementCount);
|
WirePointer.STRUCT, elementCount);
|
||||||
StructPointer.setFromStructSize(allocation.segment.buffer, allocation.ptr, elementSize);
|
StructPointer.setFromStructSize(allocation.segment.buffer, allocation.ptr, elementSize);
|
||||||
|
|
||||||
return factory.constructBuilder(allocation.segment,
|
return factory.constructBuilder(allocation.segment, capTable,
|
||||||
(allocation.ptr + 1) * Constants.BYTES_PER_WORD,
|
(allocation.ptr + 1) * Constants.BYTES_PER_WORD,
|
||||||
elementCount, wordsPerElement * Constants.BITS_PER_WORD,
|
elementCount, wordsPerElement * Constants.BITS_PER_WORD,
|
||||||
elementSize.data * Constants.BITS_PER_WORD, elementSize.pointers);
|
elementSize.data * Constants.BITS_PER_WORD, elementSize.pointers);
|
||||||
|
@ -586,7 +586,7 @@ final class WireHelpers {
|
||||||
|
|
||||||
int step = dataSize + pointerCount * Constants.BITS_PER_POINTER;
|
int step = dataSize + pointerCount * Constants.BITS_PER_POINTER;
|
||||||
|
|
||||||
return factory.constructBuilder(resolved.segment, resolved.ptr * Constants.BYTES_PER_WORD,
|
return factory.constructBuilder(resolved.segment, capTable, resolved.ptr * Constants.BYTES_PER_WORD,
|
||||||
ListPointer.elementCount(resolved.ref),
|
ListPointer.elementCount(resolved.ref),
|
||||||
step, dataSize, (short) pointerCount);
|
step, dataSize, (short) pointerCount);
|
||||||
}
|
}
|
||||||
|
@ -629,7 +629,7 @@ final class WireHelpers {
|
||||||
|
|
||||||
if (oldDataSize >= elementSize.data && oldPointerCount >= elementSize.pointers) {
|
if (oldDataSize >= elementSize.data && oldPointerCount >= elementSize.pointers) {
|
||||||
//# Old size is at least as large as we need. Ship it.
|
//# Old size is at least as large as we need. Ship it.
|
||||||
return factory.constructBuilder(resolved.segment, oldPtr * Constants.BYTES_PER_WORD,
|
return factory.constructBuilder(resolved.segment, capTable, oldPtr * Constants.BYTES_PER_WORD,
|
||||||
elementCount,
|
elementCount,
|
||||||
oldStep * Constants.BITS_PER_WORD,
|
oldStep * Constants.BITS_PER_WORD,
|
||||||
oldDataSize * Constants.BITS_PER_WORD, oldPointerCount);
|
oldDataSize * Constants.BITS_PER_WORD, oldPointerCount);
|
||||||
|
@ -685,7 +685,7 @@ final class WireHelpers {
|
||||||
memset(resolved.segment.buffer, resolved.ptr * Constants.BYTES_PER_WORD,
|
memset(resolved.segment.buffer, resolved.ptr * Constants.BYTES_PER_WORD,
|
||||||
(byte)0, (1 + oldStep * elementCount) * Constants.BYTES_PER_WORD);
|
(byte)0, (1 + oldStep * elementCount) * Constants.BYTES_PER_WORD);
|
||||||
|
|
||||||
return factory.constructBuilder(allocation.segment, newPtr * Constants.BYTES_PER_WORD,
|
return factory.constructBuilder(allocation.segment, capTable, newPtr * Constants.BYTES_PER_WORD,
|
||||||
elementCount,
|
elementCount,
|
||||||
newStep * Constants.BITS_PER_WORD,
|
newStep * Constants.BITS_PER_WORD,
|
||||||
newDataSize * Constants.BITS_PER_WORD,
|
newDataSize * Constants.BITS_PER_WORD,
|
||||||
|
@ -764,7 +764,7 @@ final class WireHelpers {
|
||||||
memset(resolved.segment.buffer, resolved.ptr * Constants.BYTES_PER_WORD,
|
memset(resolved.segment.buffer, resolved.ptr * Constants.BYTES_PER_WORD,
|
||||||
(byte)0, roundBitsUpToBytes(oldStep * elementCount));
|
(byte)0, roundBitsUpToBytes(oldStep * elementCount));
|
||||||
|
|
||||||
return factory.constructBuilder(allocation.segment, newPtr * Constants.BYTES_PER_WORD,
|
return factory.constructBuilder(allocation.segment, capTable, newPtr * Constants.BYTES_PER_WORD,
|
||||||
elementCount,
|
elementCount,
|
||||||
newStep * Constants.BITS_PER_WORD,
|
newStep * Constants.BITS_PER_WORD,
|
||||||
newDataSize * Constants.BITS_PER_WORD,
|
newDataSize * Constants.BITS_PER_WORD,
|
||||||
|
|
Loading…
Reference in a new issue