pitrou commented on code in PR #36489:
URL: https://github.com/apache/arrow/pull/36489#discussion_r1261420080
##########
cpp/src/arrow/c/bridge.h:
##########
@@ -166,6 +166,140 @@ Result<std::shared_ptr<RecordBatch>>
ImportRecordBatch(struct ArrowArray* array,
/// @}
+/// \defgroup c-data-device-interface Functions for working with the C data
device
+/// interface.
+///
+/// @{
+
+/// \brief EXPERIMENTAL: Type for freeing a sync event
+///
+/// If synchronization is necessary for accessing the data on a device,
+/// a pointer to an event needs to be passed when exporting the device
+/// array. It's the responsibility of the release function for the array
+/// to release the event.
+using ReleaseEventFunc = void (*)(void*);
+
+/// \brief EXPERIMENTAL: Export C++ Array as an ArrowDeviceArray.
+///
+/// The resulting ArrowDeviceArray struct keeps the array data and buffers
alive
+/// until its release callback is called by the consumer. All buffers in
+/// the provided array MUST have the same device_type, otherwise an error
+/// will be returned.
+///
+/// If a non-null sync_event is provided, then the sync_release func must also
be
+/// non-null. If the sync_event is null, then the sync_release parameter is
not called.
+///
+/// \param[in] array Array object to export
+/// \param[in] sync_event A pointer to an event-like object if necessary for
+/// synchronization, otherwise null.
+/// \param[in] sync_release Function pointer to release the sync event
+/// \param[out] out C struct to export the array to
+/// \param[out] out_schema optional C struct to export the array type to
+ARROW_EXPORT
+Status ExportDeviceArray(const Array& array, void* sync_event,
+ ReleaseEventFunc sync_release, struct
ArrowDeviceArray* out,
Review Comment:
I think having the user devise the `void*` and release func themselves is
just making it easier for them to shoot themselves in the foot. That said,
you're right that we can _start_ with that in this PR.
In any case, for the sake of type-proofing, perhaps we want to introduce an
intermediate struct? (there are too many things that may cast silently to
`void*` :-)).
```c++
struct RawSyncEvent {
void* sync_event = nullptr;
std::function<void(void*)> release_func;
};
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]