jorisvandenbossche commented on code in PR #37797:
URL: https://github.com/apache/arrow/pull/37797#discussion_r1345636453


##########
python/pyarrow/types.pxi:
##########
@@ -357,6 +357,53 @@ cdef class DataType(_Weakrefable):
                                            _as_c_pointer(in_ptr)))
         return pyarrow_wrap_data_type(result)
 
+    def __arrow_c_schema__(self):
+        """
+        Export to a ArrowSchema PyCapsule
+
+        Unlike _export_to_c, this will not leak memory if the capsule is not 
used.
+        """
+        cdef ArrowSchema* c_schema = <ArrowSchema*>malloc(sizeof(ArrowSchema))
+        with nogil:
+            check_status(ExportType(deref(self.type), c_schema))
+        return cpython.PyCapsule_New(c_schema, 'arrow_schema', 
&pycapsule_schema_deleter)

Review Comment:
   ```suggestion
           return PyCapsule_New(c_schema, 'arrow_schema', 
&pycapsule_schema_deleter)
   ```



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