Opened 11 years ago
Closed 11 years ago
#2678 closed defect (invalid)
ExternalObject constructor not called
Reported by: | Owned by: | Lennart Ochel | |
---|---|---|---|
Priority: | high | Milestone: | 1.9.1 |
Component: | Code Generation | Version: | trunk |
Keywords: | ExternalObject constructor | Cc: |
Description
Trying to instantiate an ExternalObject with omc nightly builds results in the constructor not being called, only the destructor.
Please see the attached testcase, to be run with
omc +s ExtObj.mo make -f Test.makefile ./Test
The result I'm seeing is this:
Dtor called (obj=(nil)) Test: ./ExtObj.h:22: void dtor(void *): Assertion `obj==(void*)0xdeadbeef' failed. Aborted (core dumped)
It looks like the constructor is not called. A look at the C sources generated by omc resulted in this (Test_01exo.c):
/* Has to be performed after _init.xml file has been read */ void Test_callExternalObjectConstructors(DATA *data) { /* data->simulationInfo.extObjs = NULL; */ infoStreamPrint(LOG_DEBUG, 0, "call external Object Constructors"); infoStreamPrint(LOG_DEBUG, 0, "call external Object Constructors finished"); } void Test_callExternalObjectDestructors(DATA *data) { if(data->simulationInfo.extObjs) { omc_NativeInterface_destructor(threadData,$Piface); free(data->simulationInfo.extObjs); data->simulationInfo.extObjs = 0; } }
So the destructor is called, the constructor is not.
Attachments (1)
Change History (2)
by , 11 years ago
Attachment: | ExtObj.zip added |
---|
comment:1 by , 11 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
model Test NativeInterface iface(param = "test parameter"); end Test;
Is not how you call the constructor. You should use:
model Test NativeInterface iface = NativeInterface(param = "test parameter"); end Test;
Full file example because omc does not support external objects as a top-level class:
package P class NativeInterface extends ExternalObject; function constructor input String param; output NativeInterface interface; external "C" interface = ctor(param) annotation(Include = "#include \"ExtObj.h\""); end constructor; function destructor input NativeInterface interface; external "C" dtor(interface) annotation(Include = "#include \"ExtObj.h\""); end destructor; end NativeInterface; end P; model Test import P.NativeInterface; parameter NativeInterface iface = NativeInterface(param = "test parameter"); end Test;
Note:
See TracTickets
for help on using tickets.
Testcase that triggers the bug