Skip to content

Commit 58a4315

Browse files
Move to function_record
1 parent 940cd44 commit 58a4315

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

include/pybind11/attr.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,12 @@ struct argument_record {
185185

186186
/// Internal data structure which holds metadata about a bound function (signature, overloads,
187187
/// etc.)
188+
// Note that function_capsule_name must be updated whenever this struct is changed
188189
struct function_record {
190+
191+
// Update the following whenever this struct is changed
192+
static constexpr const char* function_capsule_name = "pybind11_function_capsule_v1";
193+
189194
function_record()
190195
: is_constructor(false), is_new_style_constructor(false), is_stateless(false),
191196
is_operator(false), is_method(false), has_args(false), has_kwargs(false),

include/pybind11/pybind11.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,11 @@ inline bool apply_exception_translators(std::forward_list<ExceptionTranslator> &
6969
return false;
7070
}
7171

72-
constexpr const char *function_capsule_name = "pybind11_funciton_capsule_v1";
73-
7472
inline bool is_function_record_capsule(const capsule &cap) {
75-
// Compare the pointers, not the values to ensure that each extension is unique
7673
if (cap.name() == nullptr) {
7774
return false;
7875
}
79-
return (std::strcmp(cap.name(), function_capsule_name) == 0);
76+
return (std::strcmp(cap.name(), function_record::function_capsule_name) == 0);
8077
}
8178

8279
#if defined(_MSC_VER)
@@ -513,7 +510,7 @@ class cpp_function : public function {
513510

514511
capsule rec_capsule(unique_rec.release(),
515512
[](void *ptr) { destruct((detail::function_record *) ptr); });
516-
rec_capsule.set_name(detail::function_capsule_name);
513+
rec_capsule.set_name(detail::function_record::function_capsule_name);
517514
guarded_strdup.release();
518515

519516
object scope_module;
@@ -682,7 +679,7 @@ class cpp_function : public function {
682679

683680
/* Iterator over the list of potentially admissible overloads */
684681
const function_record *overloads = reinterpret_cast<function_record *>(
685-
PyCapsule_GetPointer(self, function_capsule_name)),
682+
PyCapsule_GetPointer(self, function_record::function_capsule_name)),
686683
*it = overloads;
687684
assert(overloads != nullptr);
688685

0 commit comments

Comments
 (0)