diff --git a/tests/test_libuv_api.py b/tests/test_libuv_api.py new file mode 100644 index 00000000..d0db5180 --- /dev/null +++ b/tests/test_libuv_api.py @@ -0,0 +1,22 @@ +from uvloop import _testbase as tb +from uvloop.loop import libuv_get_loop_t_ptr, libuv_get_version + + +class Test_UV_libuv(tb.UVTestCase): + def test_libuv_get_loop_t_ptr(self): + loop = self.new_loop() + cap1 = libuv_get_loop_t_ptr(loop) + cap2 = libuv_get_loop_t_ptr(loop) + cap3 = libuv_get_loop_t_ptr(self.new_loop()) + + 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)) + + def test_libuv_get_version(self): + self.assertGreater(libuv_get_version(), 0) diff --git a/tests/test_pointers.py b/tests/test_pointers.py deleted file mode 100644 index 5e526b06..00000000 --- a/tests/test_pointers.py +++ /dev/null @@ -1,18 +0,0 @@ -from uvloop import _testbase as tb - - -class Test_UV_Pointers(tb.UVTestCase): - 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() - - 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)) diff --git a/uvloop/includes/uv.pxd b/uvloop/includes/uv.pxd index 2f2f1e80..595ff899 100644 --- a/uvloop/includes/uv.pxd +++ b/uvloop/includes/uv.pxd @@ -501,3 +501,5 @@ cdef extern from "uv.h" nogil: const uv_process_options_t* options) int uv_process_kill(uv_process_t* handle, int signum) + + unsigned int uv_version() diff --git a/uvloop/loop.pyx b/uvloop/loop.pyx index ad6657a4..ef2ac47d 100644 --- a/uvloop/loop.pyx +++ b/uvloop/loop.pyx @@ -3226,9 +3226,14 @@ cdef class Loop: except Exception as ex: self.call_soon_threadsafe(future.set_exception, ex) - # Expose pointer for integration with other C-extensions - def get_uv_loop_t_ptr(self): - return PyCapsule_New(self.uvloop, NULL, NULL) + +# Expose pointer for integration with other C-extensions +def libuv_get_loop_t_ptr(loop): + return PyCapsule_New((loop).uvloop, NULL, NULL) + + +def libuv_get_version(): + return uv.uv_version() cdef void __loop_alloc_buffer(uv.uv_handle_t* uvhandle,