Skip to content

Commit

Permalink
Expose uv_loop_t pointer for integration with other C-extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavtbhat committed Jan 15, 2020
1 parent 35f8250 commit becc37c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/test_pointers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from uvloop import _testbase as tb

class Test_UV_Pointers(tb.UVTestCase):
def test_get_uvloop_ptr(self):
self.assertGreater(self.new_loop().get_uvloop_ptr(), 0)

def test_get_uvloop_ptr_capsule(self):
self.assertIsNotNone(self.new_loop().get_uvloop_ptr_capsule())
8 changes: 8 additions & 0 deletions uvloop/loop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ from cpython cimport (
PyBytes_AsStringAndSize,
Py_SIZE, PyBytes_AS_STRING, PyBUF_WRITABLE
)
from cpython.pycapsule cimport PyCapsule_New

from . import _noop

Expand Down Expand Up @@ -3108,6 +3109,13 @@ cdef class Loop:
'asyncgen': agen
})

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

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


cdef void __loop_alloc_buffer(uv.uv_handle_t* uvhandle,
size_t suggested_size,
Expand Down

0 comments on commit becc37c

Please sign in to comment.