Skip to content

Commit

Permalink
Expose uv_version() for libuv API compatibility (#491)
Browse files Browse the repository at this point in the history
* Also renamed to have libuv_ namespace
  • Loading branch information
fantix authored Sep 9, 2022
1 parent 2f1bc83 commit 089f6cb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
22 changes: 22 additions & 0 deletions tests/test_libuv_api.py
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 0 additions & 18 deletions tests/test_pointers.py

This file was deleted.

2 changes: 2 additions & 0 deletions uvloop/includes/uv.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -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()
11 changes: 8 additions & 3 deletions uvloop/loop.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<void *>self.uvloop, NULL, NULL)

# Expose pointer for integration with other C-extensions
def libuv_get_loop_t_ptr(loop):
return PyCapsule_New(<void *>(<Loop>loop).uvloop, NULL, NULL)


def libuv_get_version():
return uv.uv_version()


cdef void __loop_alloc_buffer(uv.uv_handle_t* uvhandle,
Expand Down

0 comments on commit 089f6cb

Please sign in to comment.