Skip to content

Commit 758ea71

Browse files
committed
Merge pull request #22 from avsm/master
Add `to_bigarray` to convert back into a Bigarray slice.
2 parents 6230511 + 7bb0a8f commit 758ea71

File tree

8 files changed

+1498
-422
lines changed

8 files changed

+1498
-422
lines changed

CHANGES

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
trunk (unreleased)
2-
* Improve bounds checks on sub, shift, set_len, add_len
1+
1.1.0 (2014-02-19)
2+
* Improve bounds checks on sub, shift, set_len, add_len.
3+
* Add `to_bigarray` to convert back into a Bigarray slice.
34

45
1.0.1 (2013-12-09):
56
* Fix Cstruct.shift function

_oasis

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
OASISFormat: 0.3
22
Name: cstruct
3-
Version: 1.0.1
3+
Version: 1.1.0
44
Synopsis: Manipulate external buffers as C-like structs
55
Authors: Anil Madhavapeddy, Richard Mortier, Thomas Gazagnaire, Pierre Chambart
66
License: ISC

_tags

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
true: inline(10)
22
true: debug
33
# OASIS_START
4-
# DO NOT EDIT (digest: 60dceed12f46a3257c5355789042d89e)
5-
# Ignore VCS directories, you can use the same kind of rule outside
6-
# OASIS_START/STOP if you want to exclude directories that contains
4+
# DO NOT EDIT (digest: 623ae0a45fad2527c26cc490691b077a)
5+
# Ignore VCS directories, you can use the same kind of rule outside
6+
# OASIS_START/STOP if you want to exclude directories that contains
77
# useless stuff for the build process
88
<**/.svn>: -traverse
99
<**/.svn>: not_hygienic

lib/META

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# OASIS_START
2-
# DO NOT EDIT (digest: 762d7a6f73f805c365e1539014f0009c)
3-
version = "1.0.1"
2+
# DO NOT EDIT (digest: b4981197fe71fb2a248209688d5e96a0)
3+
version = "1.1.0"
44
description = "Manipulate external buffers as C-like structs"
55
requires = "bigarray ocplib-endian ocplib-endian.bigstring"
66
archive(byte) = "cstruct.cma"
@@ -9,7 +9,7 @@ archive(native) = "cstruct.cmxa"
99
archive(native, plugin) = "cstruct.cmxs"
1010
exists_if = "cstruct.cma"
1111
package "unix" (
12-
version = "1.0.1"
12+
version = "1.1.0"
1313
description = "Manipulate external buffers as C-like structs"
1414
requires = "cstruct unix"
1515
archive(byte) = "unix_cstruct.cma"
@@ -20,16 +20,20 @@ package "unix" (
2020
)
2121

2222
package "syntax" (
23-
version = "1.0.1"
23+
version = "1.1.0"
2424
description = "Syntax extension for Cstruct"
2525
requires = "camlp4"
2626
archive(syntax, preprocessor) = "cstruct-syntax.cma"
2727
archive(syntax, toploop) = "cstruct-syntax.cma"
28+
archive(syntax, byte) = "cstruct-syntax.cma"
29+
archive(syntax, byte, plugin) = "cstruct-syntax.cma"
30+
archive(syntax, native) = "cstruct-syntax.cmxa"
31+
archive(syntax, native, plugin) = "cstruct-syntax.cmxs"
2832
exists_if = "cstruct-syntax.cma"
2933
)
3034

3135
package "lwt" (
32-
version = "1.0.1"
36+
version = "1.1.0"
3337
description = "Manipulate external buffers as C-like structs"
3438
requires = "cstruct lwt.unix"
3539
archive(byte) = "lwt_cstruct.cma"
@@ -40,7 +44,7 @@ package "lwt" (
4044
)
4145

4246
package "async" (
43-
version = "1.0.1"
47+
version = "1.1.0"
4448
description = "Manipulate external buffers as C-like structs"
4549
requires = "cstruct async threads"
4650
archive(byte) = "async_cstruct.cma"

lib/cstruct.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ let of_bigarray ?(off=0) ?len buffer =
3131
|Some len -> min len (Bigarray.Array1.dim buffer)
3232
in { buffer; off; len }
3333

34+
let to_bigarray buffer =
35+
Bigarray.Array1.sub buffer.buffer buffer.off buffer.len
36+
3437
let create len =
3538
let ba = Bigarray.Array1.create Bigarray.char Bigarray.c_layout len in
3639
of_bigarray ba

lib/cstruct.mli

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,17 @@ type uint64 = int64
162162
(** 64-bit unsigned integer. The representation is currently a
163163
boxed OCaml int64. *)
164164

165-
(** {2 Creation} *)
165+
(** {2 Creation and conversion} *)
166166

167167
val of_bigarray: ?off:int -> ?len:int -> buffer -> t
168168
(** [of_bigarray ~off ~len b] is the cstruct contained in [b] starting
169169
at [off], of length [len]. *)
170170

171+
val to_bigarray: t -> buffer
172+
(** [to_bigarray t] converts a {!t} into a {!buffer} Bigarray, using
173+
the Bigarray slicing to allocate a fresh array that preserves
174+
sharing of the underlying buffer. *)
175+
171176
val create : int -> t
172177
(** [create len] is a cstruct of size [len] with an offset of 0. *)
173178

0 commit comments

Comments
 (0)