Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove shared_ptr from Python API #271

Open
ryanmrichard opened this issue Aug 23, 2022 · 1 comment
Open

Remove shared_ptr from Python API #271

ryanmrichard opened this issue Aug 23, 2022 · 1 comment

Comments

@ryanmrichard
Copy link
Member

AFAIK the only way to add a Python module to PluginPlay is via a pattern like:

# Redundant import is issue
from pluginplay import pluginplay
from cppyy.gbl.std import make_shared

class MyModule(pluginplay.ModuleBase):
    def __init__(self):
        super().__init__(self)
        # rest of ctor

    
    def run_(self, inputs, submods):
        # rest of body

mm = pluginplay.ModuleManager()
mm.add_module("module key", make_shared[MyModule]())

# Ideal solution
# (currently doesn't work see #269)
# mm.add_module("module key", MyModule())

#Also fine 
#(currently doesn't work leads to double free or corruption error)
# mm.add_module[MyModule]("module key")

# Alternatively could expose a Python free function to wrap
# calling shared_ptr from Python, e.g.
#pluginplay.add_module(mm, MyModule)
#

Relying on std::shared_ptr is very non-Pythonic and I would suspect users would prefer one of the three suggestions over dealing with std::shared_ptr

@wadejong
Copy link
Contributor

We may be able to wrap this in the pluginplay init.py and do this behind the scenes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants