Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configure travis to test osx and linux #23

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 73 additions & 24 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,73 @@
language: elixir
elixir:
- 1.9
otp_release:
- 22.0
matrix:
include:
- elixir: 1.6
otp_release: 19.3
- elixir: 1.7
otp_release: 21.0
- elixir: 1.8
otp_release: 21.0
- elixir: 1.9
otp_release: 22.0
- elixir: 1.6
otp_release: 19.3
- elixir: 1.7
otp_release: 21.0
- elixir: 1.8
otp_release: 21.0
- elixir: 1.9
otp_release: 22.0
sudo: false
# language: elixir
language: c

os:
- linux
- osx

addons:
apt:
packages:
- elixir
- cmake
- erlang-dev
- erlang-xmerl
- erlang-parsetools
homebrew:
packages:
- cmake
- elixir
- erlang

script: ./build.sh

# elixir:
# - 1.9
# otp_release:
# - 22.0
# matrix:
# include:
# # - elixir: 1.6
# # otp_release: 19.3
# # - elixir: 1.7
# # otp_release: 21.0
# - elixir: 1.8
# otp_release: 21.0
# - elixir: 1.9
# otp_release: 22.0
sudo: false

# language: elixir
# os:
# - linux
# - osx
# elixir:
# - 1.8
# otp_release:
# - 21.0
# # elixir:
# # - 1.9
# # otp_release:
# # - 22.0
# # matrix:
# # include:
# # # - elixir: 1.6
# # # otp_release: 19.3
# # # - elixir: 1.7
# # # otp_release: 21.0
# # - elixir: 1.8
# # otp_release: 21.0
# # - elixir: 1.9
# # otp_release: 22.0
# sudo: false

# - name: "travis-osx"
# os: osx
# osx_image: xcode10
# addons:
# homebrew:
# packages:
# - cmake
# - elixir
# - erlang
# sudo: false
6 changes: 6 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

mix local.hex --force
mix deps.get
mix deps.compile
mix compile
36 changes: 36 additions & 0 deletions target/modest_worker/test/open_memstream_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

#include "test_includes.h"
/*
To check for memory leaks execute test with term_arrayalgrind.

valgrind --leak-check=yes target/modest_worker/build/test/open_memstream_test

*/
int main(int argc, const char* argterm_array[])
{

FILE *stream;
char *buf;
size_t len;
off_t eob;

stream = open_memstream (&buf, &len);
if (stream == NULL)
/* handle error */ ;
TEST_ERROR
return 1;

fprintf (stream, "hello my world");
fflush (stream);
printf ("buf=%s, len=%zu\n", buf, len);
eob = ftello(stream);
fseeko (stream, 0, SEEK_SET);
fprintf (stream, "good-bye");
fseeko (stream, eob, SEEK_SET);
fclose (stream);
printf ("buf=%s, len=%zu\n", buf, len);
free (buf);

printf("ok\n");
return 0;
}
226 changes: 226 additions & 0 deletions target/modest_worker/utils/open_memstream.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
/*-
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
*
* Copyright (c) 2013 Hudson River Trading LLC
* Written by: John H. Baldwin <[email protected]>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

#ifdef __APPLE__
#include <sys/cdefs.h>
// __FBSDID("$FreeBSD$");

// #include "namespace.h"
#include <assert.h>
#include <errno.h>
#include <limits.h>
#ifdef DEBUG
#include <stdint.h>
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <wchar.h>
// #include "un-namespace.h"

/* XXX: There is no FPOS_MAX. This assumes fpos_t is an off_t. */
#define FPOS_MAX OFF_MAX

struct memstream {
char **bufp;
size_t *sizep;
ssize_t len;
fpos_t offset;
};

static int
memstream_grow(struct memstream *ms, fpos_t newoff)
{
char *buf;
ssize_t newsize;

if (newoff < 0 || newoff >= SSIZE_MAX)
newsize = SSIZE_MAX - 1;
else
newsize = newoff;
if (newsize > ms->len) {
buf = realloc(*ms->bufp, newsize + 1);
if (buf != NULL) {
#ifdef DEBUG
fprintf(stderr, "MS: %p growing from %zd to %zd\n",
ms, ms->len, newsize);
#endif
memset(buf + ms->len + 1, 0, newsize - ms->len);
*ms->bufp = buf;
ms->len = newsize;
return (1);
}
return (0);
}
return (1);
}

static void
memstream_update(struct memstream *ms)
{

assert(ms->len >= 0 && ms->offset >= 0);
*ms->sizep = ms->len < ms->offset ? ms->len : ms->offset;
}

static int
memstream_write(void *cookie, const char *buf, int len)
{
struct memstream *ms;
ssize_t tocopy;

ms = cookie;
if (!memstream_grow(ms, ms->offset + len))
return (-1);
tocopy = ms->len - ms->offset;
if (len < tocopy)
tocopy = len;
memcpy(*ms->bufp + ms->offset, buf, tocopy);
ms->offset += tocopy;
memstream_update(ms);
#ifdef DEBUG
fprintf(stderr, "MS: write(%p, %d) = %zd\n", ms, len, tocopy);
#endif
return (tocopy);
}

static fpos_t
memstream_seek(void *cookie, fpos_t pos, int whence)
{
struct memstream *ms;
#ifdef DEBUG
fpos_t old;
#endif

ms = cookie;
#ifdef DEBUG
old = ms->offset;
#endif
switch (whence) {
case SEEK_SET:
/* _fseeko() checks for negative offsets. */
assert(pos >= 0);
ms->offset = pos;
break;
case SEEK_CUR:
/* This is only called by _ftello(). */
assert(pos == 0);
break;
case SEEK_END:
if (pos < 0) {
if (pos + ms->len < 0) {
#ifdef DEBUG
fprintf(stderr,
"MS: bad SEEK_END: pos %jd, len %zd\n",
(intmax_t)pos, ms->len);
#endif
errno = EINVAL;
return (-1);
}
} else {
if (FPOS_MAX - ms->len < pos) {
#ifdef DEBUG
fprintf(stderr,
"MS: bad SEEK_END: pos %jd, len %zd\n",
(intmax_t)pos, ms->len);
#endif
errno = EOVERFLOW;
return (-1);
}
}
ms->offset = ms->len + pos;
break;
}
memstream_update(ms);
#ifdef DEBUG
fprintf(stderr, "MS: seek(%p, %jd, %d) %jd -> %jd\n", ms, (intmax_t)pos,
whence, (intmax_t)old, (intmax_t)ms->offset);
#endif
return (ms->offset);
}

static int
memstream_close(void *cookie)
{

free(cookie);
return (0);
}

FILE *
open_memstream(char **bufp, size_t *sizep)
{
printf("open_memstream\n");
struct memstream *ms;
int save_errno;
FILE *fp;

if (bufp == NULL || sizep == NULL) {
errno = EINVAL;
printf("EINVAL\n");
return (NULL);
}
*bufp = calloc(1, 1);
printf("calloc\n");
if (*bufp == NULL)
printf("calloc NULL\n");
return (NULL);
ms = malloc(sizeof(*ms));
printf("malloc\n");
if (ms == NULL) {
printf("malloc NULL\n");
save_errno = errno;
free(*bufp);
*bufp = NULL;
errno = save_errno;
return (NULL);
}
ms->bufp = bufp;
ms->sizep = sizep;
ms->len = 0;
ms->offset = 0;
memstream_update(ms);
printf("memstream_update\n");
fp = funopen(ms, NULL, memstream_write, memstream_seek,
memstream_close);
printf("funopen\n");
if (fp == NULL) {
printf("funopen NULL\n");
save_errno = errno;
free(ms);
free(*bufp);
*bufp = NULL;
errno = save_errno;
return (NULL);
}
printf("return fp\n");
fwide(fp, -1);
return (fp);
}
#endif