Opened 10 years ago

Closed 10 years ago

Last modified 7 years ago

#3026 closed defect (fixed)

Boolean array assignment in initial equation section

Reported by: Adeel Asghar Owned by: Lennart Ochel
Priority: blocker Milestone: 1.9.4
Component: Code Generation Version: trunk
Keywords: Cc:

Description

Boolean array assignment in initial equation section generates [CodegenC.tpl:8568:16-8568:16:writable] Error: Template error: daeExpRelation:ERR if external object is used in the equation. See the attached model and script.

If there is no external object then it works fine.

Attachments (2)

Bug3026.mo (789 bytes ) - added by Adeel Asghar 10 years ago.
Bug3026.mos (73 bytes ) - added by Adeel Asghar 10 years ago.

Download all attachments as: .zip

Change History (14)

by Adeel Asghar, 10 years ago

Attachment: Bug3026.mo added

by Adeel Asghar, 10 years ago

Attachment: Bug3026.mos added

comment:1 by Adeel Asghar, 10 years ago

I tested the same model with real array and it worked fine. But if we change the array type to integer then the following error occurs,

M_06inz.c: In function 'M_eqFunction_3':
M_06inz.c:64: error: incompatible type for argument 1 of 'sub_alloc_integer_array'
C:/OpenModelica/trunk/build//include/omc/c/util/integer_array.h:183: note: expected 'const struct integer_array_t *' but argument is of type 'integer_array'
M_06inz.c:64: error: incompatible type for argument 2 of 'sub_alloc_integer_array'
C:/OpenModelica/trunk/build//include/omc/c/util/integer_array.h:183: note: expected 'const struct integer_array_t *' but argument is of type 'integer_array'
M_06inz.c:64: error: too few arguments to function 'sub_alloc_integer_array'

in reply to:  1 comment:2 by Adeel Asghar, 10 years ago

Replying to adeas31:

I tested the same model with real array and it worked fine. But if we change the array type to integer then the following error occurs,

M_06inz.c: In function 'M_eqFunction_3':
M_06inz.c:64: error: incompatible type for argument 1 of 'sub_alloc_integer_array'
C:/OpenModelica/trunk/build//include/omc/c/util/integer_array.h:183: note: expected 'const struct integer_array_t *' but argument is of type 'integer_array'
M_06inz.c:64: error: incompatible type for argument 2 of 'sub_alloc_integer_array'
C:/OpenModelica/trunk/build//include/omc/c/util/integer_array.h:183: note: expected 'const struct integer_array_t *' but argument is of type 'integer_array'
M_06inz.c:64: error: too few arguments to function 'sub_alloc_integer_array'

r23726 should fix the above error.

comment:3 by Henning Kiel, 10 years ago

Adeel, r23726 does *not* fix the problem, as you create the returned object on the stack which is likely to be destroyed when you use it!

Anyway, why do you return the array object? All other functions have a "integer_array_t * dest" pointer as parameter for this. Maybe we need to fix CodegenC.tpl to use correct signature of that function?

comment:4 by Martin Sjölund, 10 years ago

All functions that use alloc should be possible to return directly. The array is just a struct, and the data inside the struct is heap-allocated.
For the non-alloc functions, we take a dest and write to the old data locations.

The alloc functions should be used when temporary arrays are needed, but the code generation uses them more often than necessary (because the intermediate representation is poor).

comment:5 by Henning Kiel, 10 years ago

OK. So, the fixed function seems to work.

I still see lots of *_alloc_* functions (in integer_array.c) that have different parameter scheme than sub_alloc_* function.

And also one in real_array.c: void cross_alloc_real_array(const real_array_t * x,const real_array_t * y, real_array_t* dest);

Shall those be adjusted, too?

in reply to:  5 comment:6 by Adeel Asghar, 10 years ago

Replying to hkiel:

OK. So, the fixed function seems to work.

I still see lots of *_alloc_* functions (in integer_array.c) that have different parameter scheme than sub_alloc_* function.

And also one in real_array.c: void cross_alloc_real_array(const real_array_t * x,const real_array_t * y, real_array_t* dest);

Shall those be adjusted, too?

Yes.

comment:7 by Adeel Asghar, 10 years ago

r23733 should fix Boolean assignment issue.
I am not sure if the fix is done in the correct way but my tests seems to work fine.

comment:8 by Lennart Ochel, 10 years ago

Resolution: fixed
Status: newclosed

Yes, it seem to work with your changes. I close this ticket as long as no one complains.

comment:9 by Lennart Ochel, 10 years ago

BTW: Should we put the example to the testsuite or is it already tested by other ones?

comment:11 by Dietmar Winkler, 9 years ago

Milestone: Futurepre1.9.4

It doesn't make sense to keep closed ticket in the "Future" milestone that were simply forgotten to assign to the correct milestone in the past.

comment:12 by Martin Sjölund, 7 years ago

Milestone: pre1.9.41.9.4

Removing the pre1.9.4 milestone in favor of 1.9.4.

Note: See TracTickets for help on using tickets.