Make mrb_load_exec() return nil if there is a syntax error#5496
Open
dearblue wants to merge 1 commit intomruby:masterfrom
Open
Make mrb_load_exec() return nil if there is a syntax error#5496dearblue wants to merge 1 commit intomruby:masterfrom
mrb_load_exec() return nil if there is a syntax error#5496dearblue wants to merge 1 commit intomruby:masterfrom
Conversation
Previously it returned `undef`. So for example, if there was a syntax error, the following code would cause `SIGSEGV`. ```c const char *code = "syntax ? error ?"; mrb_p(mrb, mrb_load_string(mrb, code)); ``` This affects the behavior of the `MRB_API` function below: - `mrb_load_file()` - `mrb_load_file_cxt()` - `mrb_load_detect_file_cxt()` - `mrb_load_string()` - `mrb_load_nstring()` - `mrb_load_string_cxt()` - `mrb_load_nstring_cxt()` I mentioned earlier why I want to change from `undef` to `nil`, but here's why I decided to change it: - Returns `nil` if an error occurred when returning from `mrb_top_run()`. - The specific error can be found by confirming that `mrb->exc` is non-`NULL`. - Even if `mrbc_context::no_exec` is true, it is sufficient to check if it is either `proc` or `nil`. However, this change can cause compatibility issues if it has already used `mrb_undef_p()` to distinguish between syntax errors. This is the reason for making changes to the `mrdb.c` file (although the behavior does not change with or without changes).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously it returned
undef.So for example, if there was a syntax error, the following code would cause
SIGSEGV.This affects the behavior of the
MRB_APIfunction below:mrb_load_file()mrb_load_file_cxt()mrb_load_detect_file_cxt()mrb_load_string()mrb_load_nstring()mrb_load_string_cxt()mrb_load_nstring_cxt()I mentioned earlier why I want to change from
undeftonil, but here's why I decided to change it:nilif an error occurred when returning frommrb_top_run().mrb->excis non-NULL.mrbc_context::no_execis true, it is sufficient to check if it is eitherprocornil.However, this change can cause compatibility issues if it has already used
mrb_undef_p()to distinguish between syntax errors.This is the reason for making changes to the
mrdb.cfile (although the behavior does not change with or without changes).Just to be sure.
I think the current behavior of returning
undefis non-bug.