From 1ff07f240d0e8bc86c1e711169b48484f3ef11d8 Mon Sep 17 00:00:00 2001 From: Alvaro Denis Date: Wed, 15 May 2019 16:48:42 -0400 Subject: [PATCH] refactor move copyGoSlice_toGoSlice from lib/cgo/tests/testutils/libsky_testutil.c to lib/cgo/tests/testutils/common.c ref #34 --- lib/cgo/tests/testutils/common.c | 15 +++++++++++++++ lib/cgo/tests/testutils/libsky_testutil.c | 12 ------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/lib/cgo/tests/testutils/common.c b/lib/cgo/tests/testutils/common.c index bc9a03289..700e2a7f8 100644 --- a/lib/cgo/tests/testutils/common.c +++ b/lib/cgo/tests/testutils/common.c @@ -3,6 +3,9 @@ #include #include +#include "libskycoin.h" +#include "skyerrors.h" + int MEMPOOLIDX = 0; void *MEMPOOL[1024 * 256]; @@ -28,3 +31,15 @@ void * registerMemCleanup(void *p) { MEMPOOL[MEMPOOLIDX++] = p; return p; } + +int copyGoSlice_toGoSlice(GoSlice* pdest, GoSlice_* psource, int elem_size){ + pdest->len = psource->len; + pdest->cap = psource->len; + int size = pdest->len * elem_size; + pdest->data = malloc(size); + if( pdest->data == NULL ) + return SKY_ERROR; + registerMemCleanup( pdest->data ); + memcpy(pdest->data, psource->data, size ); + return SKY_OK; +} diff --git a/lib/cgo/tests/testutils/libsky_testutil.c b/lib/cgo/tests/testutils/libsky_testutil.c index 712bd8b69..b580f9d80 100644 --- a/lib/cgo/tests/testutils/libsky_testutil.c +++ b/lib/cgo/tests/testutils/libsky_testutil.c @@ -263,18 +263,6 @@ int copySlice(GoSlice_* pdest, GoSlice_* psource, int elem_size){ return SKY_OK; } -int copyGoSlice_toGoSlice(GoSlice* pdest, GoSlice_* psource, int elem_size){ - pdest->len = psource->len; - pdest->cap = psource->len; - int size = pdest->len * elem_size; - pdest->data = malloc(size); - if( pdest->data == NULL ) - return SKY_ERROR; - registerMemCleanup( pdest->data ); - memcpy(pdest->data, psource->data, size ); - return SKY_OK; -} - int cutSlice(GoSlice_* slice, int start, int end, int elem_size, GoSlice_* result){ int size = end - start; if( size <= 0)