Skip to content

Commit 098305d

Browse files
committed
Simplify setup and teardown
Allow the buffer functions to manage the internal pointer and use consistent argument order for calloc.
1 parent b1ec913 commit 098305d

1 file changed

Lines changed: 3 additions & 8 deletions

File tree

java-wasm/src/main/java/org/prism/Prism.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,9 @@ public byte[] serialize(byte[] packedOptions, byte[] source, int sourceLength) {
4040
int sourcePointer = 0;
4141
int optionsPointer = 0;
4242
int bufferPointer = 0;
43-
int resultPointer = 0;
4443
byte[] result;
4544
try {
46-
sourcePointer = exports.calloc(1, sourceLength);
45+
sourcePointer = exports.calloc(sourceLength, 1);
4746
exports.memory().write(sourcePointer, source);
4847

4948
optionsPointer = exports.calloc(1, packedOptions.length);
@@ -54,10 +53,8 @@ public byte[] serialize(byte[] packedOptions, byte[] source, int sourceLength) {
5453

5554
exports.pmSerializeParse(bufferPointer, sourcePointer, sourceLength, optionsPointer);
5655

57-
resultPointer = exports.pmBufferValue(bufferPointer);
58-
5956
result = instance.memory().readBytes(
60-
resultPointer,
57+
exports.pmBufferValue(bufferPointer),
6158
exports.pmBufferLength(bufferPointer));
6259
} finally {
6360
if (sourcePointer != 0) {
@@ -67,11 +64,9 @@ public byte[] serialize(byte[] packedOptions, byte[] source, int sourceLength) {
6764
exports.free(optionsPointer);
6865
}
6966
if (bufferPointer != 0) {
67+
exports.pmBufferFree(bufferPointer);
7068
exports.free(bufferPointer);
7169
}
72-
if (resultPointer != 0) {
73-
exports.free(resultPointer);
74-
}
7570
}
7671

7772
return result;

0 commit comments

Comments
 (0)