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

Diff for: tests/test_pointers.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from uvloop import _testbase as tb
2+
3+
class Test_UV_Pointers(tb.UVTestCase):
4+
def test_get_uvloop_ptr(self):
5+
self.assertGreater(self.new_loop().get_uvloop_ptr(), 0)
6+
7+
def test_get_uvloop_ptr_capsule(self):
8+
self.assertIsNotNone(self.new_loop().get_uvloop_ptr_capsule())

Diff for: uvloop/loop.pyx

+8
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)