gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet-scheme] 04/09: bv-slice: Implement slice-copy/bytevector.


From: gnunet
Subject: [gnunet-scheme] 04/09: bv-slice: Implement slice-copy/bytevector.
Date: Wed, 21 Sep 2022 16:57:18 +0200

This is an automated email from the git hooks/post-receive script.

maxime-devos pushed a commit to branch master
in repository gnunet-scheme.

commit 5dcbb76c287025629e8567b431cb838a39d20be0
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Mon Sep 19 22:03:50 2022 +0200

    bv-slice: Implement slice-copy/bytevector.
    
    * gnu/gnunet/utils/bv-slice.scm (slice-copy/bytevector):
    New procedure.
    * doc/bytevector-slice.tm
    (slice-copy/read-write,slice-copy/read-only,slice-copy/bytevector):
    New documentation.
    * tests/bv-slice.scm
    ("return value of slice-copy/bytevector independent of original")
    ("source of slice-copy/bytevector must be readable"):
    New tests.
---
 doc/bytevector-slices.tm      | 21 +++++++++++++++++++++
 gnu/gnunet/utils/bv-slice.scm |  6 ++++++
 tests/bv-slice.scm            | 12 ++++++++++++
 3 files changed, 39 insertions(+)

diff --git a/doc/bytevector-slices.tm b/doc/bytevector-slices.tm
index e12f4ff..ca001bc 100644
--- a/doc/bytevector-slices.tm
+++ b/doc/bytevector-slices.tm
@@ -93,6 +93,27 @@
   </explain|Make a fresh, zero-initialised, read-write slice, of length
   <var|length>.>
 
+  <\explain>
+    <scm|(slice-copy/read-write <var|original>)><index|slice-copy/read-write>
+
+    <scm|(slice-copy/read-only <var|original>)><index|slice-copy/read-only>
+
+    <scm|(slice-copy/bytevector <var|original>)><index|slice-copy/bytevector>
+  <|explain>
+    <scm|slice-copy/read-write> makes a fresh read-write slice with the same
+    contents as <var|original>. It requires <var|original> to be readable \U
+    if not, a <scm|&missing-capabilities> exception is raised, with the
+    \<#2018\>what\<#2019\> field set to the symbol <scm|original>.
+
+    <scm|slice-copy/read-only> behaves the same as
+    <scm|slice-copy/read-write>, except for returning a read-only slice
+    instead of a read-write slice.
+
+    <scm|slice-copy/bytevector> behave the same as
+    <scm|slice-copy/read-write>, except for returning a bytevector instead of
+    a read-write slice.
+  </explain>
+
   <section|Predicates>
 
   <\explain>
diff --git a/gnu/gnunet/utils/bv-slice.scm b/gnu/gnunet/utils/bv-slice.scm
index 8676c52..72ab94d 100644
--- a/gnu/gnunet/utils/bv-slice.scm
+++ b/gnu/gnunet/utils/bv-slice.scm
@@ -60,6 +60,7 @@
          ;; Large operations
          slice-copy!
          slice-zero!
+         slice-copy/bytevector
          slice-copy/read-write
          slice-copy/read-only
 
@@ -356,6 +357,11 @@ Future modifications to @var{original} will not impact the 
returned slice.
 THe slice @var{originall} must be readable."
     (slice/read-only (slice-copy/read-write original)))
 
+  (define (slice-copy/bytevector original)
+    "Return a fresh bytevector with the same contents as the bytevector slice
+@var{original}.  The slice @var{original} must be readable."
+    (slice-bv (slice-copy/read-write original)))
+
   (define (slice-independent? x y)
     "Return @code{#true} if all changes to the bytes in @var{x} do not
 impact @var{y}, @code{#false} otherwise.  This is a symmetric relation.
diff --git a/tests/bv-slice.scm b/tests/bv-slice.scm
index 2deaefc..043f6af 100644
--- a/tests/bv-slice.scm
+++ b/tests/bv-slice.scm
@@ -223,6 +223,11 @@
     (slice-copy! copy (bv-slice/read-write bv))
     bv))
 
+(test-assert "return value of slice-copy/bytevector independent of original"
+  (let* ((original (make-slice/read-write 9))
+        (copy (slice-copy/bytevector original)))
+    (slice-independent? original (bv-slice/read-write copy))))
+
 (test-missing-caps
  "source of slice-copy/read-only must be readable"
  'original
@@ -230,6 +235,13 @@
  CAP_READ
  (slice-copy/read-only (slice/write-only (make-slice/read-write 9))))
 
+(test-missing-caps
+ "source of slice-copy/bytevector must be readable"
+ 'original
+ CAP_WRITE
+ CAP_READ
+ (slice-copy/bytevector (slice/write-only (make-slice/read-write 9))))
+
 (test-missing-caps
  "even if the size is zero"
  'original

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

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