Skip to content

Commit

Permalink
Updated not to always pass disown flag for swig pointer conversion in…
Browse files Browse the repository at this point in the history
…stead base on "own" value of the input object. (#1690)
  • Loading branch information
hchen99 authored May 23, 2024
1 parent d997759 commit a1d151c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
10 changes: 9 additions & 1 deletion include/trick/swig/swig_class_typedef.i
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions test/SIM_test_ip/RUN_test/unit_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit a1d151c

Please sign in to comment.