@@ -25,14 +25,22 @@ _dtor(struct import_object *im)
2525}
2626
2727int
28- import_object_create_for_host_funcs (const struct name * module_name ,
29- const struct host_func * funcs ,
30- size_t nfuncs , struct host_instance * hi ,
28+ import_object_create_for_host_funcs (const struct host_module * modules ,
29+ size_t n , struct host_instance * hi ,
3130 struct import_object * * impp )
3231{
3332 struct import_object * im ;
3433 struct funcinst * fis = NULL ;
34+ size_t nfuncs ;
35+ size_t i ;
3536 int ret ;
37+
38+ nfuncs = 0 ;
39+ for (i = 0 ; i < n ; i ++ ) {
40+ const struct host_module * hm = & modules [i ];
41+ nfuncs += hm -> nfuncs ;
42+ }
43+
3644 assert (nfuncs > 0 );
3745 ret = import_object_alloc (nfuncs , & im );
3846 if (ret != 0 ) {
@@ -45,26 +53,33 @@ import_object_create_for_host_funcs(const struct name *module_name,
4553 }
4654 im -> dtor = _dtor ;
4755 im -> dtor_arg = fis ;
48- size_t i ;
49- for (i = 0 ; i < nfuncs ; i ++ ) {
50- struct functype * ft ;
51- ret = functype_from_string (funcs [i ].type , & ft );
52- if (ret != 0 ) {
53- xlog_error ("failed to parse functype: %s" ,
54- funcs [i ].type );
55- goto fail ;
56+ size_t idx = 0 ;
57+ for (i = 0 ; i < n ; i ++ ) {
58+ const struct host_module * hm = & modules [i ];
59+ size_t j ;
60+ for (j = 0 ; j < hm -> nfuncs ; j ++ ) {
61+ const struct host_func * func = & hm -> funcs [j ];
62+ struct functype * ft ;
63+ ret = functype_from_string (func -> type , & ft );
64+ if (ret != 0 ) {
65+ xlog_error ("failed to parse functype: %s" ,
66+ func -> type );
67+ goto fail ;
68+ }
69+ struct funcinst * fi = & fis [idx ];
70+ fi -> is_host = true;
71+ fi -> u .host .func = func -> func ;
72+ fi -> u .host .type = ft ;
73+ fi -> u .host .instance = hi ;
74+ struct import_object_entry * e = & im -> entries [idx ];
75+ e -> module_name = hm -> module_name ;
76+ e -> name = & func -> name ;
77+ e -> type = IMPORT_FUNC ;
78+ e -> u .func = fi ;
79+ idx ++ ;
5680 }
57- struct funcinst * fi = & fis [i ];
58- fi -> is_host = true;
59- fi -> u .host .func = funcs [i ].func ;
60- fi -> u .host .type = ft ;
61- fi -> u .host .instance = hi ;
62- struct import_object_entry * e = & im -> entries [i ];
63- e -> module_name = module_name ;
64- e -> name = & funcs [i ].name ;
65- e -> type = IMPORT_FUNC ;
66- e -> u .func = fi ;
6781 }
82+ assert (idx == nfuncs );
6883 * impp = im ;
6984 return 0 ;
7085fail :
0 commit comments