Skip to content

Add options to help controll lifetime and return policy #9

@edimetia3d

Description

@edimetia3d

This issue pertains to another complication involving pointers: The management of heap object lifetimes within pybind11 remains somewhat enigmatic.

By default, pybind11 presupposes that the lifespan of all heap objects will be regulated by the Python Garbage Collection system.

Consequently, pybind11 inherently supports only T* and std::unique_ptr<T>. In the case of T*, it is assumed that each pointer references either a newly created or an existing object. Meanwhile, std::unique_ptr<T> is permissible solely as a return type, invariably pointing to a newly instantiated object.

Should your API diverge from this paradigm, extensive coding involving Holder and Call Policy becomes imperative.

Currently, Pybind11-Weaver offers no solutions for managing these lifetimes; thus, if your API deviates from the default configuration of pybind11, the resultant code will also fail to serve your needs, necessitating the crafting of bespoke code to integrate these APIs.

I propose two potential enhancements:

  1. Introduce additional options to enable users to dictate the container type for each class.
  2. Implement support for specific C++ inline comment markers, such as /*return_policy=take_ownership*/, to facilitate accurate call policy determination by pybind11-weaver.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions