Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
move copyGoSlice_toGoSlice from lib/cgo/tests/testutils/libsky_testutil.c to lib/cgo/tests/testutils/common.c
ref skycoin#34
  • Loading branch information
Alvaro Denis committed May 15, 2019
1 parent c308812 commit 1ff07f2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
15 changes: 15 additions & 0 deletions lib/cgo/tests/testutils/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <string.h>
#include <stdio.h>

#include "libskycoin.h"
#include "skyerrors.h"

int MEMPOOLIDX = 0;
void *MEMPOOL[1024 * 256];

Expand All @@ -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;
}
12 changes: 0 additions & 12 deletions lib/cgo/tests/testutils/libsky_testutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 1ff07f2

Please sign in to comment.