Changeset 13908


Ignore:
Timestamp:
Oct 30, 2019 11:15:42 AM (2 weeks ago)
Author:
jwedin
Message:

Merging dev-cw-2613 to trunk. #5863

Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/Compiler/ModelicaCBackEnd/src/jastadd/CCodeGen/CCodeGenGlobals.jrag

    r13099 r13908  
    545545            String strName = v.type().name() + ".destructor";
    546546            FCallable c = getName().lookupFCallable(strName);
    547             str.print(indent, c.funcNameUnderscore(C_SUFFIX_DEF), "(", FExp.global_C(v.nameUnderscore()), ");\n");
     547            str.print(indent, "if (", FExp.global_C(v.nameUnderscore()), " != NULL) {\n");
     548            str.print(p.indent(indent), c.funcNameUnderscore(C_SUFFIX_DEF), "(", FExp.global_C(v.nameUnderscore()), ");\n");
     549            str.print(p.indent(indent), FExp.global_C(v.nameUnderscore()), " = NULL;\n");
     550            str.print(indent, "}");
    548551        }
    549552    }
  • trunk/Compiler/ModelicaCBackEnd/templates/FMIBase/base.c

    r12878 r13908  
    183183}
    184184
    185 int jmi_destruct_external_objs(jmi_t* jmi) {
     185int model_destruct_external_objects(jmi_t* jmi) {
    186186$C_destruct_external_object$
    187187    return 0;
  • trunk/Compiler/ModelicaCBackEnd/test/modelica/CCodeGenGlobalsTests.mo

    r13491 r13908  
    13771377    jmi_extobj_t CCodeGenGlobalsTests_GlobalVariables_GlobalConstantExternalObject1_P_eo1;
    13781378
     1379
    13791380jmi_extobj_t jmi_global_tmp_1(jmi_t* jmi) {
    13801381    JMI_DYNAMIC_INIT()
     
    13891390    return tmp_1;
    13901391}
    1391 
    13921392int model_init_eval_independent_globals_0(jmi_t* jmi) {
    13931393    int ef = 0;
     
    14501450
    14511451
    1452     func_CCodeGenGlobalsTests_GlobalVariables_GlobalConstantExternalObject1_P_EO_destructor_def1(JMI_GLOBAL(CCodeGenGlobalsTests_GlobalVariables_GlobalConstantExternalObject1_P_eo));
     1452    if (JMI_GLOBAL(CCodeGenGlobalsTests_GlobalVariables_GlobalConstantExternalObject1_P_eo) != NULL) {
     1453        func_CCodeGenGlobalsTests_GlobalVariables_GlobalConstantExternalObject1_P_EO_destructor_def1(JMI_GLOBAL(CCodeGenGlobalsTests_GlobalVariables_GlobalConstantExternalObject1_P_eo));
     1454        JMI_GLOBAL(CCodeGenGlobalsTests_GlobalVariables_GlobalConstantExternalObject1_P_eo) = NULL;
     1455    }
    14531456")})));
    14541457end GlobalConstantExternalObject1;
  • trunk/Python/src/tests_jmodelica/files/Modelica/ExtFunctionTests.mo

    r13719 r13908  
    11851185end MultiUse1;
    11861186
     1187model GlobalExtFunctionDestruction
     1188    package P
     1189    record R1
     1190        R2 r2;
     1191    end R1;
     1192    record R2
     1193        Real x;
     1194    end R2;
     1195   
     1196    model EO
     1197        extends ExternalObject;
     1198        function constructor
     1199            input R1 r1;
     1200            output EO eo;
     1201            external "C" eo=eo_constructor_record(r1) annotation(Library="extObjects", Include="#include \"extObjects.h\"");
     1202        end constructor;
     1203        function destructor
     1204            input EO eo;
     1205            external "C" eo_destructor_record(eo) annotation(Library="extObjects", Include="#include \"extObjects.h\"");
     1206        end destructor;
     1207    end EO;
     1208   
     1209    function f
     1210        input EO eo;
     1211        output Real y;
     1212        external "C" y=eo_use_record(eo) annotation(Library="extObjects", Include="#include \"extObjects.h\"");
     1213    end f;
     1214   
     1215    constant EO eo = EO(R1(R2(3)));
     1216    end P;
     1217   
     1218    function f
     1219        input Real x;
     1220        output Real y = x + P.f(P.eo);
     1221    algorithm
     1222    end f;
     1223
     1224    Real y = f(time);
     1225end GlobalExtFunctionDestruction;
     1226
    11871227end ExtFunctionTests;
  • trunk/Python/src/tests_jmodelica/general/test_extfunctions.py

    r13719 r13908  
    312312    def setUpClass(cls):
    313313        SimulationTest.setup_class_base('ExtFunctionTests.mo',
     314            'ExtFunctionTests.GlobalExtFunctionDestruction')
     315
     316    @testattr(stddist_full = True)
     317    def setUp(self):
     318        self.setup_base(start_time=0.0, final_time=0.1, time_step=0.01)
     319        self.run()
     320
     321    @testattr(stddist_full = True)
     322    def test_result(self):
     323        pass #We test that there is no segfault when destroying the FMU object
     324
     325class TestGlobalExternalRecordObj(SimulationTest):
     326    @classmethod
     327    def setUpClass(cls):
     328        SimulationTest.setup_class_base('ExtFunctionTests.mo',
    314329            'ExtFunctionTests.ExtFunctionRecordObj')
    315330
  • trunk/RuntimeLibrary/src

  • trunk/RuntimeLibrary/src/jmi/jmi.c

    r12796 r13908  
    607607
    608608int jmi_destruct_external_objects(jmi_t* jmi) {
    609     return jmi_generic_func(jmi, jmi_destruct_external_objs);
     609    return jmi_generic_func(jmi, model_destruct_external_objects);
    610610}
    611611
  • trunk/RuntimeLibrary/src/jmi/jmi.h

    r11759 r13908  
    512512 * @return Error code.
    513513 */
    514 int jmi_destruct_external_objs(jmi_t* jmi);
     514int model_destruct_external_objects(jmi_t* jmi);
    515515
    516516/**
Note: See TracChangeset for help on using the changeset viewer.