-
Notifications
You must be signed in to change notification settings - Fork 171
REPL str
support
#2724
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
REPL str
support
#2724
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two comments. Rest looks good. Thanks for this!
if (y == NULL) { | ||
*x = NULL; | ||
return; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this? Could you share an example where this fails currently as of the main
branch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the above change, the following fails (SEGFAULT):
❯ lp
>>> s: str
>>> s
The stack address was not found in any shared library or the main program, the stack is probably corrupted. Aborting.
Tested by Test Case PythonCompiler string 2
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is fine. I am curious about the following:
- why does
_lfortran_strcpy
get called in this case? - are you able to reproduce this same bug in normal/regular
lpython
invocation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why does
_lfortran_strcpy
get called in this case?
The global_stmt
function that is constructed with the top-level expressions, copies the string into the return variable. You can run the example code above with lp -v
flag to look at the ASR and LLVM IR generated.
The ASR and IR for the second line:
(TranslationUnit
(SymbolTable
1
{
__main__:
(Module
(SymbolTable
2
{
__main__global_stmts_2__:
(Function
(SymbolTable
3
{
__main__global_stmts_2__1:
(Variable
3
__main__global_stmts_2__1
[]
ReturnVar
()
()
Default
(Character 1 -2 ())
()
BindC
Public
Required
.false.
)
})
__main__global_stmts_2__
(FunctionType
[]
(Character 1 -2 ())
BindC
Implementation
()
.false.
.false.
.false.
.false.
.false.
[]
.false.
)
[]
[]
[(Assignment
(Var 3 __main__global_stmts_2__1)
(Var 2 s)
()
)]
(Var 3 __main__global_stmts_2__1)
Public
.false.
.false.
()
),
s:
(Variable
2
s
[]
Local
()
()
Default
(Character 1 -2 ())
()
Interactive
Public
Required
.false.
)
})
__main__
[]
.false.
.false.
)
})
[]
)
; ModuleID = 'LFortran'
source_filename = "LFortran"
@s = external global i8*
define i8* @__main__global_stmts_2__() {
.entry:
%__main__global_stmts_2__1 = alloca i8*, align 8
store i8* null, i8** %__main__global_stmts_2__1, align 8
%0 = load i8*, i8** @s, align 8
call void @_lfortran_strcpy(i8** %__main__global_stmts_2__1, i8* %0, i8 0)
br label %return
return: ; preds = %.entry
%1 = load i8*, i8** %__main__global_stmts_2__1, align 8
ret i8* %1
}
declare void @_lfortran_strcpy(i8**, i8*, i8)
are you able to reproduce this same bug in normal/regular
lpython
invocation?
No, this does not cause any problem with normal lpython
execution.
Maybe we can optimize it to not make a copy. I will look into it.
src/lpython/python_evaluator.cpp
Outdated
result.type = EvalResult::string; | ||
result.str = r; | ||
} else { | ||
goto raise_error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use goto
. Rather we can simply have throw LCompilersException("FortranEvaluator::evaluate(): Return type not supported");
here. (It might look like duplication, but I think its fine at the moment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Great work!
No description provided.