Skip to content

Commit 089f6cb

Browse files
authored
Expose uv_version() for libuv API compatibility (#491)
* Also renamed to have libuv_ namespace
1 parent 2f1bc83 commit 089f6cb

File tree

4 files changed

+32
-21
lines changed

4 files changed

+32
-21
lines changed

tests/test_libuv_api.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from uvloop import _testbase as tb
2+
from uvloop.loop import libuv_get_loop_t_ptr, libuv_get_version
3+
4+
5+
class Test_UV_libuv(tb.UVTestCase):
6+
def test_libuv_get_loop_t_ptr(self):
7+
loop = self.new_loop()
8+
cap1 = libuv_get_loop_t_ptr(loop)
9+
cap2 = libuv_get_loop_t_ptr(loop)
10+
cap3 = libuv_get_loop_t_ptr(self.new_loop())
11+
12+
import pyximport
13+
14+
pyximport.install()
15+
16+
from tests import cython_helper
17+
18+
self.assertTrue(cython_helper.capsule_equals(cap1, cap2))
19+
self.assertFalse(cython_helper.capsule_equals(cap1, cap3))
20+
21+
def test_libuv_get_version(self):
22+
self.assertGreater(libuv_get_version(), 0)

tests/test_pointers.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

uvloop/includes/uv.pxd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,3 +501,5 @@ cdef extern from "uv.h" nogil:
501501
const uv_process_options_t* options)
502502

503503
int uv_process_kill(uv_process_t* handle, int signum)
504+
505+
unsigned int uv_version()

uvloop/loop.pyx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3226,9 +3226,14 @@ cdef class Loop:
32263226
except Exception as ex:
32273227
self.call_soon_threadsafe(future.set_exception, ex)
32283228

3229-
# Expose pointer for integration with other C-extensions
3230-
def get_uv_loop_t_ptr(self):
3231-
return PyCapsule_New(<void *>self.uvloop, NULL, NULL)
3229+
3230+
# Expose pointer for integration with other C-extensions
3231+
def libuv_get_loop_t_ptr(loop):
3232+
return PyCapsule_New(<void *>(<Loop>loop).uvloop, NULL, NULL)
3233+
3234+
3235+
def libuv_get_version():
3236+
return uv.uv_version()
32323237

32333238

32343239
cdef void __loop_alloc_buffer(uv.uv_handle_t* uvhandle,

0 commit comments

Comments
 (0)