Skip to content

Commit

Permalink
Bugfix PyPushGroup refcount, need to hold a ref around in case it dro…
Browse files Browse the repository at this point in the history
…ps out of scope before engine runtimegym

Signed-off-by: Rob Ambalu <[email protected]>
  • Loading branch information
robambalu committed Jan 6, 2025
1 parent 9b81df9 commit 44b914f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 7 additions & 3 deletions cpp/csp/python/PyPushInputAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ class TypedPyPushInputAdapter : public PyPushInputAdapter
{
public:
TypedPyPushInputAdapter( Engine * engine, AdapterManager * manager, PyObjectPtr pyadapter, PyObject * pyType,
PushMode pushMode, PushGroup * pushGroup ):
PyPushInputAdapter( engine, manager, pyadapter, pyType, pushMode, pushGroup )
PushMode pushMode, PyObjectPtr pyPushGroup, PushGroup * pushGroup ):
PyPushInputAdapter( engine, manager, pyadapter, pyType, pushMode, pushGroup ),
m_pyPushGroup( pyPushGroup )
{
}

Expand All @@ -164,6 +165,9 @@ class TypedPyPushInputAdapter : public PyPushInputAdapter
<< pyTypeToString( m_pyType.ptr() ) << "\" got type \"" << Py_TYPE( value ) -> tp_name << "\"" );
}
}

private:
PyObjectPtr m_pyPushGroup;
};

struct PyPushInputAdapter_PyObject
Expand Down Expand Up @@ -289,7 +293,7 @@ static InputAdapter * pypushinputadapter_creator( csp::AdapterManager * manager,
[&]( auto tag )
{
pyAdapter -> adapter = pyengine -> engine() -> createOwnedObject<TypedPyPushInputAdapter<typename decltype(tag)::type>>(
manager, PyObjectPtr::own( ( PyObject * ) pyAdapter ), pyType, pushMode, pushGroup );
manager, PyObjectPtr::own( ( PyObject * ) pyAdapter ), pyType, pushMode, PyObjectPtr::incref( pyPushGroup ), pushGroup );
} );

return pyAdapter -> adapter;
Expand Down
10 changes: 7 additions & 3 deletions cpp/csp/python/PyPushPullInputAdapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ class TypedPyPushPullInputAdapter : public PyPushPullInputAdapter
{
public:
TypedPyPushPullInputAdapter( Engine * engine, AdapterManager * manager, PyObjectPtr pyadapter, PyObject * pyType,
PushMode pushMode, PushGroup * pushGroup ):
PyPushPullInputAdapter( engine, manager, pyadapter, pyType, pushMode, pushGroup )
PushMode pushMode, PyObjectPtr pyPushGroup, PushGroup * pushGroup ):
PyPushPullInputAdapter( engine, manager, pyadapter, pyType, pushMode, pushGroup ),
m_pyPushGroup( pyPushGroup )
{
}

Expand All @@ -80,6 +81,9 @@ class TypedPyPushPullInputAdapter : public PyPushPullInputAdapter
<< pyTypeToString( m_pyType.ptr() ) << "\" got type \"" << Py_TYPE( value ) -> tp_name << "\"" );
}
}

private:
PyObjectPtr m_pyPushGroup;
};

struct PyPushPullInputAdapter_PyObject
Expand Down Expand Up @@ -208,7 +212,7 @@ static InputAdapter * pypushpullinputadapter_creator( csp::AdapterManager * mana
[&]( auto tag )
{
pyAdapter -> adapter = pyengine -> engine() -> createOwnedObject<TypedPyPushPullInputAdapter<typename decltype(tag)::type>>(
manager, PyObjectPtr::own( ( PyObject * ) pyAdapter ), pyType, pushMode, pushGroup );
manager, PyObjectPtr::own( ( PyObject * ) pyAdapter ), pyType, pushMode, PyObjectPtr::incref( pyPushGroup ), pushGroup );
} );

return pyAdapter -> adapter;
Expand Down

0 comments on commit 44b914f

Please sign in to comment.