From: Joshua Elsasser Date: Sun, 12 May 2013 15:36:11 +0000 (-0700) Subject: Grovel timeval and timespec struct definitions rather than hard-coding. X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=7230b50bc438a7fbebd93866a96f9291e630419f;p=sbcl.git Grovel timeval and timespec struct definitions rather than hard-coding. --- diff --git a/src/code/unix.lisp b/src/code/unix.lisp index b7a30c8..0856069 100644 --- a/src/code/unix.lisp +++ b/src/code/unix.lisp @@ -203,33 +203,6 @@ corresponds to NAME, or NIL if there is none." (values #!-win32 fd #!+win32 (sb!win32::duplicate-and-unwrap-fd fd) (octets-to-string template-buffer))))))) -;;;; timebits.h - -;; A time value that is accurate to the nearest -;; microsecond but also has a range of years. -;; CLH: Note that tv-usec used to be a time-t, but that this seems -;; problematic on Darwin x86-64 (and wrong). Trying suseconds-t. -#!-(or win32 openbsd netbsd) -(define-alien-type nil - (struct timeval - (tv-sec time-t) ; seconds - (tv-usec suseconds-t))) ; and microseconds - -;; The above definition doesn't work on 64-bit OpenBSD platforms. -;; Both tv_sec and tv_usec are declared as long instead of time_t, and -;; time_t is a typedef for int. -#!+(or openbsd netbsd) -(define-alien-type nil - (struct timeval - (tv-sec long) ; seconds - (tv-usec long))) ; and microseconds - -#!+win32 -(define-alien-type nil - (struct timeval - (tv-sec time-t) ; seconds - (tv-usec long))) ; and microseconds - ;;;; resourcebits.h (defconstant rusage_self 0) ; the calling process @@ -937,23 +910,6 @@ avoiding atexit(3) hooks, etc. Otherwise exit(2) is called." ;;;; time.h -;; the POSIX.4 structure for a time value. This is like a "struct -;; timeval" but has nanoseconds instead of microseconds. -#!-(or openbsd netbsd) -(define-alien-type nil - (struct timespec - (tv-sec long) ; seconds - (tv-nsec long))) ; nanoseconds - -;; Just as with struct timeval, 64-bit OpenBSD has problems with the -;; above definition. tv_sec is declared as time_t instead of long, -;; and time_t is a typedef for int. -#!+(or openbsd netbsd) -(define-alien-type nil - (struct timespec - (tv-sec time-t) ; seconds - (tv-nsec long))) ; nanoseconds - ;; used by other time functions (define-alien-type nil (struct tm diff --git a/tools-for-build/grovel-headers.c b/tools-for-build/grovel-headers.c index 9a3e74d..315c6cd 100644 --- a/tools-for-build/grovel-headers.c +++ b/tools-for-build/grovel-headers.c @@ -39,6 +39,7 @@ #include #include #include + #include #include #include #endif @@ -48,6 +49,7 @@ #include #include #include +#include #ifdef LISP_FEATURE_HPUX #include /* for TIOCGPGRP */ @@ -64,6 +66,16 @@ #define DEFTYPE(lispname,cname) { cname foo; \ printf("(define-alien-type " lispname " (%s %d))\n", (((foo=-1)<0) ? "sb!alien:signed" : "unsigned"), (8 * (sizeof foo))); } +#define DEFSTRUCT(lispname,cname,body) { cname bar; \ + printf("(define-alien-type nil\n (struct %s", #lispname); \ + body; \ + printf("))\n"); } +#define DEFSLOT(lispname,cname) \ + printf("\n (%s (%s %d))", \ + #lispname, \ + (((bar.cname=-1)<0) ? "sb!alien:signed" : "unsigned"), \ + (8 * (sizeof bar.cname))) + void defconstant(char* lisp_name, unsigned long unix_number) { @@ -501,6 +513,15 @@ main(int argc, char *argv[]) #endif // !WIN32 printf("\n"); + printf(";;; structures\n"); + DEFSTRUCT(timeval, struct timeval, + DEFSLOT(tv-sec, tv_sec); + DEFSLOT(tv-usec, tv_usec)); + DEFSTRUCT(timespec, struct timespec, + DEFSLOT(tv-sec, tv_sec); + DEFSLOT(tv-nsec, tv_nsec)); + printf("\n"); + #ifdef LISP_FEATURE_BSD printf(";;; sysctl(3) names\n"); printf("(in-package \"SB!IMPL\")\n");