diff options
author | Ludovic Courtès <ludo@gnu.org> | 2015-07-17 23:31:29 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2015-07-17 23:31:29 +0200 |
commit | 13f0c6ed4147d381e7b5e4601a50fe9f997d0ca5 (patch) | |
tree | 2f88824921162151df8efb1efd2246a2ec9f2e0d | |
parent | 4f7b564adbc09267fa61ee93292e2fc8a470f9cd (diff) | |
download | patches-13f0c6ed4147d381e7b5e4601a50fe9f997d0ca5.tar patches-13f0c6ed4147d381e7b5e4601a50fe9f997d0ca5.tar.gz |
syscalls: Struct deserializer can now return arbitrary objects.
* guix/build/syscalls.scm (read-types): Add RETURN and VALUES parameters.
(define-c-struct): Add WRAP-FIELDS parameter and pass it to 'read-types'.
(sockaddr-in, sockaddr-in6): Add first argument that uses
'make-socket-address'.
(read-socket-address): Remove 'match' on the result of 'read-sockaddr-in'
and 'read-sockaddr-in6'.
-rw-r--r-- | guix/build/syscalls.scm | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index dcca5fc339..b7c0f7e745 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -398,22 +398,23 @@ system to PUT-OLD." (define-syntax read-types (syntax-rules () - ((_ bv offset ()) - '()) - ((_ bv offset (type0 types ...)) - (cons (read-type bv offset type0) - (read-types bv (+ offset (type-size type0)) (types ...)))))) + ((_ return bv offset () (values ...)) + (return values ...)) + ((_ return bv offset (type0 types ...) (values ...)) + (read-types return + bv (+ offset (type-size type0)) (types ...) + (values ... (read-type bv offset type0)))))) (define-syntax define-c-struct (syntax-rules () - "Define READ as an optimized serializer and WRITE! as a deserializer for -the C structure with the given TYPES." - ((_ name read write! (fields types) ...) + "Define READ as a deserializer and WRITE! as a serializer for the C +structure with the given TYPES. READ uses WRAP-FIELDS to return its value." + ((_ name wrap-fields read write! (fields types) ...) (begin (define (write! bv offset fields ...) (write-types bv offset (types ...) (fields ...))) (define (read bv offset) - (read-types bv offset (types ...))))))) + (read-types wrap-fields bv offset (types ...) ())))))) ;;; @@ -463,6 +464,8 @@ the C structure with the given TYPES." 32)) (define-c-struct sockaddr-in ;<linux/in.h> + (lambda (family port address) + (make-socket-address family address port)) read-sockaddr-in write-sockaddr-in! (family unsigned-short) @@ -470,6 +473,8 @@ the C structure with the given TYPES." (address (int32 ~ big))) (define-c-struct sockaddr-in6 ;<linux/in6.h> + (lambda (family port flowinfo address scopeid) + (make-socket-address family address port flowinfo scopeid)) read-sockaddr-in6 write-sockaddr-in6! (family unsigned-short) @@ -501,14 +506,9 @@ bytevector BV at INDEX." "Read a socket address from bytevector BV at INDEX." (let ((family (bytevector-u16-native-ref bv index))) (cond ((= family AF_INET) - (match (read-sockaddr-in bv index) - ((family port address) - (make-socket-address family address port)))) + (read-sockaddr-in bv index)) ((= family AF_INET6) - (match (read-sockaddr-in6 bv index) - ((family port flowinfo address scopeid) - (make-socket-address family address port - flowinfo scopeid)))) + (read-sockaddr-in6 bv index)) (else "unsupported socket address family" family)))) |