Skip to content

Commit

Permalink
Use capsule only and add cython test
Browse files Browse the repository at this point in the history
  • Loading branch information
fantix committed Aug 13, 2022
1 parent 2b38ee8 commit 9fd0d9d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
'pycodestyle~=2.7.0',
'pyOpenSSL~=19.0.0',
'mypy>=0.800',
CYTHON_DEPENDENCY,
]

# Dependencies required to build documentation.
Expand Down
5 changes: 5 additions & 0 deletions tests/cython_helper.pyx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from cpython.pycapsule cimport PyCapsule_GetPointer


def capsule_equals(cap1, cap2):
return PyCapsule_GetPointer(cap1, NULL) == PyCapsule_GetPointer(cap2, NULL)
17 changes: 13 additions & 4 deletions tests/test_pointers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@


class Test_UV_Pointers(tb.UVTestCase):
def test_get_uvloop_ptr(self):
self.assertGreater(self.new_loop().get_uvloop_ptr(), 0)
def test_get_uv_loop_t_ptr(self):
loop = self.new_loop()
cap1 = loop.get_uv_loop_t_ptr()
cap2 = loop.get_uv_loop_t_ptr()
cap3 = self.new_loop().get_uv_loop_t_ptr()

def test_get_uvloop_ptr_capsule(self):
self.assertIsNotNone(self.new_loop().get_uvloop_ptr_capsule())
import pyximport

pyximport.install()

from tests import cython_helper

self.assertTrue(cython_helper.capsule_equals(cap1, cap2))
self.assertFalse(cython_helper.capsule_equals(cap1, cap3))
5 changes: 1 addition & 4 deletions uvloop/loop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -3182,10 +3182,7 @@ cdef class Loop:
self.call_soon_threadsafe(future.set_exception, ex)

# Expose pointer for integration with other C-extensions
def get_uvloop_ptr(self):
return <uint64_t>self.uvloop

def get_uvloop_ptr_capsule(self):
def get_uv_loop_t_ptr(self):
return PyCapsule_New(<void *>self.uvloop, NULL, NULL)


Expand Down

0 comments on commit 9fd0d9d

Please sign in to comment.