Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit a2bb6b5

Browse files
committed
[[ Teardown ]] Make sure libscript re-uses builtin module handle
This patch ensures that when binding builtin symbols, libscript uses its prefetched self module handle, rather than re-acquiring it each time.
1 parent 377f341 commit a2bb6b5

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

libscript/src/script-instance.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -729,21 +729,28 @@ __MCScriptResolveForeignFunctionBinding(MCScriptInstanceRef p_instance,
729729
return MCScriptThrowClassNotAllowedInCBindingError();
730730
}
731731

732-
/* TODO: This leaks a module handle! */
732+
/* TODO: This leaks a module handle if library is not empty (builtin) */
733733
MCSLibraryRef t_module;
734-
if (!MCScriptLoadLibrary(MCScriptGetModuleOfInstance(p_instance),
735-
*t_library,
736-
t_module))
737-
{
738-
if (r_bound == nil)
739-
{
740-
return MCScriptThrowUnableToLoadForiegnLibraryError();
741-
}
734+
if (MCStringIsEmpty(*t_library))
735+
{
736+
t_module = MCScriptGetLibrary();
737+
}
738+
else
739+
{
740+
if (!MCScriptLoadLibrary(MCScriptGetModuleOfInstance(p_instance),
741+
*t_library,
742+
t_module))
743+
{
744+
if (r_bound == nil)
745+
{
746+
return MCScriptThrowUnableToLoadForiegnLibraryError();
747+
}
742748

743-
*r_bound = false;
749+
*r_bound = false;
744750

745-
return true;
746-
}
751+
return true;
752+
}
753+
}
747754

748755
void *t_pointer =
749756
MCSLibraryLookupSymbol(t_module,

0 commit comments

Comments
 (0)