diff options
author | Jukka Jylänki <jujjyl@gmail.com> | 2014-05-20 12:15:27 +0300 |
---|---|---|
committer | Jukka Jylänki <jujjyl@gmail.com> | 2014-05-23 02:20:06 +0300 |
commit | c81baafb6a516c0bfef67751df1dcd19a0a9c750 (patch) | |
tree | 6dbd0d9a4dec7f7fc5ba27922a650c696a3c89bb | |
parent | 955e7442312dd16b627d375c3726fa580dcdd465 (diff) |
Migrate snprintf to musl. Move the most common sprintf-related code to libc instead of libcextra to avoid pulling libcextra in on common runs.
-rw-r--r-- | src/library.js | 19 | ||||
-rw-r--r-- | system/lib/libc.symbols | 11 | ||||
-rw-r--r-- | system/lib/libc/musl/src/stdio/snprintf.c | 13 | ||||
-rw-r--r-- | system/lib/libcextra.symbols | 10 | ||||
-rw-r--r-- | tools/system_libs.py | 25 |
5 files changed, 38 insertions, 40 deletions
diff --git a/src/library.js b/src/library.js index 24eef829..6fc1a322 100644 --- a/src/library.js +++ b/src/library.js @@ -2802,25 +2802,6 @@ LibraryManager.library = { var stdin = {{{ makeGetValue(makeGlobalUse('_stdin'), '0', 'void*') }}}; return _fscanf(stdin, format, varargs); }, - snprintf__deps: ['_formatString', 'malloc'], - snprintf: function(s, n, format, varargs) { - // int snprintf(char *restrict s, size_t n, const char *restrict format, ...); - // http://pubs.opengroup.org/onlinepubs/000095399/functions/printf.html - var result = __formatString(format, varargs); - var limit = (n === undefined) ? result.length - : Math.min(result.length, Math.max(n - 1, 0)); - if (s < 0) { - s = -s; - var buf = _malloc(limit+1); - {{{ makeSetValue('s', '0', 'buf', 'i8*') }}}; - s = buf; - } - for (var i = 0; i < limit; i++) { - {{{ makeSetValue('s', 'i', 'result[i]', 'i8') }}}; - } - if (limit < n || (n === undefined)) {{{ makeSetValue('s', 'i', '0', 'i8') }}}; - return result.length; - }, fprintf__deps: ['fwrite', '_formatString'], fprintf: function(stream, format, varargs) { // int fprintf(FILE *restrict stream, const char *restrict format, ...); diff --git a/system/lib/libc.symbols b/system/lib/libc.symbols index d889d509..28e959d9 100644 --- a/system/lib/libc.symbols +++ b/system/lib/libc.symbols @@ -56,6 +56,9 @@ W bulk_free W calloc W free + T frexp + T frexpf + T frexpl W independent_calloc W independent_comalloc T isdigit @@ -72,14 +75,18 @@ W malloc_usable_size W mallopt W memalign + T MUSL_vfprintf W posix_memalign W pvalloc W realloc W realloc_in_place T scalbn T scalbnl + T memchr T memcmp T memcpy + T snprintf + T sprintf T strtod T strtoull T strtoll @@ -101,3 +108,7 @@ T strtold_l T tolower W valloc + T vsnprintf + T vsprintf + T wcrtomb + T wctomb diff --git a/system/lib/libc/musl/src/stdio/snprintf.c b/system/lib/libc/musl/src/stdio/snprintf.c new file mode 100644 index 00000000..771503b2 --- /dev/null +++ b/system/lib/libc/musl/src/stdio/snprintf.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <stdarg.h> + +int snprintf(char *restrict s, size_t n, const char *restrict fmt, ...) +{ + int ret; + va_list ap; + va_start(ap, fmt); + ret = vsnprintf(s, n, fmt, ap); + va_end(ap); + return ret; +} + diff --git a/system/lib/libcextra.symbols b/system/lib/libcextra.symbols index 32fb23e1..1ab849bd 100644 --- a/system/lib/libcextra.symbols +++ b/system/lib/libcextra.symbols @@ -34,9 +34,6 @@ T fcvt T fputwc W fputwc_unlocked - T frexp - T frexpf - T frexpl T fwprintf T gcvt T getopt @@ -117,7 +114,6 @@ T mbstowcs T mbtowc T memccpy - T memchr T memmem T mempcpy W memrchr @@ -167,7 +163,6 @@ T strverscmp T strxfrm W strxfrm_l - T sprintf T swprintf T tgamma T tgammaf @@ -187,10 +182,7 @@ T verrx T MUSL_vfscanf T vsscanf - T MUSL_vfprintf T vfwprintf - T vsnprintf - T vsprintf T vswprintf T vwarn T vwarnx @@ -199,7 +191,6 @@ T warnx T wcpcpy T wcpncpy - T wcrtomb T wcscasecmp T wcscasecmp_l T wcscat @@ -239,7 +230,6 @@ T wcsxfrm T wcsxfrm_l T wctob - T wctomb T wctrans T wctrans_l T wctype diff --git a/tools/system_libs.py b/tools/system_libs.py index d6b44efb..78bf2d48 100644 --- a/tools/system_libs.py +++ b/tools/system_libs.py @@ -67,14 +67,27 @@ def calculate(temp_files, in_temp, stdout, stderr): 'shgetc.c', ]], ['math', [ + 'frexp.c', + 'frexpf.c', + 'frexpl.c', 'scalbn.c', 'scalbnl.c', ]], + ['multibyte', [ + 'wctomb.c', + 'wcrtomb.c', + ]], ['stdio', [ '__overflow.c', '__toread.c', '__towrite.c', '__uflow.c', + 'fwrite.c', + 'snprintf.c', + 'sprintf.c', + 'vfprintf.c', + 'vsnprintf.c', + 'vsprintf.c', ]], ['stdlib', [ 'atof.c', @@ -84,6 +97,7 @@ def calculate(temp_files, in_temp, stdout, stderr): 'strtol.c', ]], ['string', [ + 'memchr.c', 'memcmp.c', 'strcasecmp.c', 'strcmp.c', @@ -199,9 +213,6 @@ def calculate(temp_files, in_temp, stdout, stderr): '__cosdf.c', '__sin.c', '__sindf.c', - 'frexp.c', - 'frexpf.c', - 'frexpl.c', 'ilogb.c', 'ilogbf.c', 'ilogbl.c', @@ -237,12 +248,10 @@ def calculate(temp_files, in_temp, stdout, stderr): 'mbsrtowcs.c', 'mbstowcs.c', 'mbtowc.c', - 'wcrtomb.c', 'wcsnrtombs.c', 'wcsrtombs.c', 'wcstombs.c', 'wctob.c', - 'wctomb.c', ]], ['regex', [ 'fnmatch.c', @@ -262,14 +271,9 @@ def calculate(temp_files, in_temp, stdout, stderr): 'wprintf.c', 'fputwc.c', 'fputws.c', - 'fwrite.c', - 'sprintf.c', 'sscanf.c', 'vasprintf.c', - 'vfprintf.c', 'vfscanf.c', - 'vsnprintf.c', - 'vsprintf.c', 'vsscanf.c', ]], ['stdlib', [ @@ -290,7 +294,6 @@ def calculate(temp_files, in_temp, stdout, stderr): 'memccpy.c', 'memmem.c', 'mempcpy.c', - 'memchr.c', 'memrchr.c', 'rindex.c', 'stpcpy.c', |