Skip to content

Commit 22fa4bd

Browse files
committed
Refactor function calls in order to allow varidic arguments or overwrite the arguments call size.
1 parent 813deb8 commit 22fa4bd

File tree

23 files changed

+165
-209
lines changed

23 files changed

+165
-209
lines changed

source/loader/source/loader.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ struct loader_host_invoke_type
6868

6969
static function_interface loader_register_interface_proxy(void);
7070

71-
static value loader_register_invoke_proxy(function func, function_impl func_impl, function_args args);
71+
static value loader_register_invoke_proxy(function func, function_impl func_impl, function_args args, size_t size);
72+
73+
static function_return loader_register_await_proxy(function func, function_impl impl, function_args args, size_t size, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context);
7274

7375
static void loader_register_destroy_proxy(function func, function_impl func_impl);
7476

@@ -157,26 +159,23 @@ int loader_is_initialized(const loader_naming_tag tag)
157159
return loader_impl_is_initialized(impl);
158160
}
159161

160-
function_return loader_register_invoke_proxy(function func, function_impl func_impl, function_args args)
162+
function_return loader_register_invoke_proxy(function func, function_impl func_impl, function_args args, size_t size)
161163
{
162164
loader_host_invoke host_invoke = (loader_host_invoke)func_impl;
163165

164-
signature s = function_signature(func);
165-
166-
const size_t args_size = signature_count(s);
167-
168166
void * data = function_closure(func);
169167

170-
return host_invoke->invoke(args_size, args, data);
168+
return host_invoke->invoke(size, args, data);
171169
}
172170

173-
function_return loader_register_await_proxy(function func, function_impl impl, function_args args, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context)
171+
function_return loader_register_await_proxy(function func, function_impl impl, function_args args, size_t size, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context)
174172
{
175173
/* TODO */
176174

177175
(void)func;
178176
(void)impl;
179177
(void)args;
178+
(void)size;
180179
(void)resolve_callback;
181180
(void)reject_callback;
182181
(void)context;

source/loader/source/loader_impl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,9 @@ int loader_impl_function_hook_call(context ctx, const char func_name[])
556556

557557
if (func_init != NULL)
558558
{
559-
void * unused[1] = { NULL };
559+
void * null_args[1] = { NULL };
560560

561-
function_return ret = function_call(func_init, unused);
561+
function_return ret = function_call(func_init, null_args, 0);
562562

563563
if (ret != NULL)
564564
{

source/loaders/c_loader/source/c_loader_impl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,26 @@ int function_c_interface_create(function func, function_impl impl)
7878
return 0;
7979
}
8080

81-
function_return function_c_interface_invoke(function func, function_impl impl, function_args args)
81+
function_return function_c_interface_invoke(function func, function_impl impl, function_args args, size_t size)
8282
{
8383
/* TODO */
8484

8585
(void)func;
8686
(void)impl;
8787
(void)args;
88+
(void)size;
8889

8990
return NULL;
9091
}
9192

92-
function_return function_c_interface_await(function func, function_impl impl, function_args args, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context)
93+
function_return function_c_interface_await(function func, function_impl impl, function_args args, size_t size, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context)
9394
{
9495
/* TODO */
9596

9697
(void)func;
9798
(void)impl;
9899
(void)args;
100+
(void)size;
99101
(void)resolve_callback;
100102
(void)reject_callback;
101103
(void)context;

source/loaders/cs_loader/include/cs_loader/simple_netcore.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,29 @@ extern "C" {
2828
#include <stdlib.h>
2929

3030
#define MAX_FILES 0xFF
31-
struct netcore_handle_type;
32-
typedef struct netcore_handle_type * netcore_handle;
3331

34-
typedef char source_file[512];
32+
struct netcore_handle_type;
33+
typedef struct netcore_handle_type * netcore_handle;
3534

36-
netcore_handle simple_netcore_create(char * dotnet_root, char * dotnet_loader_assembly_path);
35+
typedef char source_file[512];
3736

38-
reflect_function * simple_netcore_get_functions(netcore_handle, int*);
37+
netcore_handle simple_netcore_create(char * dotnet_root, char * dotnet_loader_assembly_path);
3938

40-
void simple_netcore_load_script_from_files(netcore_handle handle, char * files[MAX_FILES], size_t size);
39+
reflect_function * simple_netcore_get_functions(netcore_handle, int *);
4140

42-
void simple_netcore_load_script_from_assembly(netcore_handle handle, char * file);
41+
void simple_netcore_load_script_from_files(netcore_handle handle, char * files[MAX_FILES], size_t size);
4342

44-
void simple_netcore_load_script_from_memory(netcore_handle handle, const char * buffer, size_t size);
43+
void simple_netcore_load_script_from_assembly(netcore_handle handle, char * file);
4544

46-
execution_result* simple_netcore_invoke(netcore_handle, const char *);
45+
void simple_netcore_load_script_from_memory(netcore_handle handle, const char * buffer, size_t size);
4746

48-
void simple_netcore_destroy(netcore_handle);
47+
execution_result * simple_netcore_invoke(netcore_handle, const char *);
4948

50-
execution_result* simple_netcore_invoke_with_params(netcore_handle handle, const char *func, parameters * params);
49+
void simple_netcore_destroy(netcore_handle);
5150

52-
void simple_netcore_destroy_execution_result(netcore_handle handle, execution_result* er);
51+
execution_result* simple_netcore_invoke_with_params(netcore_handle handle, const char * func, parameters * params);
52+
53+
void simple_netcore_destroy_execution_result(netcore_handle handle, execution_result * er);
5354

5455
#ifdef __cplusplus
5556
}

source/loaders/cs_loader/source/cs_loader_impl.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ int function_cs_interface_create(function func, function_impl impl)
4848
return 0;
4949
}
5050

51-
function_return function_cs_interface_invoke(function func, function_impl impl, function_args args)
51+
function_return function_cs_interface_invoke(function func, function_impl impl, function_args args, size_t size)
5252
{
5353
(void)func;
54-
(void)impl;
55-
(void)args;
54+
(void)size; /* TODO: Assert size and param_count are equal, varidic not allowed in C# yet */
5655

5756
cs_function * cs_f = (cs_function*)impl;
5857
execution_result * result;
@@ -135,13 +134,14 @@ function_return function_cs_interface_invoke(function func, function_impl impl,
135134
return v;
136135
}
137136

138-
function_return function_cs_interface_await(function func, function_impl impl, function_args args, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context)
137+
function_return function_cs_interface_await(function func, function_impl impl, function_args args, size_t size, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context)
139138
{
140139
/* TODO */
141140

142141
(void)func;
143142
(void)impl;
144143
(void)args;
144+
(void)size;
145145
(void)resolve_callback;
146146
(void)reject_callback;
147147
(void)context;

source/loaders/cs_loader/source/simple_netcore.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@
2121
#include <cs_loader/simple_netcore.h>
2222

2323
#include <cs_loader/netcore.h>
24-
#if defined(__linux) | defined( linux)
25-
#include <cs_loader/netcore_linux.h>
24+
#if defined(__linux) | defined(linux)
25+
# include <cs_loader/netcore_linux.h>
2626
#else
27-
#include <cs_loader/netcore_win.h>
27+
# include <cs_loader/netcore_win.h>
2828
#endif
2929

3030
netcore_handle simple_netcore_create(char * dotnet_root, char * dotnet_loader_assembly_path)
3131
{
32-
#if defined(__linux) | defined( linux)
32+
#if defined(__linux) | defined(linux)
3333
netcore_linux * netcore_impl = new netcore_linux(dotnet_root, dotnet_loader_assembly_path);
3434
#else
3535
netcore_win * netcore_impl = new netcore_win(dotnet_root, dotnet_loader_assembly_path);
3636
#endif
3737

38-
bool result = netcore_impl->start();
38+
bool result = netcore_impl->start();
3939

4040
if (result == false)
4141
{
@@ -60,7 +60,7 @@ void simple_netcore_destroy(netcore_handle handle)
6060
delete core;
6161
}
6262

63-
void simple_netcore_load_script_from_files(netcore_handle handle, char * files[MAX_FILES], size_t size)
63+
void simple_netcore_load_script_from_files(netcore_handle handle, char * files[MAX_FILES], size_t size)
6464
{
6565
netcore * core = (netcore*)handle;
6666

@@ -70,7 +70,7 @@ void simple_netcore_load_script_from_files(netcore_handle handle, char * files[
7070
}
7171
}
7272

73-
void simple_netcore_load_script_from_assembly(netcore_handle handle, char * file)
73+
void simple_netcore_load_script_from_assembly(netcore_handle handle, char * file)
7474
{
7575
netcore * core = (netcore*)handle;
7676

@@ -80,7 +80,7 @@ void simple_netcore_load_script_from_assembly(netcore_handle handle, char * fil
8080
}
8181
}
8282

83-
void simple_netcore_load_script_from_memory(netcore_handle handle, const char * buffer, size_t size)
83+
void simple_netcore_load_script_from_memory(netcore_handle handle, const char * buffer, size_t size)
8484
{
8585
netcore * core = (netcore*)handle;
8686

@@ -91,14 +91,14 @@ void simple_netcore_load_script_from_memory(netcore_handle handle, const char *
9191

9292
}
9393
}
94-
execution_result * simple_netcore_invoke(netcore_handle handle, const char * func)
94+
execution_result * simple_netcore_invoke(netcore_handle handle, const char * func)
9595
{
9696
netcore * core = (netcore*)handle;
9797

9898
return core->execute((char*)func);
9999
}
100100

101-
execution_result * simple_netcore_invoke_with_params(netcore_handle handle, const char * func, parameters * params)
101+
execution_result * simple_netcore_invoke_with_params(netcore_handle handle, const char * func, parameters * params)
102102
{
103103
netcore * core = (netcore*)handle;
104104

source/loaders/file_loader/source/file_loader_impl.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,25 @@ int function_file_interface_create(function func, function_impl impl)
105105
return 0;
106106
}
107107

108-
function_return function_file_interface_invoke(function func, function_impl impl, function_args args)
108+
function_return function_file_interface_invoke(function func, function_impl impl, function_args args, size_t size)
109109
{
110110
loader_impl_file_function file_function = (loader_impl_file_function)impl;
111111

112112
(void)func;
113113
(void)args;
114+
(void)size;
114115

115116
return value_create_string(file_function->descriptor->path, file_function->descriptor->length);
116117
}
117118

118-
function_return function_file_interface_await(function func, function_impl impl, function_args args, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context)
119+
function_return function_file_interface_await(function func, function_impl impl, function_args args, size_t size, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context)
119120
{
120121
/* TODO */
121122

122123
(void)func;
123124
(void)impl;
124125
(void)args;
126+
(void)size;
125127
(void)resolve_callback;
126128
(void)reject_callback;
127129
(void)context;

source/loaders/js_loader/source/js_loader_impl.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -317,25 +317,23 @@ int function_js_interface_create(function func, function_impl impl)
317317
return 0;
318318
}
319319

320-
function_return function_js_interface_invoke(function func, function_impl impl, function_args args)
320+
function_return function_js_interface_invoke(function func, function_impl impl, function_args args, size_t size)
321321
{
322322
loader_impl_js_function js_func = static_cast<loader_impl_js_function>(impl);
323323

324324
Local<Function> func_impl_local = js_func->materialize_handle();
325325

326326
signature s = function_signature(func);
327327

328-
const size_t args_size = signature_count(s);
329-
330328
Local<Value> result;
331329

332-
if (args_size > 0)
330+
if (size > 0)
333331
{
334-
std::vector<Local<Value>> value_args(args_size);
332+
std::vector<Local<Value>> value_args(size);
335333

336334
size_t args_count;
337335

338-
for (args_count = 0; args_count < args_size; ++args_count)
336+
for (args_count = 0; args_count < size; ++args_count)
339337
{
340338
type t = signature_get_type(s, args_count);
341339

@@ -529,13 +527,14 @@ function_return function_js_interface_invoke(function func, function_impl impl,
529527
return NULL;
530528
}
531529

532-
function_return function_js_interface_await(function func, function_impl impl, function_args args, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context)
530+
function_return function_js_interface_await(function func, function_impl impl, function_args args, size_t size, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context)
533531
{
534532
/* TODO */
535533

536534
(void)func;
537535
(void)impl;
538536
(void)args;
537+
(void)size;
539538
(void)resolve_callback;
540539
(void)reject_callback;
541540
(void)context;

source/loaders/jsm_loader/source/jsm_loader_impl.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,26 @@ int function_jsm_interface_create(function func, function_impl impl)
6767
return 0;
6868
}
6969

70-
function_return function_jsm_interface_invoke(function func, function_impl impl, function_args args)
70+
function_return function_jsm_interface_invoke(function func, function_impl impl, function_args args, size_t size)
7171
{
7272
/* TODO */
7373

7474
(void)func;
7575
(void)impl;
7676
(void)args;
77+
(void)size;
7778

7879
return NULL;
7980
}
8081

81-
function_return function_jsm_interface_await(function func, function_impl impl, function_args args, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context)
82+
function_return function_jsm_interface_await(function func, function_impl impl, function_args args, size_t size, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context)
8283
{
8384
/* TODO */
8485

8586
(void)func;
8687
(void)impl;
8788
(void)args;
89+
(void)size;
8890
(void)resolve_callback;
8991
(void)reject_callback;
9092
(void)context;

source/loaders/mock_loader/source/mock_loader_function_interface.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ function_interface function_mock_singleton(void);
3030

3131
int function_mock_interface_create(function func, function_impl impl);
3232

33-
function_return function_mock_interface_invoke(function func, function_impl impl, function_args args);
33+
function_return function_mock_interface_invoke(function func, function_impl impl, function_args args, size_t size);
3434

35-
void function_mock_interface_await(function func, function_impl impl, function_args args, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context);
35+
void function_mock_interface_await(function func, function_impl impl, function_args args, size_t size, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context);
3636

3737
void function_mock_interface_destroy(function func, function_impl impl);
3838

@@ -62,23 +62,21 @@ int function_mock_interface_create(function func, function_impl impl)
6262
return 0;
6363
}
6464

65-
function_return function_mock_interface_invoke(function func, function_impl impl, function_args args)
65+
function_return function_mock_interface_invoke(function func, function_impl impl, function_args args, size_t size)
6666
{
6767
loader_impl_mock_function mock_function = (loader_impl_mock_function)impl;
6868

6969
signature s = function_signature(func);
7070

7171
type ret_type = signature_get_return(s);
7272

73-
const size_t args_size = signature_count(s);
74-
7573
(void)mock_function;
7674

77-
if (args_size > 0)
75+
if (size > 0)
7876
{
7977
size_t args_count;
8078

81-
for (args_count = 0; args_count < args_size; ++args_count)
79+
for (args_count = 0; args_count < size; ++args_count)
8280
{
8381
type t = signature_get_type(s, args_count);
8482

@@ -140,7 +138,7 @@ function_return function_mock_interface_invoke(function func, function_impl impl
140138
}
141139
}
142140

143-
log_write("metacall", LOG_LEVEL_DEBUG, "Calling mock function with arguments (%lu)", args_size);
141+
log_write("metacall", LOG_LEVEL_DEBUG, "Calling mock function with arguments (%lu)", size);
144142
}
145143
else
146144
{
@@ -198,13 +196,14 @@ function_return function_mock_interface_invoke(function func, function_impl impl
198196
return NULL;
199197
}
200198

201-
function_return function_mock_interface_await(function func, function_impl impl, function_args args, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context)
199+
function_return function_mock_interface_await(function func, function_impl impl, function_args args, size_t size, function_resolve_callback resolve_callback, function_reject_callback reject_callback, void * context)
202200
{
203201
/* TODO */
204202

205203
(void)func;
206204
(void)impl;
207205
(void)args;
206+
(void)size;
208207
(void)resolve_callback;
209208
(void)reject_callback;
210209
(void)context;

0 commit comments

Comments
 (0)