Skip to content

Commit

Permalink
Look for orig$ functions from side modules too (emscripten-core#9906)
Browse files Browse the repository at this point in the history
  • Loading branch information
kripken authored Jan 9, 2020
1 parent 5b2fc36 commit ffed1d3
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
7 changes: 4 additions & 3 deletions emscripten.py
Original file line number Diff line number Diff line change
Expand Up @@ -1823,10 +1823,11 @@ def create_fp_accessors(metadata):
accessors.append('''
Module['%(full)s'] = function() {
%(assert)s
// Use the wasm function itself, for the table.
// Use the original wasm function itself, for the table, from the main module.
var func = Module['asm']['%(original)s'];
// If there is no wasm function, this may be a JS library function or
// something from another module.
// Try an original version from a side module.
if (!func) func = Module['_%(original)s'];
// Otherwise, look for a regular function or JS library function.
if (!func) func = Module['%(mangled)s'];
if (!func) func = %(mangled)s;
var fp = addFunction(func, '%(sig)s');
Expand Down
51 changes: 51 additions & 0 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3996,6 +3996,57 @@ def test_dylink_i64_b(self):
}
''', 'other says -1311768467750121224.\nmy fp says: 43.\nmy second fp says: 43.')

@needs_dlfcn
def test_dylink_i64_c(self):
self.dylink_test(r'''
#include <cstdio>
#include <cinttypes>
#include "header.h"
typedef int32_t (*fp_type_32)(int32_t, int32_t, int32_t);
typedef int64_t (*fp_type_64)(int32_t, int32_t, int32_t);
int32_t internal_function_ret_32(int32_t i, int32_t j, int32_t k) {
return 32;
}
int64_t internal_function_ret_64(int32_t i, int32_t j, int32_t k) {
return 64;
}
int main() {
fp_type_32 fp32_internal = &internal_function_ret_32;
fp_type_32 fp32_external = &function_ret_32;
fp_type_64 fp64_external = &function_ret_64;
fp_type_64 fp64_internal = &internal_function_ret_64;
int32_t ires32 = fp32_internal(0,0,0);
printf("res32 - internal %d\n",ires32);
int32_t eres32 = fp32_external(0,0,0);
printf("res32 - external %d\n",eres32);
int64_t ires64 = fp64_internal(0,0,0);
printf("res64 - internal %" PRId64 "\n",ires64);
int64_t eres64 = fp64_external(0,0,0);
printf("res64 - external %" PRId64 "\n",eres64);
return 0;
}
''', '''
#include "header.h"
int32_t function_ret_32(int32_t i, int32_t j, int32_t k) {
return 32;
}
int64_t function_ret_64(int32_t i, int32_t j, int32_t k) {
return 64;
}
''', '''res32 - internal 32
res32 - external 32
res64 - internal 64
res64 - external 64\n''', header='''
#include <emscripten.h>
#include <cstdint>
EMSCRIPTEN_KEEPALIVE int32_t function_ret_32(int32_t i, int32_t j, int32_t k);
EMSCRIPTEN_KEEPALIVE int64_t function_ret_64(int32_t i, int32_t j, int32_t k);
''')

@needs_dlfcn
def test_dylink_class(self):
self.dylink_test(header=r'''
Expand Down

0 comments on commit ffed1d3

Please sign in to comment.