From c2454badf7d9401425bab91ba44e4287e690607b Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Sat, 25 Feb 2017 16:11:17 -0500 Subject: [PATCH] Use standard compilation approach for the C extension --- ansi/main.rkt | 4 ++-- ansi/private/install.rkt | 38 ++++++++++++-------------------- ansi/private/tty-raw-extension.c | 22 +++++++++++++----- ansi/test-raw.rkt | 2 +- 4 files changed, 33 insertions(+), 33 deletions(-) diff --git a/ansi/main.rkt b/ansi/main.rkt index f07e899..02bdaa9 100644 --- a/ansi/main.rkt +++ b/ansi/main.rkt @@ -2,8 +2,8 @@ (require "ansi.rkt" "lcd-terminal.rkt" - "private/tty-raw-extension") + "private/tty-raw-extension.rkt") (provide (all-from-out "ansi.rkt") (all-from-out "lcd-terminal.rkt") - (all-from-out "private/tty-raw-extension")) + (all-from-out "private/tty-raw-extension.rkt")) diff --git a/ansi/private/install.rkt b/ansi/private/install.rkt index b122735..896e3df 100644 --- a/ansi/private/install.rkt +++ b/ansi/private/install.rkt @@ -1,29 +1,19 @@ #lang racket/base +(require make/setup-extension) + (provide pre-installer) -(require racket/file) -(require dynext/file) -(require dynext/compile) -(require dynext/link) - (define (pre-installer collections-top-path collection-path) - (define private-path (build-path collection-path "private")) - (parameterize ((current-directory private-path)) - (define shared-object-target-path (build-path private-path - "compiled" - "native" - (system-library-subpath))) - (define shared-object-target (build-path shared-object-target-path - (append-extension-suffix "tty-raw-extension"))) - (when (file-exists? shared-object-target) (delete-file shared-object-target)) - (define c-source (build-path private-path "tty-raw-extension.c")) - (define object (build-path shared-object-target-path "tty-raw-extension.o")) - (make-directory* shared-object-target-path) - (compile-extension #f ;; not quiet - c-source - object - '()) - (link-extension #f ;; not quiet - (list object) - shared-object-target))) + (pre-install collection-path + (build-path collection-path "private") + "tty-raw-extension.c" + "." + '() + '() + '() + '() + '() + '() + (lambda (thunk) (thunk)) + #t)) diff --git a/ansi/private/tty-raw-extension.c b/ansi/private/tty-raw-extension.c index 891b48a..fa633f3 100644 --- a/ansi/private/tty-raw-extension.c +++ b/ansi/private/tty-raw-extension.c @@ -13,7 +13,9 @@ static int is_raw = 0; static struct termios saved; -static int ttyraw(void) { +static int ttyraw(void) + XFORM_SKIP_PROC +{ /* Based on the settings given in http://www.minek.com/files/unix_examples/raw.html */ struct termios t; @@ -35,8 +37,10 @@ static int ttyraw(void) { is_raw = 1; return 0; } - -static int ttyrestore(void) { + +static int ttyrestore(void) + XFORM_SKIP_PROC +{ if (!is_raw) return 0; if (tcsetattr(STDIN_FD, TCSAFLUSH, &saved) < 0) return -1; @@ -46,11 +50,15 @@ static int ttyrestore(void) { } static Scheme_Object *sch_ttyraw(int argc, Scheme_Object **argv) { - return ttyraw() == 0 ? scheme_true : scheme_false; + int result; + result = ttyraw(); + return result == 0 ? scheme_true : scheme_false; } static Scheme_Object *sch_ttyrestore(int argc, Scheme_Object **argv) { - return ttyrestore() == 0 ? scheme_true : scheme_false; + int result; + result = ttyrestore(); + return result == 0 ? scheme_true : scheme_false; } Scheme_Object *scheme_reload(Scheme_Env *env) { @@ -66,7 +74,9 @@ Scheme_Object *scheme_reload(Scheme_Env *env) { return scheme_void; } -Scheme_Object *scheme_initialize(Scheme_Env *env) { +Scheme_Object *scheme_initialize(Scheme_Env *env) + XFORM_SKIP_PROC +{ atexit((void (*)(void)) ttyrestore); return scheme_reload(env); } diff --git a/ansi/test-raw.rkt b/ansi/test-raw.rkt index 40948dd..3c18787 100644 --- a/ansi/test-raw.rkt +++ b/ansi/test-raw.rkt @@ -1,6 +1,6 @@ #lang racket/base -(require "private/tty-raw-extension") +(require "private/tty-raw-extension.rkt") (require "main.rkt") (require racket/set)