webruby 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (245) hide show
  1. checksums.yaml +4 -4
  2. data/lib/webruby/config.rb +4 -9
  3. data/lib/webruby/rake/files.rake +2 -2
  4. data/modules/emscripten/AUTHORS +9 -1
  5. data/modules/emscripten/CONTRIBUTING.markdown +5 -0
  6. data/modules/emscripten/ChangeLog +435 -0
  7. data/modules/emscripten/cmake/Modules/FindOpenAL.cmake +26 -0
  8. data/modules/emscripten/cmake/Platform/Emscripten.cmake +9 -2
  9. data/modules/emscripten/em++ +0 -2
  10. data/modules/emscripten/emcc +92 -32
  11. data/modules/emscripten/emlink.py +16 -13
  12. data/modules/emscripten/emmake +1 -1
  13. data/modules/emscripten/emrun +918 -0
  14. data/modules/emscripten/emrun.bat +2 -0
  15. data/modules/emscripten/emscripten.py +545 -20
  16. data/modules/emscripten/src/analyzer.js +6 -1
  17. data/modules/emscripten/src/compiler.js +25 -16
  18. data/modules/emscripten/src/emrun_postjs.js +20 -0
  19. data/modules/emscripten/{tests → src}/hello_world.js +0 -0
  20. data/modules/emscripten/src/intertyper.js +45 -16
  21. data/modules/emscripten/src/jsifier.js +78 -48
  22. data/modules/emscripten/src/library.js +381 -96
  23. data/modules/emscripten/src/library_browser.js +50 -53
  24. data/modules/emscripten/src/library_egl.js +66 -24
  25. data/modules/emscripten/src/library_fs.js +122 -90
  26. data/modules/emscripten/src/library_gl.js +739 -353
  27. data/modules/emscripten/src/library_glfw.js +9 -3
  28. data/modules/emscripten/src/library_glut.js +10 -5
  29. data/modules/emscripten/src/library_idbfs.js +14 -14
  30. data/modules/emscripten/src/library_memfs.js +65 -41
  31. data/modules/emscripten/src/library_nodefs.js +61 -9
  32. data/modules/emscripten/src/library_openal.js +4 -4
  33. data/modules/emscripten/src/library_path.js +9 -13
  34. data/modules/emscripten/src/library_sdl.js +301 -64
  35. data/modules/emscripten/src/library_sockfs.js +7 -5
  36. data/modules/emscripten/src/modules.js +62 -22
  37. data/modules/emscripten/src/parseTools.js +135 -102
  38. data/modules/emscripten/src/postamble.js +3 -4
  39. data/modules/emscripten/src/preamble.js +49 -29
  40. data/modules/emscripten/src/proxyClient.js +1 -1
  41. data/modules/emscripten/src/proxyWorker.js +10 -10
  42. data/modules/emscripten/src/relooper/Relooper.cpp +15 -4
  43. data/modules/emscripten/src/runtime.js +32 -8
  44. data/modules/emscripten/src/settings.js +25 -8
  45. data/modules/emscripten/src/shell.html +6 -3
  46. data/modules/emscripten/src/shell.js +13 -11
  47. data/modules/emscripten/src/simd.js +602 -432
  48. data/modules/emscripten/src/struct_info.json +22 -2
  49. data/modules/emscripten/src/utility.js +32 -17
  50. data/modules/emscripten/system/include/SDL/SDL_events.h +1 -0
  51. data/modules/emscripten/system/include/compat/ctype.h +17 -0
  52. data/modules/emscripten/system/include/compat/wchar.h +23 -0
  53. data/modules/emscripten/system/include/compat/wctype.h +23 -0
  54. data/modules/emscripten/system/include/emscripten/emmintrin.h +87 -0
  55. data/modules/emscripten/system/include/emscripten/emscripten.h +30 -4
  56. data/modules/emscripten/system/include/emscripten/vector.h +29 -1
  57. data/modules/emscripten/system/include/emscripten/xmmintrin.h +131 -0
  58. data/modules/emscripten/system/include/libcxx/CREDITS.TXT +9 -1
  59. data/modules/emscripten/system/include/libcxx/__bit_reference +8 -8
  60. data/modules/emscripten/system/include/libcxx/__config +95 -17
  61. data/modules/emscripten/system/include/libcxx/__debug +25 -4
  62. data/modules/emscripten/system/include/libcxx/__functional_03 +7 -7
  63. data/modules/emscripten/system/include/libcxx/__functional_base +169 -9
  64. data/modules/emscripten/system/include/libcxx/__functional_base_03 +1 -1
  65. data/modules/emscripten/system/include/libcxx/__hash_table +25 -25
  66. data/modules/emscripten/system/include/libcxx/__locale +21 -19
  67. data/modules/emscripten/system/include/libcxx/__mutex_base +2 -33
  68. data/modules/emscripten/system/include/libcxx/__split_buffer +9 -9
  69. data/modules/emscripten/system/include/libcxx/__std_stream +14 -0
  70. data/modules/emscripten/system/include/libcxx/__tree +35 -26
  71. data/modules/emscripten/system/include/libcxx/__tuple +15 -15
  72. data/modules/emscripten/system/include/libcxx/__tuple_03 +2 -2
  73. data/modules/emscripten/system/include/libcxx/__undef_min_max +8 -0
  74. data/modules/emscripten/system/include/libcxx/algorithm +121 -110
  75. data/modules/emscripten/system/include/libcxx/array +15 -15
  76. data/modules/emscripten/system/include/libcxx/bitset +4 -4
  77. data/modules/emscripten/system/include/libcxx/chrono +51 -17
  78. data/modules/emscripten/system/include/libcxx/cmath +25 -23
  79. data/modules/emscripten/system/include/libcxx/codecvt +21 -18
  80. data/modules/emscripten/system/include/libcxx/complex +48 -7
  81. data/modules/emscripten/system/include/libcxx/cstddef +1 -1
  82. data/modules/emscripten/system/include/libcxx/cstdio +8 -1
  83. data/modules/emscripten/system/include/libcxx/cstdlib +1 -1
  84. data/modules/emscripten/system/include/libcxx/cwchar +1 -1
  85. data/modules/emscripten/system/include/libcxx/deque +26 -12
  86. data/modules/emscripten/system/include/libcxx/dynarray +311 -0
  87. data/modules/emscripten/system/include/libcxx/exception +4 -4
  88. data/modules/emscripten/system/include/libcxx/ext/__hash +3 -3
  89. data/modules/emscripten/system/include/libcxx/ext/hash_map +19 -15
  90. data/modules/emscripten/system/include/libcxx/ext/hash_set +7 -3
  91. data/modules/emscripten/system/include/libcxx/forward_list +33 -7
  92. data/modules/emscripten/system/include/libcxx/fstream +4 -4
  93. data/modules/emscripten/system/include/libcxx/functional +200 -170
  94. data/modules/emscripten/system/include/libcxx/future +83 -39
  95. data/modules/emscripten/system/include/libcxx/initializer_list +24 -11
  96. data/modules/emscripten/system/include/libcxx/iomanip +147 -0
  97. data/modules/emscripten/system/include/libcxx/ios +24 -16
  98. data/modules/emscripten/system/include/libcxx/iosfwd +19 -19
  99. data/modules/emscripten/system/include/libcxx/istream +13 -8
  100. data/modules/emscripten/system/include/libcxx/iterator +108 -417
  101. data/modules/emscripten/system/include/libcxx/limits +8 -4
  102. data/modules/emscripten/system/include/libcxx/list +28 -8
  103. data/modules/emscripten/system/include/libcxx/locale +153 -390
  104. data/modules/emscripten/system/include/libcxx/map +280 -100
  105. data/modules/emscripten/system/include/libcxx/memory +49 -97
  106. data/modules/emscripten/system/include/libcxx/mutex +2 -2
  107. data/modules/emscripten/system/include/libcxx/new +43 -14
  108. data/modules/emscripten/system/include/libcxx/numeric +2 -2
  109. data/modules/emscripten/system/include/libcxx/optional +697 -0
  110. data/modules/emscripten/system/include/libcxx/ostream +17 -8
  111. data/modules/emscripten/system/include/libcxx/queue +5 -5
  112. data/modules/emscripten/system/include/libcxx/random +53 -51
  113. data/modules/emscripten/system/include/libcxx/ratio +11 -11
  114. data/modules/emscripten/system/include/libcxx/readme.txt +1 -1
  115. data/modules/emscripten/system/include/libcxx/regex +23 -20
  116. data/modules/emscripten/system/include/libcxx/scoped_allocator +1 -1
  117. data/modules/emscripten/system/include/libcxx/set +166 -2
  118. data/modules/emscripten/system/include/libcxx/shared_mutex +419 -0
  119. data/modules/emscripten/system/include/libcxx/sstream +4 -4
  120. data/modules/emscripten/system/include/libcxx/stack +3 -3
  121. data/modules/emscripten/system/include/libcxx/streambuf +5 -5
  122. data/modules/emscripten/system/include/libcxx/string +372 -324
  123. data/modules/emscripten/system/include/libcxx/support/ibm/limits.h +99 -0
  124. data/modules/emscripten/system/include/libcxx/support/ibm/support.h +54 -0
  125. data/modules/emscripten/system/include/libcxx/support/ibm/xlocale.h +326 -0
  126. data/modules/emscripten/system/include/libcxx/support/win32/limits_win32.h +6 -6
  127. data/modules/emscripten/system/include/libcxx/support/win32/locale_win32.h +15 -15
  128. data/modules/emscripten/system/include/libcxx/support/win32/math_win32.h +2 -0
  129. data/modules/emscripten/system/include/libcxx/support/win32/support.h +6 -1
  130. data/modules/emscripten/system/include/libcxx/system_error +14 -8
  131. data/modules/emscripten/system/include/libcxx/thread +7 -8
  132. data/modules/emscripten/system/include/libcxx/tuple +29 -88
  133. data/modules/emscripten/system/include/libcxx/type_traits +253 -209
  134. data/modules/emscripten/system/include/libcxx/typeindex +3 -3
  135. data/modules/emscripten/system/include/libcxx/unordered_map +162 -101
  136. data/modules/emscripten/system/include/libcxx/unordered_set +79 -2
  137. data/modules/emscripten/system/include/libcxx/utility +20 -20
  138. data/modules/emscripten/system/include/libcxx/valarray +23 -23
  139. data/modules/emscripten/system/include/libcxx/vector +114 -91
  140. data/modules/emscripten/system/lib/libc/musl/src/regex/regcomp.c +3352 -0
  141. data/modules/emscripten/system/lib/libc/musl/src/regex/regerror.c +35 -0
  142. data/modules/emscripten/system/lib/libc/musl/src/regex/regexec.c +1011 -0
  143. data/modules/emscripten/system/lib/libc/musl/src/regex/tre-mem.c +158 -0
  144. data/modules/emscripten/system/lib/libc/musl/src/regex/tre.h +231 -0
  145. data/modules/emscripten/system/lib/libcextra.symbols +7 -0
  146. data/modules/emscripten/system/lib/libcxx/CREDITS.TXT +9 -1
  147. data/modules/emscripten/system/lib/libcxx/algorithm.cpp +1 -0
  148. data/modules/emscripten/system/lib/libcxx/debug.cpp +66 -42
  149. data/modules/emscripten/system/lib/libcxx/exception.cpp +88 -16
  150. data/modules/emscripten/system/lib/libcxx/future.cpp +6 -0
  151. data/modules/emscripten/system/lib/libcxx/ios.cpp +7 -2
  152. data/modules/emscripten/system/lib/libcxx/iostream.cpp +8 -8
  153. data/modules/emscripten/system/lib/libcxx/locale.cpp +38 -11
  154. data/modules/emscripten/system/lib/libcxx/mutex.cpp +3 -0
  155. data/modules/emscripten/system/lib/libcxx/new.cpp +44 -10
  156. data/modules/emscripten/system/lib/libcxx/optional.cpp +25 -0
  157. data/modules/emscripten/system/lib/libcxx/random.cpp +26 -0
  158. data/modules/emscripten/system/lib/libcxx/readme.txt +1 -1
  159. data/modules/emscripten/system/lib/libcxx/shared_mutex.cpp +101 -0
  160. data/modules/emscripten/system/lib/libcxx/stdexcept.cpp +11 -7
  161. data/modules/emscripten/system/lib/libcxx/string.cpp +3 -1
  162. data/modules/emscripten/system/lib/libcxx/strstream.cpp +7 -7
  163. data/modules/emscripten/system/lib/libcxx/support/win32/locale_win32.cpp +12 -13
  164. data/modules/emscripten/system/lib/libcxx/support/win32/support.cpp +33 -36
  165. data/modules/emscripten/system/lib/libcxx/symbols +187 -168
  166. data/modules/emscripten/system/lib/libcxx/system_error.cpp +1 -0
  167. data/modules/emscripten/system/lib/libcxx/thread.cpp +7 -3
  168. data/modules/emscripten/system/lib/libcxx/typeinfo.cpp +9 -6
  169. data/modules/emscripten/system/lib/libcxx/valarray.cpp +2 -0
  170. data/modules/emscripten/third_party/lzma.js/doit.bat +4 -0
  171. data/modules/emscripten/third_party/lzma.js/doit.sh +9 -2
  172. data/modules/emscripten/tools/cache.py +5 -7
  173. data/modules/emscripten/tools/cache.pyc +0 -0
  174. data/modules/emscripten/tools/eliminator/asm-eliminator-test-output.js +7 -0
  175. data/modules/emscripten/tools/eliminator/asm-eliminator-test.js +9 -1
  176. data/modules/emscripten/tools/eliminator/eliminator-test-output.js +3 -0
  177. data/modules/emscripten/tools/eliminator/eliminator-test.js +9 -1
  178. data/modules/emscripten/tools/file_packager.py +93 -50
  179. data/modules/emscripten/tools/js-optimizer.js +98 -48
  180. data/modules/emscripten/tools/js_optimizer.py +4 -4
  181. data/modules/emscripten/tools/js_optimizer.pyc +0 -0
  182. data/modules/emscripten/tools/jsrun.py +1 -1
  183. data/modules/emscripten/tools/jsrun.pyc +0 -0
  184. data/modules/emscripten/tools/response_file.py +6 -0
  185. data/modules/emscripten/tools/response_file.pyc +0 -0
  186. data/modules/emscripten/tools/settings_template_readonly.py +2 -0
  187. data/modules/emscripten/tools/shared.py +88 -34
  188. data/modules/emscripten/tools/shared.pyc +0 -0
  189. data/modules/emscripten/tools/split.py +21 -13
  190. data/modules/mruby/build_config.rb +7 -1
  191. data/modules/mruby/doc/compile/README.md +5 -9
  192. data/modules/mruby/include/mrbconf.h +5 -2
  193. data/modules/mruby/include/mruby/array.h +1 -0
  194. data/modules/mruby/include/mruby/compile.h +2 -4
  195. data/modules/mruby/include/mruby/dump.h +7 -16
  196. data/modules/mruby/include/mruby/hash.h +1 -1
  197. data/modules/mruby/include/mruby/irep.h +14 -2
  198. data/modules/mruby/include/mruby/khash.h +8 -7
  199. data/modules/mruby/include/mruby/string.h +1 -0
  200. data/modules/mruby/include/mruby/value.h +5 -2
  201. data/modules/mruby/include/mruby.h +12 -13
  202. data/modules/mruby/mrbgems/mruby-bin-mirb/tools/mirb/mirb.c +16 -6
  203. data/modules/mruby/mrbgems/mruby-bin-mruby/tools/mruby/mruby.c +18 -30
  204. data/modules/mruby/mrbgems/mruby-fiber/src/fiber.c +21 -0
  205. data/modules/mruby/mrbgems/mruby-math/src/math.c +1 -1
  206. data/modules/mruby/mrbgems/mruby-random/src/random.c +144 -47
  207. data/modules/mruby/mrbgems/mruby-random/test/random.rb +44 -0
  208. data/modules/mruby/mrbgems/mruby-struct/src/struct.c +5 -5
  209. data/modules/mruby/mrblib/numeric.rb +99 -33
  210. data/modules/mruby/src/array.c +11 -4
  211. data/modules/mruby/src/backtrace.c +2 -2
  212. data/modules/mruby/src/class.c +49 -30
  213. data/modules/mruby/src/codegen.c +131 -79
  214. data/modules/mruby/src/debug.c +1 -1
  215. data/modules/mruby/src/dump.c +213 -163
  216. data/modules/mruby/src/error.c +17 -17
  217. data/modules/mruby/src/error.h +1 -1
  218. data/modules/mruby/src/etc.c +10 -0
  219. data/modules/mruby/src/gc.c +35 -17
  220. data/modules/mruby/src/hash.c +5 -5
  221. data/modules/mruby/src/kernel.c +36 -14
  222. data/modules/mruby/src/load.c +238 -296
  223. data/modules/mruby/src/numeric.c +18 -98
  224. data/modules/mruby/src/object.c +3 -5
  225. data/modules/mruby/src/parse.y +63 -56
  226. data/modules/mruby/src/proc.c +8 -5
  227. data/modules/mruby/src/re.h +0 -1
  228. data/modules/mruby/src/state.c +65 -27
  229. data/modules/mruby/src/string.c +3 -31
  230. data/modules/mruby/src/symbol.c +3 -3
  231. data/modules/mruby/src/variable.c +12 -5
  232. data/modules/mruby/src/vm.c +90 -72
  233. data/modules/mruby/tasks/mruby_build.rake +10 -1
  234. data/modules/mruby/tasks/toolchains/gcc.rake +12 -2
  235. data/modules/mruby/tasks/toolchains/{vs2012.rake → visualcpp.rake} +1 -1
  236. data/modules/mruby/test/driver.c +3 -3
  237. data/modules/mruby/test/t/array.rb +5 -5
  238. data/modules/mruby/test/t/class.rb +14 -1
  239. data/modules/mruby/test/t/kernel.rb +4 -0
  240. data/modules/mruby/test/t/module.rb +4 -4
  241. data/modules/mruby/test/t/nameerror.rb +1 -1
  242. data/modules/mruby/tools/mrbc/mrbc.c +23 -17
  243. data/modules/mruby/travis_config.rb +10 -1
  244. metadata +28 -5
  245. data/modules/mruby/tasks/toolchains/vs2010.rake +0 -3
@@ -23,6 +23,7 @@ LibraryManager.library = {
23
23
  stdout: 'allocate(1, "i32*", ALLOC_STATIC)',
24
24
  stderr: 'allocate(1, "i32*", ALLOC_STATIC)',
25
25
  _impure_ptr: 'allocate(1, "i32*", ALLOC_STATIC)',
26
+ __dso_handle: 'allocate(1, "i32*", ALLOC_STATIC)',
26
27
 
27
28
  // ==========================================================================
28
29
  // dirent.h
@@ -471,6 +472,11 @@ LibraryManager.library = {
471
472
  mkstemp: function(template) {
472
473
  return _creat(_mktemp(template), 0600);
473
474
  },
475
+ mkdtemp__deps: ['mktemp', 'mkdir'],
476
+ mkdtemp: function(template) {
477
+ template = _mktemp(template);
478
+ return (_mkdir(template, 0700) === 0) ? template : 0;
479
+ },
474
480
  fcntl__deps: ['$FS', '__setErrNo', '$ERRNO_CODES'],
475
481
  fcntl: function(fildes, cmd, varargs, dup2) {
476
482
  // int fcntl(int fildes, int cmd, ...);
@@ -535,7 +541,7 @@ LibraryManager.library = {
535
541
  // Advise as much as you wish. We don't care.
536
542
  return 0;
537
543
  },
538
- posix_madvise: 'posix_fadvise',
544
+ posix_madvise: function(){ return 0 }, // ditto as fadvise
539
545
  posix_fallocate__deps: ['$FS', '__setErrNo', '$ERRNO_CODES'],
540
546
  posix_fallocate: function(fd, offset, len) {
541
547
  // int posix_fallocate(int fd, off_t offset, off_t len);
@@ -847,10 +853,7 @@ LibraryManager.library = {
847
853
  ___setErrNo(ERRNO_CODES.ERANGE);
848
854
  return 0;
849
855
  } else {
850
- for (var i = 0; i < cwd.length; i++) {
851
- {{{ makeSetValue('buf', 'i', 'cwd.charCodeAt(i)', 'i8') }}}
852
- }
853
- {{{ makeSetValue('buf', 'i', '0', 'i8') }}}
856
+ writeAsciiToMemory(cwd, buf);
854
857
  return buf;
855
858
  }
856
859
  },
@@ -1193,7 +1196,6 @@ LibraryManager.library = {
1193
1196
  _exit: function(status) {
1194
1197
  // void _exit(int status);
1195
1198
  // http://pubs.opengroup.org/onlinepubs/000095399/functions/exit.html
1196
- Module.print('exit(' + status + ') called');
1197
1199
  Module['exit'](status);
1198
1200
  },
1199
1201
  fork__deps: ['__setErrNo', '$ERRNO_CODES'],
@@ -1293,10 +1295,7 @@ LibraryManager.library = {
1293
1295
  if (namesize < ret.length + 1) {
1294
1296
  return ___setErrNo(ERRNO_CODES.ERANGE);
1295
1297
  } else {
1296
- for (var i = 0; i < ret.length; i++) {
1297
- {{{ makeSetValue('name', 'i', 'ret.charCodeAt(i)', 'i8') }}}
1298
- }
1299
- {{{ makeSetValue('name', 'i', '0', 'i8') }}}
1298
+ writeAsciiToMemory(ret, name);
1300
1299
  return 0;
1301
1300
  }
1302
1301
  },
@@ -1579,12 +1578,12 @@ LibraryManager.library = {
1579
1578
  // stdio.h
1580
1579
  // ==========================================================================
1581
1580
 
1582
- _isFloat: function(text) {
1583
- return !!(/^[+-]?[0-9]*\.?[0-9]+([eE][+-]?[0-9]+)?$/.exec(text));
1581
+ _getFloat: function(text) {
1582
+ return /^[+-]?[0-9]*\.?[0-9]+([eE][+-]?[0-9]+)?/.exec(text);
1584
1583
  },
1585
1584
 
1586
1585
  // TODO: Document.
1587
- _scanString__deps: ['_isFloat'],
1586
+ _scanString__deps: ['_getFloat'],
1588
1587
  _scanString: function(format, get, unget, varargs) {
1589
1588
  if (!__scanString.whiteSpace) {
1590
1589
  __scanString.whiteSpace = {};
@@ -1602,12 +1601,12 @@ LibraryManager.library = {
1602
1601
  if (format.indexOf('%n') >= 0) {
1603
1602
  // need to track soFar
1604
1603
  var _get = get;
1605
- get = function() {
1604
+ get = function get() {
1606
1605
  soFar++;
1607
1606
  return _get();
1608
1607
  }
1609
1608
  var _unget = unget;
1610
- unget = function() {
1609
+ unget = function unget() {
1611
1610
  soFar--;
1612
1611
  return _unget();
1613
1612
  }
@@ -1743,15 +1742,13 @@ LibraryManager.library = {
1743
1742
  // Read characters according to the format. floats are trickier, they may be in an unfloat state in the middle, then be a valid float later
1744
1743
  if (type == 'f' || type == 'e' || type == 'g' ||
1745
1744
  type == 'F' || type == 'E' || type == 'G') {
1746
- var last = 0;
1747
1745
  next = get();
1748
- while (next > 0) {
1746
+ while (next > 0 && (!(next in __scanString.whiteSpace))) {
1749
1747
  buffer.push(String.fromCharCode(next));
1750
- if (__isFloat(buffer.join(''))) {
1751
- last = buffer.length;
1752
- }
1753
1748
  next = get();
1754
1749
  }
1750
+ var m = __getFloat(buffer.join(''));
1751
+ var last = m ? m[0].length : 0;
1755
1752
  for (var i = 0; i < buffer.length - last + 1; i++) {
1756
1753
  unget();
1757
1754
  }
@@ -1864,17 +1861,20 @@ LibraryManager.library = {
1864
1861
  // int x = 4; printf("%c\n", (char)x);
1865
1862
  var ret;
1866
1863
  if (type === 'double') {
1864
+ #if TARGET_LE32 == 2
1865
+ ret = {{{ makeGetValue('varargs', 'argIndex', 'double', undefined, undefined, true, 4) }}};
1866
+ #else
1867
1867
  ret = {{{ makeGetValue('varargs', 'argIndex', 'double', undefined, undefined, true) }}};
1868
+ #endif
1868
1869
  #if USE_TYPED_ARRAYS == 2
1869
1870
  } else if (type == 'i64') {
1870
-
1871
- #if TARGET_LE32
1871
+ #if TARGET_LE32 == 1
1872
1872
  ret = [{{{ makeGetValue('varargs', 'argIndex', 'i32', undefined, undefined, true) }}},
1873
1873
  {{{ makeGetValue('varargs', 'argIndex+8', 'i32', undefined, undefined, true) }}}];
1874
1874
  argIndex += {{{ STACK_ALIGN }}}; // each 32-bit chunk is in a 64-bit block
1875
1875
  #else
1876
- ret = [{{{ makeGetValue('varargs', 'argIndex', 'i32', undefined, undefined, true) }}},
1877
- {{{ makeGetValue('varargs', 'argIndex+4', 'i32', undefined, undefined, true) }}}];
1876
+ ret = [{{{ makeGetValue('varargs', 'argIndex', 'i32', undefined, undefined, true, 4) }}},
1877
+ {{{ makeGetValue('varargs', 'argIndex+4', 'i32', undefined, undefined, true, 4) }}}];
1878
1878
  #endif
1879
1879
 
1880
1880
  #else
@@ -1885,7 +1885,11 @@ LibraryManager.library = {
1885
1885
  type = 'i32'; // varargs are always i32, i64, or double
1886
1886
  ret = {{{ makeGetValue('varargs', 'argIndex', 'i32', undefined, undefined, true) }}};
1887
1887
  }
1888
+ #if TARGET_LE32 == 2
1889
+ argIndex += Runtime.getNativeFieldSize(type);
1890
+ #else
1888
1891
  argIndex += Math.max(Runtime.getNativeFieldSize(type), Runtime.getAlignSize(type, null, true));
1892
+ #endif
1889
1893
  return ret;
1890
1894
  }
1891
1895
 
@@ -2514,6 +2518,10 @@ LibraryManager.library = {
2514
2518
  }
2515
2519
  var bytesRead = 0;
2516
2520
  var streamObj = FS.getStream(stream);
2521
+ if (!streamObj) {
2522
+ ___setErrNo(ERRNO_CODES.EBADF);
2523
+ return 0;
2524
+ }
2517
2525
  while (streamObj.ungotten.length && bytesToRead > 0) {
2518
2526
  {{{ makeSetValue('ptr++', '0', 'streamObj.ungotten.pop()', 'i8') }}}
2519
2527
  bytesToRead--;
@@ -2701,10 +2709,7 @@ LibraryManager.library = {
2701
2709
  var result = dir + '/' + name;
2702
2710
  if (!_tmpnam.buffer) _tmpnam.buffer = _malloc(256);
2703
2711
  if (!s) s = _tmpnam.buffer;
2704
- for (var i = 0; i < result.length; i++) {
2705
- {{{ makeSetValue('s', 'i', 'result.charCodeAt(i)', 'i8') }}};
2706
- }
2707
- {{{ makeSetValue('s', 'i', '0', 'i8') }}};
2712
+ writeAsciiToMemory(result, s);
2708
2713
  return s;
2709
2714
  },
2710
2715
  tempnam__deps: ['tmpnam'],
@@ -2757,12 +2762,12 @@ LibraryManager.library = {
2757
2762
  return -1;
2758
2763
  }
2759
2764
  var buffer = [];
2760
- var get = function() {
2765
+ function get() {
2761
2766
  var c = _fgetc(stream);
2762
2767
  buffer.push(c);
2763
2768
  return c;
2764
2769
  };
2765
- var unget = function() {
2770
+ function unget() {
2766
2771
  _ungetc(buffer.pop(), stream);
2767
2772
  };
2768
2773
  return __scanString(format, get, unget, varargs);
@@ -2779,8 +2784,8 @@ LibraryManager.library = {
2779
2784
  // int sscanf(const char *restrict s, const char *restrict format, ... );
2780
2785
  // http://pubs.opengroup.org/onlinepubs/000095399/functions/scanf.html
2781
2786
  var index = 0;
2782
- var get = function() { return {{{ makeGetValue('s', 'index++', 'i8') }}}; };
2783
- var unget = function() { index--; };
2787
+ function get() { return {{{ makeGetValue('s', 'index++', 'i8') }}}; };
2788
+ function unget() { index--; };
2784
2789
  return __scanString(format, get, unget, varargs);
2785
2790
  },
2786
2791
  snprintf__deps: ['_formatString'],
@@ -3042,7 +3047,7 @@ LibraryManager.library = {
3042
3047
  },
3043
3048
 
3044
3049
  bsearch: function(key, base, num, size, compar) {
3045
- var cmp = function(x, y) {
3050
+ function cmp(x, y) {
3046
3051
  #if ASM_JS
3047
3052
  return Module['dynCall_iii'](compar, x, y);
3048
3053
  #else
@@ -3205,7 +3210,7 @@ LibraryManager.library = {
3205
3210
  }
3206
3211
  }
3207
3212
  if (!finalBase) finalBase = 10;
3208
- start = str;
3213
+ var start = str;
3209
3214
 
3210
3215
  // Get digits.
3211
3216
  var chr;
@@ -3345,10 +3350,7 @@ LibraryManager.library = {
3345
3350
  var ptrSize = {{{ Runtime.getNativeTypeSize('i8*') }}};
3346
3351
  for (var i = 0; i < strings.length; i++) {
3347
3352
  var line = strings[i];
3348
- for (var j = 0; j < line.length; j++) {
3349
- {{{ makeSetValue('poolPtr', 'j', 'line.charCodeAt(j)', 'i8') }}};
3350
- }
3351
- {{{ makeSetValue('poolPtr', 'j', '0', 'i8') }}};
3353
+ writeAsciiToMemory(line, poolPtr);
3352
3354
  {{{ makeSetValue('envPtr', 'i * ptrSize', 'poolPtr', 'i8*') }}};
3353
3355
  poolPtr += line.length + 1;
3354
3356
  }
@@ -3537,13 +3539,15 @@ LibraryManager.library = {
3537
3539
  llvm_memcpy_p0i8_p0i8_i32: 'memcpy',
3538
3540
  llvm_memcpy_p0i8_p0i8_i64: 'memcpy',
3539
3541
 
3540
- memmove__sig: 'viii',
3542
+ memmove__sig: 'iiii',
3541
3543
  memmove__asm: true,
3542
3544
  memmove__deps: ['memcpy'],
3543
3545
  memmove: function(dest, src, num) {
3544
3546
  dest = dest|0; src = src|0; num = num|0;
3547
+ var ret = 0;
3545
3548
  if (((src|0) < (dest|0)) & ((dest|0) < ((src + num)|0))) {
3546
3549
  // Unlikely case: Copy backwards in a safe manner
3550
+ ret = dest;
3547
3551
  src = (src + num)|0;
3548
3552
  dest = (dest + num)|0;
3549
3553
  while ((num|0) > 0) {
@@ -3552,9 +3556,11 @@ LibraryManager.library = {
3552
3556
  num = (num - 1)|0;
3553
3557
  {{{ makeSetValueAsm('dest', 0, makeGetValueAsm('src', 0, 'i8'), 'i8') }}};
3554
3558
  }
3559
+ dest = ret;
3555
3560
  } else {
3556
3561
  _memcpy(dest, src, num) | 0;
3557
3562
  }
3563
+ return dest | 0;
3558
3564
  },
3559
3565
  llvm_memmove_i32: 'memmove',
3560
3566
  llvm_memmove_i64: 'memmove',
@@ -3571,7 +3577,7 @@ LibraryManager.library = {
3571
3577
  memset__inline: function(ptr, value, num, align) {
3572
3578
  return makeSetValues(ptr, 0, value, 'null', num, align);
3573
3579
  },
3574
- memset__sig: 'viii',
3580
+ memset__sig: 'iiii',
3575
3581
  memset__asm: true,
3576
3582
  memset: function(ptr, value, num) {
3577
3583
  #if USE_TYPED_ARRAYS == 2
@@ -3600,8 +3606,10 @@ LibraryManager.library = {
3600
3606
  {{{ makeSetValueAsm('ptr', 0, 'value', 'i8') }}};
3601
3607
  ptr = (ptr+1)|0;
3602
3608
  }
3609
+ return (ptr-num)|0;
3603
3610
  #else
3604
3611
  {{{ makeSetValues('ptr', '0', 'value', 'null', 'num') }}};
3612
+ return ptr;
3605
3613
  #endif
3606
3614
  },
3607
3615
  llvm_memset_i32: 'memset',
@@ -3978,10 +3986,7 @@ LibraryManager.library = {
3978
3986
  return ___setErrNo(ERRNO_CODES.ERANGE);
3979
3987
  } else {
3980
3988
  var msg = ERRNO_MESSAGES[errnum];
3981
- for (var i = 0; i < msg.length; i++) {
3982
- {{{ makeSetValue('strerrbuf', 'i', 'msg.charCodeAt(i)', 'i8') }}}
3983
- }
3984
- {{{ makeSetValue('strerrbuf', 'i', 0, 'i8') }}}
3989
+ writeAsciiToMemory(msg, strerrbuf);
3985
3990
  return 0;
3986
3991
  }
3987
3992
  } else {
@@ -4165,6 +4170,11 @@ LibraryManager.library = {
4165
4170
  return me.ret;
4166
4171
  },
4167
4172
 
4173
+ // ==========================================================================
4174
+ // GCC/LLVM specifics
4175
+ // ==========================================================================
4176
+ __builtin_prefetch: function(){},
4177
+
4168
4178
  // ==========================================================================
4169
4179
  // LLVM specifics
4170
4180
  // ==========================================================================
@@ -4670,6 +4680,10 @@ LibraryManager.library = {
4670
4680
 
4671
4681
  llvm_dbg_declare__inline: function() { throw 'llvm_debug_declare' }, // avoid warning
4672
4682
 
4683
+ // llvm-nacl
4684
+
4685
+ llvm_nacl_atomic_store_i32__inline: true,
4686
+
4673
4687
  // ==========================================================================
4674
4688
  // llvm-mono integration
4675
4689
  // ==========================================================================
@@ -5064,10 +5078,7 @@ LibraryManager.library = {
5064
5078
  var layout = {{{ JSON.stringify(C_STRUCTS.utsname) }}};
5065
5079
  function copyString(element, value) {
5066
5080
  var offset = layout[element];
5067
- for (var i = 0; i < value.length; i++) {
5068
- {{{ makeSetValue('name', 'offset + i', 'value.charCodeAt(i)', 'i8') }}}
5069
- }
5070
- {{{ makeSetValue('name', 'offset + i', '0', 'i8') }}}
5081
+ writeAsciiToMemory(value, name + offset);
5071
5082
  }
5072
5083
  if (name === 0) {
5073
5084
  return -1;
@@ -5110,7 +5121,7 @@ LibraryManager.library = {
5110
5121
  table[from + i] = {};
5111
5122
  sigs.forEach(function(sig) { // TODO: new Function etc.
5112
5123
  var full = 'dynCall_' + sig;
5113
- table[from + i][sig] = function() {
5124
+ table[from + i][sig] = function dynCall_sig() {
5114
5125
  arguments[0] -= from;
5115
5126
  return asm[full].apply(null, arguments);
5116
5127
  }
@@ -5134,7 +5145,7 @@ LibraryManager.library = {
5134
5145
 
5135
5146
  // patch js module dynCall_* to use functionTable
5136
5147
  sigs.forEach(function(sig) {
5137
- jsModule['dynCall_' + sig] = function() {
5148
+ jsModule['dynCall_' + sig] = function dynCall_sig() {
5138
5149
  return table[arguments[0]][sig].apply(null, arguments);
5139
5150
  };
5140
5151
  });
@@ -5297,6 +5308,16 @@ LibraryManager.library = {
5297
5308
  }
5298
5309
  },
5299
5310
 
5311
+ dladdr: function(addr, info) {
5312
+ // report all function pointers as coming from this program itself XXX not really correct in any way
5313
+ var fname = allocate(intArrayFromString("/bin/this.program"), 'i8', ALLOC_NORMAL); // XXX leak
5314
+ {{{ makeSetValue('addr', 0, 'fname', 'i32') }}};
5315
+ {{{ makeSetValue('addr', QUANTUM_SIZE, '0', 'i32') }}};
5316
+ {{{ makeSetValue('addr', QUANTUM_SIZE*2, '0', 'i32') }}};
5317
+ {{{ makeSetValue('addr', QUANTUM_SIZE*3, '0', 'i32') }}};
5318
+ return 1;
5319
+ },
5320
+
5300
5321
  // ==========================================================================
5301
5322
  // pwd.h
5302
5323
  // ==========================================================================
@@ -5598,7 +5619,7 @@ LibraryManager.library = {
5598
5619
  var WEEKDAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
5599
5620
  var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
5600
5621
 
5601
- var leadingSomething = function(value, digits, character) {
5622
+ function leadingSomething(value, digits, character) {
5602
5623
  var str = typeof value === 'number' ? value.toString() : (value || '');
5603
5624
  while (str.length < digits) {
5604
5625
  str = character[0]+str;
@@ -5606,12 +5627,12 @@ LibraryManager.library = {
5606
5627
  return str;
5607
5628
  };
5608
5629
 
5609
- var leadingNulls = function(value, digits) {
5630
+ function leadingNulls(value, digits) {
5610
5631
  return leadingSomething(value, digits, '0');
5611
5632
  };
5612
5633
 
5613
- var compareByDay = function(date1, date2) {
5614
- var sgn = function(value) {
5634
+ function compareByDay(date1, date2) {
5635
+ function sgn(value) {
5615
5636
  return value < 0 ? -1 : (value > 0 ? 1 : 0);
5616
5637
  };
5617
5638
 
@@ -5624,7 +5645,7 @@ LibraryManager.library = {
5624
5645
  return compare;
5625
5646
  };
5626
5647
 
5627
- var getFirstWeekStartDate = function(janFourth) {
5648
+ function getFirstWeekStartDate(janFourth) {
5628
5649
  switch (janFourth.getDay()) {
5629
5650
  case 0: // Sunday
5630
5651
  return new Date(janFourth.getFullYear()-1, 11, 29);
@@ -5643,7 +5664,7 @@ LibraryManager.library = {
5643
5664
  }
5644
5665
  };
5645
5666
 
5646
- var getWeekBasedYear = function(date) {
5667
+ function getWeekBasedYear(date) {
5647
5668
  var thisDate = __addDays(new Date(date.tm_year+1900, 0, 1), date.tm_yday);
5648
5669
 
5649
5670
  var janFourthThisYear = new Date(thisDate.getFullYear(), 0, 4);
@@ -5930,8 +5951,8 @@ LibraryManager.library = {
5930
5951
  var matches = new RegExp('^'+pattern).exec(Pointer_stringify(buf))
5931
5952
  // Module['print'](Pointer_stringify(buf)+ ' is matched by '+((new RegExp('^'+pattern)).source)+' into: '+JSON.stringify(matches));
5932
5953
 
5933
- var initDate = function() {
5934
- var fixup = function(value, min, max) {
5954
+ function initDate() {
5955
+ function fixup(value, min, max) {
5935
5956
  return (typeof value !== 'number' || isNaN(value)) ? min : (value>=min ? (value<=max ? value: max): min);
5936
5957
  };
5937
5958
  return {
@@ -5948,7 +5969,7 @@ LibraryManager.library = {
5948
5969
  var date = initDate();
5949
5970
  var value;
5950
5971
 
5951
- var getMatch = function(symbol) {
5972
+ function getMatch(symbol) {
5952
5973
  var pos = capture.indexOf(symbol);
5953
5974
  // check if symbol appears in regexp
5954
5975
  if (pos >= 0) {
@@ -6118,16 +6139,23 @@ LibraryManager.library = {
6118
6139
  // int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
6119
6140
  var seconds = {{{ makeGetValue('rqtp', C_STRUCTS.timespec.tv_sec, 'i32') }}};
6120
6141
  var nanoseconds = {{{ makeGetValue('rqtp', C_STRUCTS.timespec.tv_nsec, 'i32') }}};
6121
- {{{ makeSetValue('rmtp', C_STRUCTS.timespec.tv_sec, '0', 'i32') }}}
6122
- {{{ makeSetValue('rmtp', C_STRUCTS.timespec.tv_nsec, '0', 'i32') }}}
6142
+ if (rmtp !== 0) {
6143
+ {{{ makeSetValue('rmtp', C_STRUCTS.timespec.tv_sec, '0', 'i32') }}}
6144
+ {{{ makeSetValue('rmtp', C_STRUCTS.timespec.tv_nsec, '0', 'i32') }}}
6145
+ }
6123
6146
  return _usleep((seconds * 1e6) + (nanoseconds / 1000));
6124
6147
  },
6125
- // TODO: Implement these for real.
6148
+ clock_gettime__deps: ['emscripten_get_now'],
6126
6149
  clock_gettime: function(clk_id, tp) {
6127
6150
  // int clock_gettime(clockid_t clk_id, struct timespec *tp);
6128
- var now = Date.now();
6151
+ var now;
6152
+ if (clk_id === {{{ cDefine('CLOCK_REALTIME') }}}) {
6153
+ now = Date.now();
6154
+ } else {
6155
+ now = _emscripten_get_now();
6156
+ }
6129
6157
  {{{ makeSetValue('tp', C_STRUCTS.timespec.tv_sec, 'Math.floor(now/1000)', 'i32') }}}; // seconds
6130
- {{{ makeSetValue('tp', C_STRUCTS.timespec.tv_nsec, '(now % 1000) * 1000 * 1000', 'i32') }}}; // nanoseconds (really milliseconds)
6158
+ {{{ makeSetValue('tp', C_STRUCTS.timespec.tv_nsec, 'Math.floor((now % 1000)*1000*1000)', 'i32') }}}; // nanoseconds
6131
6159
  return 0;
6132
6160
  },
6133
6161
  clock_settime: function(clk_id, tp) {
@@ -6135,10 +6163,17 @@ LibraryManager.library = {
6135
6163
  // Nothing.
6136
6164
  return 0;
6137
6165
  },
6166
+ clock_getres__deps: ['emscripten_get_now_res'],
6138
6167
  clock_getres: function(clk_id, res) {
6139
6168
  // int clock_getres(clockid_t clk_id, struct timespec *res);
6169
+ var nsec;
6170
+ if (clk_id === {{{ cDefine('CLOCK_REALTIME') }}}) {
6171
+ nsec = 1000 * 1000;
6172
+ } else {
6173
+ nsec = _emscripten_get_now_res();
6174
+ }
6140
6175
  {{{ makeSetValue('res', C_STRUCTS.timespec.tv_sec, '1', 'i32') }}}
6141
- {{{ makeSetValue('res', C_STRUCTS.timespec.tv_nsec, '1000 * 1000', 'i32') }}} // resolution is milliseconds
6176
+ {{{ makeSetValue('res', C_STRUCTS.timespec.tv_nsec, 'nsec', 'i32') }}} // resolution is milliseconds
6142
6177
  return 0;
6143
6178
  },
6144
6179
 
@@ -6559,10 +6594,7 @@ LibraryManager.library = {
6559
6594
 
6560
6595
  var me = _nl_langinfo;
6561
6596
  if (!me.ret) me.ret = _malloc(32);
6562
- for (var i = 0; i < result.length; i++) {
6563
- {{{ makeSetValue('me.ret', 'i', 'result.charCodeAt(i)', 'i8') }}}
6564
- }
6565
- {{{ makeSetValue('me.ret', 'i', '0', 'i8') }}}
6597
+ writeAsciiToMemory(result, me.ret);
6566
6598
  return me.ret;
6567
6599
  },
6568
6600
 
@@ -6878,6 +6910,10 @@ LibraryManager.library = {
6878
6910
  pthread_mutex_trylock: function() {
6879
6911
  return 0;
6880
6912
  },
6913
+ pthread_mutexattr_setpshared: function(attr, pshared) {
6914
+ // XXX implement if/when getpshared is required
6915
+ return 0;
6916
+ },
6881
6917
  pthread_cond_init: function() {},
6882
6918
  pthread_cond_destroy: function() {},
6883
6919
  pthread_cond_broadcast: function() {
@@ -6946,7 +6982,7 @@ LibraryManager.library = {
6946
6982
 
6947
6983
  pthread_setspecific__deps: ['$PTHREAD_SPECIFIC', '$ERRNO_CODES'],
6948
6984
  pthread_setspecific: function(key, value) {
6949
- if (value == 0) {
6985
+ if (!(key in PTHREAD_SPECIFIC)) {
6950
6986
  return ERRNO_CODES.EINVAL;
6951
6987
  }
6952
6988
  PTHREAD_SPECIFIC[key] = value;
@@ -6973,6 +7009,10 @@ LibraryManager.library = {
6973
7009
  _pthread_cleanup_push.level = __ATEXIT__.length;
6974
7010
  },
6975
7011
 
7012
+ pthread_rwlock_init: function() {
7013
+ return 0; // XXX
7014
+ },
7015
+
6976
7016
  // ==========================================================================
6977
7017
  // malloc.h
6978
7018
  // ==========================================================================
@@ -7314,6 +7354,7 @@ LibraryManager.library = {
7314
7354
  // we're generating fake IP addresses with lookup_name that we can
7315
7355
  // resolve later on with lookup_addr.
7316
7356
  // We do the aliasing in 172.29.*.*, giving us 65536 possibilities.
7357
+ $DNS__deps: ['_inet_pton4_raw', '_inet_pton6_raw'],
7317
7358
  $DNS: {
7318
7359
  address_map: {
7319
7360
  id: 1,
@@ -7321,7 +7362,6 @@ LibraryManager.library = {
7321
7362
  names: {}
7322
7363
  },
7323
7364
 
7324
- lookup_name__deps: ['_inet_pton4_raw', '_inet_pton6_raw'],
7325
7365
  lookup_name: function (name) {
7326
7366
  // If the name is already a valid ipv4 / ipv6 address, don't generate a fake one.
7327
7367
  var res = __inet_pton4_raw(name);
@@ -7412,6 +7452,9 @@ LibraryManager.library = {
7412
7452
 
7413
7453
  getaddrinfo__deps: ['$Sockets', '$DNS', '_inet_pton4_raw', '_inet_ntop4_raw', '_inet_pton6_raw', '_inet_ntop6_raw', '_write_sockaddr', 'htonl'],
7414
7454
  getaddrinfo: function(node, service, hint, out) {
7455
+ // Note getaddrinfo currently only returns a single addrinfo with ai_next defaulting to NULL. When NULL
7456
+ // hints are specified or ai_family set to AF_UNSPEC or ai_socktype or ai_protocol set to 0 then we
7457
+ // really should provide a linked list of suitable addrinfo values.
7415
7458
  var addrs = [];
7416
7459
  var canon = null;
7417
7460
  var addr = 0;
@@ -7466,6 +7509,15 @@ LibraryManager.library = {
7466
7509
  type = proto === {{{ cDefine('IPPROTO_UDP') }}} ? {{{ cDefine('SOCK_DGRAM') }}} : {{{ cDefine('SOCK_STREAM') }}};
7467
7510
  }
7468
7511
 
7512
+ // If type or proto are set to zero in hints we should really be returning multiple addrinfo values, but for
7513
+ // now default to a TCP STREAM socket so we can at least return a sensible addrinfo given NULL hints.
7514
+ if (proto === 0) {
7515
+ proto = {{{ cDefine('IPPROTO_TCP') }}};
7516
+ }
7517
+ if (type === 0) {
7518
+ type = {{{ cDefine('SOCK_STREAM') }}};
7519
+ }
7520
+
7469
7521
  if (!node && !service) {
7470
7522
  return {{{ cDefine('EAI_NONAME') }}};
7471
7523
  }
@@ -7473,14 +7525,14 @@ LibraryManager.library = {
7473
7525
  {{{ cDefine('AI_NUMERICSERV') }}}|{{{ cDefine('AI_V4MAPPED') }}}|{{{ cDefine('AI_ALL') }}}|{{{ cDefine('AI_ADDRCONFIG') }}})) {
7474
7526
  return {{{ cDefine('EAI_BADFLAGS') }}};
7475
7527
  }
7476
- if (({{{ makeGetValue('hint', C_STRUCTS.addrinfo.ai_flags, 'i32') }}} & {{{ cDefine('AI_CANONNAME') }}}) && !node) {
7528
+ if (hint !== 0 && ({{{ makeGetValue('hint', C_STRUCTS.addrinfo.ai_flags, 'i32') }}} & {{{ cDefine('AI_CANONNAME') }}}) && !node) {
7477
7529
  return {{{ cDefine('EAI_BADFLAGS') }}};
7478
7530
  }
7479
7531
  if (flags & {{{ cDefine('AI_ADDRCONFIG') }}}) {
7480
7532
  // TODO
7481
7533
  return {{{ cDefine('EAI_NONAME') }}};
7482
7534
  }
7483
- if (type !== {{{ cDefine('SOCK_STREAM') }}} && type !== {{{ cDefine('SOCK_DGRAM') }}}) {
7535
+ if (type !== 0 && type !== {{{ cDefine('SOCK_STREAM') }}} && type !== {{{ cDefine('SOCK_DGRAM') }}}) {
7484
7536
  return {{{ cDefine('EAI_SOCKTYPE') }}};
7485
7537
  }
7486
7538
  if (family !== {{{ cDefine('AF_UNSPEC') }}} && family !== {{{ cDefine('AF_INET') }}} && family !== {{{ cDefine('AF_INET6') }}}) {
@@ -7610,12 +7662,131 @@ LibraryManager.library = {
7610
7662
 
7611
7663
  return 0;
7612
7664
  },
7665
+ // Can't use a literal for $GAI_ERRNO_MESSAGES as was done for $ERRNO_MESSAGES as the keys (e.g. EAI_BADFLAGS)
7666
+ // are actually negative numbers and you can't have expressions as keys in JavaScript literals.
7667
+ $GAI_ERRNO_MESSAGES: {},
7613
7668
 
7669
+ gai_strerror__deps: ['$GAI_ERRNO_MESSAGES'],
7614
7670
  gai_strerror: function(val) {
7615
- if (!_gai_strerror.error) {
7616
- _gai_strerror.error = allocate(intArrayFromString("unknown error"), 'i8', ALLOC_NORMAL);
7671
+ var buflen = 256;
7672
+
7673
+ // On first call to gai_strerror we initialise the buffer and populate the error messages.
7674
+ if (!_gai_strerror.buffer) {
7675
+ _gai_strerror.buffer = _malloc(buflen);
7676
+
7677
+ GAI_ERRNO_MESSAGES['0'] = 'Success';
7678
+ GAI_ERRNO_MESSAGES['' + {{{ cDefine('EAI_BADFLAGS') }}}] = 'Invalid value for \'ai_flags\' field';
7679
+ GAI_ERRNO_MESSAGES['' + {{{ cDefine('EAI_NONAME') }}}] = 'NAME or SERVICE is unknown';
7680
+ GAI_ERRNO_MESSAGES['' + {{{ cDefine('EAI_AGAIN') }}}] = 'Temporary failure in name resolution';
7681
+ GAI_ERRNO_MESSAGES['' + {{{ cDefine('EAI_FAIL') }}}] = 'Non-recoverable failure in name res';
7682
+ GAI_ERRNO_MESSAGES['' + {{{ cDefine('EAI_FAMILY') }}}] = '\'ai_family\' not supported';
7683
+ GAI_ERRNO_MESSAGES['' + {{{ cDefine('EAI_SOCKTYPE') }}}] = '\'ai_socktype\' not supported';
7684
+ GAI_ERRNO_MESSAGES['' + {{{ cDefine('EAI_SERVICE') }}}] = 'SERVICE not supported for \'ai_socktype\'';
7685
+ GAI_ERRNO_MESSAGES['' + {{{ cDefine('EAI_MEMORY') }}}] = 'Memory allocation failure';
7686
+ GAI_ERRNO_MESSAGES['' + {{{ cDefine('EAI_SYSTEM') }}}] = 'System error returned in \'errno\'';
7687
+ GAI_ERRNO_MESSAGES['' + {{{ cDefine('EAI_OVERFLOW') }}}] = 'Argument buffer overflow';
7688
+ }
7689
+
7690
+ var msg = 'Unknown error';
7691
+
7692
+ if (val in GAI_ERRNO_MESSAGES) {
7693
+ if (GAI_ERRNO_MESSAGES[val].length > buflen - 1) {
7694
+ msg = 'Message too long'; // EMSGSIZE message. This should never occur given the GAI_ERRNO_MESSAGES above.
7695
+ } else {
7696
+ msg = GAI_ERRNO_MESSAGES[val];
7697
+ }
7698
+ }
7699
+
7700
+ writeAsciiToMemory(msg, _gai_strerror.buffer);
7701
+ return _gai_strerror.buffer;
7702
+ },
7703
+
7704
+ // Implement netdb.h protocol entry (getprotoent, getprotobyname, getprotobynumber, setprotoent, endprotoent)
7705
+ // http://pubs.opengroup.org/onlinepubs/9699919799/functions/getprotobyname.html
7706
+ // The Protocols object holds our 'fake' protocols 'database'.
7707
+ $Protocols: {
7708
+ list: [],
7709
+ map: {}
7710
+ },
7711
+ setprotoent__deps: ['$Protocols'],
7712
+ setprotoent: function(stayopen) {
7713
+ // void setprotoent(int stayopen);
7714
+
7715
+ // Allocate and populate a protoent structure given a name, protocol number and array of aliases
7716
+ function allocprotoent(name, proto, aliases) {
7717
+ // write name into buffer
7718
+ var nameBuf = _malloc(name.length + 1);
7719
+ writeAsciiToMemory(name, nameBuf);
7720
+
7721
+ // write aliases into buffer
7722
+ var j = 0;
7723
+ var length = aliases.length;
7724
+ var aliasListBuf = _malloc((length + 1) * 4); // Use length + 1 so we have space for the terminating NULL ptr.
7725
+
7726
+ for (var i = 0; i < length; i++, j += 4) {
7727
+ var alias = aliases[i];
7728
+ var aliasBuf = _malloc(alias.length + 1);
7729
+ writeAsciiToMemory(alias, aliasBuf);
7730
+ {{{ makeSetValue('aliasListBuf', 'j', 'aliasBuf', 'i8*') }}};
7731
+ }
7732
+ {{{ makeSetValue('aliasListBuf', 'j', '0', 'i8*') }}}; // Terminating NULL pointer.
7733
+
7734
+ // generate protoent
7735
+ var pe = _malloc({{{ C_STRUCTS.protoent.__size__ }}});
7736
+ {{{ makeSetValue('pe', C_STRUCTS.protoent.p_name, 'nameBuf', 'i8*') }}};
7737
+ {{{ makeSetValue('pe', C_STRUCTS.protoent.p_aliases, 'aliasListBuf', 'i8**') }}};
7738
+ {{{ makeSetValue('pe', C_STRUCTS.protoent.p_proto, 'proto', 'i32') }}};
7739
+ return pe;
7740
+ };
7741
+
7742
+ // Populate the protocol 'database'. The entries are limited to tcp and udp, though it is fairly trivial
7743
+ // to add extra entries from /etc/protocols if desired - though not sure if that'd actually be useful.
7744
+ var list = Protocols.list;
7745
+ var map = Protocols.map;
7746
+ if (list.length === 0) {
7747
+ var entry = allocprotoent('tcp', 6, ['TCP']);
7748
+ list.push(entry);
7749
+ map['tcp'] = map['6'] = entry;
7750
+ entry = allocprotoent('udp', 17, ['UDP']);
7751
+ list.push(entry);
7752
+ map['udp'] = map['17'] = entry;
7753
+ }
7754
+
7755
+ _setprotoent.index = 0;
7756
+ },
7757
+
7758
+ endprotoent: function() {
7759
+ // void endprotoent(void);
7760
+ // We're not using a real protocol database so we don't do a real close.
7761
+ },
7762
+
7763
+ getprotoent__deps: ['setprotoent', '$Protocols'],
7764
+ getprotoent: function(number) {
7765
+ // struct protoent *getprotoent(void);
7766
+ // reads the next entry from the protocols 'database' or return NULL if 'eof'
7767
+ if (_setprotoent.index === Protocols.list.length) {
7768
+ return 0;
7769
+ } else {
7770
+ var result = Protocols.list[_setprotoent.index++];
7771
+ return result;
7617
7772
  }
7618
- return _gai_strerror.error;
7773
+ },
7774
+
7775
+ getprotobyname__deps: ['setprotoent', '$Protocols'],
7776
+ getprotobyname: function(name) {
7777
+ // struct protoent *getprotobyname(const char *);
7778
+ name = Pointer_stringify(name);
7779
+ _setprotoent(true);
7780
+ var result = Protocols.map[name];
7781
+ return result;
7782
+ },
7783
+
7784
+ getprotobynumber__deps: ['setprotoent', '$Protocols'],
7785
+ getprotobynumber: function(number) {
7786
+ // struct protoent *getprotobynumber(int proto);
7787
+ _setprotoent(true);
7788
+ var result = Protocols.map[number];
7789
+ return result;
7619
7790
  },
7620
7791
 
7621
7792
  // ==========================================================================
@@ -7683,7 +7854,7 @@ LibraryManager.library = {
7683
7854
  var session = Module['webrtc']['session'];
7684
7855
  var peer = new Peer(broker);
7685
7856
  var listenOptions = Module['webrtc']['hostOptions'] || {};
7686
- peer.onconnection = function(connection) {
7857
+ peer.onconnection = function peer_onconnection(connection) {
7687
7858
  console.log('connected');
7688
7859
  var addr;
7689
7860
  /* If this peer is connecting to the host, assign 10.0.0.1 to the host so it can be
@@ -7697,7 +7868,7 @@ LibraryManager.library = {
7697
7868
  }
7698
7869
  connection['addr'] = addr;
7699
7870
  Sockets.connections[addr] = connection;
7700
- connection.ondisconnect = function() {
7871
+ connection.ondisconnect = function connection_ondisconnect() {
7701
7872
  console.log('disconnect');
7702
7873
  // Don't return the host address (10.0.0.1) to the pool
7703
7874
  if (!(session && session === Sockets.connections[addr]['route'])) {
@@ -7709,12 +7880,12 @@ LibraryManager.library = {
7709
7880
  Module['webrtc']['ondisconnect'](peer);
7710
7881
  }
7711
7882
  };
7712
- connection.onerror = function(error) {
7883
+ connection.onerror = function connection_onerror(error) {
7713
7884
  if (Module['webrtc']['onerror'] && 'function' === typeof Module['webrtc']['onerror']) {
7714
7885
  Module['webrtc']['onerror'](error);
7715
7886
  }
7716
7887
  };
7717
- connection.onmessage = function(label, message) {
7888
+ connection.onmessage = function connection_onmessage(label, message) {
7718
7889
  if ('unreliable' === label) {
7719
7890
  handleMessage(addr, message.data);
7720
7891
  }
@@ -7724,13 +7895,13 @@ LibraryManager.library = {
7724
7895
  Module['webrtc']['onconnect'](peer);
7725
7896
  }
7726
7897
  };
7727
- peer.onpending = function(pending) {
7898
+ peer.onpending = function peer_onpending(pending) {
7728
7899
  console.log('pending from: ', pending['route'], '; initiated by: ', (pending['incoming']) ? 'remote' : 'local');
7729
7900
  };
7730
- peer.onerror = function(error) {
7901
+ peer.onerror = function peer_onerror(error) {
7731
7902
  console.error(error);
7732
7903
  };
7733
- peer.onroute = function(route) {
7904
+ peer.onroute = function peer_onroute(route) {
7734
7905
  if (Module['webrtc']['onpeer'] && 'function' === typeof Module['webrtc']['onpeer']) {
7735
7906
  Module['webrtc']['onpeer'](peer, route);
7736
7907
  }
@@ -7746,7 +7917,7 @@ LibraryManager.library = {
7746
7917
  console.log("unable to deliver message: ", addr, header[1], message);
7747
7918
  }
7748
7919
  }
7749
- window.onbeforeunload = function() {
7920
+ window.onbeforeunload = function window_onbeforeunload() {
7750
7921
  var ids = Object.keys(Sockets.connections);
7751
7922
  ids.forEach(function(id) {
7752
7923
  Sockets.connections[id].close();
@@ -7815,7 +7986,7 @@ LibraryManager.library = {
7815
7986
  }
7816
7987
  info.addr = Sockets.localAddr; // 10.0.0.254
7817
7988
  info.host = __inet_ntop4_raw(info.addr);
7818
- info.close = function() {
7989
+ info.close = function info_close() {
7819
7990
  Sockets.portmap[info.port] = undefined;
7820
7991
  }
7821
7992
  Sockets.portmap[info.port] = info;
@@ -8181,7 +8352,7 @@ LibraryManager.library = {
8181
8352
  },
8182
8353
 
8183
8354
  accept__deps: ['$FS', '$SOCKFS', '$DNS', '$ERRNO_CODES', '__setErrNo', '_write_sockaddr'],
8184
- accept: function(fd, addrp, addrlen) {
8355
+ accept: function(fd, addr, addrlen) {
8185
8356
  var sock = SOCKFS.getSocket(fd);
8186
8357
  if (!sock) {
8187
8358
  ___setErrNo(ERRNO_CODES.EBADF);
@@ -8189,7 +8360,7 @@ LibraryManager.library = {
8189
8360
  }
8190
8361
  try {
8191
8362
  var newsock = sock.sock_ops.accept(sock);
8192
- if (addrp) {
8363
+ if (addr) {
8193
8364
  var res = __write_sockaddr(addr, newsock.family, DNS.lookup_name(newsock.daddr), newsock.dport);
8194
8365
  assert(!res.errno);
8195
8366
  }
@@ -8547,7 +8718,13 @@ LibraryManager.library = {
8547
8718
  return -1;
8548
8719
  }
8549
8720
  var arg = {{{ makeGetValue('varargs', '0', 'i32') }}};
8550
- return FS.ioctl(stream, request, arg);
8721
+
8722
+ try {
8723
+ return FS.ioctl(stream, request, arg);
8724
+ } catch (e) {
8725
+ FS.handleFSError(e);
8726
+ return -1;
8727
+ }
8551
8728
  },
8552
8729
  #endif
8553
8730
 
@@ -8580,7 +8757,7 @@ LibraryManager.library = {
8580
8757
  },
8581
8758
 
8582
8759
  emscripten_run_script_string: function(ptr) {
8583
- var s = eval(Pointer_stringify(ptr));
8760
+ var s = eval(Pointer_stringify(ptr)) + '';
8584
8761
  var me = _emscripten_run_script_string;
8585
8762
  if (!me.bufferSize || me.bufferSize < s.length+1) {
8586
8763
  if (me.bufferSize) _free(me.buffer);
@@ -8614,12 +8791,120 @@ LibraryManager.library = {
8614
8791
  },
8615
8792
 
8616
8793
  emscripten_asm_const: function(code) {
8617
- // code is a constant string on the heap, so we can cache these
8618
- if (!Runtime.asmConstCache) Runtime.asmConstCache = {};
8619
- var func = Runtime.asmConstCache[code];
8620
- if (func) return func();
8621
- func = Runtime.asmConstCache[code] = eval('(function(){ ' + Pointer_stringify(code) + ' })'); // new Function does not allow upvars in node
8622
- return func();
8794
+ Runtime.getAsmConst(code, 0)();
8795
+ },
8796
+
8797
+ emscripten_asm_const_int__jsargs: true,
8798
+ emscripten_asm_const_int: function(code) {
8799
+ var args = Array.prototype.slice.call(arguments, 1);
8800
+ return Runtime.getAsmConst(code, args.length).apply(null, args) | 0;
8801
+ },
8802
+
8803
+ emscripten_asm_const_double__jsargs: true,
8804
+ emscripten_asm_const_double: function(code) {
8805
+ var args = Array.prototype.slice.call(arguments, 1);
8806
+ return +Runtime.getAsmConst(code, args.length).apply(null, args);
8807
+ },
8808
+
8809
+ emscripten_get_now: function() {
8810
+ if (!_emscripten_get_now.actual) {
8811
+ if (ENVIRONMENT_IS_NODE) {
8812
+ _emscripten_get_now.actual = function _emscripten_get_now_actual() {
8813
+ var t = process['hrtime']();
8814
+ return t[0] * 1e3 + t[1] / 1e6;
8815
+ }
8816
+ } else if (typeof dateNow !== 'undefined') {
8817
+ _emscripten_get_now.actual = dateNow;
8818
+ } else if (ENVIRONMENT_IS_WEB && window['performance'] && window['performance']['now']) {
8819
+ _emscripten_get_now.actual = function _emscripten_get_now_actual() { return window['performance']['now'](); };
8820
+ } else {
8821
+ _emscripten_get_now.actual = Date.now;
8822
+ }
8823
+ }
8824
+ return _emscripten_get_now.actual();
8825
+ },
8826
+
8827
+ emscripten_get_now_res: function() { // return resolution of get_now, in nanoseconds
8828
+ if (ENVIRONMENT_IS_NODE) {
8829
+ return 1; // nanoseconds
8830
+ } else if (typeof dateNow !== 'undefined' ||
8831
+ (ENVIRONMENT_IS_WEB && window['performance'] && window['performance']['now'])) {
8832
+ return 1000; // microseconds (1/1000 of a millisecond)
8833
+ } else {
8834
+ return 1000*1000; // milliseconds
8835
+ }
8836
+ },
8837
+
8838
+ //============================
8839
+ // emscripten vector ops
8840
+ //============================
8841
+
8842
+ emscripten_float32x4_signmask__inline: function(a) {
8843
+ return 'SIMD.float32x4.bitsToInt32x4(' + a + ').signMask';
8844
+ },
8845
+
8846
+ emscripten_float32x4_min__inline: function(a, b) {
8847
+ return 'SIMD.float32x4.min(' + a + ', ' + b + ')';
8848
+ },
8849
+
8850
+ emscripten_float32x4_max__inline: function(a, b) {
8851
+ return 'SIMD.float32x4.max(' + a + ', ' + b + ')';
8852
+ },
8853
+
8854
+ emscripten_float32x4_sqrt__inline: function(a) {
8855
+ return 'SIMD.float32x4.sqrt(' + a + ')';
8856
+ },
8857
+
8858
+ emscripten_float32x4_lessThan__inline: function(a, b) {
8859
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.float32x4.lessThan(' + a + ', ' + b + '))';
8860
+ },
8861
+
8862
+ emscripten_float32x4_lessThanOrEqual__inline: function(a, b) {
8863
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.float32x4.lessThanOrEqual(' + a + ', ' + b + '))';
8864
+ },
8865
+
8866
+ emscripten_float32x4_equal__inline: function(a, b) {
8867
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.float32x4.equal(' + a + ', ' + b + '))';
8868
+ },
8869
+
8870
+ emscripten_float32x4_greaterThanOrEqual__inline: function(a, b) {
8871
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.float32x4.greaterThanOrEqual(' + a + ', ' + b + '))';
8872
+ },
8873
+
8874
+ emscripten_float32x4_greaterThan__inline: function(a, b) {
8875
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.float32x4.greaterThan(' + a + ', ' + b + '))';
8876
+ },
8877
+
8878
+ emscripten_float32x4_and__inline: function(a, b) {
8879
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.int32x4.and(SIMD.float32x4.bitsToInt32x4(' + a + '), SIMD.float32x4.bitsToInt32x4(' + b + ')))';
8880
+ },
8881
+
8882
+ emscripten_float32x4_andNot__inline: function(a, b) {
8883
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.int32x4.and(SIMD.int32x4.not(SIMD.float32x4.bitsToInt32x4(' + a + ')), SIMD.float32x4.bitsToInt32x4(' + b + ')))';
8884
+ },
8885
+
8886
+ emscripten_float32x4_or__inline: function(a, b) {
8887
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.int32x4.or(SIMD.float32x4.bitsToInt32x4(' + a + '), SIMD.float32x4.bitsToInt32x4(' + b + ')))';
8888
+ },
8889
+
8890
+ emscripten_float32x4_xor__inline: function(a, b) {
8891
+ return 'SIMD.int32x4.bitsToFloat32x4(SIMD.int32x4.xor(SIMD.float32x4.bitsToInt32x4(' + a + '), SIMD.float32x4.bitsToInt32x4(' + b + ')))';
8892
+ },
8893
+
8894
+ emscripten_int32x4_bitsToFloat32x4__inline: function(a) {
8895
+ return 'SIMD.int32x4.bitsToFloat32x4(' + a + ')';
8896
+ },
8897
+
8898
+ emscripten_int32x4_toFloat32x4__inline: function(a) {
8899
+ return 'SIMD.int32x4.toFloat32x4(' + a + ')';
8900
+ },
8901
+
8902
+ emscripten_float32x4_bitsToInt32x4__inline: function(a) {
8903
+ return 'SIMD.float32x4.bitsToInt32x4(' + a + ')';
8904
+ },
8905
+
8906
+ emscripten_float32x4_toInt32x4__inline: function(a) {
8907
+ return 'SIMD.float32x4.toInt32x4(' + a + ')';
8623
8908
  },
8624
8909
 
8625
8910
  //============================
@@ -8718,6 +9003,6 @@ function autoAddDeps(object, name) {
8718
9003
 
8719
9004
  // Add aborting stubs for various libc stuff needed by libc++
8720
9005
  ['pthread_cond_signal', 'pthread_equal', 'wcstol', 'wcstoll', 'wcstoul', 'wcstoull', 'wcstof', 'wcstod', 'wcstold', 'pthread_join', 'pthread_detach', 'catgets', 'catopen', 'catclose', 'fputwc', '__lockfile', '__unlockfile'].forEach(function(aborter) {
8721
- LibraryManager.library[aborter] = function() { throw 'TODO: ' + aborter };
9006
+ LibraryManager.library[aborter] = function aborting_stub() { throw 'TODO: ' + aborter };
8722
9007
  });
8723
9008