pitrou commented on code in PR #39977:
URL: https://github.com/apache/arrow/pull/39977#discussion_r1483260834


##########
python/pyarrow/types.pxi:
##########
@@ -114,7 +123,14 @@ cdef void* _as_c_pointer(v, allow_null=False) except *:
             "Arrow library", UserWarning, stacklevel=2)
         c_ptr = <void*> <uintptr_t > v
     elif PyCapsule_CheckExact(v):
-        c_ptr = PyCapsule_GetPointer(v, NULL)
+        capsule_name = PyCapsule_GetName(v)
+        if capsule_name == NULL or capsule_name == "r_extptr":
+            c_ptr = PyCapsule_GetPointer(v, capsule_name)
+        else:
+            capsule_name_str = capsule_name.decode("UTF-8")
+            raise ValueError(
+                f"Can't convert PyCapsule with name '{capsule_name_str}' to 
pointer address"
+            )

Review Comment:
   utf8 is the default encoding when decoding.
   ```suggestion
               capsule_name_str = capsule_name.decode()
               raise ValueError(
                   f"Can't convert PyCapsule with name '{capsule_name_str}' to 
pointer address"
               )
   ```



##########
python/pyarrow/types.pxi:
##########
@@ -15,7 +15,15 @@
 # specific language governing permissions and limitations
 # under the License.
 
-from cpython.pycapsule cimport PyCapsule_CheckExact, PyCapsule_GetPointer, 
PyCapsule_New, PyCapsule_IsValid
+from cpython.pycapsule cimport (
+    PyCapsule_CheckExact,
+    PyCapsule_GetPointer,
+    PyCapsule_GetName,
+    PyCapsule_New,
+    PyCapsule_IsValid
+)
+
+from libc.string cimport strcmp

Review Comment:
   This can be removed now?



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