Skip to content

Commit

Permalink
Merge pull request #74 from jeromekelleher/c-api-fixes
Browse files Browse the repository at this point in the history
C api fixes
  • Loading branch information
jeromekelleher authored Jan 22, 2019
2 parents b96d7cf + c0f304b commit fb5933b
Show file tree
Hide file tree
Showing 10 changed files with 116 additions and 321 deletions.
25 changes: 11 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,43 +47,40 @@ jobs:
- run:
name: Compile C
command: |
CFLAGS=--coverage meson c/ build-gcc && cd build-gcc && ninja
# Build with coverage options
meson c/ build-gcc -D b_coverage=true && cd build-gcc && ninja
- run:
name: Run C tests
command: |
export KASTORE_SOPATH=./build-gcc/libkastore.so
./build-gcc/tests
./build-gcc/dynamic_api_tests
./build-gcc/cpp_tests
./build-gcc/malloc_tests
./build-gcc/io_tests
- run:
name: Valgrind for C tests.
command: |
export KASTORE_SOPATH=./build-gcc/libkastore.so
valgrind --leak-check=full --error-exitcode=1 ./build-gcc/tests
valgrind --leak-check=full --error-exitcode=1 ./build-gcc/dynamic_api_tests
valgrind --leak-check=full --error-exitcode=1 ./build-gcc/malloc_tests
valgrind --leak-check=full --error-exitcode=1 ./build-gcc/io_tests
- run:
name: Run gcov & upload coverage.
command: |
gcov -pb -o ./python/build/temp.linux*/ python/_kastoremodule.c
gcov -pb ./build-gcc/tests@exe/kastore.c.gcno \
./build-gcc/malloc_tests@exe/kastore.c.gcno \
./build-gcc/io_tests@exe/kastore.c.gcno \
./build-gcc/dynamic_api_tests@exe/kastore.c.gcno \
./build-gcc/kastore@sha/kastore.c.gcno
codecov -X gcov -F C
- run:
name: Valgrind for C tests.
command: |
valgrind --leak-check=full --error-exitcode=1 ./build-gcc/tests
valgrind --leak-check=full --error-exitcode=1 ./build-gcc/cpp_tests
valgrind --leak-check=full --error-exitcode=1 ./build-gcc/malloc_tests
valgrind --leak-check=full --error-exitcode=1 ./build-gcc/io_tests
- run:
name: Compile C tests under clang
command: |
CC=clang meson c/ build-clang && cd build-clang && ninja
- run:
name: Run clang C tests
command: |
export KASTORE_SOPATH=./build-clang/libkastore.so
./build-clang/tests
./build-clang/dynamic_api_tests
./build-clang/cpp_tests
./build-clang/malloc_tests
./build-clang/io_tests
Expand Down
6 changes: 6 additions & 0 deletions c/CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
--------------------
[1.0.0] - 2019-01-22
--------------------

Remove the dynamic C API option and add support for C++.

--------------------
[0.1.0] - 2018-12-07
--------------------
Expand Down
36 changes: 36 additions & 0 deletions c/cpp_tests.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Very simple test to check that kastore works with C++. */

#include <iostream>
#include <assert.h>
#include <sstream>

#include <kastore.h>

using namespace std;

void
test_strerror()
{
std::cout << "test_strerror" << endl;
std::ostringstream o;
o << kas_strerror(KAS_ERR_NO_MEMORY);
assert(std::string("Out of memory").compare(o.str()) == 0);
}

void
test_open_error()
{
std::cout << "test_open_error" << endl;
kastore_t store;
int ret = kastore_open(&store, "no such file", "r", 0);
assert(ret == KAS_ERR_IO);

kastore_close(&store);
}

int main()
{
test_open_error();
test_strerror();
return 0;
}
40 changes: 0 additions & 40 deletions c/kastore.c
Original file line number Diff line number Diff line change
Expand Up @@ -898,43 +898,3 @@ kastore_print_state(kastore_t *self, FILE *out)
}
fprintf(out, "============================\n");
}

kas_funcptr *
kas_dynamic_api_init(void)
{
static kas_funcptr kas_dynamic_api[KAS_DYNAMIC_API_NUM];
kas_dynamic_api[KAS_INDEX_OPEN] = (kas_funcptr) kastore_open;
kas_dynamic_api[KAS_INDEX_CLOSE] = (kas_funcptr) kastore_close;

kas_dynamic_api[KAS_INDEX_GET] = (kas_funcptr) kastore_get;
kas_dynamic_api[KAS_INDEX_GETS] = (kas_funcptr) kastore_gets;
kas_dynamic_api[KAS_INDEX_GETS_INT8] = (kas_funcptr) kastore_gets_int8;
kas_dynamic_api[KAS_INDEX_GETS_UINT8] = (kas_funcptr) kastore_gets_uint8;
kas_dynamic_api[KAS_INDEX_GETS_INT16] = (kas_funcptr) kastore_gets_int16;
kas_dynamic_api[KAS_INDEX_GETS_UINT16] = (kas_funcptr) kastore_gets_uint16;
kas_dynamic_api[KAS_INDEX_GETS_INT32] = (kas_funcptr) kastore_gets_int32;
kas_dynamic_api[KAS_INDEX_GETS_UINT32] = (kas_funcptr) kastore_gets_uint32;
kas_dynamic_api[KAS_INDEX_GETS_INT64] = (kas_funcptr) kastore_gets_int64;
kas_dynamic_api[KAS_INDEX_GETS_UINT64] = (kas_funcptr) kastore_gets_uint64;
kas_dynamic_api[KAS_INDEX_GETS_FLOAT32] = (kas_funcptr) kastore_gets_float32;
kas_dynamic_api[KAS_INDEX_GETS_FLOAT64] = (kas_funcptr) kastore_gets_float64;

kas_dynamic_api[KAS_INDEX_PUT] = (kas_funcptr) kastore_put;
kas_dynamic_api[KAS_INDEX_PUTS] = (kas_funcptr) kastore_puts;
kas_dynamic_api[KAS_INDEX_PUTS_INT8] = (kas_funcptr) kastore_puts_int8;
kas_dynamic_api[KAS_INDEX_PUTS_UINT8] = (kas_funcptr) kastore_puts_uint8;
kas_dynamic_api[KAS_INDEX_PUTS_INT16] = (kas_funcptr) kastore_puts_int16;
kas_dynamic_api[KAS_INDEX_PUTS_UINT16] = (kas_funcptr) kastore_puts_uint16;
kas_dynamic_api[KAS_INDEX_PUTS_INT32] = (kas_funcptr) kastore_puts_int32;
kas_dynamic_api[KAS_INDEX_PUTS_UINT32] = (kas_funcptr) kastore_puts_uint32;
kas_dynamic_api[KAS_INDEX_PUTS_INT64] = (kas_funcptr) kastore_puts_int64;
kas_dynamic_api[KAS_INDEX_PUTS_UINT64] = (kas_funcptr) kastore_puts_uint64;
kas_dynamic_api[KAS_INDEX_PUTS_FLOAT32] = (kas_funcptr) kastore_puts_float32;
kas_dynamic_api[KAS_INDEX_PUTS_FLOAT64] = (kas_funcptr) kastore_puts_float64;

kas_dynamic_api[KAS_INDEX_PRINT_STATE] = (kas_funcptr) kastore_print_state;
kas_dynamic_api[KAS_INDEX_STRERROR] = (kas_funcptr) kas_strerror;
kas_dynamic_api[KAS_INDEX_VERSION] = (kas_funcptr) kas_version;

return kas_dynamic_api;
}
Loading

0 comments on commit fb5933b

Please sign in to comment.