Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose uv_version() for libuv API compatibility #491

Merged
merged 2 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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