Skip to content

Commit

Permalink
Solve minor bugs from C# loader.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Feb 12, 2021
1 parent 7c55580 commit 6a68bdd
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 22 deletions.
1 change: 1 addition & 0 deletions source/loaders/cs_loader/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ add_library(${target} MODULE
# Add target dependencies
add_dependencies(${target}
${LOADER_MODULE_NAMES}
cs_loader_impl
)

# Create namespaced alias
Expand Down
6 changes: 3 additions & 3 deletions source/loaders/cs_loader/include/cs_loader/simple_netcore.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ netcore_handle simple_netcore_create(char * dotnet_root, char * dotnet_loader_as

reflect_function * simple_netcore_get_functions(netcore_handle, int *);

void simple_netcore_load_script_from_files(netcore_handle handle, char * files[MAX_FILES], size_t size);
int simple_netcore_load_script_from_files(netcore_handle handle, char * files[MAX_FILES], size_t size);

void simple_netcore_load_script_from_assembly(netcore_handle handle, char * file);
int simple_netcore_load_script_from_assembly(netcore_handle handle, char * file);

void simple_netcore_load_script_from_memory(netcore_handle handle, const char * buffer, size_t size);
int simple_netcore_load_script_from_memory(netcore_handle handle, const char * buffer, size_t size);

execution_result * simple_netcore_invoke(netcore_handle, const char *);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public bool LoadFromAssembly(string assemblyFile)
catch (Exception exName)
{
this.log.Error(exName.Message, exName);
return false;
}
}

Expand Down
16 changes: 12 additions & 4 deletions source/loaders/cs_loader/source/cs_loader_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,27 +274,35 @@ loader_handle cs_loader_impl_load_from_file(loader_impl impl, const loader_namin
files[i] = (char*)paths[i];
}

simple_netcore_load_script_from_files(nhandle, files, size);
if (simple_netcore_load_script_from_files(nhandle, files, size) != 0)
{
return NULL;
}

return (loader_handle)impl;
}

loader_handle cs_loader_impl_load_from_package(loader_impl impl, const loader_naming_path path) {
netcore_handle nhandle = (netcore_handle)loader_impl_get(impl);

simple_netcore_load_script_from_assembly(nhandle, (char *)path);
if (simple_netcore_load_script_from_assembly(nhandle, (char *)path) != 0)
{
return NULL;
}

return (loader_handle)impl;
}

loader_handle cs_loader_impl_load_from_memory(loader_impl impl, const loader_naming_name name, const char * buffer, size_t size)
{

(void)name;

netcore_handle nhandle = (netcore_handle)loader_impl_get(impl);

simple_netcore_load_script_from_memory(nhandle, buffer, size);
if (simple_netcore_load_script_from_memory(nhandle, buffer, size) != 0)
{
return NULL;
}

return (loader_handle)impl;
}
Expand Down
22 changes: 7 additions & 15 deletions source/loaders/cs_loader/source/simple_netcore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,37 +60,29 @@ void simple_netcore_destroy(netcore_handle handle)
delete core;
}

void simple_netcore_load_script_from_files(netcore_handle handle, char * files[MAX_FILES], size_t size)
int simple_netcore_load_script_from_files(netcore_handle handle, char * files[MAX_FILES], size_t size)
{
netcore * core = (netcore*)handle;

if (core->load_files(files, size))
{

}
return core->load_files(files, size) == true ? 0 : 1;
}

void simple_netcore_load_script_from_assembly(netcore_handle handle, char * file)
int simple_netcore_load_script_from_assembly(netcore_handle handle, char * file)
{
netcore * core = (netcore*)handle;

if (core->load_assembly(file))
{

}
return core->load_assembly(file) == true ? 0 : 1;
}

void simple_netcore_load_script_from_memory(netcore_handle handle, const char * buffer, size_t size)
int simple_netcore_load_script_from_memory(netcore_handle handle, const char * buffer, size_t size)
{
netcore * core = (netcore*)handle;

(void)size;

if (core->load_source((char*)buffer))
{

}
return core->load_source((char*)buffer) == true ? 0 : 1;
}

execution_result * simple_netcore_invoke(netcore_handle handle, const char * func)
{
netcore * core = (netcore*)handle;
Expand Down
13 changes: 13 additions & 0 deletions source/tests/cs_loader_test/source/cs_loader_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,16 @@ TEST_F(cs_loader_test, Concat)

metacall_value_destroy(ret);
}

TEST_F(cs_loader_test, Fail)
{
/* This is a Python script on purpose, in order to test C# when it fails */
static const char buffer[] =
"#!/usr/bin/env python3\n"
"def multmem(left: int, right: int) -> int:\n"
"\tresult = left * right;\n"
"\tprint(left, ' * ', right, ' = ', result);\n"
"\treturn result;";

EXPECT_EQ((int) 1, (int) metacall_load_from_memory("cs", buffer, sizeof(buffer), NULL));
}

0 comments on commit 6a68bdd

Please sign in to comment.