Skip to content

Commit ad0f669

Browse files
committed
Convert extended string handling functions into JS library code
1 parent 794362a commit ad0f669

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+357
-434
lines changed

ChangeLog.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,21 @@ See docs/process.md for more on how version tagging works.
3434
- addFunction
3535
- removeFunction
3636
- allocate
37+
- AsciiToString
38+
- stringToAscii
39+
- UTF16ToString
40+
- stringToUTF16
41+
- lengthBytesUTF16
42+
- UTF32ToString
43+
- stringToUTF32
44+
- lengthBytesUTF32
45+
- allocateUTF8
46+
- allocateUTF8OnStack
47+
- writeStringToMemory
48+
- writeArrayToMemory
49+
- writeAsciiToMemory
50+
- intArrayFromString
51+
- intArrayToString
3752
This means they won't get included in the output unless explictly required.
3853
Exporting them via `EXPORTED_RUNTIME_METHODS` will continue to work. For
3954
internal usage (without exporting them) they can be added to

emcc.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2132,7 +2132,9 @@ def phase_linker_setup(options, state, newargs, user_settings):
21322132
'$jsStackTrace',
21332133
'$stackTrace',
21342134
# Called by `callMain` to handle exceptions
2135-
'$handleException'
2135+
'$handleException',
2136+
# Needed by ccall (remove this once ccall itself is a library function)
2137+
'$writeArrayToMemory',
21362138
]
21372139

21382140
if not settings.STANDALONE_WASM and (settings.EXIT_RUNTIME or settings.ASSERTIONS):
@@ -2873,6 +2875,8 @@ def phase_emscript(options, in_wasm, wasm_target, memfile):
28732875

28742876
if embed_memfile():
28752877
settings.SUPPORT_BASE64_EMBEDDING = 1
2878+
# _read in shell.js depends on intArrayToString when SUPPORT_BASE64_EMBEDDING is set
2879+
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE.append('$intArrayToString')
28762880

28772881
emscripten.run(in_wasm, wasm_target, final_js, memfile)
28782882
save_intermediate('original')

emscripten.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,9 @@ def update_settings_glue(wasm_file, metadata):
152152
# When using dynamic linking the main function might be in a side module.
153153
# To be safe assume they do take input parametes.
154154
settings.MAIN_READS_PARAMS = metadata['mainReadsParams'] or bool(settings.MAIN_MODULE)
155+
if settings.MAIN_READS_PARAMS and not settings.STANDALONE_WASM:
156+
# callMain depends on this library function
157+
settings.DEFAULT_LIBRARY_FUNCS_TO_INCLUDE += ['$allocateUTF8OnStack']
155158

156159
if settings.STACK_OVERFLOW_CHECK and not settings.SIDE_MODULE:
157160
settings.EXPORTED_RUNTIME_METHODS += ['writeStackCookie', 'checkStackCookie']

src/embind/embind.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -784,10 +784,8 @@ var LibraryEmbind = {
784784
_embind_register_std_wstring__sig: 'vppp',
785785
_embind_register_std_wstring__deps: [
786786
'$readLatin1String', '$registerType', '$simpleReadValueFromPointer',
787-
#if MINIMAL_RUNTIME
788787
'$UTF16ToString', '$stringToUTF16', '$lengthBytesUTF16',
789788
'$UTF32ToString', '$stringToUTF32', '$lengthBytesUTF32',
790-
#endif
791789
],
792790
_embind_register_std_wstring: function(rawType, charSize, name) {
793791
name = readLatin1String(name);

src/jsifier.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,6 @@ function ${name}(${args}) {
516516

517517
if (!MINIMAL_RUNTIME) {
518518
print('var ASSERTIONS = ' + !!ASSERTIONS + ';\n');
519-
520-
print(preprocess(read('arrayUtils.js')));
521519
}
522520

523521
if ((SUPPORT_BASE64_EMBEDDING || FORCE_FILESYSTEM) && !MINIMAL_RUNTIME) {

src/library.js

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -566,11 +566,7 @@ mergeInto(LibraryManager.library, {
566566
tzset_impl__internal: true,
567567
tzset_impl__proxy: 'sync',
568568
tzset_impl__sig: 'viii',
569-
tzset_impl__deps: [
570-
#if MINIMAL_RUNTIME
571-
'$allocateUTF8'
572-
#endif
573-
],
569+
tzset_impl__deps: ['$allocateUTF8'],
574570
tzset_impl: function(timezone, daylight, tzname) {
575571
var currentYear = new Date().getFullYear();
576572
var winter = new Date(currentYear, 0, 1);
@@ -655,10 +651,8 @@ mergeInto(LibraryManager.library, {
655651

656652
// Note: this is not used in STANDALONE_WASM mode, because it is more
657653
// compact to do it in JS.
658-
strftime__deps: ['_isLeapYear', '_arraySum', '_addDays', '_MONTH_DAYS_REGULAR', '_MONTH_DAYS_LEAP'
659-
#if MINIMAL_RUNTIME
660-
, '$intArrayFromString', '$writeArrayToMemory'
661-
#endif
654+
strftime__deps: ['_isLeapYear', '_arraySum', '_addDays', '_MONTH_DAYS_REGULAR', '_MONTH_DAYS_LEAP',
655+
'$intArrayFromString', '$writeArrayToMemory'
662656
],
663657
strftime__sig: 'ppppp',
664658
strftime: function(s, maxsize, format, tm) {
@@ -954,11 +948,8 @@ mergeInto(LibraryManager.library, {
954948
return _strftime(s, maxsize, format, tm); // no locale support yet
955949
},
956950

957-
strptime__deps: ['_isLeapYear', '_arraySum', '_addDays', '_MONTH_DAYS_REGULAR', '_MONTH_DAYS_LEAP', '$jstoi_q'
958-
#if MINIMAL_RUNTIME
959-
, '$intArrayFromString'
960-
#endif
961-
],
951+
strptime__deps: ['_isLeapYear', '_arraySum', '_addDays', '_MONTH_DAYS_REGULAR', '_MONTH_DAYS_LEAP',
952+
'$jstoi_q', '$intArrayFromString' ],
962953
strptime__sig: 'pppp',
963954
strptime: function(buf, format, tm) {
964955
// char *strptime(const char *restrict buf, const char *restrict format, struct tm *restrict tm);
@@ -2079,11 +2070,7 @@ mergeInto(LibraryManager.library, {
20792070
list: [],
20802071
map: {}
20812072
},
2082-
setprotoent__deps: ['$Protocols'
2083-
#if MINIMAL_RUNTIME
2084-
, '$writeAsciiToMemory'
2085-
#endif
2086-
],
2073+
setprotoent__deps: ['$Protocols', '$writeAsciiToMemory'],
20872074
setprotoent: function(stayopen) {
20882075
// void setprotoent(int stayopen);
20892076

@@ -2773,13 +2760,7 @@ mergeInto(LibraryManager.library, {
27732760

27742761
// Look up the function name from our stack frame cache with our PC representation.
27752762
#if USE_OFFSET_CONVERTER
2776-
emscripten_pc_get_function__deps: [
2777-
'$UNWIND_CACHE',
2778-
'free',
2779-
#if MINIMAL_RUNTIME
2780-
'$allocateUTF8',
2781-
#endif
2782-
],
2763+
emscripten_pc_get_function__deps: ['$UNWIND_CACHE', 'free', '$allocateUTF8'],
27832764
// Don't treat allocation of _emscripten_pc_get_function.ret as a leak
27842765
emscripten_pc_get_function__noleakcheck: true,
27852766
emscripten_pc_get_function__sig: 'pp',
@@ -2840,11 +2821,7 @@ mergeInto(LibraryManager.library, {
28402821
},
28412822

28422823
// Look up the file name from our stack frame cache with our PC representation.
2843-
emscripten_pc_get_file__deps: ['$convertPCtoSourceLocation', 'free',
2844-
#if MINIMAL_RUNTIME
2845-
'$allocateUTF8',
2846-
#endif
2847-
],
2824+
emscripten_pc_get_file__deps: ['$convertPCtoSourceLocation', 'free', '$allocateUTF8'],
28482825
// Don't treat allocation of _emscripten_pc_get_file.ret as a leak
28492826
emscripten_pc_get_file__noleakcheck: true,
28502827
emscripten_pc_get_file__sig: 'pp',

src/library_bootstrap.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ mergeInto(LibraryManager.library, {
2323

2424
// printf/puts implementations for when musl is not pulled in - very
2525
// partial, but enough for bootstrapping structInfo
26-
printf__deps: ['$formatString'],
26+
printf__deps: ['$formatString', '$intArrayToString'],
2727
printf__sig: 'ipp',
2828
printf: function(format, varargs) {
2929
// int printf(const char *restrict format, ...);

src/library_dylink.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,7 @@ var LibraryDylink = {
249249
},
250250

251251
$dlSetError__internal: true,
252-
$dlSetError__deps: ['__dl_seterr',
253-
#if MINIMAL_RUNTIME
254-
'$intArrayFromString'
255-
#endif
256-
],
252+
$dlSetError__deps: ['__dl_seterr', '$allocateUTF8OnStack'],
257253
$dlSetError: function(msg) {
258254
withStackSave(function() {
259255
var cmsg = allocateUTF8OnStack(msg);

src/library_egl.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,7 @@ var LibraryEGL = {
522522
},
523523

524524
// EGLAPI const char * EGLAPIENTRY eglQueryString(EGLDisplay dpy, EGLint name);
525-
#if MINIMAL_RUNTIME
526525
eglQueryString__deps: ['$allocateUTF8'],
527-
#endif
528526
eglQueryString__proxy: 'sync',
529527
eglQueryString__sig: 'iii',
530528
eglQueryString: function(display, name) {

src/library_formatString.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,7 @@ mergeInto(LibraryManager.library, {
5252
// varargs: A pointer to the start of the arguments list.
5353
// Returns the resulting string string as a character array.
5454
$formatString__deps: ['$reallyNegative', '$convertI32PairToI53', '$convertU32PairToI53',
55-
'$reSign', '$unSign', '$strLen',
56-
#if MINIMAL_RUNTIME
57-
, '$intArrayFromString'
58-
#endif
55+
'$reSign', '$unSign', '$strLen', '$intArrayFromString'
5956
],
6057
$formatString: function(format, varargs) {
6158
#if ASSERTIONS

src/library_fs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
mergeInto(LibraryManager.library, {
8-
$FS__deps: ['$getRandomDevice', '$PATH', '$PATH_FS', '$TTY', '$MEMFS', '$asyncLoad',
8+
$FS__deps: ['$getRandomDevice', '$PATH', '$PATH_FS', '$TTY', '$MEMFS', '$asyncLoad', '$intArrayFromString',
99
#if LibraryManager.has('library_idbfs.js')
1010
'$IDBFS',
1111
#endif

src/library_glew.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*/
2121

2222
var LibraryGLEW = {
23-
$GLEW__deps: ['glGetString'],
23+
$GLEW__deps: ['glGetString', '$allocateUTF8'],
2424
$GLEW: {
2525
isLinaroFork: 1,
2626
extensions: null,

src/library_glfw.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ var LibraryGLFW = {
8181

8282
$GLFW__deps: ['emscripten_get_now', '$GL', '$Browser', '$GLFW_Window',
8383
'$callUserCallback',
84+
'$allocateUTF8',
8485
#if FILESYSTEM
8586
'$FS',
8687
#endif

src/library_openal.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2402,6 +2402,7 @@ var LibraryOpenAL = {
24022402

24032403
alcGetString__proxy: 'sync',
24042404
alcGetString__sig: 'iii',
2405+
alcGetString__deps: ['$allocateUTF8'],
24052406
alcGetString: function(deviceId, param) {
24062407
if (AL.alcStringCache[param]) {
24072408
return AL.alcStringCache[param];
@@ -2657,7 +2658,7 @@ var LibraryOpenAL = {
26572658

26582659
emscripten_alcGetStringiSOFT__proxy: 'sync',
26592660
emscripten_alcGetStringiSOFT__sig: 'iiii',
2660-
emscripten_alcGetStringiSOFT__deps: ['alcGetString'],
2661+
emscripten_alcGetStringiSOFT__deps: ['alcGetString', '$allocateUTF8'],
26612662
emscripten_alcGetStringiSOFT: function(deviceId, param, index) {
26622663
if (!(deviceId in AL.deviceRefCounts)) {
26632664
#if OPENAL_DEBUG
@@ -3054,6 +3055,7 @@ var LibraryOpenAL = {
30543055

30553056
alGetString__proxy: 'sync',
30563057
alGetString__sig: 'ii',
3058+
alGetString__deps: ['$allocateUTF8'],
30573059
alGetString: function(param) {
30583060
if (AL.stringCache[param]) {
30593061
return AL.stringCache[param];

src/library_sdl.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1779,6 +1779,7 @@ var LibrarySDL = {
17791779

17801780
SDL_GetKeyName__proxy: 'sync',
17811781
SDL_GetKeyName__sig: 'ii',
1782+
SDL_GetKeyName__deps: ['$allocateUTF8'],
17821783
SDL_GetKeyName: function(key) {
17831784
if (!SDL.keyName) {
17841785
SDL.keyName = allocateUTF8('unknown key');
@@ -1841,6 +1842,7 @@ var LibrarySDL = {
18411842

18421843
SDL_GetError__proxy: 'sync',
18431844
SDL_GetError__sig: 'i',
1845+
SDL_GetError__deps: ['$allocateUTF8'],
18441846
SDL_GetError: function() {
18451847
if (!SDL.errorMessage) {
18461848
SDL.errorMessage = allocateUTF8("unknown SDL-emscripten error");
@@ -3573,6 +3575,7 @@ var LibrarySDL = {
35733575

35743576
SDL_JoystickName__proxy: 'sync',
35753577
SDL_JoystickName__sig: 'ii',
3578+
SDL_JoystickName__deps: ['$allocateUTF8'],
35763579
SDL_JoystickName: function(deviceIndex) {
35773580
var gamepad = SDL.getGamepad(deviceIndex);
35783581
if (gamepad) {
@@ -3712,6 +3715,7 @@ var LibrarySDL = {
37123715
},
37133716

37143717
SDL_GetNumAudioDrivers: function() { return 1 },
3718+
SDL_GetCurrentAudioDriver__deps: ['$allocateUTF8'],
37153719
SDL_GetCurrentAudioDriver: function() {
37163720
return allocateUTF8('Emscripten Audio');
37173721
},

0 commit comments

Comments
 (0)