Skip to content

Commit

Permalink
library_pthread.js: Ensure transferredCanvasNames is iterable (#22623)
Browse files Browse the repository at this point in the history
This was first broken back in #17577 and then fixed in #17752.

I then broke it again in #22545 (yay!) (see #22620).

This time I will include a test to ensure this doesn't happen again.
  • Loading branch information
sbc100 authored Sep 26, 2024
1 parent a0fc53c commit ef0efd2
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,10 @@ var LibraryPThread = {
transferredCanvasNames = '{{{ OFFSCREENCANVASES_TO_PTHREAD }}}';
} else
#endif
transferredCanvasNames &&= UTF8ToString(transferredCanvasNames).trim();
transferredCanvasNames &&= transferredCanvasNames.split(',');
{
transferredCanvasNames = UTF8ToString(transferredCanvasNames).trim();
}
transferredCanvasNames = transferredCanvasNames ? transferredCanvasNames.split(',') : [];
#if GL_DEBUG
dbg(`pthread_create: transferredCanvasNames="${transferredCanvasNames}"`);
#endif
Expand Down
17 changes: 17 additions & 0 deletions test/other/test_pthread_hello.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <assert.h>
#include <pthread.h>
#include <stdio.h>

void* thread_func(void* arg) {
printf("Hello from thread\n");
return NULL;
}

int main() {
pthread_t t;
pthread_create(&t, NULL, thread_func, NULL);
assert(t);
pthread_join(t, NULL);
printf("done\n");
return 0;
}
2 changes: 2 additions & 0 deletions test/other/test_pthread_hello.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Hello from thread
done
8 changes: 8 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -12080,6 +12080,14 @@ def test_pthread_reuse(self):
self.set_setting('PTHREAD_POOL_SIZE', 1)
self.do_other_test('test_pthread_reuse.c')

@parameterized({
'': ([],),
'offscreen_canvas': (['-sOFFSCREENCANVAS_SUPPORT', '-sDEFAULT_LIBRARY_FUNCS_TO_INCLUDE=$GL'],),
})
@node_pthreads
def test_pthread_hello(self, args):
self.do_other_test('test_pthread_hello.c', args)

@node_pthreads
def test_pthread_relocatable(self):
self.do_run_in_out_file_test('hello_world.c', emcc_args=['-sRELOCATABLE'])
Expand Down

0 comments on commit ef0efd2

Please sign in to comment.