Skip to content

Commit becc37c

Browse files
committed
Expose uv_loop_t pointer for integration with other C-extensions
1 parent 35f8250 commit becc37c

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

‎tests/test_pointers.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fromuvloopimport_testbaseastb
2+
3+
classTest_UV_Pointers(tb.UVTestCase):
4+
deftest_get_uvloop_ptr(self):
5+
self.assertGreater(self.new_loop().get_uvloop_ptr(), 0)
6+
7+
deftest_get_uvloop_ptr_capsule(self):
8+
self.assertIsNotNone(self.new_loop().get_uvloop_ptr_capsule())

‎uvloop/loop.pyx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ from cpython cimport (
3838
PyBytes_AsStringAndSize,
3939
Py_SIZE, PyBytes_AS_STRING, PyBUF_WRITABLE
4040
)
41+
from cpython.pycapsule cimport PyCapsule_New
4142

4243
from . import _noop
4344

@@ -3108,6 +3109,13 @@ cdef class Loop:
31083109
'asyncgen': agen
31093110
})
31103111

3112+
# Expose pointer for integration with other C-extensions
3113+
defget_uvloop_ptr(self):
3114+
return<uint64_t>self.uvloop
3115+
3116+
defget_uvloop_ptr_capsule(self):
3117+
return PyCapsule_New(<void*>self.uvloop, NULL, NULL)
3118+
31113119

31123120
cdef void __loop_alloc_buffer(uv.uv_handle_t* uvhandle,
31133121
size_t suggested_size,

0 commit comments

Comments
(0)