Move callback wrappers to Python layer#544
Conversation
|
/ok to test |
This comment has been minimized.
This comment has been minimized.
leofang
left a comment
There was a problem hiding this comment.
I have reviewed 3 out of 4 files (haven't had time to cover runtime.pyx.in yet).
Q: I assume so far we have not supported passing a pure Python function as callback to any of the bindings directly, without using ctypes or other means as a trampoline?
| cdef cuAsyncCallbackData *cbData = NULL | ||
| cbData = <cuAsyncCallbackData *>malloc(sizeof(cbData[0])) | ||
| if cbData == NULL: | ||
| return CUresult.CUDA_ERROR_OUT_OF_MEMORY |
There was a problem hiding this comment.
Q: Should this be a 1-tuple?
| return CUresult.CUDA_ERROR_OUT_OF_MEMORY | |
| return (CUresult.CUDA_ERROR_OUT_OF_MEMORY,) |
There was a problem hiding this comment.
Good catch. Fixed.
There was a problem hiding this comment.
It would be good to have type annotations or something else as a way to prevent issues like this from sneaking in.
There was a problem hiding this comment.
It seems currently Cython cannot raise a compile-time error for either case, only a run-time error (which is not desired I think).
cpdef tuple f():
return 42
def g() -> tuple:
return 42Output:
>>> import test_tuple
>>> test_tuple.f()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "test_tuple.pyx", line 1, in test_tuple.f
cpdef tuple f():
File "test_tuple.pyx", line 3, in test_tuple.f
return 42
TypeError: Expected tuple, got int
>>> test_tuple.g()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "test_tuple.pyx", line 7, in test_tuple.g
return 42
TypeError: Expected tuple, got int
Correct. |
|
/ok to test |
|
close #531