diff --git a/include/trick/swig/swig_class_typedef.i b/include/trick/swig/swig_class_typedef.i index de549175..07a15165 100644 --- a/include/trick/swig/swig_class_typedef.i +++ b/include/trick/swig/swig_class_typedef.i @@ -51,7 +51,15 @@ // TYPE * void * temp_ptr ; - if ( SWIG_IsOK(SWIG_ConvertPtr($input, &temp_ptr,$1_descriptor, SWIG_POINTER_DISOWN)) ) { + SwigPyObject *sobj = SWIG_Python_GetSwigThis($input) ; + // isDisown is set to SWIG_POINTER_DISOWN by default + int isDisown = SWIG_POINTER_DISOWN ; + if (sobj) { + // isDisown is re-set based on whether the Python processor owns the input object + isDisown = !sobj->own ; + } + + if ( SWIG_IsOK(SWIG_ConvertPtr($input, &temp_ptr,$1_descriptor, isDisown)) ) { $1 = reinterpret_cast< $1_ltype >(temp_ptr) ; } else if ( SWIG_IsOK(SWIG_ConvertPtr($input, &temp_ptr,SWIG_TypeQuery("_p_swig_ref"), 0)) ) { // Array to pointer assignment diff --git a/test/SIM_test_ip/RUN_test/unit_test.py b/test/SIM_test_ip/RUN_test/unit_test.py index 35ecab8d..746fdbe3 100644 --- a/test/SIM_test_ip/RUN_test/unit_test.py +++ b/test/SIM_test_ip/RUN_test/unit_test.py @@ -2781,12 +2781,16 @@ def main(): # Polymorphic assignments and access test_suite = "polymorphism" - test_so.a = trick.Cat() + #test_so.a = trick.Cat() + # use MM to allocate memory for a pointer declared in S_define + test_so.a = trick.TMM_declare_var_s("Cat") TRICK_EXPECT_EQ( test_so.a.id , 1, test_suite , "single abstract ptr" ) trick.trick_test_add_parent( test_suite , "single abstract ptr" , "1770735610") #test_so.a.speak() #test_so.a[0].speak() - test_so.a = trick.Dog() + #test_so.a = trick.Dog() + # use MM to allocate memory for a pointer declared in S_define + test_so.a = trick.TMM_declare_var_s("Dog") TRICK_EXPECT_EQ( test_so.a.id , 2, test_suite , "single abstract ptr" ) test_so.aarray[0] = trick.Cat()