@sync
def test_ccall(self):
    self.emcc_args.append('-Wno-return-stack-address')
    self.set_setting('EXTRA_EXPORTED_RUNTIME_METHODS', ['ccall', 'cwrap'])
    create_test_file('post.js', '\n      out(\'*\');\n      var ret;\n      ret = Module[\'ccall\'](\'get_int\', \'number\'); out([typeof ret, ret].join(\',\'));\n      ret = ccall(\'get_float\', \'number\'); out([typeof ret, ret.toFixed(2)].join(\',\'));\n      ret = ccall(\'get_bool\', \'boolean\'); out([typeof ret, ret].join(\',\'));\n      ret = ccall(\'get_string\', \'string\'); out([typeof ret, ret].join(\',\'));\n      ret = ccall(\'print_int\', null, [\'number\'], [12]); out(typeof ret);\n      ret = ccall(\'print_float\', null, [\'number\'], [14.56]); out(typeof ret);\n      ret = ccall(\'print_bool\', null, [\'boolean\'], [true]); out(typeof ret);\n      ret = ccall(\'print_string\', null, [\'string\'], ["cheez"]); out(typeof ret);\n      ret = ccall(\'print_string\', null, [\'array\'], [[97, 114, 114, 45, 97, 121, 0]]); out(typeof ret); // JS array\n      ret = ccall(\'print_string\', null, [\'array\'], [new Uint8Array([97, 114, 114, 45, 97, 121, 0])]); out(typeof ret); // typed array\n      ret = ccall(\'multi\', \'number\', [\'number\', \'number\', \'number\', \'string\'], [2, 1.4, 3, \'more\']); out([typeof ret, ret].join(\',\'));\n      var p = ccall(\'malloc\', \'pointer\', [\'number\'], [4]);\n      setValue(p, 650, \'i32\');\n      ret = ccall(\'pointer\', \'pointer\', [\'pointer\'], [p]); out([typeof ret, getValue(ret, \'i32\')].join(\',\'));\n      out(\'*\');\n      // part 2: cwrap\n      var noThirdParam = Module[\'cwrap\'](\'get_int\', \'number\');\n      out(noThirdParam());\n      var multi = Module[\'cwrap\'](\'multi\', \'number\', [\'number\', \'number\', \'number\', \'string\']);\n      out(multi(2, 1.4, 3, \'atr\'));\n      out(multi(8, 5.4, 4, \'bret\'));\n      out(\'*\');\n      // part 3: avoid stack explosion and check it\'s restored correctly\n      for (var i = 0; i < TOTAL_STACK/60; i++) {\n        ccall(\'multi\', \'number\', [\'number\', \'number\', \'number\', \'string\'], [0, 0, 0, \'123456789012345678901234567890123456789012345678901234567890\']);\n      }\n      out(\'stack is ok.\');\n      ccall(\'call_ccall_again\', null);\n      ')
    self.emcc_args += ['--post-js', 'post.js']
    self.set_setting('EXPORTED_FUNCTIONS', ['_get_int', '_get_float', '_get_bool', '_get_string', '_print_int', '_print_float', '_print_bool', '_print_string', '_multi', '_pointer', '_call_ccall_again', '_malloc'])
    self.do_run_in_out_file_test('tests', 'core', 'test_ccall')
    if (('-O2' in self.emcc_args) and ('-g' not in self.emcc_args)):
        print('with closure')
        self.emcc_args += ['--closure', '1']
        self.do_run_in_out_file_test('tests', 'core', 'test_ccall')
@sync
def test_ccall(self):
    self.emcc_args.append('-Wno-return-stack-address')
    self.set_setting('EXTRA_EXPORTED_RUNTIME_METHODS', ['ccall', 'cwrap'])
    create_test_file('post.js', '\n      out(\'*\');\n      var ret;\n      ret = Module[\'ccall\'](\'get_int\', \'number\'); out([typeof ret, ret].join(\',\'));\n      ret = ccall(\'get_float\', \'number\'); out([typeof ret, ret.toFixed(2)].join(\',\'));\n      ret = ccall(\'get_bool\', \'boolean\'); out([typeof ret, ret].join(\',\'));\n      ret = ccall(\'get_string\', \'string\'); out([typeof ret, ret].join(\',\'));\n      ret = ccall(\'print_int\', null, [\'number\'], [12]); out(typeof ret);\n      ret = ccall(\'print_float\', null, [\'number\'], [14.56]); out(typeof ret);\n      ret = ccall(\'print_bool\', null, [\'boolean\'], [true]); out(typeof ret);\n      ret = ccall(\'print_string\', null, [\'string\'], ["cheez"]); out(typeof ret);\n      ret = ccall(\'print_string\', null, [\'array\'], [[97, 114, 114, 45, 97, 121, 0]]); out(typeof ret); // JS array\n      ret = ccall(\'print_string\', null, [\'array\'], [new Uint8Array([97, 114, 114, 45, 97, 121, 0])]); out(typeof ret); // typed array\n      ret = ccall(\'multi\', \'number\', [\'number\', \'number\', \'number\', \'string\'], [2, 1.4, 3, \'more\']); out([typeof ret, ret].join(\',\'));\n      var p = ccall(\'malloc\', \'pointer\', [\'number\'], [4]);\n      setValue(p, 650, \'i32\');\n      ret = ccall(\'pointer\', \'pointer\', [\'pointer\'], [p]); out([typeof ret, getValue(ret, \'i32\')].join(\',\'));\n      out(\'*\');\n      // part 2: cwrap\n      var noThirdParam = Module[\'cwrap\'](\'get_int\', \'number\');\n      out(noThirdParam());\n      var multi = Module[\'cwrap\'](\'multi\', \'number\', [\'number\', \'number\', \'number\', \'string\']);\n      out(multi(2, 1.4, 3, \'atr\'));\n      out(multi(8, 5.4, 4, \'bret\'));\n      out(\'*\');\n      // part 3: avoid stack explosion and check it\'s restored correctly\n      for (var i = 0; i < TOTAL_STACK/60; i++) {\n        ccall(\'multi\', \'number\', [\'number\', \'number\', \'number\', \'string\'], [0, 0, 0, \'123456789012345678901234567890123456789012345678901234567890\']);\n      }\n      out(\'stack is ok.\');\n      ccall(\'call_ccall_again\', null);\n      ')
    self.emcc_args += ['--post-js', 'post.js']
    self.set_setting('EXPORTED_FUNCTIONS', ['_get_int', '_get_float', '_get_bool', '_get_string', '_print_int', '_print_float', '_print_bool', '_print_string', '_multi', '_pointer', '_call_ccall_again', '_malloc'])
    self.do_run_in_out_file_test('tests', 'core', 'test_ccall')
    if (('-O2' in self.emcc_args) and ('-g' not in self.emcc_args)):
        print('with closure')
        self.emcc_args += ['--closure', '1']
        self.do_run_in_out_file_test('tests', 'core', 'test_ccall')