Skip to content

Commit

Permalink
Change variable name it to curr_overl to improve readability, add…
Browse files Browse the repository at this point in the history
… `assert()` in the only place where `curr_overl` could become `nullptr`.
  • Loading branch information
Ralf W. Grosse-Kunstleve committed Aug 25, 2023
1 parent 76b8858 commit b00e577
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ class cpp_function : public function {
/* Iterator over the list of potentially admissible overloads */
const function_record *overloads = reinterpret_cast<function_record *>(
PyCapsule_GetPointer(self, get_function_record_capsule_name())),
*it = overloads;
*curr_overl = overloads;
assert(overloads != nullptr);

/* Need to know how many arguments + keyword arguments there are to pick the right
Expand Down Expand Up @@ -757,9 +757,9 @@ class cpp_function : public function {
std::vector<function_call> second_pass;

// However, if there are no overloads, we can just skip the no-convert pass entirely
const bool overloaded = it != nullptr && it->next != nullptr;
const bool overloaded = curr_overl != nullptr && curr_overl->next != nullptr;

for (; it != nullptr; it = it->next) {
for (; curr_overl != nullptr; curr_overl = curr_overl->next) {

/* For each overload:
1. Copy all positional arguments we were given, also checking to make sure that
Expand All @@ -780,7 +780,7 @@ class cpp_function : public function {
a result other than PYBIND11_TRY_NEXT_OVERLOAD.
*/

const function_record &func = *it;
const function_record &func = *curr_overl;
size_t num_args = func.nargs; // Number of positional arguments that we need
if (func.has_args) {
--num_args; // (but don't count py::args
Expand Down Expand Up @@ -1018,10 +1018,11 @@ class cpp_function : public function {
}

if (result.ptr() != PYBIND11_TRY_NEXT_OVERLOAD) {
// The error reporting logic below expects 'it' to be valid, as it would be
// if we'd encountered this failure in the first-pass loop.
// The error reporting logic below expects 'curr_overl' to be valid, as it
// would be if we'd encountered this failure in the first-pass loop.
if (!result) {
it = &call.func;
curr_overl = &call.func;
assert(curr_overl != nullptr);
}
break;
}
Expand Down Expand Up @@ -1168,7 +1169,7 @@ class cpp_function : public function {
if (!result) {
std::string msg = "Unable to convert function return value to a "
"Python type! The signature was\n\t";
msg += it->signature;
msg += curr_overl->signature;
append_note_if_missing_header_is_suspected(msg);
// Attach additional error info to the exception if supported
if (PyErr_Occurred()) {
Expand Down

0 comments on commit b00e577

Please sign in to comment.