guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] 04/17: Add a few utility functions. * binding-utils.scm: add `p


From: Rémi Birot-Delrue
Subject: [gnunet] 04/17: Add a few utility functions. * binding-utils.scm: add `pointer->string*`. * common.scm: add `bool->int` and `int->bool`, two functions to easily convert `gnunet-ok`, `gnunet-no`, `gnunet-syserror` values to booleans. * fs/uri.scm: export `keyword-list->string`. * tests/uri.scm: test `keyword-list->string`. * scheduler.scm: add `cancel-task!`.
Date: Wed, 12 Aug 2015 18:24:37 +0000

remibd pushed a commit to branch master
in repository gnunet.

commit 6fc73cee9beb1d9498dee6de90ff089794e55f3f
Author: RĂ©mi Birot-Delrue <address@hidden>
Date:   Tue Jul 21 13:01:28 2015 +0200

    Add a few utility functions.
    * binding-utils.scm: add `pointer->string*`.
    * common.scm: add `bool->int` and `int->bool`, two functions to easily 
convert
                  `gnunet-ok`, `gnunet-no`, `gnunet-syserror` values to 
booleans.
    * fs/uri.scm: export `keyword-list->string`.
    * tests/uri.scm: test `keyword-list->string`.
    * scheduler.scm: add `cancel-task!`.
---
 gnu/gnunet/binding-utils.scm |    4 ++++
 gnu/gnunet/common.scm        |    9 +++++++++
 gnu/gnunet/fs/uri.scm        |    4 +++-
 gnu/gnunet/scheduler.scm     |    3 +++
 tests/uri.scm                |    4 ++++
 5 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/gnu/gnunet/binding-utils.scm b/gnu/gnunet/binding-utils.scm
index 4f33306..cabbcf7 100644
--- a/gnu/gnunet/binding-utils.scm
+++ b/gnu/gnunet/binding-utils.scm
@@ -32,6 +32,7 @@
             rassoc-ref
 
             string->pointer*
+            pointer->string*
             make-c-struct*))
 
 (define (getf plist value)
@@ -74,3 +75,6 @@
 if STRING is empty (\"\")."
   (if (string=? "" string) %null-pointer (string->pointer string)))
 
+(define (pointer->string* ptr)
+  (if (eq? %null-pointer ptr) #f (pointer->string ptr)))
+
diff --git a/gnu/gnunet/common.scm b/gnu/gnunet/common.scm
index 7aa6a35..d5a56b6 100644
--- a/gnu/gnunet/common.scm
+++ b/gnu/gnunet/common.scm
@@ -24,6 +24,8 @@
             gnunet-system-error
             gnunet-yes
             gnunet-no
+            bool->int
+            int->bool
 
             time-relative
             time-absolute
@@ -96,6 +98,13 @@
   "GNUNET_STRINGS_string_to_data" : (list '* size_t '* size_t) -> int)
 
 
+(define (bool->int x) (if x gnunet-yes gnunet-no))
+(define (int->bool x)
+  (cond ((= gnunet-yes x)          #t)
+        ((= gnunet-no x)           #f)
+        ((= gnunet-system-error x) #:system-error)
+        (else                      #:unknown)))
+
 (define %xfilename (string->pointer "guile"))
 
 (define (%free pointer)
diff --git a/gnu/gnunet/fs/uri.scm b/gnu/gnunet/fs/uri.scm
index 9503408..9e43841 100644
--- a/gnu/gnunet/fs/uri.scm
+++ b/gnu/gnunet/fs/uri.scm
@@ -36,7 +36,9 @@
             unwrap-uri
             uri-type
             uri-file-size
-            uri->string))
+            uri->string
+
+            keyword-list->string))
 
 (define-record-type <uri>
   (%wrap-uri pointer type)
diff --git a/gnu/gnunet/scheduler.scm b/gnu/gnunet/scheduler.scm
index 94c147a..e45aacd 100644
--- a/gnu/gnunet/scheduler.scm
+++ b/gnu/gnunet/scheduler.scm
@@ -26,6 +26,7 @@
             call-with-scheduler
            add-task!
            set-next-task!
+            cancel-task!
             schedule-shutdown!))
 
 
@@ -52,6 +53,8 @@
   "GNUNET_SCHEDULER_add_delayed_with_priority" :
   (list time-relative unsigned-int '* '*) -> '*)
 
+(define-gnunet cancel-task! "GNUNET_SCHEDULER_cancel" : '(*) -> '*)
+
 (define-gnunet %speedup-start "GNUNET_SPEEDUP_start_" : '(*)  -> int)
 (define-gnunet %speedup-stop  "GNUNET_SPEEDUP_stop_"  : '() -> void)
 
diff --git a/tests/uri.scm b/tests/uri.scm
index ba3660b..4453a95 100644
--- a/tests/uri.scm
+++ b/tests/uri.scm
@@ -22,6 +22,10 @@
 
 (test-begin "test-fs-uri")
 
+;; keyword-list->string
+(test-equal "" (keyword-list->string '()))
+(test-equal "foo bar baz" (keyword-list->string '("foo" "bar" "baz")))
+
 ;; parse-uri
 (test-error 'invalid-arg (parse-uri ""))
 (let ((uri (parse-uri "gnunet://fs/ksk/trek")))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]