Skip to content

Commit

Permalink
Release v0.7.2!
Browse files Browse the repository at this point in the history
  • Loading branch information
toots committed Nov 22, 2021
1 parent 9d34910 commit 441ca45
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 13 deletions.
32 changes: 24 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
name: Build
on: [push]
jobs:
cancel_previous_run:
runs-on: ubuntu-latest
steps:
- name: Cancel Previous Runs
uses: styfle/[email protected]
with:
access_token: ${{ github.token }}

build:
runs-on: ${{ matrix.operating-system }}
strategy:
matrix:
operating-system: [ubuntu-20.04, macos-latest]
operating-system: [ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v1
- uses: avsm/setup-ocaml@master
- run: opam pin add -n .
- run: opam depext -yti mm ao mad pulseaudio theora gstreamer # SDL and graphics fail on OSX
if: matrix.operating-system == 'macos-latest'
- run: opam depext -yti mm alsa ao mad pulseaudio ocamlsdl theora graphics gstreamer
- name: Checkout code
uses: actions/checkout@v1
- name: Install OCaml
uses: ocaml/setup-ocaml@v2
- name: Update packages
run: |
sudo apt-get update
if: matrix.operating-system != 'macos-latest'
- run: eval $(opam env) && dune build
- name: Pin locally
run: opam pin -y add --no-action .
- name: Install locally
run: opam install -y mm ao mad pulseaudio theora gstreamer # SDL and graphics fail on OSX
if: matrix.operating-system == 'macos-latest'
- run: opam install -y mm alsa ao mad pulseaudio ocamlsdl theora graphics gstreamer
if: matrix.operating-system != 'macos-latest'
- name: Run tests locally
run: opam exec dune runtest
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
0.7.2 ()
0.7.2 (22-11-2021)
=====
* Fix offsets in to_{s16, u8} functions.
* Switch to `aligned_alloc` for allocate aligned
memory, fix minor heap stats when allocating
bigarrays with aligned memory. (ocaml/ocaml#10788)

0.7.1 (10-01-2021)
=====
Expand Down
24 changes: 20 additions & 4 deletions src/image_data.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
#include <caml/memory.h>
#include <caml/misc.h>
#include <caml/mlvalues.h>
#include <caml/unixsupport.h>

#include <stdlib.h>
#include <string.h>
#include <stddef.h>
#include <stdalign.h>

#include "image_data.h"

Expand All @@ -21,11 +24,20 @@ CAMLprim value caml_data_aligned(value _alignment, value _len) {
int len = Int_val(_len);
unsigned char *data;

data = memalign(alignment, len);
// This is until: https://github.com/ocaml/ocaml/pull/10788 is merged
ans = caml_ba_alloc_dims(CAML_BA_C_LAYOUT | CAML_BA_UINT8,
1, NULL, len);

if (alignment < alignof(max_align_t)) {
CAMLreturn(ans);
}

data = aligned_alloc(alignment, len);
if (data == NULL)
caml_raise_out_of_memory();
ans = caml_ba_alloc_dims(CAML_BA_MANAGED | CAML_BA_C_LAYOUT | CAML_BA_UINT8,
1, data, len);
uerror("aligned_alloc", Nothing);

free(Caml_ba_data_val(ans));
Caml_ba_array_val(ans)->data = data;

CAMLreturn(ans);
}
Expand All @@ -35,6 +47,8 @@ CAMLprim value caml_data_of_string(value s) {
CAMLlocal1(ans);
long len = caml_string_length(s);
unsigned char *data = malloc(len);
if (data == NULL)
caml_raise_out_of_memory();
memcpy(data, String_val(s), len);
ans = caml_ba_alloc_dims(CAML_BA_MANAGED | CAML_BA_C_LAYOUT | CAML_BA_UINT8,
1, data, len);
Expand All @@ -57,6 +71,8 @@ CAMLprim value caml_data_copy(value _src) {
unsigned char *src = Caml_ba_data_val(_src);
long len = Caml_ba_array_val(_src)->dim[0];
unsigned char *dst = malloc(len);
if (dst == NULL)
caml_raise_out_of_memory();
memcpy(dst, src, len);
ans = caml_ba_alloc_dims(CAML_BA_MANAGED | CAML_BA_C_LAYOUT | CAML_BA_UINT8,
1, dst, len);
Expand Down

0 comments on commit 441ca45

Please sign in to comment.