Skip to content

Commit a6c883e

Browse files
authored
Reduce usage of POINTER_TYPE in JS library code (#24490)
Instead, prefer '*' which is more commonly used and also results in audomatic conversion to `Number` under wasm64. We only had 15 usages of POINTER_TYPE compared to 196 usages of `'*`.
1 parent 30d8e0d commit a6c883e

File tree

6 files changed

+15
-15
lines changed

6 files changed

+15
-15
lines changed

src/lib/libcore.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1154,14 +1154,14 @@ addToLibrary({
11541154
var alias = aliases[i];
11551155
var aliasBuf = _malloc(alias.length + 1);
11561156
stringToAscii(alias, aliasBuf);
1157-
{{{ makeSetValue('aliasListBuf', 'j', 'aliasBuf', POINTER_TYPE) }}};
1157+
{{{ makeSetValue('aliasListBuf', 'j', 'aliasBuf', '*') }}};
11581158
}
1159-
{{{ makeSetValue('aliasListBuf', 'j', '0', POINTER_TYPE) }}}; // Terminating NULL pointer.
1159+
{{{ makeSetValue('aliasListBuf', 'j', '0', '*') }}}; // Terminating NULL pointer.
11601160

11611161
// generate protoent
11621162
var pe = _malloc({{{ C_STRUCTS.protoent.__size__ }}});
1163-
{{{ makeSetValue('pe', C_STRUCTS.protoent.p_name, 'nameBuf', POINTER_TYPE) }}};
1164-
{{{ makeSetValue('pe', C_STRUCTS.protoent.p_aliases, 'aliasListBuf', POINTER_TYPE) }}};
1163+
{{{ makeSetValue('pe', C_STRUCTS.protoent.p_name, 'nameBuf', '*') }}};
1164+
{{{ makeSetValue('pe', C_STRUCTS.protoent.p_aliases, 'aliasListBuf', '*') }}};
11651165
{{{ makeSetValue('pe', C_STRUCTS.protoent.p_proto, 'proto', 'i32') }}};
11661166
return pe;
11671167
};

src/lib/libglfw.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,7 @@ var LibraryGLFW = {
871871

872872
var filename = stringToNewUTF8(path);
873873
filenamesArray.push(filename);
874-
{{{ makeSetValue('filenames', `i*${POINTER_SIZE}` , 'filename', POINTER_TYPE) }}};
874+
{{{ makeSetValue('filenames', `i*${POINTER_SIZE}` , 'filename', '*') }}};
875875
}
876876

877877
for (var i = 0; i < count; ++i) {

src/lib/libsdl.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -367,12 +367,12 @@ var LibrarySDL = {
367367
}
368368

369369
{{{ makeSetValue('surf', C_STRUCTS.SDL_Surface.flags, 'flags', 'i32') }}};
370-
{{{ makeSetValue('surf', C_STRUCTS.SDL_Surface.format, 'pixelFormat', POINTER_TYPE) }}};
370+
{{{ makeSetValue('surf', C_STRUCTS.SDL_Surface.format, 'pixelFormat', '*') }}};
371371
{{{ makeSetValue('surf', C_STRUCTS.SDL_Surface.w, 'width', 'i32') }}};
372372
{{{ makeSetValue('surf', C_STRUCTS.SDL_Surface.h, 'height', 'i32') }}};
373373
{{{ makeSetValue('surf', C_STRUCTS.SDL_Surface.pitch, 'width * bpp', 'i32') }}}; // assuming RGBA or indexed for now,
374374
// since that is what ImageData gives us in browsers
375-
{{{ makeSetValue('surf', C_STRUCTS.SDL_Surface.pixels, 'buffer', POINTER_TYPE) }}};
375+
{{{ makeSetValue('surf', C_STRUCTS.SDL_Surface.pixels, 'buffer', '*') }}};
376376

377377
var canvas = Browser.getCanvas();
378378
{{{ makeSetValue('surf', C_STRUCTS.SDL_Surface.clip_rect+C_STRUCTS.SDL_Rect.x, '0', 'i32') }}};
@@ -1564,14 +1564,14 @@ var LibrarySDL = {
15641564

15651565
if (!surfData.buffer) {
15661566
surfData.buffer = _malloc(surfData.width * surfData.height * 4);
1567-
{{{ makeSetValue('surf', C_STRUCTS.SDL_Surface.pixels, 'surfData.buffer', POINTER_TYPE) }}};
1567+
{{{ makeSetValue('surf', C_STRUCTS.SDL_Surface.pixels, 'surfData.buffer', '*') }}};
15681568
}
15691569

15701570
// Mark in C/C++-accessible SDL structure
15711571
// SDL_Surface has the following fields: Uint32 flags, SDL_PixelFormat *format; int w, h; Uint16 pitch; void *pixels; ...
15721572
// So we have fields all of the same size, and 5 of them before us.
15731573
// TODO: Use macros like in library.js
1574-
{{{ makeSetValue('surf', C_STRUCTS.SDL_Surface.pixels, 'surfData.buffer', POINTER_TYPE) }}};
1574+
{{{ makeSetValue('surf', C_STRUCTS.SDL_Surface.pixels, 'surfData.buffer', '*') }}};
15751575

15761576
if (surf == SDL.screen && Module.screenIsReadOnly && surfData.image) return 0;
15771577

src/lib/libsyscall.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ var SyscallsLibrary = {
472472
var view = new Uint8Array(total);
473473
var offset = 0;
474474
for (var i = 0; i < num; i++) {
475-
var iovbase = {{{ makeGetValue('iov', `(${C_STRUCTS.iovec.__size__} * i) + ${C_STRUCTS.iovec.iov_base}`, POINTER_TYPE) }}};
475+
var iovbase = {{{ makeGetValue('iov', `(${C_STRUCTS.iovec.__size__} * i) + ${C_STRUCTS.iovec.iov_base}`, '*') }}};
476476
var iovlen = {{{ makeGetValue('iov', `(${C_STRUCTS.iovec.__size__} * i) + ${C_STRUCTS.iovec.iov_len}`, 'i32') }}};
477477
for (var j = 0; j < iovlen; j++) {
478478
view[offset++] = {{{ makeGetValue('iovbase', 'j', 'i8') }}};
@@ -484,7 +484,7 @@ var SyscallsLibrary = {
484484
__syscall_recvmsg__deps: ['$getSocketFromFD', '$writeSockaddr', '$DNS'],
485485
__syscall_recvmsg: (fd, message, flags, d1, d2, d3) => {
486486
var sock = getSocketFromFD(fd);
487-
var iov = {{{ makeGetValue('message', C_STRUCTS.msghdr.msg_iov, POINTER_TYPE) }}};
487+
var iov = {{{ makeGetValue('message', C_STRUCTS.msghdr.msg_iov, '*') }}};
488488
var num = {{{ makeGetValue('message', C_STRUCTS.msghdr.msg_iovlen, 'i32') }}};
489489
// get the total amount of data we can read across all arrays
490490
var total = 0;
@@ -515,7 +515,7 @@ var SyscallsLibrary = {
515515
var bytesRead = 0;
516516
var bytesRemaining = msg.buffer.byteLength;
517517
for (var i = 0; bytesRemaining > 0 && i < num; i++) {
518-
var iovbase = {{{ makeGetValue('iov', `(${C_STRUCTS.iovec.__size__} * i) + ${C_STRUCTS.iovec.iov_base}`, POINTER_TYPE) }}};
518+
var iovbase = {{{ makeGetValue('iov', `(${C_STRUCTS.iovec.__size__} * i) + ${C_STRUCTS.iovec.iov_base}`, '*') }}};
519519
var iovlen = {{{ makeGetValue('iov', `(${C_STRUCTS.iovec.__size__} * i) + ${C_STRUCTS.iovec.iov_len}`, 'i32') }}};
520520
if (!iovlen) {
521521
continue;

src/lib/libtime.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ addToLibrary({
170170
// Coordinated Universal Time (UTC) and local standard time."), the same
171171
// as returned by stdTimezoneOffset.
172172
// See http://pubs.opengroup.org/onlinepubs/009695399/functions/tzset.html
173-
{{{ makeSetValue('timezone', '0', 'stdTimezoneOffset * 60', POINTER_TYPE) }}};
173+
{{{ makeSetValue('timezone', '0', 'stdTimezoneOffset * 60', '*') }}};
174174

175175
{{{ makeSetValue('daylight', '0', 'Number(winterOffset != summerOffset)', 'i32') }}};
176176

src/lib/libwasi.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ var WasiLibrary = {
104104
var envp = 0;
105105
for (var string of getEnvStrings()) {
106106
var ptr = environ_buf + bufSize;
107-
{{{ makeSetValue('__environ', 'envp', 'ptr', POINTER_TYPE) }}};
107+
{{{ makeSetValue('__environ', 'envp', 'ptr', '*') }}};
108108
bufSize += stringToUTF8(string, ptr, Infinity) + 1;
109109
envp += {{{ POINTER_SIZE }}};
110110
}
@@ -134,7 +134,7 @@ var WasiLibrary = {
134134
var bufSize = 0;
135135
mainArgs.forEach((arg, i) => {
136136
var ptr = argv_buf + bufSize;
137-
{{{ makeSetValue('argv', `i*${POINTER_SIZE}`, 'ptr', POINTER_TYPE) }}};
137+
{{{ makeSetValue('argv', `i*${POINTER_SIZE}`, 'ptr', '*') }}};
138138
stringToAscii(arg, ptr);
139139
bufSize += arg.length + 1;
140140
});

0 commit comments

Comments
 (0)