Skip to content

Commit

Permalink
Replace deprecated execute_job with run_job for lwt_unix >= 2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ncihnegn authored and jeremiedimino committed Jun 1, 2018
1 parent 3df6e4c commit e79232c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
10 changes: 3 additions & 7 deletions src/lTerm_windows.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ type input =
| Key of LTerm_key.t
| Mouse of LTerm_mouse.t

external read_console_input_job : Unix.file_descr -> [ `read_console_input ] Lwt_unix.job = "lt_windows_read_console_input_job"
external read_console_input_result : [ `read_console_input ] Lwt_unix.job -> input = "lt_windows_read_console_input_result"
external read_console_input_free : [ `read_console_input ] Lwt_unix.job -> unit = "lt_windows_read_console_input_free"
external read_console_input_job : Unix.file_descr -> input Lwt_unix.job = "lt_windows_read_console_input_job"

let controls = [|
UChar.of_char ' ';
Expand Down Expand Up @@ -63,10 +61,8 @@ let controls = [|

let read_console_input fd =
Lwt_unix.check_descriptor fd;
Lwt_unix.execute_job ?async_method:None
~job:(read_console_input_job (Lwt_unix.unix_file_descr fd))
~result:read_console_input_result
~free:read_console_input_free
Lwt_unix.run_job ?async_method:None
(read_console_input_job (Lwt_unix.unix_file_descr fd))
>|= function
| Key({ LTerm_key.code = LTerm_key.Char ch ; _ } as key) when UChar.code ch < 32 ->
Key { key with LTerm_key.code = LTerm_key.Char controls.(UChar.code ch) }
Expand Down
26 changes: 10 additions & 16 deletions src/lTerm_windows_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,27 @@ static void worker_read_console_input(struct job_read_console_input *job)

CAMLprim value lt_windows_read_console_input_job(value val_fd)
{
struct job_read_console_input *job = lwt_unix_new(struct job_read_console_input);
job->job.worker = (lwt_unix_job_worker)worker_read_console_input;
LWT_UNIX_INIT_JOB(job, read_console_input, 0);
job->handle = Handle_val(val_fd);
job->error_code = 0;
return lwt_unix_alloc_job(&(job->job));
CAMLreturn(lwt_unix_alloc_job(&(job->job)));
}

CAMLprim value lt_windows_read_console_input_result(value val_job)
static value result_read_console_input_result(struct job_read_console_input *job)
{
INPUT_RECORD *input;
INPUT_RECORD input;
DWORD cks, bs;
WORD code;
int i;
CAMLparam1(val_job);
CAMLparam0();
CAMLlocal3(result, x, y);
struct job_read_console_input *job = Job_read_console_input_val(val_job);
if (job->error_code) {
win32_maperr(job->error_code);
int error_code = job->error_code;
input = job->input;
lwt_unix_free_job(&job->job);
if (error_code) {
win32_maperr(error_code);
uerror("ReadConsoleInput", Nothing);
}
input = &(job->input);
switch (input->EventType) {
case KEY_EVENT: {
result = caml_alloc(1, 0);
Expand Down Expand Up @@ -212,12 +212,6 @@ CAMLprim value lt_windows_read_console_input_result(value val_job)
CAMLreturn(Val_int(0));
}

CAMLprim value lt_windows_read_console_input_free(value val_job)
{
lwt_unix_free_job(&(Job_read_console_input_val(val_job))->job);
return Val_unit;
}

/* +-----------------------------------------------------------------+
| Console informations |
+-----------------------------------------------------------------+ */
Expand Down

0 comments on commit e79232c

Please sign in to comment.