From 3b4b9211924e219b9b0092f08b4a6991c61cbd27 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Sun, 22 Jan 2017 09:23:53 -0500 Subject: [PATCH] Changed keep_alive template arguments from int to size_t Passing a negative value wasn't valid anyway, and moreover this avoids a little bit of extra code to avoid signed/unsigned argument warnings. --- include/pybind11/attr.h | 14 +++++++------- include/pybind11/pybind11.h | 6 +++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/pybind11/attr.h b/include/pybind11/attr.h index c07cd6c9..054ca081 100644 --- a/include/pybind11/attr.h +++ b/include/pybind11/attr.h @@ -42,7 +42,7 @@ template struct base { }; /// Keep patient alive while nurse lives -template struct keep_alive { }; +template struct keep_alive { }; /// Annotation indicating that a class is involved in a multiple inheritance relationship struct multiple_inheritance { }; @@ -69,7 +69,7 @@ struct undefined_t; template struct op_; template struct init; template struct init_alias; -inline void keep_alive_impl(int Nurse, int Patient, function_arguments args, handle ret); +inline void keep_alive_impl(size_t Nurse, size_t Patient, function_arguments args, handle ret); /// Internal data structure which holds metadata about a keyword argument struct argument_record { @@ -360,14 +360,14 @@ struct process_attribute : process_attribute_default {}; * pre-call handler if both Nurse, Patient != 0 and use the post-call handler * otherwise */ -template struct process_attribute> : public process_attribute_default> { - template = 0> +template struct process_attribute> : public process_attribute_default> { + template = 0> static void precall(function_arguments args) { keep_alive_impl(Nurse, Patient, args, handle()); } - template = 0> + template = 0> static void postcall(function_arguments, handle) { } - template = 0> + template = 0> static void precall(function_arguments) { } - template = 0> + template = 0> static void postcall(function_arguments args, handle ret) { keep_alive_impl(Nurse, Patient, args, ret); } }; diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index dc21caf6..a23ea702 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -1494,10 +1494,10 @@ inline void keep_alive_impl(handle nurse, handle patient) { (void) wr.release(); } -PYBIND11_NOINLINE inline void keep_alive_impl(int Nurse, int Patient, function_arguments args, handle ret) { +PYBIND11_NOINLINE inline void keep_alive_impl(size_t Nurse, size_t Patient, function_arguments args, handle ret) { keep_alive_impl( - Nurse == 0 ? ret : Nurse > 0 && (size_t) Nurse <= args.size() ? args[Nurse - 1] : handle(), - Patient == 0 ? ret : Patient > 0 && (size_t) Patient <= args.size() ? args[Patient - 1] : handle() + Nurse == 0 ? ret : Nurse <= args.size() ? args[Nurse - 1] : handle(), + Patient == 0 ? ret : Patient <= args.size() ? args[Patient - 1] : handle() ); }