Skip to content

Commit fb2caef

Browse files
committed
Update exchange API to be capsule following new convention
This PR updates the exchange API to be capsule following the new convention. Note that the exchange API python recommendation is not yet updated on the array-api side and so far there hasn't yet been downstream implementation, so this change should be safe in generally.
1 parent 93c8f2a commit fb2caef

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

include/dlpack/dlpack.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#define DLPACK_MAJOR_VERSION 1
2020

2121
/*! \brief The current minor version of dlpack */
22-
#define DLPACK_MINOR_VERSION 2
22+
#define DLPACK_MINOR_VERSION 3
2323

2424
/*! \brief DLPACK_DLL prefix for windows */
2525
#ifdef _WIN32
@@ -375,7 +375,7 @@ typedef struct DLManagedTensorVersioned {
375375
} DLManagedTensorVersioned;
376376

377377
//----------------------------------------------------------------------
378-
// DLPack `__c_dlpack_exchange_api__` fast exchange protocol definitions
378+
// DLPack `__dlpack_c_exchange_api__` fast exchange protocol definitions
379379
//----------------------------------------------------------------------
380380
/*!
381381
* \brief Request a producer library to create a new tensor.
@@ -531,16 +531,17 @@ typedef struct DLPackExchangeAPIHeader {
531531
* \brief Framework-specific function pointers table for DLPack exchange.
532532
*
533533
* Additionally to `__dlpack__()` we define a C function table sharable by
534-
* Python implementations via `__c_dlpack_exchange_api__`.
535-
* This attribute must be set on the type as a Python integer compatible
536-
* with `PyLong_FromVoidPtr`/`PyLong_AsVoidPtr`.
534+
*
535+
* Python implementations via `__dlpack_c_exchange_api__`.
536+
* This attribute must be set on the type as a Python PyCapsule
537+
* with name "dlpack_exchange_api".
537538
*
538539
* A consumer library may use a pattern such as:
539540
*
540541
* \code
541542
*
542-
* PyObject *api_obj = type(tensor_obj).__c_dlpack_exchange_api__; // as C-code
543-
* MyDLPackExchangeAPI *api = PyLong_AsVoidPtr(api_obj);
543+
* PyObject *api_obj = type(tensor_obj).__dlpack_c_exchange_api__; // as C-code
544+
* MyDLPackExchangeAPI *api = PyCapsule_GetPointer(api_obj, "dlpack_exchange_api");
544545
* if (api == NULL && PyErr_Occurred()) { goto handle_error; }
545546
*
546547
* \endcode

0 commit comments

Comments
 (0)