Skip to content

Commit 64feee6

Browse files
committed
fix(cuda.bindings): accept ints in handle-array setters under Cython 3.3
Cython 3.3 enforces declared list item types at runtime. The pArray setters on CUeglFrame.frame and cudaEglFrame.frame were annotated as list[CUarray] / list[cudaArray_t], so passing plain ints raised TypeError. The fix is a generator change (cybind !621, cython_gen): widen the annotation to list[CUarray | int] / list[cudaArray_t | int]. The setter body already converts each element with int() before casting, so accepting plain ints was always safe; the annotation was just narrower than the implementation. Generated files updated from cybind branch accept-int-handle-arrays (da353763) against CTK 12.9 (cuda_bindings_12) and 13.5 (cuda_bindings_13). Seals recomputed. Test workarounds that wrapped plain ints in handle objects are reverted to their original plain-int form.
1 parent 79ecfe4 commit 64feee6

8 files changed

Lines changed: 16 additions & 16 deletions

File tree

‎cuda_bindings_12/cuda/bindings/driver.pyx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
# This code was automatically generated with version 12.9.0. Do not modify it directly.
5-
# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=7bd998915de52155f2e27696c9a4d514071b9c721d94e05f0a00c7a07394a961
5+
# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=bf8e1dce0f71d6b31a55d614b637bd33dc8c7c6a411c30404c41ac3b8c018e96
66
from typing import Any, Optional
77
import cython
88
import ctypes
@@ -22422,7 +22422,7 @@ cdef class anon_union15:
2242222422
def pArray(self):
2242322423
return [CUarray(init_value=<void_ptr>_pArray) for _pArray in self._pvt_ptr[0].frame.pArray]
2242422424
@pArray.setter
22425-
def pArray(self, pArray : list[CUarray]):
22425+
def pArray(self, pArray : list[CUarray | int]):
2242622426
if len(pArray) != 3:
2242722427
raise IndexError('not enough values found during array assignment, expected 3, got', len(pArray))
2242822428
pArray = [int(_pArray) for _pArray in pArray]

‎cuda_bindings_12/cuda/bindings/runtime.pyx.in‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
# This code was automatically generated with version 12.9.0. Do not modify it directly.
5-
# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=e8e09d2b9dc5c50f5e7a6d85f94bd57c0c0776668393328be79deebdefce1c11
5+
# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=c52a25ba8511a913611475923d9095ece16701fd06230a108878839bdf372687
66
from typing import Any, Optional
77
import cython
88
import ctypes
@@ -18808,7 +18808,7 @@ cdef class anon_union11:
1880818808
def pArray(self):
1880918809
return [cudaArray_t(init_value=<void_ptr>_pArray) for _pArray in self._pvt_ptr[0].frame.pArray]
1881018810
@pArray.setter
18811-
def pArray(self, pArray : list[cudaArray_t]):
18811+
def pArray(self, pArray : list[cudaArray_t | int]):
1881218812
if len(pArray) != 3:
1881318813
raise IndexError('not enough values found during array assignment, expected 3, got', len(pArray))
1881418814
pArray = [int(_pArray) for _pArray in pArray]

‎cuda_bindings_12/tests/test_cuda.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -863,12 +863,12 @@ def test_eglFrame():
863863
assert int(val.frame.pArray[0]) == 0
864864
assert int(val.frame.pArray[1]) == 0
865865
assert int(val.frame.pArray[2]) == 0
866-
val.frame.pArray = [cuda.CUarray(x) for x in (1, 2, 3)]
866+
val.frame.pArray = [1, 2, 3]
867867
# [<CUarray 0x1>, <CUarray 0x2>, <CUarray 0x3>]
868868
assert int(val.frame.pArray[0]) == 1
869869
assert int(val.frame.pArray[1]) == 2
870870
assert int(val.frame.pArray[2]) == 3
871-
val.frame.pArray = [cuda.CUarray(x) for x in (4, 2, 3)]
871+
val.frame.pArray = [cuda.CUarray(4), 2, 3]
872872
# [<CUarray 0x4>, <CUarray 0x2>, <CUarray 0x3>]
873873
assert int(val.frame.pArray[0]) == 4
874874
assert int(val.frame.pArray[1]) == 2

‎cuda_bindings_12/tests/test_cudart.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,12 +1194,12 @@ def test_cudart_eglFrame():
11941194
assert int(frame.frame.pArray[0]) == 0
11951195
assert int(frame.frame.pArray[1]) == 0
11961196
assert int(frame.frame.pArray[2]) == 0
1197-
frame.frame.pArray = [cudart.cudaArray_t(x) for x in (1, 2, 3)]
1197+
frame.frame.pArray = [1, 2, 3]
11981198
# [<cudaArray_t 0x1>, <cudaArray_t 0x2>, <cudaArray_t 0x3>]
11991199
assert int(frame.frame.pArray[0]) == 1
12001200
assert int(frame.frame.pArray[1]) == 2
12011201
assert int(frame.frame.pArray[2]) == 3
1202-
frame.frame.pArray = [cudart.cudaArray_t(x) for x in (1, 2, 4)]
1202+
frame.frame.pArray = [1, 2, cudart.cudaArray_t(4)]
12031203
# [<cudaArray_t 0x1>, <cudaArray_t 0x2>, <cudaArray_t 0x4>]
12041204
assert int(frame.frame.pArray[0]) == 1
12051205
assert int(frame.frame.pArray[1]) == 2

‎cuda_bindings_13/cuda/bindings/driver.pyx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
# This code was automatically generated with version 13.5.0. Do not modify it directly.
5-
# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=31ee6b840352a46ffa3e1fe1c52799ecf357ffc86e8ecfe2a6b73590006e86ea
5+
# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=a9861cd2390709aa722c402deb710e0b922d2ac7cf483a2208a997a00027a479
66
from typing import Any, Optional
77
import cython
88
import ctypes
@@ -26277,7 +26277,7 @@ cdef class anon_union24:
2627726277
def pArray(self):
2627826278
return [CUarray(init_value=<void_ptr>_pArray) for _pArray in self._pvt_ptr[0].frame.pArray]
2627926279
@pArray.setter
26280-
def pArray(self, pArray : list[CUarray]):
26280+
def pArray(self, pArray : list[CUarray | int]):
2628126281
if len(pArray) != 3:
2628226282
raise IndexError('not enough values found during array assignment, expected 3, got', len(pArray))
2628326283
pArray = [int(_pArray) for _pArray in pArray]

‎cuda_bindings_13/cuda/bindings/runtime.pyx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
# This code was automatically generated with version 13.5.0. Do not modify it directly.
5-
# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=fd56bdd31c4c12f8618529544aa12f69d7cb782da716c7e2eb06d3f3fdd1fecd
5+
# CYTHON-BINDINGS-GENERATED-DO-NOT-MODIFY-THIS-FILE: format=1; content-sha256=b2610805a773c0962631e67e0bd215f5b5a613e533637c379ba70c29d1143947
66
from typing import Any, Optional
77
import cython
88
import ctypes
@@ -20219,7 +20219,7 @@ cdef class anon_union13:
2021920219
def pArray(self):
2022020220
return [cudaArray_t(init_value=<void_ptr>_pArray) for _pArray in self._pvt_ptr[0].frame.pArray]
2022120221
@pArray.setter
20222-
def pArray(self, pArray : list[cudaArray_t]):
20222+
def pArray(self, pArray : list[cudaArray_t | int]):
2022320223
if len(pArray) != 3:
2022420224
raise IndexError('not enough values found during array assignment, expected 3, got', len(pArray))
2022520225
pArray = [int(_pArray) for _pArray in pArray]

‎cuda_bindings_13/tests/legacy_api/test_legacy_cuda.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -746,12 +746,12 @@ def test_eglFrame():
746746
assert int(val.frame.pArray[0]) == 0
747747
assert int(val.frame.pArray[1]) == 0
748748
assert int(val.frame.pArray[2]) == 0
749-
val.frame.pArray = [cuda.CUarray(x) for x in (1, 2, 3)]
749+
val.frame.pArray = [1, 2, 3]
750750
# [<CUarray 0x1>, <CUarray 0x2>, <CUarray 0x3>]
751751
assert int(val.frame.pArray[0]) == 1
752752
assert int(val.frame.pArray[1]) == 2
753753
assert int(val.frame.pArray[2]) == 3
754-
val.frame.pArray = [cuda.CUarray(x) for x in (4, 2, 3)]
754+
val.frame.pArray = [cuda.CUarray(4), 2, 3]
755755
# [<CUarray 0x4>, <CUarray 0x2>, <CUarray 0x3>]
756756
assert int(val.frame.pArray[0]) == 4
757757
assert int(val.frame.pArray[1]) == 2

‎cuda_bindings_13/tests/test_cudart.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,12 +1289,12 @@ def test_cudart_eglFrame():
12891289
assert int(frame.frame.pArray[0]) == 0
12901290
assert int(frame.frame.pArray[1]) == 0
12911291
assert int(frame.frame.pArray[2]) == 0
1292-
frame.frame.pArray = [cudart.cudaArray_t(x) for x in (1, 2, 3)]
1292+
frame.frame.pArray = [1, 2, 3]
12931293
# [<cudaArray_t 0x1>, <cudaArray_t 0x2>, <cudaArray_t 0x3>]
12941294
assert int(frame.frame.pArray[0]) == 1
12951295
assert int(frame.frame.pArray[1]) == 2
12961296
assert int(frame.frame.pArray[2]) == 3
1297-
frame.frame.pArray = [cudart.cudaArray_t(x) for x in (1, 2, 4)]
1297+
frame.frame.pArray = [1, 2, cudart.cudaArray_t(4)]
12981298
# [<cudaArray_t 0x1>, <cudaArray_t 0x2>, <cudaArray_t 0x4>]
12991299
assert int(frame.frame.pArray[0]) == 1
13001300
assert int(frame.frame.pArray[1]) == 2

0 commit comments

Comments
 (0)