Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
044056a1
Commit
044056a1
authored
Feb 23, 2021
by
Ralf W. Grosse-Kunstleve
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix after rebase
parent
a886a567
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
98 additions
and
13 deletions
+98
-13
CMakeLists.txt
+1
-1
include/pybind11/cast.h
+0
-0
include/pybind11/detail/is_smart_holder_type_caster.h
+29
-0
include/pybind11/detail/smart_holder_init_inline_include.h
+6
-4
include/pybind11/detail/smart_holder_type_casters.h
+41
-3
include/pybind11/pybind11.h
+19
-1
include/pybind11/smart_holder.h
+1
-0
tests/class_sh_module_local_0.cpp
+0
-1
tests/class_sh_module_local_1.cpp
+0
-1
tests/class_sh_module_local_2.cpp
+0
-1
tests/extra_python_package/test_files.py
+1
-1
No files found.
CMakeLists.txt
View file @
044056a1
...
@@ -107,7 +107,7 @@ set(PYBIND11_HEADERS
...
@@ -107,7 +107,7 @@ set(PYBIND11_HEADERS
include/pybind11/detail/internals.h
include/pybind11/detail/internals.h
include/pybind11/detail/smart_holder_init_inline_include.h
include/pybind11/detail/smart_holder_init_inline_include.h
include/pybind11/detail/smart_holder_poc.h
include/pybind11/detail/smart_holder_poc.h
include/pybind11/detail/smart_holder_type_casters
_inline_include
.h
include/pybind11/detail/smart_holder_type_casters.h
include/pybind11/detail/typeid.h
include/pybind11/detail/typeid.h
include/pybind11/attr.h
include/pybind11/attr.h
include/pybind11/buffer_info.h
include/pybind11/buffer_info.h
...
...
include/pybind11/cast.h
View file @
044056a1
This diff is collapsed.
Click to expand it.
include/pybind11/detail/is_smart_holder_type_caster.h
0 → 100644
View file @
044056a1
#pragma once
#include "common.h"
#include <type_traits>
#ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
// #define PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
// Currently the main purpose of this switch is to enable non-intrusive comprehensive testing. If
// and when `smart_holder` will actually become the released default is currently open. In the
// meantime, the full functionality is easily available by using `py::classh`, which is just a
// handy shortcut for `py::class_<T, py::smart_holder>` (see `pybind11/smart_holder.h`). Classes
// wrapped in this way are fully compatible with everything existing.
#endif
PYBIND11_NAMESPACE_BEGIN
(
PYBIND11_NAMESPACE
)
PYBIND11_NAMESPACE_BEGIN
(
detail
)
template
<
typename
T
>
struct
is_smart_holder_type
:
std
::
false_type
{};
// Tag to be used as base class, inspected by is_smart_holder_type_caster<T> test.
struct
is_smart_holder_type_caster_base_tag
{};
template
<
typename
T
>
struct
is_smart_holder_type_caster
;
PYBIND11_NAMESPACE_END
(
detail
)
PYBIND11_NAMESPACE_END
(
PYBIND11_NAMESPACE
)
include/pybind11/detail/smart_holder_init_inline_include.h
View file @
044056a1
...
@@ -11,7 +11,8 @@ void construct(value_and_holder &v_h, std::unique_ptr<Cpp<Class>, D> &&unq_ptr,
...
@@ -11,7 +11,8 @@ void construct(value_and_holder &v_h, std::unique_ptr<Cpp<Class>, D> &&unq_ptr,
if
(
Class
::
has_alias
&&
need_alias
)
if
(
Class
::
has_alias
&&
need_alias
)
throw
type_error
(
"pybind11::init(): construction failed: returned std::unique_ptr pointee "
throw
type_error
(
"pybind11::init(): construction failed: returned std::unique_ptr pointee "
"is not an alias instance"
);
"is not an alias instance"
);
auto
smhldr
=
smart_holder
::
from_unique_ptr
(
std
::
move
(
unq_ptr
));
auto
smhldr
=
type_caster
<
Cpp
<
Class
>>::
template
smart_holder_from_unique_ptr
(
std
::
move
(
unq_ptr
));
v_h
.
value_ptr
()
=
ptr
;
v_h
.
value_ptr
()
=
ptr
;
v_h
.
type
->
init_instance
(
v_h
.
inst
,
&
smhldr
);
v_h
.
type
->
init_instance
(
v_h
.
inst
,
&
smhldr
);
}
}
...
@@ -24,7 +25,8 @@ void construct(value_and_holder &v_h,
...
@@ -24,7 +25,8 @@ void construct(value_and_holder &v_h,
bool
/*need_alias*/
)
{
bool
/*need_alias*/
)
{
auto
*
ptr
=
unq_ptr
.
get
();
auto
*
ptr
=
unq_ptr
.
get
();
no_nullptr
(
ptr
);
no_nullptr
(
ptr
);
auto
smhldr
=
smart_holder
::
from_unique_ptr
(
std
::
move
(
unq_ptr
));
auto
smhldr
=
type_caster
<
Alias
<
Class
>>::
template
smart_holder_from_unique_ptr
(
std
::
move
(
unq_ptr
));
v_h
.
value_ptr
()
=
ptr
;
v_h
.
value_ptr
()
=
ptr
;
v_h
.
type
->
init_instance
(
v_h
.
inst
,
&
smhldr
);
v_h
.
type
->
init_instance
(
v_h
.
inst
,
&
smhldr
);
}
}
...
@@ -37,7 +39,7 @@ void construct(value_and_holder &v_h, std::shared_ptr<Cpp<Class>> &&shd_ptr, boo
...
@@ -37,7 +39,7 @@ void construct(value_and_holder &v_h, std::shared_ptr<Cpp<Class>> &&shd_ptr, boo
if
(
Class
::
has_alias
&&
need_alias
)
if
(
Class
::
has_alias
&&
need_alias
)
throw
type_error
(
"pybind11::init(): construction failed: returned std::shared_ptr pointee "
throw
type_error
(
"pybind11::init(): construction failed: returned std::shared_ptr pointee "
"is not an alias instance"
);
"is not an alias instance"
);
auto
smhldr
=
smart_holder
::
from_shared_ptr
(
std
::
move
(
shd_ptr
)
);
auto
smhldr
=
type_caster
<
Cpp
<
Class
>>::
template
smart_holder_from_shared_ptr
(
shd_ptr
);
v_h
.
value_ptr
()
=
ptr
;
v_h
.
value_ptr
()
=
ptr
;
v_h
.
type
->
init_instance
(
v_h
.
inst
,
&
smhldr
);
v_h
.
type
->
init_instance
(
v_h
.
inst
,
&
smhldr
);
}
}
...
@@ -49,7 +51,7 @@ void construct(value_and_holder &v_h,
...
@@ -49,7 +51,7 @@ void construct(value_and_holder &v_h,
bool
/*need_alias*/
)
{
bool
/*need_alias*/
)
{
auto
*
ptr
=
shd_ptr
.
get
();
auto
*
ptr
=
shd_ptr
.
get
();
no_nullptr
(
ptr
);
no_nullptr
(
ptr
);
auto
smhldr
=
smart_holder
::
from_shared_ptr
(
std
::
move
(
shd_ptr
)
);
auto
smhldr
=
type_caster
<
Alias
<
Class
>>::
template
smart_holder_from_shared_ptr
(
shd_ptr
);
v_h
.
value_ptr
()
=
ptr
;
v_h
.
value_ptr
()
=
ptr
;
v_h
.
type
->
init_instance
(
v_h
.
inst
,
&
smhldr
);
v_h
.
type
->
init_instance
(
v_h
.
inst
,
&
smhldr
);
}
}
include/pybind11/detail/smart_holder_type_casters
_inline_include
.h
→
include/pybind11/detail/smart_holder_type_casters.h
View file @
044056a1
#ifndef PYBIND11_CAST_H_SMART_HOLDER_TYPE_CASTERS_INLINE_INCLUDE_SAFETY_GUARD
#pragma once
# error "THIS FILE MUST ONLY BE INCLUDED FROM pybind11/cast.h"
#define PYBIND11_SMART_HOLDER_TYPE_CASTERS_H_IS_INCLUDED
#endif
#include "is_smart_holder_type_caster.h"
#include "smart_holder_poc.h"
#include "smart_holder_poc.h"
#include "type_caster_base.h"
PYBIND11_NAMESPACE_BEGIN
(
PYBIND11_NAMESPACE
)
PYBIND11_NAMESPACE_BEGIN
(
PYBIND11_NAMESPACE
)
...
@@ -10,6 +11,9 @@ using pybindit::memory::smart_holder;
...
@@ -10,6 +11,9 @@ using pybindit::memory::smart_holder;
PYBIND11_NAMESPACE_BEGIN
(
detail
)
PYBIND11_NAMESPACE_BEGIN
(
detail
)
template
<>
struct
is_smart_holder_type
<
smart_holder
>
:
std
::
true_type
{};
// SMART_HOLDER_WIP: Needs refactoring of existing pybind11 code.
// SMART_HOLDER_WIP: Needs refactoring of existing pybind11 code.
inline
void
register_instance
(
instance
*
self
,
void
*
valptr
,
const
type_info
*
tinfo
);
inline
void
register_instance
(
instance
*
self
,
void
*
valptr
,
const
type_info
*
tinfo
);
inline
bool
deregister_instance
(
instance
*
self
,
void
*
valptr
,
const
type_info
*
tinfo
);
inline
bool
deregister_instance
(
instance
*
self
,
void
*
valptr
,
const
type_info
*
tinfo
);
...
@@ -266,6 +270,16 @@ struct smart_holder_type_caster_class_hooks : is_smart_holder_type_caster_base_t
...
@@ -266,6 +270,16 @@ struct smart_holder_type_caster_class_hooks : is_smart_holder_type_caster_base_t
}
}
v_h
.
set_holder_constructed
();
v_h
.
set_holder_constructed
();
}
}
template
<
typename
T
,
typename
D
>
static
smart_holder
smart_holder_from_unique_ptr
(
std
::
unique_ptr
<
T
,
D
>
&&
unq_ptr
)
{
return
pybindit
::
memory
::
smart_holder
::
from_unique_ptr
(
std
::
move
(
unq_ptr
));
}
template
<
typename
T
>
static
smart_holder
smart_holder_from_shared_ptr
(
std
::
shared_ptr
<
T
>
shd_ptr
)
{
return
pybindit
::
memory
::
smart_holder
::
from_shared_ptr
(
shd_ptr
);
}
};
};
template
<
typename
T
>
template
<
typename
T
>
...
@@ -668,6 +682,7 @@ struct smart_holder_type_caster<std::unique_ptr<T const, D>>
...
@@ -668,6 +682,7 @@ struct smart_holder_type_caster<std::unique_ptr<T const, D>>
};
};
#ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
#ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
# define PYBIND11_SMART_HOLDER_TYPE_CASTERS(T) \
# define PYBIND11_SMART_HOLDER_TYPE_CASTERS(T) \
namespace pybind11 { \
namespace pybind11 { \
namespace detail { \
namespace detail { \
...
@@ -687,6 +702,29 @@ struct smart_holder_type_caster<std::unique_ptr<T const, D>>
...
@@ -687,6 +702,29 @@ struct smart_holder_type_caster<std::unique_ptr<T const, D>>
: public smart_holder_type_caster<std::unique_ptr<T const, D>> {}; \
: public smart_holder_type_caster<std::unique_ptr<T const, D>> {}; \
} \
} \
}
}
#else
# define PYBIND11_SMART_HOLDER_TYPE_CASTERS(T)
template
<
typename
T
>
class
type_caster_for_class_
:
public
smart_holder_type_caster
<
T
>
{};
template
<
typename
T
>
class
type_caster_for_class_
<
std
::
shared_ptr
<
T
>>
:
public
smart_holder_type_caster
<
std
::
shared_ptr
<
T
>>
{};
template
<
typename
T
>
class
type_caster_for_class_
<
std
::
shared_ptr
<
T
const
>>
:
public
smart_holder_type_caster
<
std
::
shared_ptr
<
T
const
>>
{};
template
<
typename
T
,
typename
D
>
class
type_caster_for_class_
<
std
::
unique_ptr
<
T
,
D
>>
:
public
smart_holder_type_caster
<
std
::
unique_ptr
<
T
,
D
>>
{};
template
<
typename
T
,
typename
D
>
class
type_caster_for_class_
<
std
::
unique_ptr
<
T
const
,
D
>>
:
public
smart_holder_type_caster
<
std
::
unique_ptr
<
T
const
,
D
>>
{};
#endif
#endif
PYBIND11_NAMESPACE_END
(
detail
)
PYBIND11_NAMESPACE_END
(
detail
)
...
...
include/pybind11/pybind11.h
View file @
044056a1
...
@@ -1245,9 +1245,27 @@ auto method_adaptor(Return (Class::*pmf)(Args...) const) -> Return (Derived::*)(
...
@@ -1245,9 +1245,27 @@ auto method_adaptor(Return (Class::*pmf)(Args...) const) -> Return (Derived::*)(
// clang-format on
// clang-format on
template
<
typename
T
>
template
<
typename
T
>
#ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
#ifndef PYBIND11_USE_SMART_HOLDER_AS_DEFAULT
using
default_holder_type
=
std
::
unique_ptr
<
T
>
;
using
default_holder_type
=
std
::
unique_ptr
<
T
>
;
# define PYBIND11_SMART_POINTER_HOLDER_TYPE_CASTERS(T, ...)
#else
#else
using
default_holder_type
=
smart_holder
;
using
default_holder_type
=
smart_holder
;
// This define could be hidden away inside detail/smart_holder_type_casters.h, but is kept here
// for clarity.
# define PYBIND11_SMART_POINTER_HOLDER_TYPE_CASTERS(T, ...) \
namespace pybind11 { \
namespace detail { \
template <> \
class type_caster<T> : public type_caster_base<T> {}; \
template <> \
class type_caster<__VA_ARGS__> : public type_caster_holder<T, __VA_ARGS__> {}; \
} \
}
#endif
#endif
// clang-format off
// clang-format off
...
@@ -1294,7 +1312,7 @@ public:
...
@@ -1294,7 +1312,7 @@ public:
// clang-format on
// clang-format on
static
constexpr
bool
holder_is_smart_holder
static
constexpr
bool
holder_is_smart_holder
=
std
::
is_same
<
holder_type
,
smart_holder
>::
value
;
=
detail
::
is_smart_holder_type
<
holder_type
>::
value
;
static
constexpr
bool
type_caster_type_is_smart_holder_type_caster
static
constexpr
bool
type_caster_type_is_smart_holder_type_caster
=
detail
::
is_smart_holder_type_caster
<
type
>::
value
;
=
detail
::
is_smart_holder_type_caster
<
type
>::
value
;
static
constexpr
bool
type_caster_type_is_type_caster_base_subtype
static
constexpr
bool
type_caster_type_is_type_caster_base_subtype
...
...
include/pybind11/smart_holder.h
View file @
044056a1
...
@@ -4,6 +4,7 @@
...
@@ -4,6 +4,7 @@
#pragma once
#pragma once
#include "detail/smart_holder_type_casters.h"
#include "pybind11.h"
#include "pybind11.h"
PYBIND11_NAMESPACE_BEGIN
(
PYBIND11_NAMESPACE
)
PYBIND11_NAMESPACE_BEGIN
(
PYBIND11_NAMESPACE
)
...
...
tests/class_sh_module_local_0.cpp
View file @
044056a1
#include <pybind11/pybind11.h>
#include <pybind11/smart_holder.h>
#include <pybind11/smart_holder.h>
#include <string>
#include <string>
...
...
tests/class_sh_module_local_1.cpp
View file @
044056a1
// Identical to class_sh_module_local_2.cpp, except 2 replaced with 1.
// Identical to class_sh_module_local_2.cpp, except 2 replaced with 1.
#include <pybind11/pybind11.h>
#include <pybind11/smart_holder.h>
#include <pybind11/smart_holder.h>
#include <string>
#include <string>
...
...
tests/class_sh_module_local_2.cpp
View file @
044056a1
// Identical to class_sh_module_local_1.cpp, except 1 replaced with 2.
// Identical to class_sh_module_local_1.cpp, except 1 replaced with 2.
#include <pybind11/pybind11.h>
#include <pybind11/smart_holder.h>
#include <pybind11/smart_holder.h>
#include <string>
#include <string>
...
...
tests/extra_python_package/test_files.py
View file @
044056a1
...
@@ -45,7 +45,7 @@ detail_headers = {
...
@@ -45,7 +45,7 @@ detail_headers = {
"include/pybind11/detail/internals.h"
,
"include/pybind11/detail/internals.h"
,
"include/pybind11/detail/smart_holder_init_inline_include.h"
,
"include/pybind11/detail/smart_holder_init_inline_include.h"
,
"include/pybind11/detail/smart_holder_poc.h"
,
"include/pybind11/detail/smart_holder_poc.h"
,
"include/pybind11/detail/smart_holder_type_casters
_inline_include
.h"
,
"include/pybind11/detail/smart_holder_type_casters.h"
,
"include/pybind11/detail/typeid.h"
,
"include/pybind11/detail/typeid.h"
,
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment