Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
move registerMemCleanup from lib/cgo/tests/testutils/libsky_testutil.c to lib/cgo/tests/testutils/common.c
ref #34
  • Loading branch information
stdevAlDen committed May 15, 2019
1 parent bc3c949 commit a16a448
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 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>

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

GoInt_ isU8Eq(unsigned char p1[], unsigned char p2[], size_t len) {

if (strncmp(p1, p2, len) == 0) {
Expand All @@ -13,3 +16,15 @@ GoInt_ isU8Eq(unsigned char p1[], unsigned char p2[], size_t len) {
printf("p2 %s\n", p2);
return 0;
}

void * registerMemCleanup(void *p) {
int i;
for (i = 0; i < MEMPOOLIDX; i++) {
if(MEMPOOL[i] == NULL){
MEMPOOL[i] = p;
return p;
}
}
MEMPOOL[MEMPOOLIDX++] = p;
return p;
}
16 changes: 2 additions & 14 deletions lib/cgo/tests/testutils/libsky_testutil.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
//Define function SKY_handle_close to avoid including libskycoin.h
void SKY_handle_close(Handle p0);

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

int JSONPOOLIDX = 0;
json_value* JSON_POOL[128];
Expand All @@ -40,18 +40,6 @@ wallet_register WALLET_POOL[64];
int stdout_backup;
int pipefd[2];

void * registerMemCleanup(void *p) {
int i;
for (i = 0; i < MEMPOOLIDX; i++) {
if(MEMPOOL[i] == NULL){
MEMPOOL[i] = p;
return p;
}
}
MEMPOOL[MEMPOOLIDX++] = p;
return p;
}

void freeRegisteredMemCleanup(void *p){
int i;
for (i = 0; i < MEMPOOLIDX; i++) {
Expand Down

0 comments on commit a16a448

Please sign in to comment.