Skip to content

Add libuv.c3l to vendor #50

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This repository contains external libraries for use with C3.
- PQ (PostgreSQL) https://www.postgresql.org/docs/current/libpq.html
- MySQL 8 https://dev.mysql.com/doc/c-api/8.0/en/
- SQLite 3 https://sqlite.com/c3ref/intro.html
- libuv https://github.com/libuv/libuv

## Guide for writing bindings

Expand Down
14 changes: 14 additions & 0 deletions libraries/libuv.c3l/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# libuv.c3l

Port of libuv to C3 language

## Installation

- Install libuv to your OS
- Inside your project libs directory run:
```
git clone https://github.com/velikoss/libuv.c3l
```
- And add libuv to your project.json dependencies

*README will change with further development*
1 change: 1 addition & 0 deletions libraries/libuv.c3l/aix.c3i
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module libuv @if(env::OS_TYPE == OsType.AIX);
3 changes: 3 additions & 0 deletions libraries/libuv.c3l/bsd.c3i
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module libuv @if(env::BSD_FAMILY);

const MAXHOSTNAMELEN @if(!$defined(MAXHOSTNAMELEN)) = 64;
5 changes: 5 additions & 0 deletions libraries/libuv.c3l/darwin.c3i
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module libuv @if(env::DARWIN);

// https://stackoverflow.com/questions/9602685/why-does-mode-t-use-4-byte#comment12181688_9602685
// darwin uses 16 bits for mode_t
def Unix_mode_t = CUShort;
9 changes: 9 additions & 0 deletions libraries/libuv.c3l/issues.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Issues
- @if(!env::WIN32) for UNIX fields, which is not great. Consider adding @if(env::UNIX)
- double as C3 type, not C. Needs to be checked for bugs

# Todoes
- Port all tests from libuv GitHub to test bindings
- Check if fields order is neceserry for libuv to work properly. If not, consider simplifying dublicate fields for multiple platforms
- UV_PLATFORM_SEM_t for all platforms. Currently is CLong which is not correct
- Implement ipv6
9 changes: 9 additions & 0 deletions libraries/libuv.c3l/linux.c3i
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module libuv @if(env::OS_TYPE == OsType.LINUX);

struct UV_PLATFORM_LOOP_FIELDS_t {
UV__Io inotify_read_watcher;
void* inotify_watchers;
CInt inotify_fd;
}

const MAXHOSTNAMELEN = 1024;
23 changes: 23 additions & 0 deletions libraries/libuv.c3l/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"provides" : "libuv",
"targets" : {
"macos-x64" : {
"link-args" : [],
"dependencies" : [],
"linked-libraries" : ["uv"]
},
"macos-aarch64" : {
"link-args" : [],
"dependencies" : [],
"linked-libraries" : ["uv"]
},
"linux-x64" : {
"link-args" : [],
"dependencies" : [],
"linked-libraries" : ["uv"]
},
"windows-x64" : {
"linked-libraries" : ["libuv"]
}
}
}
8 changes: 8 additions & 0 deletions libraries/libuv.c3l/misc.c3i
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module libuv::tree(<TreeType>);

struct Win32_RB_ENTRY {
TreeType *rbe_left; /* left element */
TreeType *rbe_right; /* right element */
TreeType *rbe_parent; /* parent element */
CInt rbe_color;
}
1 change: 1 addition & 0 deletions libraries/libuv.c3l/os390.c3i
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// include/uv/os390.h
9 changes: 9 additions & 0 deletions libraries/libuv.c3l/posix.c3i
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module libuv @if(env::POSIX);
import std::net::os;

struct UV_PLATFORM_LOOP_FIELDS_t @if(!$defined(UV_PLATFORM_LOOP_FIELDS_t)) {
os::Posix_pollfd* poll_fds;
int128 poll_fds_used; // size_t
int128 poll_fds_size; // size_t
CUChar poll_fds_iterating;
}
8 changes: 8 additions & 0 deletions libraries/libuv.c3l/sunos.c3i
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module libuv @if(env::OS_TYPE == OsType.SOLARIS);

import std::net::os;

/* For the sake of convenience and reduced #ifdef-ery in src/unix/sunos.c,
* add the fs_event fields even when this version of SunOS doesn't support
* file watching.
*/
139 changes: 139 additions & 0 deletions libraries/libuv.c3l/unix.c3i
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
module libuv @if(!env::WIN32);
import std::os::posix;

def Async_unused = fn void();
import std::thread::os;

def Platform_sockaddr_in6 = void*; // todo implement ipv6

struct UVBuf {
CChar* base;
CLongLong len;
}

// struct UV_LOOP_PRIVATE_FIELDS_t {
// inline UV_PLATFORM_LOOP_FIELDS_t uv_platform_loop_fields;
// CULong flags;
// CInt backend_fd;
// UV__Queue pending_queue;
// UV__Queue watcher_queue;
// UV__Io** watchers;
// CUInt nwatchers;
// CUInt nfds;
// UV__Queue wq;
// UVMutex wq_mutex;
// UVAsync wq_async;
// UVRwlue prepare_handles;
// UV__Queue check_handles;
// UV__Queue idle_handles;
// UV__Queue async_handles;
// Async_unused async_unused; /* TODO(bnoordhuis) Remove in libuv v2. */
// UV__Io async_io_watcher;
// CInt async_wfd;
// struct timer_heap {
// void* min;
// CUInt nelts;
// }
// CULongLong timer_counter;
// CULongLong time;
// CInt[2]* signal_pipefd;
// UV__Io signal_io_watcher;
// UVSignal child_watcher;
// CInt emfile_fd;
// }

// struct UV_PLATFORM_LOOP_FIELDS_t @if(!$defined(UV_PLATFORM_LOOP_FIELDS_t)) {
// void* empty;
// }

struct UV_HANDLE_PRIVATE_FIELDS_t {
CUInt flags;
}

def Unix_sa_family = CUChar;
def UV__IoCb = fn void(UVLoop* loop, UV__Io* w, CUInt events);

struct UV__Io {
UV__IoCb cb;
UV__Queue pending_queue;
UV__Queue watcher_queue;
CUInt pevents; /* Pending event mask i.e. mask at next tick. */
CUInt events; /* Current event mask. */
CInt fd;
CInt rcount @if(env::BSD_FAMILY || env::DARWIN);
CInt wcount @if(env::BSD_FAMILY || env::DARWIN);
}

def Platform_sockaddr = Unix_sockaddr;
def Platform_sockaddr_in = Unix_sockaddr_in;

def Unix_in_addr_t = uint;
def Unix_in_port_t = ushort;

struct Unix_in_addr {
Unix_in_addr_t s_addr;
}

struct Unix_sockaddr_in {
Unix_sa_family sin_family; /* AF_INET */
Unix_in_port_t sin_port; /* Port number */
Unix_in_addr sin_addr; /* IPv4 address */
}

struct Unix_sockaddr {
CUChar sa_len;
Unix_sa_family sa_family;
CChar[14]* sa_data;
}

struct Unix_sockaddr_storage {
CUChar ss_len;
Unix_sa_family ss_family;
CChar[(CLong.sizeof - CUChar.sizeof - Unix_sa_family.sizeof)]* __ss_pad1;
CLongLong __ss_align;
CChar[(128 - CUChar.sizeof - Unix_sa_family.sizeof - ((CLong.sizeof) - CUChar.sizeof - Unix_sa_family.sizeof) - (CLong.sizeof))]* __ss_pad2;
}

def Platform_addrinfo = Unix_addrinfo;

// https://www.man7.org/linux/man-pages/man3/getaddrinfo.3.html
struct Unix_addrinfo {
CInt ai_flags;
CInt ai_family;
CInt ai_socktype;
CInt ai_protocol;
CInt ai_addrlen; // socklen_t ?
Unix_sockaddr *ai_addr;
char *ai_canonname;
Unix_addrinfo *ai_next;
}

// https://stackoverflow.com/questions/9602685/why-does-mode-t-use-4-byte
// todo: needs to be 32 bits. please make check
def Unix_mode_t = CULong @if(!$defined(Unix_mode_t));
// https://stackoverflow.com/a/23924078
// there mode_t uses unsigned int. please check
def Unix_dev_t = CULong;
def Unix_uid_t = CUInt;
def Unix_gid_t = CUInt;
def Unix_ino_t = CULong;
def Unix_ino64_t = CULong;
def Unix_nlink_t = CULong;
def Unix_off_t = CLong;
def Unix_off64_t = CLong;

def UVFile = CInt;
def UVOsSock = CInt;
def UVOsFd = CInt;
def UVPid = CInt;
def UVUid = Unix_uid_t;
def UVGid = Unix_gid_t;

def UVOnce = Pthread_once_t;
def UVThread = Pthread_t;
def UVMutex = Pthread_mutex_t;
def UVRWLock = Pthread_rwlock_t;
def UV_PLATFORM_SEM_t = CLong @if(!$defined(UV_PLATFORM_SEM_t));
def UVSem = UV_PLATFORM_SEM_t; // todo: implement all unix os
def UVCond = Pthread_cond_t;
def UVKey = Pthread_key_t;
Loading
Loading