What is the difference of C_TO_PY_ARG_SWITCH and RETURN_SWITCH

Hi Guys:

I am reading the TVM code, and feels confuse about C_TO_PY_ARG_SWITCH and RETURN_SWITCH defined in _ctypes/types.py.

It seems that they are dictionaries to transform the C output to the python counterpart. I know that their definition is enlarged at function.py. But I still don’t understand the real difference between them:

  1. What scenario will each of them be used ?
  2. Why we need two dictionaries instead of one ?

Thanks.

C_TO_PY_ARG_SWITCH is used to translating callback arguments, while RETURN_SWITCH is used to translate the return value of a function.

There is a slight difference between the two. The callback argument can pass in DLTensor pointer, which is a weak reference that can go out of scope when the callback ends, while the functionc an only return strong reference.