Skip to content

Commit 386772c

Browse files
committed
Use PyMem_Calloc for 3.5+
Earlier versions need the malloc + memset to replicated the initialize and set to 0 behaviour.
1 parent 16f30e5 commit 386772c

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

include/pybind11/cast.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,10 +380,14 @@ PYBIND11_NOINLINE inline void instance::allocate_layout() {
380380
space += tinfo->holder_size_in_ptrs;
381381
}
382382

383-
// Allocate space for flags, values, and holders:
383+
// Allocate space for flags, values, and holders; initialize the space to 0 (flags and
384+
// values need to be 0, and it doesn't hurt the holders)
385+
#if PY_VERSION_HEX >= 0x03050000
386+
values_and_holders = (void **) PyMem_Calloc(space, sizeof(void *));
387+
#else
384388
values_and_holders = (void **) PyMem_New(void *, space);
385-
// flags and values need to start out equal to 0; it doesn't hurt the holders
386389
std::memset(values_and_holders, 0, space * sizeof(void *));
390+
#endif
387391
}
388392
owned = true;
389393
}

0 commit comments

Comments
 (0)