Skip to content

Commit 2cf32ca

Browse files
committed
Solve issues with c loader and strings.
1 parent 1d14941 commit 2cf32ca

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

source/loaders/c_loader/source/c_loader_impl.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,8 @@ function_return function_c_interface_invoke(function func, function_impl impl, f
689689
}
690690
else if (id == TYPE_STRING)
691691
{
692-
char *str = value_to_string((value)args[args_count]);
693-
c_function->values[args_count] = &str;
692+
/* String requires to be pointer to a string */
693+
c_function->values[args_count] = value_create_ptr((value)args[args_count]);
694694
}
695695
else
696696
{
@@ -717,7 +717,7 @@ function_return function_c_interface_invoke(function func, function_impl impl, f
717717

718718
if (ret_id == TYPE_NULL)
719719
{
720-
result = value_create_null();
720+
ret = value_create_null();
721721
result_ptr = NULL;
722722
}
723723
else if (ret_id != TYPE_STRING)
@@ -734,6 +734,18 @@ function_return function_c_interface_invoke(function func, function_impl impl, f
734734
}
735735
}
736736

737+
for (size_t args_count = 0; args_count < args_size; ++args_count)
738+
{
739+
type t = signature_get_type(s, args_count);
740+
type_id id = type_index(t);
741+
742+
if (id == TYPE_STRING)
743+
{
744+
/* Clear the pointer to string allocated before */
745+
value_type_destroy(c_function->values[args_count]);
746+
}
747+
}
748+
737749
/* Clear allocated closures if any */
738750
for (c_loader_closure_value *closure : closures)
739751
{

source/scripts/c/compiled/source/compiled.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ char *return_text(void)
2020

2121
void process_text(char *input)
2222
{
23-
printf("'%s'\n", input);
23+
printf("inside of compiled script '%s'\n", input);
2424
assert(strcmp(input, "test_test") == 0);
2525
}

0 commit comments

Comments
 (0)