~ chicken-core (chicken-5) ce32cb8942f75c88babd4b174b2133c1d9502279
commit ce32cb8942f75c88babd4b174b2133c1d9502279
Author: felix <felix@call-with-current-continuation.org>
AuthorDate: Wed Mar 12 10:13:56 2025 +0100
Commit: felix <felix@call-with-current-continuation.org>
CommitDate: Wed Mar 12 10:13:56 2025 +0100
Added number-vector-data to (chicken memory representation) to access numvector backing store
diff --git a/NEWS b/NEWS
index a2832681..d4508ea9 100644
--- a/NEWS
+++ b/NEWS
@@ -69,6 +69,7 @@
- `include' and `include-relative' accept multiple filenames, `include-ci'
has been added.
- Added `include-path' to (chicken platform) module.
+ - Added `number-vector-data' to (chicken memory representation) module.
- The platform-identifier "mingw32" has been renamed to "mingw".
- Syntax expander:
diff --git a/lolevel.scm b/lolevel.scm
index 760bbdc9..68118358 100644
--- a/lolevel.scm
+++ b/lolevel.scm
@@ -416,7 +416,7 @@ EOF
number-of-slots object-become! object-copy procedure-data
record->vector record-instance-length record-instance-slot
record-instance-slot-set! record-instance-type record-instance?
- set-procedure-data! vector-like?)
+ set-procedure-data! vector-like? number-vector-data)
(import scheme chicken.base chicken.fixnum chicken.foreign)
@@ -554,11 +554,23 @@ EOF
(##sys#check-closure old 'mutate-procedure!)
(##sys#check-closure proc 'mutate-procedure!)
(let* ([n (##sys#size old)]
- [words (##core#inline "C_words" n)]
- [new (##core#inline "C_copy_block" old (##sys#make-vector words))] )
+ [words (##core#inline "C_words" n)]
+ [new (##core#inline "C_copy_block" old (##sys#make-vector words))] )
(##sys#become! (list (cons old (proc new))))
new ) )
+
+;;; access backing store of numeric vector
+
+(define (number-vector-data v)
+ (cond ((and (##core#inline "C_blockp" v)
+ (##core#inline "C_bytevectorp" v))
+ v)
+ ((##sys#srfi-4-vector? v) (##sys#slot v 1))
+ (else (##sys#signal-hook #:type-error 'number-vector-data
+ "bad argument type - not a numeric vector" v))))
+
+
) ; chicken.memory.representation
diff --git a/manual/Module (chicken memory representation) b/manual/Module (chicken memory representation)
index 1ca47f43..28caa7d3 100644
--- a/manual/Module (chicken memory representation)
+++ b/manual/Module (chicken memory representation)
@@ -122,6 +122,17 @@ Copies {{X}} recursively and returns the fresh copy. Objects allocated
in static memory are copied back into garbage collected storage.
+==== number-vector-data
+
+<procedure>(number-vector-data VECTOR)</procedure>
+
+Returns the bytevector holding the raw data of the numeric vector {{VECTOR}},
+which should be a bytevector or a homogenous number vector as those
+exposed by the {{(chicken numvector)}} and {{srfi-4}} library modules.
+If {{VECTOR}} is a bytevector, the result will be identical to the argument.
+The returned bytevector shares storage with the original value.
+
+
=== Record instance
Trap