Skip to content

Instantly share code, notes, and snippets.

@wkcn
Last active February 21, 2020 04:27
Show Gist options
  • Save wkcn/501cd118b8ceb1608bd6c8fa968e7912 to your computer and use it in GitHub Desktop.
Save wkcn/501cd118b8ceb1608bd6c8fa968e7912 to your computer and use it in GitHub Desktop.
testdel
import ctypes
from ctypes import *
ctypes.pythonapi.PyCapsule_New.restype = ctypes.py_object
ctypes.pythonapi.PyCapsule_New.argtypes = [ctypes.c_void_p, ctypes.c_char_p,
ctypes.c_void_p]
def dfunc(dltensor):
pass
cfunc = ctypes.CFUNCTYPE(None, ctypes.c_void_p)
def test():
a = ctypes.pythonapi.PyCapsule_New(1, b'dltensor', cfunc(dfunc))
test()
@wkcn
Copy link
Author

wkcn commented Feb 21, 2020

@mkmoisen,

Hi Matthew,

There was a bug in my gist code.
In the line 11, cfunc = ctypes.CFUNCTYPE(None, ctypes.py_object) is wrong.
The type of parameter should be ctypes.c_void_p rather than ctypes.py_object. I have fixed it.

Thanks,
wkcn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment