Skip to content

Commit 0eb34a7

Browse files
committed
fix memory leak in rawkernelarg
the __dealloc__ method was missing trailing underscores, so would not be recognized as the deallocator by Cython
1 parent 39b31e6 commit 0eb34a7

1 file changed

Lines changed: 26 additions & 34 deletions

File tree

dpctl/_sycl_queue.pyx

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,9 @@ cdef DPCTLSyclEventRef _memcpy_impl(
488488
src_is_buf = True
489489
else:
490490
raise TypeError(
491-
"Parameter `src` should have either type `dpctl.memory._Memory` "
492-
"or a type that supports Python buffer protocol"
491+
"Parameter `src` should have either type "
492+
"`dpctl.memory._Memory` or a type that "
493+
"supports Python buffer protocol"
493494
)
494495

495496
if isinstance(dst, _Memory):
@@ -507,8 +508,9 @@ cdef DPCTLSyclEventRef _memcpy_impl(
507508
dst_is_buf = True
508509
else:
509510
raise TypeError(
510-
"Parameter `dst` should have either type `dpctl.memory._Memory` "
511-
"or a type that supports Python buffer protocol"
511+
"Parameter `dst` should have either type "
512+
"`dpctl.memory._Memory` or a type that "
513+
"supports Python buffer protocol"
512514
)
513515

514516
if dep_events_count == 0 or dep_events is NULL:
@@ -1590,8 +1592,7 @@ cdef class SyclQueue(_SyclQueue):
15901592
else:
15911593
raise TypeError(
15921594
"dependent_events must either None, or a sequence of "
1593-
"`dpctl.SyclEvent` objects"
1594-
)
1595+
":class:`dpctl.SyclEvent` objects")
15951596
if nDE > 0:
15961597
depEvents = (
15971598
<DPCTLSyclEventRef*>malloc(nDE*sizeof(DPCTLSyclEventRef))
@@ -1702,28 +1703,25 @@ cdef class WorkGroupMemory:
17021703
raise RuntimeError("Workgroup memory extension not available")
17031704

17041705
if not (0 < len(args) < 3):
1705-
raise TypeError(
1706-
"WorkGroupMemory constructor takes 1 or 2 arguments, but "
1707-
f"{len(args)} were given"
1708-
)
1706+
raise TypeError("WorkGroupMemory constructor takes 1 or 2 "
1707+
f"arguments, but {len(args)} were given")
17091708

17101709
if len(args) == 1:
17111710
if not isinstance(args[0], numbers.Integral):
1712-
raise TypeError(
1713-
"WorkGroupMemory single argument constructor expects "
1714-
f"first argument to be `int` but got {type(args[0])}"
1715-
)
1711+
raise TypeError("WorkGroupMemory single argument constructor"
1712+
"expects first argument to be `int`",
1713+
f"but got {type(args[0])}")
17161714
nbytes = <size_t>(args[0])
17171715
else:
17181716
if not isinstance(args[0], str):
17191717
raise TypeError(
1720-
"WorkGroupMemory constructor expects first argument to be "
1721-
f"`str`, but got {type(args[0])}"
1718+
"WorkGroupMemory constructor expects first"
1719+
f"argument to be `str`, but got {type(args[0])}"
17221720
)
17231721
if not isinstance(args[1], numbers.Integral):
17241722
raise TypeError(
1725-
"WorkGroupMemory constructor expects second argument to "
1726-
f"be `int`, but got {type(args[1])}"
1723+
"WorkGroupMemory constructor expects second"
1724+
f"argument to be `int`, but got {type(args[1])}"
17271725
)
17281726
dtype = <str>(args[0])
17291727
count = <size_t>(args[1])
@@ -1753,7 +1751,7 @@ cdef class WorkGroupMemory:
17531751

17541752

17551753
cdef class _RawKernelArg:
1756-
def __dealloc(self):
1754+
def __dealloc__(self):
17571755
if(self._arg_ref):
17581756
DPCTLRawKernelArg_Delete(self._arg_ref)
17591757

@@ -1802,16 +1800,14 @@ cdef class RawKernelArg:
18021800
raise RuntimeError("Raw kernel arg extension not available")
18031801

18041802
if not (0 < len(args) < 3):
1805-
raise TypeError(
1806-
"RawKernelArg constructor takes 1 or 2 arguments, but "
1807-
f"{len(args)} were given"
1808-
)
1803+
raise TypeError("RawKernelArg constructor takes 1 or 2 "
1804+
f"arguments, but {len(args)} were given")
18091805

18101806
if len(args) == 1:
18111807
if not _is_buffer(args[0]):
1812-
raise TypeError(
1813-
"RawKernelArg single argument constructor expects "
1814-
f"argument to be buffer but got {type(args[0])}")
1808+
raise TypeError("RawKernelArg single argument constructor"
1809+
"expects argument to be buffer",
1810+
f"but got {type(args[0])}")
18151811

18161812
ret_code = PyObject_GetBuffer(args[0], &(_buffer),
18171813
PyBUF_SIMPLE | PyBUF_ANY_CONTIGUOUS)
@@ -1823,15 +1819,11 @@ cdef class RawKernelArg:
18231819
_is_buf = True
18241820
else:
18251821
if not isinstance(args[0], numbers.Integral):
1826-
raise TypeError(
1827-
"RawKernelArg constructor expects first argument to be "
1828-
f"`int`, but got {type(args[0])}"
1829-
)
1822+
raise TypeError("RawKernelArg constructor expects first"
1823+
"argument to be `int`, but got {type(args[0])}")
18301824
if not isinstance(args[1], numbers.Integral):
1831-
raise TypeError(
1832-
"RawKernelArg constructor expects second argument to be "
1833-
f"`int`, but got {type(args[1])}"
1834-
)
1825+
raise TypeError("RawKernelArg constructor expects second"
1826+
"argument to be `int`, but got {type(args[1])}")
18351827

18361828
_is_buf = False
18371829
count = args[0]

0 commit comments

Comments
 (0)