Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix MSVC compilation error in DEBUG mode due to free macro #253

Merged
merged 1 commit into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading