Skip to content

Commit 9826737

Browse files
committed
C_CPP: Support stride in Allocate
1 parent 1ac934a commit 9826737

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/libasr/codegen/asr_to_c_cpp.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2569,7 +2569,8 @@ PyMODINIT_FUNC PyInit_lpython_module_)" + fn_name + R"((void) {
25692569
if (ASRUtils::is_array(type)) {
25702570
std::string size_str = "1";
25712571
out += indent + sym + "->n_dims = " + std::to_string(x.m_args[i].n_dims) + ";\n";
2572-
for (size_t j=0; j<x.m_args[i].n_dims; j++) {
2572+
std::string stride = "1";
2573+
for (int j = (int)x.m_args[i].n_dims - 1; j >= 0; j--) {
25732574
std::string st, l;
25742575
if (x.m_args[i].m_dims[j].m_start) {
25752576
self().visit_expr(*x.m_args[i].m_dims[j].m_start);
@@ -2588,6 +2589,9 @@ PyMODINIT_FUNC PyInit_lpython_module_)" + fn_name + R"((void) {
25882589
out += st + ";\n";
25892590
out += indent + sym + "->dims[" + std::to_string(j) + "].length = ";
25902591
out += l + ";\n";
2592+
out += indent + sym + "->dims[" + std::to_string(j) + "].stride = ";
2593+
out += stride + ";\n";
2594+
stride = "(" + stride + " * " + l + ")";
25912595
}
25922596
std::string ty = CUtils::get_c_type_from_ttype_t(
25932597
ASRUtils::type_get_past_array(

0 commit comments

Comments
 (0)