Skip to content

Commit

Permalink
fix compilation error with MSVC in DEBUG mode due to macro "free" bei…
Browse files Browse the repository at this point in the history
…ng defined as "_free_dbg"
  • Loading branch information
polyvertex committed Aug 8, 2023
1 parent 3f57b04 commit d2edf9e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions include/nanobind/nb_attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ enum class func_flags : uint32_t {
is_implicit = (1 << 12),
/// Is this function an arithmetic operator?
is_operator = (1 << 13),
/// When the function is GCed, do we need to call func_data_prelim::free?
/// When the function is GCed, do we need to call func_data_prelim::free_capture?
has_free = (1 << 14),
/// Should the func_new() call return a new reference?
return_ref = (1 << 15),
Expand All @@ -129,7 +129,7 @@ template <size_t Size> struct func_data_prelim {
void *capture[3];

// Callback to clean up the 'capture' field
void (*free)(void *);
void (*free_capture)(void *);

/// Implementation of the function call
PyObject *(*impl)(void *, PyObject **, uint8_t *, rv_policy,
Expand Down
4 changes: 2 additions & 2 deletions include/nanobind/nb_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ NB_INLINE PyObject *func_create(Func &&func, Return (*)(Args...),

if constexpr (!std::is_trivially_destructible_v<capture>) {
f.flags |= (uint32_t) func_flags::has_free;
f.free = [](void *p) {
f.free_capture = [](void *p) {
((capture *) p)->~capture();
};
}
Expand All @@ -97,7 +97,7 @@ NB_INLINE PyObject *func_create(Func &&func, Return (*)(Args...),
cap[0] = new capture{ (forward_t<Func>) func };

f.flags |= (uint32_t) func_flags::has_free;
f.free = [](void *p) {
f.free_capture = [](void *p) {
delete (capture *) ((void **) p)[0];
};
}
Expand Down
2 changes: 1 addition & 1 deletion src/nb_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void nb_func_dealloc(PyObject *self) {

for (size_t i = 0; i < size; ++i) {
if (f->flags & (uint32_t) func_flags::has_free)
f->free(f->capture);
f->free_capture(f->capture);

if (f->flags & (uint32_t) func_flags::has_args) {
for (size_t j = 0; j < f->nargs; ++j) {
Expand Down

0 comments on commit d2edf9e

Please sign in to comment.