code: def _dlpack_deleter(pycapsule):
      pycapsule = ctypes.cast(pycapsule, ctypes.py_object)
      if ctypes.pythonapi.PyCapsule_IsValid(pycapsule, _c_str_dltensor):
          ptr = ctypes.pythonapi.PyCapsule_GetPointer(
              pycapsule, _c_str_dltensor
          )
          # XXX(minjie): The below cast should be unnecessary given the code to
          #   set restype of PyCapsule calls. But weirdly, this does not
          #   work out always.
          ptr = ctypes.cast(ptr, ctypes.c_void_p)
          _LIB.DGLDLManagedTensorCallDeleter(ptr)
          ctypes.pythonapi.PyCapsule_SetDestructor(
              pycapsule, DGLPyCapsuleDestructor(0)
          )
  
file_path: dgl/python/dgl/_ffi/_ctypes/ndarray.py
imports: from __future__ import absolute_import
  import ctypes
  from ..base import _LIB, c_str, check_call
  from ..runtime_ctypes import DGLArrayHandle
  from .types import _return_handle, _wrap_arg_func, C_TO_PY_ARG_SWITCH, RETURN_SWITCH
label_desc: Use image node_id 2 for calling a global function with example usage: _dlpack_deleter(pycapsule) without return types