pitrou commented on PR #5070:
URL: https://github.com/apache/arrow-rs/pull/5070#issuecomment-1808089235

   > Perhaps we could get some of the people who designed PyCapsule to weigh in 
here, from my reading of it this appears to primarily be an API for python 
libraries to communicate with each other?
   
   It is designed as a Python-specific protocol (in the Python sense: it uses 
well-known special methods) around the C Data Interface, and automates 
conversion between producers and consumers of Arrow data. There is no 
requirement that the producer or consumer is implemented in Python.
   
   The two main points of this protocol are:
   1) the protocol does not depend on any particular implementation of Arrow; 
the consumer can consume any PyCapsule provider in an implementation-agnostic 
manner (it does not need to write any PyArrow-specific code, for example)
   2) the PyCapsule has a destructor that releases the underlying C Data 
Interface structure if it wasn't moved already; this makes this protocol safer 
than passing raw pointers as integers (if an exception occurs between exporting 
and importing, for example, a leak is avoided)
   
   In practice:
   1) provider P exposes a Python object that has a `__arrow_c_schema__` method
   2) consumer C is invoked with said Python object, calls `__arrow_c_schema__` 
and imports the C Data Interface structure pointed to by the returned 
PyCapsule; consumer C does know anything about provider P
   
   > I also am very confused by what the ownership semantics of this API are, 
does the PyCapsule remain the owner?
   
   The PyCapsule just contains a raw pointer. The semantics of the pointer 
embedded in a PyCapsule are usage-dependent. In this case, the ownership 
semantics are those of the C Data Interface itself: the contents can be moved 
by setting the `release` pointer to NULL.
   


-- 
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]

Reply via email to