-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port to CFFI, integrate CL-POSIX as OSICAT-POSIX, and more.
- Three new modules: POSIX (code imported from CL-POSIX aka IOLIB-POSIX aka CFFI-UNIX), MACH, and WINDOWS. Those last two don't have much though. - Port high-level interface to CFFI and using the low-level interface defined in OSICAT-POSIX. - Added new file/pathname utilities adapted from CL-FAD: WALK-DIRECTORY, DELETE-DIRECTORY-AND-FILES, DIRECTORY-EXISTS-P, LIST-DIRECTORY, FILE-EXISTS-P, DIRECTORY-PATHNAME-P, PATHNAME-AS-DIRECTORY, PATHNAME-AS-FILE. - New: PATHNAME-DIRECTORY-PATHNAME and GET-MONOTONIC-TIME.
- Loading branch information
Showing
27 changed files
with
3,989 additions
and
926 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
-*- text -*- | ||
|
||
====== | ||
Osicat | ||
|
||
* define an error hierarchy. | ||
|
||
================================= | ||
cl-posix/iolib-posix/osicat-posix | ||
|
||
* add missing Linux IOCTLs | ||
* add definitions of struct types used by Linux IOCTLs | ||
* add FreeBSD IOCTLs | ||
* add getgroups, alarm, utime, utimes, wait, waitpid, getpagesize, | ||
things from termios.h | ||
|
||
* some ideas: | ||
|
||
-> return T instead of 0 on success. | ||
|
||
-> probably not worth the trouble: add finalizers to stuff such as | ||
the return value of OPENDIR (perhaps wrap them in objects?) | ||
|
||
-> SB-POSIX returns class objects instead of multiple values | ||
for functions like GETPWUID. Which approach is better? | ||
|
||
-> simple documentation with the short docstrings plus links to | ||
linux and BSD manpages. | ||
|
||
============================== | ||
osicat-windows and osicat-mach | ||
|
||
* handle errors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- | ||
;;; | ||
;;; mach.lisp --- Low-level interface to the Mach API. | ||
;;; | ||
;;; Copyright (c) 2007, Luis Oliveira <[email protected]> | ||
;;; | ||
;;; Permission is hereby granted, free of charge, to any person | ||
;;; obtaining a copy of this software and associated documentation | ||
;;; files (the "Software"), to deal in the Software without | ||
;;; restriction, including without limitation the rights to use, copy, | ||
;;; modify, merge, publish, distribute, sublicense, and/or sell copies | ||
;;; of the Software, and to permit persons to whom the Software is | ||
;;; furnished to do so, subject to the following conditions: | ||
;;; | ||
;;; The above copyright notice and this permission notice shall be | ||
;;; included in all copies or substantial portions of the Software. | ||
;;; | ||
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
;;; DEALINGS IN THE SOFTWARE. | ||
|
||
(in-package #:osicat-mach) | ||
|
||
(defctype kern-return :int) | ||
(defctype clock-res :int) | ||
(defctype clock-id :int) | ||
(defctype port :unsigned-int) ; not sure | ||
(defctype clock-serv port) | ||
|
||
(defconstant kern-success 0) | ||
|
||
(defconstant system-clock 0) | ||
(defconstant calendar-clock 1) | ||
(defconstant realtime-clock 0) | ||
|
||
(defcstruct timespec | ||
(tv-sec :unsigned-int) | ||
(tv-nsec clock-res)) | ||
|
||
(defcfun "mach_host_self" port) | ||
|
||
(defcfun ("host_get_clock_service" %host-get-clock-service) kern-return | ||
(host port) | ||
(id clock-id) | ||
(clock-name (:pointer clock-serv))) | ||
|
||
(defun host-get-clock-service (id &optional (host (mach-host-self))) | ||
(with-foreign-object (clock 'clock-serv) | ||
(host-get-clock-service host id clock) | ||
(mem-ref clock :int))) | ||
|
||
(defcfun ("clock_get_time" %clock-get-time) kern-return | ||
(clock-serv clock-serv) | ||
(cur-time timespec)) | ||
|
||
(defun clock-get-time (clock-service) | ||
(with-foreign-object (time 'timespec) | ||
(clock-get-time clock-service time) | ||
(with-foreign-slots ((tv-sec tv-nsec) time timespec) | ||
(values tv-sec tv-nsec)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- | ||
;;; | ||
;;; package.lisp --- Package definition. | ||
;;; | ||
;;; Copyright (c) 2007, Luis Oliveira <[email protected]> | ||
;;; | ||
;;; Permission is hereby granted, free of charge, to any person | ||
;;; obtaining a copy of this software and associated documentation | ||
;;; files (the "Software"), to deal in the Software without | ||
;;; restriction, including without limitation the rights to use, copy, | ||
;;; modify, merge, publish, distribute, sublicense, and/or sell copies | ||
;;; of the Software, and to permit persons to whom the Software is | ||
;;; furnished to do so, subject to the following conditions: | ||
;;; | ||
;;; The above copyright notice and this permission notice shall be | ||
;;; included in all copies or substantial portions of the Software. | ||
;;; | ||
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
;;; DEALINGS IN THE SOFTWARE. | ||
|
||
(in-package #:cl-user) | ||
|
||
(defpackage #:osicat-mach | ||
(:use #:common-lisp #:cffi) | ||
(:nicknames #:mach) | ||
(:export | ||
;; Functions | ||
#:mach-host-self | ||
#:host-get-clock-service | ||
#:clock-get-time | ||
|
||
;; Constants | ||
#:system-clock | ||
#:realtime-clock | ||
#:calendar-clock | ||
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,100 +1,77 @@ | ||
;; Copyright (c) 2003, 2004 Nikodemus Siivola <[email protected]> | ||
;; | ||
;; Permission is hereby granted, free of charge, to any person obtaining | ||
;; a copy of this software and associated documentation files (the | ||
;; "Software"), to deal in the Software without restriction, including | ||
;; without limitation the rights to use, copy, modify, merge, publish, | ||
;; distribute, sublicense, and/or sell copies of the Software, and to | ||
;; permit persons to whom the Software is furnished to do so, subject to | ||
;; the following conditions: | ||
;; | ||
;; The above copyright notice and this permission notice shall be included | ||
;; in all copies or substantial portions of the Software. | ||
;; | ||
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
;; IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
;; CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
|
||
(defpackage :osicat-system | ||
(:use :cl :asdf)) | ||
|
||
(in-package :osicat-system) | ||
|
||
;;;; C-SOURCE FILE HANDLING | ||
|
||
(defvar *gcc* "/usr/bin/gcc") | ||
(defvar *gcc-options* '(#-darwin "-shared" | ||
#+darwin "-dynamiclib" | ||
"-fPIC")) | ||
|
||
(defmethod output-files ((o compile-op) (c c-source-file)) | ||
(list (make-pathname :name (component-name c) | ||
:type "so" | ||
:defaults (component-pathname c)))) | ||
|
||
(defmethod perform ((o load-op) (c c-source-file)) | ||
(let ((loader (intern "LOAD-FOREIGN-LIBRARY" :uffi))) | ||
(dolist (file (asdf::input-files o c)) | ||
(funcall loader file :module "osicat" :force-load t)))) | ||
|
||
(defmethod perform ((o compile-op) (c c-source-file)) | ||
(unless (zerop (run-shell-command "~A ~A ~{~A ~}-o ~A" | ||
*gcc* | ||
(namestring (component-pathname c)) | ||
*gcc-options* | ||
(namestring (car (output-files o c))))) | ||
(error 'operation-error :component c :operation o))) | ||
|
||
;;;; GROVELING | ||
|
||
(defclass grovel-file (cl-source-file) ()) | ||
|
||
(defmethod perform ((o compile-op) (c grovel-file)) | ||
(let* ((output-file (car (output-files o c))) | ||
(filename (component-pathname c)) | ||
(c-source (merge-pathnames "tmp.c" output-file)) | ||
(a-dot-out (merge-pathnames "a.out" output-file)) | ||
(constants (merge-pathnames "grovel.lisp-temp" output-file)) | ||
(*grovel*)) | ||
(declare (special *grovel*)) | ||
;; Loading the groveler will bind the *govel* hook. | ||
(load filename) | ||
(and (funcall (the function *grovel*) c-source a-dot-out constants) | ||
(compile-file constants :output-file output-file)))) | ||
|
||
;;;; SYSTEM | ||
|
||
(defsystem :osicat | ||
:version "0.5.0" | ||
:depends-on (:uffi) | ||
;;;; -*- Mode: lisp; indent-tabs-mode: nil -*- | ||
;;; | ||
;;; osicat.asd --- ASDF system definition. | ||
;;; | ||
;;; Copyright (C) 2007, Luis Oliveira <[email protected]> | ||
;;; | ||
;;; Permission is hereby granted, free of charge, to any person | ||
;;; obtaining a copy of this software and associated documentation | ||
;;; files (the "Software"), to deal in the Software without | ||
;;; restriction, including without limitation the rights to use, copy, | ||
;;; modify, merge, publish, distribute, sublicense, and/or sell copies | ||
;;; of the Software, and to permit persons to whom the Software is | ||
;;; furnished to do so, subject to the following conditions: | ||
;;; | ||
;;; The above copyright notice and this permission notice shall be | ||
;;; included in all copies or substantial portions of the Software. | ||
;;; | ||
;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
;;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
;;; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
;;; DEALINGS IN THE SOFTWARE. | ||
|
||
(eval-when (:load-toplevel :execute) | ||
(operate 'load-op 'trivial-features) | ||
(operate 'load-op 'cffi-grovel)) | ||
|
||
(use-package 'cffi-grovel) | ||
|
||
;;; We could split these modules into separate systems if anyone feels | ||
;;; that might be useful. --luis | ||
|
||
(defsystem osicat | ||
:version "0.6.0-pre1" | ||
:depends-on (cffi cffi-grovel alexandria trivial-features) | ||
:components | ||
((:module osicat-sys | ||
:pathname #p"src/" | ||
:components | ||
((:c-source-file "osicat-glue") | ||
(:file "packages") | ||
(:grovel-file "grovel-constants" :depends-on ("packages")) | ||
(:file "early-util" :depends-on ("packages")) | ||
(:file "ffi" :depends-on ("early-util")) | ||
(:file "ports" :depends-on ("packages")) | ||
(:file "osicat" :depends-on | ||
("osicat-glue" "ports" "ffi" "grovel-constants")))) | ||
|
||
;;;; TESTING | ||
|
||
(defsystem :osicat-test | ||
:depends-on (:osicat :rt #+sbcl :sb-posix) | ||
:components ((:file "test-tools") | ||
(:file "test-osicat" :depends-on ("test-tools")))) | ||
|
||
(defmethod perform ((o test-op) (c (eql (find-system :osicat)))) | ||
(operate 'load-op :osicat-test) | ||
(funcall (intern "SETUP" :osicat-test)) | ||
(unwind-protect | ||
(operate 'test-op :osicat-test :force t) | ||
(funcall (intern "TEARDOWN" :osicat-test)))) | ||
|
||
(defmethod perform ((o test-op) (c (eql (find-system :osicat-test)))) | ||
(or (funcall (intern "DO-TESTS" :rt)) | ||
(error "test-op failed"))) | ||
((:file "osicat-sys"))) | ||
(:module posix | ||
:depends-on (osicat-sys) | ||
:serial t | ||
:components | ||
((:file "packages") | ||
(:grovel-file "basic-unixint") | ||
#-windows (:grovel-file "unixint") | ||
(:file "early") | ||
(:wrapper-file "wrappers") | ||
(:file "basic-unix") | ||
#-windows (:file "unix") | ||
#+linux (:file "linux") | ||
#+bsd (:file "bsd") | ||
#+windows (:file "windows") | ||
(:file "misc"))) | ||
#+windows | ||
(:module windows | ||
:depends-on (osicat-sys) | ||
:components | ||
((:file "package") | ||
(:file "windows" :depends-on ("package")))) | ||
#+darwin | ||
(:module mach | ||
:depends-on (osicat-sys) | ||
:components | ||
((:file "package") | ||
(:file "mach" :depends-on ("package")))) | ||
(:module src | ||
:depends-on (osicat-sys posix #+windows windows #+darwin mach) | ||
:components | ||
((:file "packages") | ||
;; (:file "fd-streams" :depends-on ("packages")) | ||
(:file "osicat" :depends-on ("packages" #-(and) "fd-streams")) | ||
(:file "time" :depends-on ("packages")))))) |
Oops, something went wrong.