Skip to content

Returning new instances of a derived type via a virtual factory function fails to keep the derived type alive #1774

Closed
@yeswalrus

Description

@yeswalrus

Given a virtual function meant to return new instances of a type via a pointer to a base class, and a derived type declared in python, the return value cast won't keep the python object alive, resulting in a failure when attempting to call the virtual method on the new instance via the pointer. Because this function is called from c++, the return value policy has no effect.

Reproducible example code

https://github.com/yeswalrus/pybind11/tree/virtual-vector-return

Metadata

Metadata

Assignees

No one assigned

    Labels

    holdersIssues and PRs regarding holders

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions