Skip to content

Commit 206c3e1

Browse files
committed
Merge branch 'main' into sm-webpack-workaround
2 parents ba0799f + 8eb432e commit 206c3e1

40 files changed

+388
-779
lines changed

.circleci/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ jobs:
515515
asan.test_externref_emjs_dynlink
516516
asan.test_asyncify_longjmp
517517
asan.test_pthread_run_on_main_thread
518+
lsan.test_dylink_dso_needed
518519
lsan.test_stdio_locking
519520
lsan.test_dlfcn_basic
520521
lsan.test_pthread_create

ChangeLog.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ See docs/process.md for more on how version tagging works.
2020

2121
3.1.68 (in development)
2222
-----------------------
23+
- Pthread-based programs no longer generates `.worker.js` file. This file was
24+
made redundant back in 3.1.58 and now is completely removed. (#22598)
25+
- The freetype port was updated from v2.6 to v2.13.3. (#22585)
26+
- The number of arguments passed to Embind function calls is now only verified
27+
with ASSERTIONS enabled. (#22591)
28+
- Optional arguments can now be omitted from Embind function calls. (#22591)
2329

2430
3.1.67 - 09/17/24
2531
-----------------

src/embind/embind.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ var LibraryEmbind = {
5757
// TODO: do we need a deleteObject here? write a test where
5858
// emval is passed into JS via an interface
5959
}`,
60+
$EmValOptionalType__deps: ['$EmValType'],
61+
$EmValOptionalType: '=Object.assign({optional: true}, EmValType);',
6062
$init_embind__deps: [
6163
'$getInheritedInstanceCount', '$getLiveInheritedInstances',
6264
'$flushPendingDeletes', '$setDelayFunction'],
@@ -687,9 +689,9 @@ var LibraryEmbind = {
687689
__embind_register_emval(rawType);
688690
},
689691

690-
_embind_register_optional__deps: ['_embind_register_emval'],
692+
_embind_register_optional__deps: ['$registerType', '$EmValOptionalType'],
691693
_embind_register_optional: (rawOptionalType, rawType) => {
692-
__embind_register_emval(rawOptionalType);
694+
registerType(rawOptionalType, EmValOptionalType);
693695
},
694696

695697
_embind_register_memory_view__deps: ['$readLatin1String', '$registerType'],
@@ -778,6 +780,10 @@ var LibraryEmbind = {
778780
#endif
779781
#if ASYNCIFY
780782
'$Asyncify',
783+
#endif
784+
#if ASSERTIONS
785+
'$getRequiredArgCount',
786+
'$checkArgCount',
781787
#endif
782788
],
783789
$craftInvokerFunction: function(humanName, argTypes, classType, cppInvokerFunc, cppTargetFunc, /** boolean= */ isAsync) {
@@ -821,15 +827,18 @@ var LibraryEmbind = {
821827

822828
var returns = (argTypes[0].name !== "void");
823829

824-
#if DYNAMIC_EXECUTION == 0 && !EMBIND_AOT
825830
var expectedArgCount = argCount - 2;
831+
#if ASSERTIONS
832+
var minArgs = getRequiredArgCount(argTypes);
833+
#endif
834+
#if DYNAMIC_EXECUTION == 0 && !EMBIND_AOT
826835
var argsWired = new Array(expectedArgCount);
827836
var invokerFuncArgs = [];
828837
var destructors = [];
829838
var invokerFn = function(...args) {
830-
if (args.length !== expectedArgCount) {
831-
throwBindingError(`function ${humanName} called with ${args.length} arguments, expected ${expectedArgCount}`);
832-
}
839+
#if ASSERTIONS
840+
checkArgCount(args.length, minArgs, expectedArgCount, humanName, throwBindingError);
841+
#endif
833842
#if EMSCRIPTEN_TRACING
834843
Module.emscripten_trace_enter_context(`embind::${humanName}`);
835844
#endif
@@ -901,6 +910,9 @@ var LibraryEmbind = {
901910
}
902911
}
903912
}
913+
#if ASSERTIONS
914+
closureArgs.push(checkArgCount, minArgs, expectedArgCount);
915+
#endif
904916

905917
#if EMBIND_AOT
906918
var signature = createJsInvokerSignature(argTypes, isClassMethodFunc, returns, isAsync);

src/embind/embind_shared.js

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,29 @@ var LibraryEmbindShared = {
204204
return signature.join('');
205205
},
206206

207-
$createJsInvoker__deps: ['$usesDestructorStack'],
207+
$checkArgCount(numArgs, minArgs, maxArgs, humanName, throwBindingError) {
208+
if (numArgs < minArgs || numArgs > maxArgs) {
209+
var argCountMessage = minArgs == maxArgs ? minArgs : `${minArgs} to ${maxArgs}`;
210+
throwBindingError(`function ${humanName} called with ${numArgs} arguments, expected ${argCountMessage}`);
211+
}
212+
},
213+
214+
$getRequiredArgCount(argTypes) {
215+
var requiredArgCount = argTypes.length - 2;
216+
for (var i = argTypes.length - 1; i >= 2; --i) {
217+
if (!argTypes[i].optional) {
218+
break;
219+
}
220+
requiredArgCount--;
221+
}
222+
return requiredArgCount;
223+
},
224+
225+
$createJsInvoker__deps: ['$usesDestructorStack',
226+
#if ASSERTIONS
227+
'$checkArgCount',
228+
#endif
229+
],
208230
$createJsInvoker(argTypes, isClassMethodFunc, returns, isAsync) {
209231
var needsDestructorStack = usesDestructorStack(argTypes);
210232
var argCount = argTypes.length - 2;
@@ -220,11 +242,11 @@ var LibraryEmbindShared = {
220242
argsList = argsList.join(',')
221243
argsListWired = argsListWired.join(',')
222244

223-
var invokerFnBody = `
224-
return function (${argsList}) {
225-
if (arguments.length !== ${argCount}) {
226-
throwBindingError('function ' + humanName + ' called with ' + arguments.length + ' arguments, expected ${argCount}');
227-
}`;
245+
var invokerFnBody = `return function (${argsList}) {\n`;
246+
247+
#if ASSERTIONS
248+
invokerFnBody += "checkArgCount(arguments.length, minArgs, maxArgs, humanName, throwBindingError);\n";
249+
#endif
228250

229251
#if EMSCRIPTEN_TRACING
230252
invokerFnBody += `Module.emscripten_trace_enter_context('embind::' + humanName );\n`;
@@ -295,6 +317,7 @@ var LibraryEmbindShared = {
295317
invokerFnBody += "}\n";
296318

297319
#if ASSERTIONS
320+
args1.push('checkArgCount', 'minArgs', 'maxArgs');
298321
invokerFnBody = `if (arguments.length !== ${args1.length}){ throw new Error(humanName + "Expected ${args1.length} closure arguments " + arguments.length + " given."); }\n${invokerFnBody}`;
299322
#endif
300323
return [args1, invokerFnBody];

src/library.js

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,14 +1428,14 @@ addToLibrary({
14281428

14291429
emscripten_random: () => Math.random(),
14301430

1431-
emscripten_get_now: `;
14321431
#if PTHREADS && !AUDIO_WORKLET
1433-
// Pthreads need their clocks synchronized to the execution of the main
1434-
// thread, so, when using them, make sure to adjust all timings to the
1435-
// respective time origins.
1436-
_emscripten_get_now = () => performance.timeOrigin + {{{ getPerformanceNow() }}}();
1432+
// Pthreads need their clocks synchronized to the execution of the main
1433+
// thread, so, when using them, make sure to adjust all timings to the
1434+
// respective time origins.
1435+
emscripten_get_now: () => performance.timeOrigin + {{{ getPerformanceNow() }}}(),
14371436
#else
14381437
#if MIN_FIREFOX_VERSION <= 14 || MIN_CHROME_VERSION <= 23 || MIN_SAFARI_VERSION <= 80400 || AUDIO_WORKLET // https://caniuse.com/#feat=high-resolution-time
1438+
emscripten_get_now: `;
14391439
// AudioWorkletGlobalScope does not have performance.now()
14401440
// (https://github.com/WebAudio/web-audio-api/issues/2527), so if building
14411441
// with
@@ -1449,14 +1449,14 @@ addToLibrary({
14491449
} else {
14501450
_emscripten_get_now = Date.now;
14511451
}
1452+
`,
14521453
#else
1453-
// Modern environment where performance.now() is supported:
1454-
// N.B. a shorter form "_emscripten_get_now = performance.now;" is
1455-
// unfortunately not allowed even in current browsers (e.g. FF Nightly 75).
1456-
_emscripten_get_now = () => {{{ getPerformanceNow() }}}();
1454+
// Modern environment where performance.now() is supported:
1455+
// N.B. a shorter form "_emscripten_get_now = performance.now;" is
1456+
// unfortunately not allowed even in current browsers (e.g. FF Nightly 75).
1457+
emscripten_get_now: () => {{{ getPerformanceNow() }}}(),
14571458
#endif
14581459
#endif
1459-
`,
14601460

14611461
emscripten_get_now_res: () => { // return resolution of get_now, in nanoseconds
14621462
#if ENVIRONMENT_MAY_BE_NODE
@@ -1574,21 +1574,26 @@ addToLibrary({
15741574

15751575
#if USE_ASAN || USE_LSAN || UBSAN_RUNTIME
15761576
// When lsan or asan is enabled withBuiltinMalloc temporarily replaces calls
1577-
// to malloc, free, and memalign.
1578-
$withBuiltinMalloc__deps: ['emscripten_builtin_malloc', 'emscripten_builtin_free', 'emscripten_builtin_memalign'
1579-
],
1577+
// to malloc, calloc, free, and memalign.
1578+
$withBuiltinMalloc__deps: [
1579+
'malloc', 'calloc', 'free', 'memalign',
1580+
'emscripten_builtin_malloc', 'emscripten_builtin_free', 'emscripten_builtin_memalign', 'emscripten_builtin_calloc'
1581+
],
15801582
$withBuiltinMalloc__docs: '/** @suppress{checkTypes} */',
15811583
$withBuiltinMalloc: (func) => {
15821584
var prev_malloc = typeof _malloc != 'undefined' ? _malloc : undefined;
1585+
var prev_calloc = typeof _calloc != 'undefined' ? _calloc : undefined;
15831586
var prev_memalign = typeof _memalign != 'undefined' ? _memalign : undefined;
15841587
var prev_free = typeof _free != 'undefined' ? _free : undefined;
15851588
_malloc = _emscripten_builtin_malloc;
1589+
_calloc = _emscripten_builtin_calloc;
15861590
_memalign = _emscripten_builtin_memalign;
15871591
_free = _emscripten_builtin_free;
15881592
try {
15891593
return func();
15901594
} finally {
15911595
_malloc = prev_malloc;
1596+
_calloc = prev_calloc;
15921597
_memalign = prev_memalign;
15931598
_free = prev_free;
15941599
}

src/library_dylink.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ var LibraryDylink = {
363363
// Allocate memory even if malloc isn't ready yet. The allocated memory here
364364
// must be zero initialized since its used for all static data, including bss.
365365
$getMemory__noleakcheck: true,
366-
$getMemory__deps: ['$GOT', '__heap_base', '$zeroMemory', '$alignMemory', 'malloc'],
366+
$getMemory__deps: ['$GOT', '__heap_base', '$alignMemory', 'calloc'],
367367
$getMemory: (size) => {
368368
// After the runtime is initialized, we must only use sbrk() normally.
369369
#if DYLINK_DEBUG
@@ -373,7 +373,7 @@ var LibraryDylink = {
373373
// Currently we don't support freeing of static data when modules are
374374
// unloaded via dlclose. This function is tagged as `noleakcheck` to
375375
// avoid having this reported as leak.
376-
return zeroMemory(_malloc(size), size);
376+
return _calloc(size, 1);
377377
}
378378
var ret = ___heap_base;
379379
// Keep __heap_base stack aligned.
@@ -599,7 +599,7 @@ var LibraryDylink = {
599599
$loadWebAssemblyModule__deps: [
600600
'$loadDynamicLibrary', '$getMemory',
601601
'$relocateExports', '$resolveGlobalSymbol', '$GOTHandler',
602-
'$getDylinkMetadata', '$alignMemory', '$zeroMemory',
602+
'$getDylinkMetadata', '$alignMemory',
603603
'$currentModuleWeakSymbols',
604604
'$updateTableMap',
605605
'$wasmTable',

src/library_pthread.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var LibraryPThread = {
3535
$PThread__postset: 'PThread.init();',
3636
$PThread__deps: ['_emscripten_thread_init',
3737
'$terminateWorker',
38-
'$cleanupThread', '$zeroMemory',
38+
'$cleanupThread',
3939
#if MAIN_MODULE
4040
'$markAsFinished',
4141
#endif

src/library_sdl.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ var LibrarySDL = {
13571357
return SDL.version;
13581358
},
13591359

1360-
SDL_Init__deps: ['$zeroMemory', 'memcpy'],
1360+
SDL_Init__deps: ['calloc', 'memcpy'],
13611361
SDL_Init__proxy: 'sync',
13621362
SDL_Init__docs: '/** @param{number} initFlags */',
13631363
SDL_Init: (initFlags) => {
@@ -1376,8 +1376,7 @@ var LibrarySDL = {
13761376
}
13771377

13781378
window.addEventListener("unload", SDL.receiveEvent);
1379-
SDL.keyboardState = _malloc(0x10000); // Our SDL needs 512, but 64K is safe for older SDLs
1380-
zeroMemory(SDL.keyboardState, 0x10000);
1379+
SDL.keyboardState = _calloc(0x10000, 1); // Our SDL needs 512, but 64K is safe for older SDLs
13811380
// Initialize this structure carefully for closure
13821381
SDL.DOMEventToSDLEvent['keydown'] = 0x300 /* SDL_KEYDOWN */;
13831382
SDL.DOMEventToSDLEvent['keyup'] = 0x301 /* SDL_KEYUP */;
@@ -1413,11 +1412,10 @@ var LibrarySDL = {
14131412
return 1;
14141413
},
14151414

1416-
SDL_GetVideoInfo__deps: ['$zeroMemory'],
1415+
SDL_GetVideoInfo__deps: ['calloc'],
14171416
SDL_GetVideoInfo__proxy: 'sync',
14181417
SDL_GetVideoInfo: () => {
1419-
var ret = _malloc({{{ C_STRUCTS.SDL_VideoInfo.__size__ }}});
1420-
zeroMemory(ret, {{{ C_STRUCTS.SDL_version.__size__ }}});
1418+
var ret = _calloc({{{ C_STRUCTS.SDL_VideoInfo.__size__ }}}, 1);
14211419
{{{ makeSetValue('ret', C_STRUCTS.SDL_VideoInfo.current_w, 'Module["canvas"].width', 'i32') }}};
14221420
{{{ makeSetValue('ret', C_STRUCTS.SDL_VideoInfo.current_h, 'Module["canvas"].height', 'i32') }}};
14231421
return ret;

system/include/emscripten/bind.h

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,27 @@ struct reference : public allow_raw_pointers {};
359359

360360
namespace internal {
361361

362+
#if __cplusplus >= 201703L
363+
template <typename... Args> using conjunction = std::conjunction<Args...>;
364+
template <typename... Args> using disjunction = std::disjunction<Args...>;
365+
#else
366+
// Helper available in C++14.
367+
template <bool _Test, class _T1, class _T2>
368+
using conditional_t = typename std::conditional<_Test, _T1, _T2>::type;
369+
370+
template<class...> struct conjunction : std::true_type {};
371+
template<class B1> struct conjunction<B1> : B1 {};
372+
template<class B1, class... Bn>
373+
struct conjunction<B1, Bn...>
374+
: conditional_t<bool(B1::value), conjunction<Bn...>, B1> {};
375+
376+
template<class...> struct disjunction : std::false_type {};
377+
template<class B1> struct disjunction<B1> : B1 {};
378+
template<class B1, class... Bn>
379+
struct disjunction<B1, Bn...>
380+
: conditional_t<bool(B1::value), disjunction<Bn...>, B1> {};
381+
#endif
382+
362383
template<typename... Policies>
363384
struct isPolicy;
364385

@@ -428,40 +449,10 @@ struct GetReturnValuePolicy<ReturnType, T, Rest...> {
428449
};
429450

430451
template<typename... Policies>
431-
struct isAsync;
432-
433-
template<typename... Rest>
434-
struct isAsync<async, Rest...> {
435-
static constexpr bool value = true;
436-
};
437-
438-
template<typename T, typename... Rest>
439-
struct isAsync<T, Rest...> {
440-
static constexpr bool value = isAsync<Rest...>::value;
441-
};
442-
443-
template<>
444-
struct isAsync<> {
445-
static constexpr bool value = false;
446-
};
452+
using isAsync = disjunction<std::is_same<async, Policies>...>;
447453

448454
template<typename... Policies>
449-
struct isNonnullReturn;
450-
451-
template<typename... Rest>
452-
struct isNonnullReturn<nonnull<ret_val>, Rest...> {
453-
static constexpr bool value = true;
454-
};
455-
456-
template<typename T, typename... Rest>
457-
struct isNonnullReturn<T, Rest...> {
458-
static constexpr bool value = isNonnullReturn<Rest...>::value;
459-
};
460-
461-
template<>
462-
struct isNonnullReturn<> {
463-
static constexpr bool value = false;
464-
};
455+
using isNonnullReturn = disjunction<std::is_same<nonnull<ret_val>, Policies>...>;
465456

466457
}
467458

@@ -985,18 +976,6 @@ struct SetterPolicy<PropertyTag<Setter, SetterArgumentType>> {
985976
}
986977
};
987978

988-
// Helper available in C++14.
989-
template <bool _Test, class _T1, class _T2>
990-
using conditional_t = typename std::conditional<_Test, _T1, _T2>::type;
991-
992-
// Conjunction is available in C++17
993-
template<class...> struct conjunction : std::true_type {};
994-
template<class B1> struct conjunction<B1> : B1 {};
995-
template<class B1, class... Bn>
996-
struct conjunction<B1, Bn...>
997-
: conditional_t<bool(B1::value), conjunction<Bn...>, B1> {};
998-
999-
1000979
class noncopyable {
1001980
protected:
1002981
noncopyable() {}

system/include/emscripten/heap.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ size_t emscripten_get_heap_max(void);
4242
// dlmalloc and emmalloc.
4343
void *emscripten_builtin_memalign(size_t alignment, size_t size);
4444
void *emscripten_builtin_malloc(size_t size);
45+
void *emscripten_builtin_calloc(size_t nmemb, size_t size);
4546
void emscripten_builtin_free(void *ptr);
4647

4748
#ifdef __cplusplus

0 commit comments

Comments
 (0)