Skip to content

Commit 628d590

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

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

tests/test_pointers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from uvloop import _testbase as tb
2+
3+
4+
class Test_UV_Pointers(tb.UVTestCase):
5+
def test_get_uvloop_ptr(self):
6+
self.assertGreater(self.new_loop().get_uvloop_ptr(), 0)
7+
8+
def test_get_uvloop_ptr_capsule(self):
9+
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+
def get_uvloop_ptr(self):
3114+
return <uint64_t>self.uvloop
3115+
3116+
def get_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)