Closed rebcabin closed 5 months ago
@rebcabin I am unable to reproduce this bug. I tried reproducing it by calling the function with the required arguments, and got the following different error:
(base) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py
ASR verify pass error: ASR verify: The variable in ArrayItem must be an array, not a scalar
Internal Compiler Error: Unhandled exception
Traceback (most recent call last):
Binary file "/home/saurabh-kumar/Projects/System/lpython/src/bin/lpython", in _start()
File "./csu/../csu/libc-start.c", line 360, in __libc_start_main_impl()
File "./csu/../sysdeps/x86/libc-start.c", line 58, in __libc_start_call_main()
File "/home/saurabh-kumar/Projects/System/lpython/src/bin/lpython.cpp", line 1932, in main()
err = compile_python_to_object_file(arg_file, tmp_o, runtime_library_dir,
File "/home/saurabh-kumar/Projects/System/lpython/src/bin/lpython.cpp", line 838, in compile_python_to_object_file()
!(arg_c && compiler_options.po.disable_main), "__main__", infile);
LCompilersException: Verify failed
This code is incorrect, but should produce an error message instead of a SIGSEGV. The error is in the return type of spot_print...
I think the return type is fine. We have some examples in integration tests that use a return type as used in your example (for example see integration_tests/bindpy_04.py
.
As per the latest main
, the example shared in the description works fine for me.
% cat examples/expr2.py
from numpy import array, empty, int16
from lpython import (i16, i32, ccallback, c_p_pointer, Pointer, u64, CPtr, i64,
ccall, sizeof, Array, Allocatable, TypeVar, Const)
rows = TypeVar("rows")
cols = TypeVar("cols")
def spot_print_lpython_array(a: i16[:], rows: i32, cols: i32) -> i16[rows, cols]:
pass
def main() -> i32:
print ("hello, world!")
return 0
if __name__ == "__main__":
main()
% python examples/expr2.py
hello, world!
% lpython_in_main examples/expr2.py
hello, world!
% echo $?
0
The following modified example also works for me.
% cat examples/expr2.py
from numpy import array, empty, int16
from lpython import (i16, i32, ccallback, c_p_pointer, Pointer, u64, CPtr, i64,
ccall, sizeof, Array, Allocatable, TypeVar, Const)
rows = TypeVar("rows")
cols = TypeVar("cols")
def spot_print_lpython_array(a: i16[:], rows: i32, cols: i32) -> i16[rows, cols]:
res: i16[rows, cols] = empty((rows, cols), dtype=int16)
res[0, 2] = i16(-20)
res[1, 2] = i16(102)
return res
def main() -> i32:
a: i16[5] = empty(5, dtype=int16)
b: i16[2, 3]
b = spot_print_lpython_array(a, 2, 3)
print(b[0, 2], b[1, 2])
print ("hello, world!")
return 0
if __name__ == "__main__":
main()
% python examples/expr2.py
-20 102
hello, world!
% lpython_in_main examples/expr2.py
-20 102
hello, world!
@rebcabin and @kmr-srbh please check if the example in the issue description works for you with the latest main and we can close this issue.
The above example provided by you works for me. :+1: I noticed that I had passed the wrong input, which yielded the above error.
Thanks for trying the example. I am closing this issue as it seems fixed. We can open open it later if there is any issue in future.
This code is incorrect, but should produce an error message instead of a
SIGSEGV
. The error is in the return type ofspot_print...
. Changing the return type toNone
makes the problem go away. Also removing a call ofmain
makes the problem go away because the code does not run.