Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Add functions to look up req and handle sizes
Browse files Browse the repository at this point in the history
Useful for FFI bindings. Closes #370.
  • Loading branch information
avalanche123 authored and piscisaureus committed Apr 4, 2012
1 parent 5f38ba1 commit f09f7bc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/uv.h
Expand Up @@ -382,6 +382,18 @@ struct uv_handle_s {
UV_HANDLE_FIELDS
};

/*
* Returns size of various handle types, useful for FFI
* bindings to allocate correct memory without copying struct
* definitions
*/
UV_EXTERN size_t uv_handle_size(uv_handle_type type);

/*
* Returns size of request types, useful for dynamic lookup with FFI
*/
UV_EXTERN size_t uv_req_size(uv_req_type type);

/*
* Returns 1 if the prepare/check/idle/timer handle has been started, 0
* otherwise. For other handle types this always returns 1.
Expand Down
19 changes: 19 additions & 0 deletions src/uv-common.c
Expand Up @@ -32,6 +32,25 @@
#include "ares/inet_net_pton.h"
#include "ares/inet_ntop.h"

#define XX(uc, lc) case UV_##uc: return sizeof(uv_##lc##_t);

size_t uv_handle_size(uv_handle_type type) {
switch (type) {
UV_HANDLE_TYPE_MAP(XX)
default:
return -1;
}
}

size_t uv_req_size(uv_req_type type) {
switch(type) {
UV_REQ_TYPE_MAP(XX)
default:
return -1;
}
}

#undef XX

size_t uv_strlcpy(char* dst, const char* src, size_t size) {
size_t n;
Expand Down

0 comments on commit f09f7bc

Please sign in to comment.