Skip to content

Commit a1d151c

Browse files
authored
Updated not to always pass disown flag for swig pointer conversion instead base on "own" value of the input object. (#1690)
1 parent d997759 commit a1d151c

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

include/trick/swig/swig_class_typedef.i

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@
5151
// TYPE *
5252
void * temp_ptr ;
5353

54-
if ( SWIG_IsOK(SWIG_ConvertPtr($input, &temp_ptr,$1_descriptor, SWIG_POINTER_DISOWN)) ) {
54+
SwigPyObject *sobj = SWIG_Python_GetSwigThis($input) ;
55+
// isDisown is set to SWIG_POINTER_DISOWN by default
56+
int isDisown = SWIG_POINTER_DISOWN ;
57+
if (sobj) {
58+
// isDisown is re-set based on whether the Python processor owns the input object
59+
isDisown = !sobj->own ;
60+
}
61+
62+
if ( SWIG_IsOK(SWIG_ConvertPtr($input, &temp_ptr,$1_descriptor, isDisown)) ) {
5563
$1 = reinterpret_cast< $1_ltype >(temp_ptr) ;
5664
} else if ( SWIG_IsOK(SWIG_ConvertPtr($input, &temp_ptr,SWIG_TypeQuery("_p_swig_ref"), 0)) ) {
5765
// Array to pointer assignment

test/SIM_test_ip/RUN_test/unit_test.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2781,12 +2781,16 @@ def main():
27812781
# Polymorphic assignments and access
27822782
test_suite = "polymorphism"
27832783

2784-
test_so.a = trick.Cat()
2784+
#test_so.a = trick.Cat()
2785+
# use MM to allocate memory for a pointer declared in S_define
2786+
test_so.a = trick.TMM_declare_var_s("Cat")
27852787
TRICK_EXPECT_EQ( test_so.a.id , 1, test_suite , "single abstract ptr" )
27862788
trick.trick_test_add_parent( test_suite , "single abstract ptr" , "1770735610")
27872789
#test_so.a.speak()
27882790
#test_so.a[0].speak()
2789-
test_so.a = trick.Dog()
2791+
#test_so.a = trick.Dog()
2792+
# use MM to allocate memory for a pointer declared in S_define
2793+
test_so.a = trick.TMM_declare_var_s("Dog")
27902794
TRICK_EXPECT_EQ( test_so.a.id , 2, test_suite , "single abstract ptr" )
27912795

27922796
test_so.aarray[0] = trick.Cat()

0 commit comments

Comments
 (0)