mirror of
https://github.com/pybind/pybind11.git
synced 2026-05-13 09:46:10 +00:00
Merge branch 'master' into sh_merge_master
This commit is contained in:
@@ -26,6 +26,9 @@ struct is_method {
|
||||
explicit is_method(const handle &c) : class_(c) {}
|
||||
};
|
||||
|
||||
/// Annotation for setters
|
||||
struct is_setter {};
|
||||
|
||||
/// Annotation for operators
|
||||
struct is_operator {};
|
||||
|
||||
@@ -188,8 +191,8 @@ struct argument_record {
|
||||
struct function_record {
|
||||
function_record()
|
||||
: is_constructor(false), is_new_style_constructor(false), is_stateless(false),
|
||||
is_operator(false), is_method(false), has_args(false), has_kwargs(false),
|
||||
prepend(false) {}
|
||||
is_operator(false), is_method(false), is_setter(false), has_args(false),
|
||||
has_kwargs(false), prepend(false) {}
|
||||
|
||||
/// Function name
|
||||
char *name = nullptr; /* why no C++ strings? They generate heavier code.. */
|
||||
@@ -230,6 +233,9 @@ struct function_record {
|
||||
/// True if this is a method
|
||||
bool is_method : 1;
|
||||
|
||||
/// True if this is a setter
|
||||
bool is_setter : 1;
|
||||
|
||||
/// True if the function has a '*args' argument
|
||||
bool has_args : 1;
|
||||
|
||||
@@ -426,6 +432,12 @@ struct process_attribute<is_method> : process_attribute_default<is_method> {
|
||||
}
|
||||
};
|
||||
|
||||
/// Process an attribute which indicates that this function is a setter
|
||||
template <>
|
||||
struct process_attribute<is_setter> : process_attribute_default<is_setter> {
|
||||
static void init(const is_setter &, function_record *r) { r->is_setter = true; }
|
||||
};
|
||||
|
||||
/// Process an attribute which indicates the parent scope of a method
|
||||
template <>
|
||||
struct process_attribute<scope> : process_attribute_default<scope> {
|
||||
|
||||
@@ -85,6 +85,7 @@ public:
|
||||
cpp_function() = default;
|
||||
// NOLINTNEXTLINE(google-explicit-constructor)
|
||||
cpp_function(std::nullptr_t) {}
|
||||
cpp_function(std::nullptr_t, const is_setter &) {}
|
||||
|
||||
/// Construct a cpp_function from a vanilla function pointer
|
||||
template <typename Return, typename... Args, typename... Extra>
|
||||
@@ -245,10 +246,16 @@ protected:
|
||||
using Guard = extract_guard_t<Extra...>;
|
||||
|
||||
/* Perform the function call */
|
||||
handle result
|
||||
= cast_out::cast(std::move(args_converter).template call<Return, Guard>(cap->f),
|
||||
policy,
|
||||
call.parent);
|
||||
handle result;
|
||||
if (call.func.is_setter) {
|
||||
(void) std::move(args_converter).template call<Return, Guard>(cap->f);
|
||||
result = none().release();
|
||||
} else {
|
||||
result = cast_out::cast(
|
||||
std::move(args_converter).template call<Return, Guard>(cap->f),
|
||||
policy,
|
||||
call.parent);
|
||||
}
|
||||
|
||||
/* Invoke call policy post-call hook */
|
||||
process_attributes<Extra...>::postcall(call, result);
|
||||
@@ -1968,7 +1975,8 @@ public:
|
||||
template <typename Getter, typename Setter, typename... Extra>
|
||||
class_ &
|
||||
def_property(const char *name, const Getter &fget, const Setter &fset, const Extra &...extra) {
|
||||
return def_property(name, fget, cpp_function(method_adaptor<type>(fset)), extra...);
|
||||
return def_property(
|
||||
name, fget, cpp_function(method_adaptor<type>(fset), is_setter()), extra...);
|
||||
}
|
||||
template <typename Getter, typename... Extra>
|
||||
class_ &def_property(const char *name,
|
||||
|
||||
Reference in New Issue
Block a user