Skip to content

Commit

Permalink
chore: Fix Windows build issue
Browse files Browse the repository at this point in the history
  • Loading branch information
joehendrix committed Dec 20, 2023
1 parent 499f76b commit dd34085
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 80 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
uses: Homebrew/actions/setup-homebrew@master
- name: Prereqs OSX
if: matrix.os == 'macos-latest'
run: brew install elan-init libuv pkg-config
run: brew install elan-init
- name: Add msys2 to path (Windows)
if: matrix.os == 'windows-latest'
run: |
Expand Down
16 changes: 0 additions & 16 deletions LibUV/Check.lean
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,10 @@ namespace UV

alloy c section

struct lean_uv_check_s {
uv_check_t uv;
// Lean function to invoke callback on.
// Initialized to be valid object.
lean_object* callback;
};

typedef struct lean_uv_check_s lean_uv_check_t;

static void Check_foreach(void* ptr, b_lean_obj_arg f) {
fatal_st_only("Check");
}

// Close the check handle if the loop stops
void lean_uv_check_loop_stop(uv_handle_t* h) {
lean_uv_check_t* check = (lean_uv_check_t*) h;
lean_dec_optref(check->callback);
uv_close(h, (uv_close_cb) &free);
}

static void Check_finalize(void* ptr) {
bool is_active = ((lean_uv_check_t*) ptr)->callback != NULL;
lean_uv_finalize_handle((uv_handle_t*) ptr, is_active);
Expand Down
18 changes: 0 additions & 18 deletions LibUV/Idle.lean
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ alloy c include <lean_uv.h>
namespace UV

alloy c section

struct lean_uv_idle_s {
uv_idle_t uv;
// callback object
lean_object* callback;
};

typedef struct lean_uv_idle_s lean_uv_idle_t;

/* Return lean object representing this idler */
static uv_handle_t* idle_handle(lean_uv_idle_t* p) {
return (uv_handle_t*) &(p->uv);
Expand All @@ -25,15 +16,6 @@ static lean_object** idle_callback(lean_uv_idle_t* p) {
return &(p->callback);
}

// Close the check handle if the loop stops
void lean_uv_idle_loop_stop(uv_handle_t* h) {
lean_uv_idle_t* idle = (lean_uv_idle_t*) h;
if (idle->callback != NULL) {
lean_dec_ref(idle->callback);
}
uv_close(h, (uv_close_cb) &free);
}

static void Idle_foreach(void* ptr, b_lean_obj_arg f) {
fatal_st_only("Idle");
}
Expand Down
43 changes: 37 additions & 6 deletions LibUV/Loop.lean
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ alloy c section
#define LUV_EINVAL 2
#define LUV_ETIMEDOUT 3

lean_object* lean_uv_error_mk(int code) {
LEAN_EXPORT lean_object* lean_uv_error_mk(int code) {
if (code >= 0)
fatal_error("Unexpected success code %d.\n", code);
size_t r;
Expand Down Expand Up @@ -54,7 +54,7 @@ alloy c section
lean_object* lean_uv_error_errorcode(lean_object* err);

/* Returns an IO error for the given error code. */
extern lean_object* lean_uv_io_error(int err) {
LEAN_EXPORT lean_object* lean_uv_io_error(int err) {
return lean_io_result_mk_error(lean_uv_error_errorcode(lean_uv_error_mk(err)));
}

Expand Down Expand Up @@ -109,10 +109,38 @@ private def raiseInvalidArgument (message:String) : UV.IO α :=

alloy c section

void lean_uv_check_loop_stop(uv_handle_t* h);
void lean_uv_idle_loop_stop(uv_handle_t* h);
void lean_uv_tcp_loop_stop(uv_handle_t* h);
void lean_uv_timer_loop_stop(uv_handle_t* h);
static void uv_close_and_free(uv_handle_t* h) {
uv_close(h, (uv_close_cb) &free);
}

// Close the check handle if the loop stops
static void lean_uv_check_loop_stop(uv_handle_t* h) {
lean_uv_check_t* check = (lean_uv_check_t*) h;
lean_dec_optref(check->callback);
uv_close_and_free(h);
}

// Close the idle handle if the loop stops
static void lean_uv_idle_loop_stop(uv_handle_t* h) {
lean_uv_idle_t* idle = (lean_uv_idle_t*) h;
lean_dec_optref(idle->callback);
uv_close_and_free(h);
}

// Close the check handle if the loop stops
static void lean_uv_tcp_loop_stop(uv_handle_t* h) {
lean_uv_tcp_t* tcp = lean_stream_base(h);
lean_stream_callbacks_t* callbacks = &tcp->callbacks;
lean_dec_optref(callbacks->listen_callback);
lean_dec_optref(callbacks->read_callback);
uv_close(h, &lean_uv_close_stream);
}

static void lean_uv_timer_loop_stop(uv_handle_t* h) {
lean_uv_timer_t* timer = (lean_uv_timer_t*) h;
lean_dec_optref(timer->callback);
uv_close_and_free(h);
}

static void stop_handles(uv_handle_t* h, void* arg) {
if (uv_is_closing(h)) return;
Expand Down Expand Up @@ -200,12 +228,15 @@ def mkLoop (options : Loop.Options := {}) : BaseIO Loop := {
fatal_error("uv_loop_configure failed (error = %d).\n", err);
}
}
#if defined(WIN32) || defined(_WIN32)
#else
if (block) {
int err = uv_loop_configure(uv_loop, UV_LOOP_BLOCK_SIGNAL, SIGPROF);
if (err != 0) {
fatal_error("uv_loop_configure failed (error = %d).\n", err);
}
}
#endif
return lean_io_result_mk_ok(r);
}

Expand Down
21 changes: 0 additions & 21 deletions LibUV/Stream.lean
Original file line number Diff line number Diff line change
Expand Up @@ -615,31 +615,10 @@ section TCP

alloy c section

struct lean_uv_tcp_s {
lean_stream_callbacks_t callbacks;
uv_tcp_t uv;
bool connecting;
};

typedef struct lean_uv_tcp_s lean_uv_tcp_t;

static void TCP_foreach(void* ptr, b_lean_obj_arg f) {
fatal_st_only("TCP");
}

void lean_uv_close_stream(uv_handle_t* h) {
free(lean_stream_base(h));
}

// Close the check handle if the loop stops
extern void lean_uv_tcp_loop_stop(uv_handle_t* h) {
lean_uv_tcp_t* tcp = lean_stream_base(h);
lean_stream_callbacks_t* callbacks = &tcp->callbacks;
lean_dec_optref(callbacks->listen_callback);
lean_dec_optref(callbacks->read_callback);
uv_close(h, &lean_uv_close_stream);
}

static void TCP_finalize(void* ptr) {
lean_uv_tcp_t* tcp = lean_stream_base((uv_handle_t*) ptr);
lean_stream_callbacks_t* callbacks = &tcp->callbacks;
Expand Down
14 changes: 0 additions & 14 deletions LibUV/Timer.lean
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,10 @@ namespace UV

alloy c section

struct lean_uv_timer_s {
uv_timer_t uv;
lean_object* callback; // Callback for timer event
};

typedef struct lean_uv_timer_s lean_uv_timer_t;

static void Timer_foreach(void* ptr, b_lean_obj_arg f) {
fatal_st_only("Timer");
}

// Close the check handle if the loop stops
void lean_uv_timer_loop_stop(uv_handle_t* h) {
lean_uv_timer_t* timer = (lean_uv_timer_t*) h;
lean_dec_optref(timer->callback);
uv_close(h, (uv_close_cb) &free);
}

static void Timer_finalize(void* ptr) {
bool is_active = ((lean_uv_timer_t*) ptr)->callback != NULL;
lean_uv_finalize_handle((uv_handle_t*) ptr, is_active);
Expand Down
51 changes: 47 additions & 4 deletions include/lean_uv.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ typedef struct lean_uv_loop_s lean_uv_loop_t;

/** Return the Lean loop object from the */
static uv_loop_t* of_loop(lean_object* l) {
return lean_get_external_data(l);
return (uv_loop_t*) lean_get_external_data(l);
}

/** Return the Lean loop object from the */
static lean_uv_loop_t* of_loop_ext(lean_object* l) {
return lean_get_external_data(l);
return (lean_uv_loop_t*) lean_get_external_data(l);
}

/* Return lean object representing this handle */
Expand All @@ -60,7 +60,7 @@ static inline void lean_uv_finalize_handle(uv_handle_t* h, bool is_active) {
} else {
uv_close(h, (uv_close_cb) free);
}
lean_dec(h->loop->data);
lean_dec((lean_object*) h->loop->data);
}

/*
Expand Down Expand Up @@ -136,4 +136,47 @@ typedef struct lean_stream_callbacks_s lean_stream_callbacks_t;
static void* lean_stream_base(uv_handle_t* h) {
lean_stream_callbacks_t* op = (lean_stream_callbacks_t*) h;
return (op - 1);
}
}

static void lean_uv_close_stream(uv_handle_t* h) {
free(lean_stream_base(h));
}

// Check

struct lean_uv_check_s {
uv_check_t uv;
// Lean function to invoke callback on.
// Initialized to be valid object.
lean_object* callback;
};

typedef struct lean_uv_check_s lean_uv_check_t;

// Idle
struct lean_uv_idle_s {
uv_idle_t uv;
// callback object
lean_object* callback;
};

typedef struct lean_uv_idle_s lean_uv_idle_t;

// TCP

struct lean_uv_tcp_s {
lean_stream_callbacks_t callbacks;
uv_tcp_t uv;
bool connecting;
};

typedef struct lean_uv_tcp_s lean_uv_tcp_t;

// Timer

struct lean_uv_timer_s {
uv_timer_t uv;
lean_object* callback; // Callback for timer event
};

typedef struct lean_uv_timer_s lean_uv_timer_t;

0 comments on commit dd34085

Please sign in to comment.