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

pyverbs: Memset the memory after posix_memalign #783

Merged
merged 1 commit into from
Jul 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion pyverbs/mem_alloc.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ from posix.stdlib cimport posix_memalign as c_posix_memalign
from libc.stdlib cimport malloc as c_malloc, free as c_free
from posix.mman cimport mmap as c_mmap, munmap as c_munmap
from libc.stdint cimport uintptr_t
from libc.string cimport memset
cimport posix.mman as mm

cdef extern from 'sys/mman.h':
Expand Down Expand Up @@ -58,7 +59,8 @@ def malloc(size):

def posix_memalign(size, alignment=8):
"""
Python wrapper for the stdlib posix_memalign function
Python wrapper for the stdlib posix_memalign function.
The function calls posix_memalign and memsets the memory to 0.
:param size: The size of the memory block in bytes
:param alignment: Alignment of the allocated memory, must be a power of two
:return: The address of the allocated memory, which is a multiple of
Expand All @@ -68,6 +70,7 @@ def posix_memalign(size, alignment=8):
ret = c_posix_memalign(&ptr, alignment, size)
if ret:
raise MemoryError('Failed to allocate memory ({err}'.format(ret))
memset(ptr, 0, size)
return <uintptr_t>ptr


Expand Down