Skip to content

Commit cb9f57f

Browse files
committed
Specify MemoryBIO contract better
1 parent 9158542 commit cb9f57f

File tree

1 file changed

+9
-3
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl

1 file changed

+9
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/ssl/PMemoryBIO.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,13 @@ public ByteBuffer getBufferForReading() {
8181

8282
/**
8383
* Update read position from a buffer previously obtained using {@link #getBufferForReading()}
84+
* The caller is responsible for making sure the buffer was obtained for this BIO, that this BIO
85+
* was not concurrently updated since the {@link #getBufferForReading()} call and that the
86+
* position was not moved backwards.
8487
*/
8588
public void applyRead(ByteBuffer buffer) {
8689
readPosition = buffer.position();
87-
assert readPosition <= bytes.length;
90+
assert buffer.array() == bytes;
8891
assert readPosition <= writePosition;
8992
}
9093

@@ -100,11 +103,14 @@ public ByteBuffer getBufferForWriting() {
100103
}
101104

102105
/**
103-
* Update write position from a buffer previously obtained using {@link #getBufferForWriting()}
106+
* Update write position from a buffer previously obtained using {@link #getBufferForWriting()}.
107+
* The caller is responsible for making sure the buffer was obtained for this BIO, that this BIO
108+
* was not concurrently updated since the {@link #getBufferForWriting()} call and that the
109+
* position was not moved backwards.
104110
*/
105111
public void applyWrite(ByteBuffer buffer) {
106112
writePosition = buffer.position();
107-
assert writePosition <= bytes.length;
113+
assert buffer.array() == bytes;
108114
assert readPosition <= writePosition;
109115
}
110116

0 commit comments

Comments
 (0)