aboutsummaryrefslogtreecommitdiff
path: root/src/library.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/library.js')
-rw-r--r--src/library.js65
1 files changed, 53 insertions, 12 deletions
diff --git a/src/library.js b/src/library.js
index 3b229dfa..9268edd5 100644
--- a/src/library.js
+++ b/src/library.js
@@ -52,7 +52,7 @@ LibraryManager.library = {
streams: [null],
#if ASSERTIONS
checkStreams: function() {
- for (var i in FS.streams) assert(i >= 0 && i < FS.streams.length); // no keys not in dense span
+ for (var i in FS.streams) if (FS.streams.hasOwnProperty(i)) assert(i >= 0 && i < FS.streams.length); // no keys not in dense span
for (var i = 0; i < FS.streams.length; i++) assert(typeof FS.streams[i] == 'object'); // no non-null holes in dense span
},
#endif
@@ -2611,6 +2611,7 @@ LibraryManager.library = {
// format: A pointer to the format string.
// varargs: A pointer to the start of the arguments list.
// Returns the resulting string string as a character array.
+ _formatString__deps: ['strlen'],
_formatString: function(format, varargs) {
var textIndex = format;
var argIndex = 0;
@@ -2937,7 +2938,7 @@ LibraryManager.library = {
} else if (next == 's'.charCodeAt(0)) {
// String.
var arg = getNextArg('i8*') || nullString;
- var argLength = String_len(arg);
+ var argLength = _strlen(arg);
if (precisionSet) argLength = Math.min(argLength, precision);
if (!flagLeftAlign) {
while (argLength < width--) {
@@ -3500,6 +3501,12 @@ LibraryManager.library = {
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') }}};
}
@@ -3529,10 +3536,15 @@ LibraryManager.library = {
// http://pubs.opengroup.org/onlinepubs/000095399/functions/printf.html
return _snprintf(s, undefined, format, varargs);
},
+ asprintf__deps: ['sprintf'],
+ asprintf: function(s, format, varargs) {
+ return _sprintf(-s, format, varargs);
+ },
vfprintf: 'fprintf',
vsnprintf: 'snprintf',
vprintf: 'printf',
vsprintf: 'sprintf',
+ vasprintf: 'asprintf',
vscanf: 'scanf',
vfscanf: 'fscanf',
vsscanf: 'sscanf',
@@ -3617,7 +3629,7 @@ LibraryManager.library = {
* implementation (replaced by dlmalloc normally) so
* not an issue.
*/
- ptr = Runtime.staticAlloc(bytes + 8);
+ var ptr = Runtime.staticAlloc(bytes + 8);
return (ptr+8) & 0xFFFFFFF8;
},
free: function(){},
@@ -4213,6 +4225,8 @@ LibraryManager.library = {
}
},
+ wmemcpy: function() { throw 'wmemcpy not implemented' },
+
llvm_memcpy_i32: 'memcpy',
llvm_memcpy_i64: 'memcpy',
llvm_memcpy_p0i8_p0i8_i32: 'memcpy',
@@ -4238,6 +4252,8 @@ LibraryManager.library = {
llvm_memmove_p0i8_p0i8_i32: 'memmove',
llvm_memmove_p0i8_p0i8_i64: 'memmove',
+ wmemmove: function() { throw 'wmemmove not implemented' },
+
memset__inline: function(ptr, value, num, align) {
return makeSetValues(ptr, 0, value, 'null', num, align);
},
@@ -4272,8 +4288,17 @@ LibraryManager.library = {
llvm_memset_p0i8_i32: 'memset',
llvm_memset_p0i8_i64: 'memset',
+ wmemset: function() { throw 'wmemset not implemented' },
+
+ strlen__asm: 'ii',
strlen: function(ptr) {
- return String_len(ptr);
+ ptr = ptr|0;
+ var curr = 0;
+ curr = ptr;
+ while ({{{ makeGetValueAsm('curr', '0', 'i8') }}}|0 != 0) {
+ curr = (curr + 1)|0;
+ }
+ return (curr - ptr)|0;
},
// TODO: Implement when we have real unicode support.
@@ -4281,6 +4306,13 @@ LibraryManager.library = {
return 1;
},
+ wcslen: function() { throw 'wcslen not implemented' },
+ mbrlen: function() { throw 'mbrlen not implemented' },
+ mbsrtowcs: function() { throw 'mbsrtowcs not implemented' },
+ wcsnrtombs: function() { throw 'wcsnrtombs not implemented' },
+ mbsnrtowcs: function() { throw 'mbsnrtowcs not implemented' },
+ mbrtowc: function() { throw 'mbrtowc not implemented' },
+
strspn: function(pstr, pset) {
var str = pstr, set, strcurr, setcurr;
while (1) {
@@ -4497,17 +4529,18 @@ LibraryManager.library = {
},
rindex: 'strrchr',
+ strdup__deps: ['strlen'],
strdup: function(ptr) {
- var len = String_len(ptr);
+ var len = _strlen(ptr);
var newStr = _malloc(len + 1);
{{{ makeCopyValues('newStr', 'ptr', 'len', 'null', null, 1) }}};
{{{ makeSetValue('newStr', 'len', '0', 'i8') }}};
return newStr;
},
- strndup__deps: ['strdup'],
+ strndup__deps: ['strdup', 'strlen'],
strndup: function(ptr, size) {
- var len = String_len(ptr);
+ var len = _strlen(ptr);
if (size >= len) {
return _strdup(ptr);
@@ -4898,12 +4931,12 @@ LibraryManager.library = {
} else {
__ZSt18uncaught_exceptionv.uncaught_exception++;
}
- throw ptr;
+ {{{ makeThrow('ptr') }}};
},
__cxa_rethrow__deps: ['llvm_eh_exception', '__cxa_end_catch'],
__cxa_rethrow: function() {
___cxa_end_catch.rethrown = true;
- throw {{{ makeGetValue('_llvm_eh_exception.buf', '0', 'void*') }}};
+ {{{ makeThrow(makeGetValue('_llvm_eh_exception.buf', '0', 'void*')) }}};
},
llvm_eh_exception__postset: '_llvm_eh_exception.buf = allocate(12, "void*", ALLOC_STATIC);',
llvm_eh_exception: function() {
@@ -4966,11 +4999,10 @@ LibraryManager.library = {
},
_Unwind_Resume_or_Rethrow: function(ptr) {
- throw ptr;
+ {{{ makeThrow('ptr') }}};
},
- _Unwind_RaiseException__deps: ['llvm_eh_exception', '__cxa_find_matching_catch'],
_Unwind_RaiseException: function(ptr) {
- throw ptr;
+ {{{ makeThrow('ptr') }}};
},
_Unwind_DeleteException: function(ptr) {},
@@ -5074,6 +5106,8 @@ LibraryManager.library = {
_ZNSt9exceptionD2Ev: function(){}, // XXX a dependency of dlmalloc, but not actually needed if libcxx is not anyhow included
+ _ZNSt9type_infoD2Ev: function(){},
+
// RTTI hacks for exception handling, defining type_infos for common types.
// The values are dummies. We simply use the addresses of these statically
// allocated variables as unique identifiers.
@@ -6130,6 +6164,8 @@ LibraryManager.library = {
return me.ret;
},
+ __locale_mb_cur_max: function() { throw '__locale_mb_cur_max not implemented' },
+
// ==========================================================================
// langinfo.h
// ==========================================================================
@@ -6310,6 +6346,10 @@ LibraryManager.library = {
return me.ret;
},
+ _Z7catopenPKci: function() { throw 'catopen not implemented' },
+ _Z7catgetsP8_nl_catdiiPKc: function() { throw 'catgets not implemented' },
+ _Z8catcloseP8_nl_catd: function() { throw 'catclose not implemented' },
+
// ==========================================================================
// errno.h
// ==========================================================================
@@ -6553,6 +6593,7 @@ LibraryManager.library = {
pthread_cond_init: function() {},
pthread_cond_destroy: function() {},
pthread_cond_broadcast: function() {},
+ pthread_cond_wait: function() {},
pthread_self: function() {
//FIXME: assumes only a single thread
return 0;