-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
61 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#include "pybind11_tests.h" | ||
|
||
namespace test_type_caster_incomplete_type { | ||
|
||
struct ForwardDeclaredType {}; | ||
|
||
} // namespace test_type_caster_incomplete_type | ||
|
||
using ForwardDeclaredType = test_type_caster_incomplete_type::ForwardDeclaredType; | ||
|
||
// TODO: Move to pybind11/type_caster_incomplete_type.h, wrap in a macro. | ||
namespace pybind11 { | ||
namespace detail { | ||
|
||
template <> | ||
class type_caster<ForwardDeclaredType> { | ||
public: | ||
static constexpr auto name = const_name("object"); | ||
|
||
static handle cast(ForwardDeclaredType * /*src*/, | ||
return_value_policy /*policy*/, | ||
handle /*parent*/) { | ||
return py::none().release(); // TODO: Build and return capsule with src pointer; | ||
} | ||
|
||
bool load(handle /*src*/, bool /*convert*/) { | ||
// TODO: Assign pointer_capsule = src after inspecting src. | ||
return true; | ||
} | ||
|
||
template <typename T> | ||
using cast_op_type = ForwardDeclaredType *; | ||
|
||
explicit operator ForwardDeclaredType *() { | ||
return nullptr; // TODO: Retrieve C++ pointer from pointer_capsule. | ||
} | ||
|
||
private: | ||
capsule pointer_capsule; | ||
}; | ||
|
||
} // namespace detail | ||
} // namespace pybind11 | ||
|
||
TEST_SUBMODULE(type_caster_incomplete_type, m) { | ||
m.def("rtrn_fwd_decl_type_ptr", | ||
[]() { return reinterpret_cast<ForwardDeclaredType *>(0); }); | ||
m.def("pass_fwd_decl_type_ptr", [](ForwardDeclaredType *) {}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from __future__ import annotations | ||
|
||
from pybind11_tests import type_caster_incomplete_type as m | ||
|
||
|
||
def test_rtrn_fwd_decl_type_ptr(): | ||
assert m.rtrn_fwd_decl_type_ptr() is None | ||
|
||
|
||
def test_pass_fwd_decl_type_ptr(): | ||
assert m.pass_fwd_decl_type_ptr(None) is None |