Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: introduce three new functions call(), loadstring() and loadfile() #101

Merged
merged 6 commits into from
Aug 24, 2022

Conversation

jow-
Copy link
Owner

@jow- jow- commented Aug 24, 2022

Introduce new functions dealing with on-the-fly compilation of code and
execution of functions with different global scope.

The loadstring() and loadfile() functions will compile the given
ucode source string or ucode file path respectively and return the entry
function of the resulting program.

An optional dictionary specifying parse options may be given as second
argument.

Both functions return null on invalid arguments and throw an exception
in case of compilation errors.

The call() function allows invoking a given function value with a
different this context and/or a different global environment.

Finally refactor the existing uc_require_ucode() implementation to
reuse the new uc_loadfile() and uc_call() implementations and adjust
as well as simplify affected testcases.

jow- added 6 commits August 24, 2022 12:55
Signed-off-by: Jo-Philipp Wich <[email protected]>
When a module function with unpatched upvalues is freed, ucv_free() might
access a NULL pointer through ucv_put_value(), so make sure to skip those
unset upvalue slots when freeing a closure.

Signed-off-by: Jo-Philipp Wich <[email protected]>
When loading a precompiled program from stdin, the input source runpath
is unset which subsequently leads to a null pointer being passed to
uc_source_runpath_set() when will then attempt to strdup() it, leading
to a null pointer access.

Properly handle this case and only duplicate non-null pointers.

Signed-off-by: Jo-Philipp Wich <[email protected]>
Align the path resolving logic with compiler.c and use strrchr() and a
width limited printf pattern to extract the directory name portion.

Signed-off-by: Jo-Philipp Wich <[email protected]>
Factor out the nested syntax error message indentation logic into a
separate helper procedure for reuse in other places.

Signed-off-by: Jo-Philipp Wich <[email protected]>
Introduce new functions dealing with on-the-fly compilation of code and
execution of functions with different global scope.

The `loadstring()` and `loadfile()` functions will compile the given
ucode source string or ucode file path respectively and return the entry
function of the resulting program.

An optional dictionary specifying parse options may be given as second
argument.

Both functions return `null` on invalid arguments and throw an exception
in case of compilation errors.

The `call()` function allows invoking a given function value with a
different `this` context and/or a different global environment.

Finally refactor the existing `uc_require_ucode()` implementation to
reuse the new `uc_loadfile()` and `uc_call()` implementations and adjust
as well as simplify affected testcases.

Signed-off-by: Jo-Philipp Wich <[email protected]>
@jow- jow- force-pushed the loadfile-support branch from a1d1b45 to 131d99c Compare August 24, 2022 13:33
@jow- jow- merged commit 66bbda7 into master Aug 24, 2022
@jow- jow- deleted the loadfile-support branch August 24, 2022 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant