Skip to content

Commit efde69b

Browse files
committed
feat: Apply suggestions from code review
1 parent d2e9abe commit efde69b

6 files changed

Lines changed: 29 additions & 29 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ full changeset diff at the end of each section.
1515
Current Trunk
1616
-------------
1717
- Add a `BinaryenDataSegmentRef` type to the C API. (#8286)
18-
- Add `BinaryenGetMemorySegment` and `BinaryenGetMemorySegmentByIndex` to the C API, which allow looking up a memory segment by name or index.
19-
- Add `BinaryenGetMemorySegmentName` to the C API, which allows looking up a memory segment's name.
18+
- Add `BinaryenGetDataSegment` and `BinaryenGetDataSegmentByIndex` to the C API, which allow looking up a data segment by name or index.
19+
- Add `BinaryenDataSegmentGetName` to the C API, which allows looking up a data segment's name.
2020
- Convert `BinaryenGetMemorySegmentByteOffset`, `BinaryenGetMemorySegmentByteLength`, `BinaryenGetMemorySegmentPassive` and `BinaryenCopyMemorySegmentData` to take a `BinaryenDataSegmentRef` instead of a name.
21-
- Add `module.getMemorySegment`, `module.getMemorySegmentByIndex` to the JS API, which allows looking up a memory segment by name or index.
22-
- Convert `module.getMemorySegmentInfo` to take a memory segment reference instead of a name, and return the name as part of the info.
21+
- Add `module.getDataSegment`, `module.getDataSegmentByIndex` to the JS API, which allows looking up a data segment by name or index.
22+
- Convert `module.getMemorySegmentInfo` to take a data segment reference instead of a name, and return the name as part of the info.
2323

2424
- Add support for non-nullable table types and initialization expressions for
2525
tables. This comes with a breaking change to C API: `BinaryenAddTable` takes

src/binaryen-c.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5492,19 +5492,19 @@ void BinaryenSetMemory(BinaryenModuleRef module,
54925492
uint32_t BinaryenGetNumMemorySegments(BinaryenModuleRef module) {
54935493
return ((Module*)module)->dataSegments.size();
54945494
}
5495-
BinaryenDataSegmentRef BinaryenGetMemorySegment(BinaryenModuleRef module,
5495+
BinaryenDataSegmentRef BinaryenGetDataSegment(BinaryenModuleRef module,
54965496
const char* segmentName) {
54975497
return ((Module*)module)->getDataSegmentOrNull(Name(segmentName));
54985498
}
5499-
BinaryenDataSegmentRef BinaryenGetMemorySegmentByIndex(BinaryenModuleRef module,
5499+
BinaryenDataSegmentRef BinaryenGetDataSegmentByIndex(BinaryenModuleRef module,
55005500
BinaryenIndex index) {
55015501
const auto& dataSegments = ((Module*)module)->dataSegments;
55025502
if (dataSegments.size() <= index) {
55035503
Fatal() << "invalid memory segment index.";
55045504
}
55055505
return dataSegments[index].get();
55065506
}
5507-
const char* BinaryenGetMemorySegmentName(BinaryenDataSegmentRef segment) {
5507+
const char* BinaryenDataSegmentGetName(BinaryenDataSegmentRef segment) {
55085508
return ((DataSegment*)segment)->name.str.data();
55095509
}
55105510
uint32_t BinaryenGetMemorySegmentByteOffset(BinaryenModuleRef module,

src/binaryen-c.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3009,11 +3009,11 @@ BINARYEN_REF(DataSegment);
30093009

30103010
BINARYEN_API uint32_t BinaryenGetNumMemorySegments(BinaryenModuleRef module);
30113011
BINARYEN_API BinaryenDataSegmentRef
3012-
BinaryenGetMemorySegment(BinaryenModuleRef module, const char* segmentName);
3012+
BinaryenGetDataSegment(BinaryenModuleRef module, const char* segmentName);
30133013
BINARYEN_API BinaryenDataSegmentRef
3014-
BinaryenGetMemorySegmentByIndex(BinaryenModuleRef module, BinaryenIndex index);
3014+
BinaryenGetDataSegmentByIndex(BinaryenModuleRef module, BinaryenIndex index);
30153015
BINARYEN_API const char*
3016-
BinaryenGetMemorySegmentName(BinaryenDataSegmentRef segment);
3016+
BinaryenDataSegmentGetName(BinaryenDataSegmentRef segment);
30173017
BINARYEN_API uint32_t BinaryenGetMemorySegmentByteOffset(
30183018
BinaryenModuleRef module, BinaryenDataSegmentRef segment);
30193019
BINARYEN_API size_t

src/js/binaryen.js-post.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,26 +2773,26 @@ function wrapModule(module, self = {}) {
27732773
return Module['_BinaryenGetNumMemorySegments'](module);
27742774
};
27752775
/**
2776-
* Gets the memory segment with the given name.
2776+
* Gets the data segment with the given name.
27772777
*
2778-
* @param {string} name - The name of the memory segment to get.
2779-
* @returns {number} A MemorySegmentRef referring to the memory segment with the given name, or `0` if no such segment exists.
2778+
* @param {string} name - The name of the data segment to get.
2779+
* @returns {number} A DataSegmentRef referring to the data segment with the given name, or `0` if no such segment exists.
27802780
*/
2781-
self['getMemorySegment'] = function(name) {
2781+
self['getDataSegment'] = function(name) {
27822782
return preserveStack(() => {
2783-
return Module['_BinaryenGetMemorySegment'](module, strToStack(name));
2783+
return Module['_BinaryenGetDataSegment'](module, strToStack(name));
27842784
});
27852785
};
27862786
/**
2787-
* Gets the memory segment at the given index.
2787+
* Gets the data segment at the given index.
27882788
*
2789-
* @param {number} index - The index of the memory segment to get.
2790-
* @returns {number} A MemorySegmentRef referring to the memory segment at the given index.
2789+
* @param {number} index - The index of the data segment to get.
2790+
* @returns {number} A DataSegmentRef referring to the data segment at the given index.
27912791
*
2792-
* @throws If no memory segment exists at the given index.
2792+
* @throws If no data segment exists at the given index.
27932793
*/
2794-
self['getMemorySegmentByIndex'] = function(index) {
2795-
return Module['_BinaryenGetMemorySegmentByIndex'](module, index);
2794+
self['getDataSegmentByIndex'] = function(index) {
2795+
return Module['_BinaryenGetDataSegmentByIndex'](module, index);
27962796
};
27972797
/**
27982798
* Queries information about a memory segment.
@@ -2813,7 +2813,7 @@ function wrapModule(module, self = {}) {
28132813
offset = Module['_BinaryenGetMemorySegmentByteOffset'](module, segment);
28142814
}
28152815
return {
2816-
'name': UTF8ToString(Module['_BinaryenGetMemorySegmentName'](segment)),
2816+
'name': UTF8ToString(Module['_BinaryenDataSegmentGetName'](segment)),
28172817
'offset': offset,
28182818
'data': (function(){
28192819
const size = Module['_BinaryenGetMemorySegmentByteLength'](segment);

test/binaryen.js/kitchen-sink.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,10 +1144,10 @@ function test_for_each() {
11441144
data: expected_data[2].split('').map(function(x) { return x.charCodeAt(0) })
11451145
}
11461146
], false);
1147-
assert(module.getMemorySegment(expected_names[0]) !== 0);
1148-
assert(module.getMemorySegment("NonExistantSegment") === 0);
1147+
assert(module.getDataSegment(expected_names[0]) !== 0);
1148+
assert(module.getDataSegment("NonExistantSegment") === 0);
11491149
for (i = 0; i < module.getNumMemorySegments(); i++) {
1150-
var segment = module.getMemorySegmentByIndex(i);
1150+
var segment = module.getDataSegmentByIndex(i);
11511151
var info = module.getMemorySegmentInfo(segment);
11521152
assert(expected_names[i] === info.name);
11531153
assert(expected_offsets[i] === info.offset);

test/example/c-api-kitchen-sink.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,14 +2019,14 @@ void test_for_each() {
20192019
BinaryenTypeInt32(),
20202020
0,
20212021
makeInt32(module, expected_offsets[1]));
2022-
assert(BinaryenGetMemorySegment(module, segmentNames[0]) != NULL);
2023-
assert(BinaryenGetMemorySegment(module, "NonExistantSegment") == NULL);
2022+
assert(BinaryenGetDataSegment(module, segmentNames[0]) != NULL);
2023+
assert(BinaryenGetDataSegment(module, "NonExistantSegment") == NULL);
20242024
for (i = 0; i < BinaryenGetNumMemorySegments(module); i++) {
20252025
char out[15] = {};
20262026
BinaryenDataSegmentRef segment =
2027-
BinaryenGetMemorySegmentByIndex(module, i);
2027+
BinaryenGetDataSegmentByIndex(module, i);
20282028
assert(segment != NULL);
2029-
assert(BinaryenGetMemorySegmentName(segment) != NULL);
2029+
assert(BinaryenDataSegmentGetName(segment) != NULL);
20302030
assert(BinaryenGetMemorySegmentByteOffset(module, segment) ==
20312031
expected_offsets[i]);
20322032
assert(BinaryenGetMemorySegmentByteLength(segment) == segmentSizes[i]);

0 commit comments

Comments
 (0)