Skip to content

Commit 89a5f0a

Browse files
committed
Enable Windows build
1 parent 44ec630 commit 89a5f0a

File tree

6 files changed

+102
-57
lines changed

6 files changed

+102
-57
lines changed

src/CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ add_subdirectory(coarse)
2626

2727
set(UMF_LIBS $<BUILD_INTERFACE:umf_utils> $<BUILD_INTERFACE:coarse>)
2828

29-
if(LINUX OR MACOSX)
30-
set(CTL_SOURCES
31-
${CMAKE_CURRENT_SOURCE_DIR}/ctl/alloc.c
32-
${CMAKE_CURRENT_SOURCE_DIR}/ctl/ctl.c
33-
${CMAKE_CURRENT_SOURCE_DIR}/ctl/ctl_debug.c)
34-
endif()
29+
# if(LINUX OR MACOSX)
30+
set(CTL_SOURCES
31+
# ${CMAKE_CURRENT_SOURCE_DIR}/ctl/alloc.c
32+
${CMAKE_CURRENT_SOURCE_DIR}/ctl/ctl.c
33+
${CMAKE_CURRENT_SOURCE_DIR}/ctl/ctl_debug.c)
34+
# endif()
3535

3636
if(LINUX)
3737
set(BA_SOURCES ${BA_SOURCES}

src/ctl/alloc.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99
// #include "fault_injection.h"
1010

11-
Malloc_func fn_malloc = malloc;
12-
Realloc_func fn_realloc = realloc;
11+
// Malloc_func fn_malloc = malloc;
12+
// Realloc_func fn_realloc = realloc;
1313

1414
#if FAULT_INJECTION
1515
#include "log_internal.h"
@@ -78,8 +78,8 @@ void set_func_realloc(void *(*realloc_func)(void *ptr, size_t size)) {
7878
/*
7979
* our versions of malloc & friends start off pointing to the libc versions
8080
*/
81-
Free_func Free = free;
82-
Strdup_func Strdup = strdup;
81+
// Free_func Free = free;
82+
// Strdup_func Strdup = strdup;
8383

8484
/*
8585
* Zalloc -- allocate zeroed memory
@@ -95,12 +95,12 @@ void *Zalloc(size_t sz) {
9595
/*
9696
* util_set_alloc_funcs -- allow one to override malloc, etc.
9797
*/
98-
void util_set_alloc_funcs(void *(*malloc_func)(size_t size),
99-
void (*free_func)(void *ptr),
100-
void *(*realloc_func)(void *ptr, size_t size),
101-
char *(*strdup_func)(const char *s)) {
102-
set_func_malloc(malloc_func);
103-
Free = (free_func == NULL) ? free : free_func;
104-
set_func_realloc(realloc_func);
105-
Strdup = (strdup_func == NULL) ? strdup : strdup_func;
106-
}
98+
// void util_set_alloc_funcs(void *(*malloc_func)(size_t size),
99+
// void (*free_func)(void *ptr),
100+
// void *(*realloc_func)(void *ptr, size_t size),
101+
// char *(*strdup_func)(const char *s)) {
102+
// set_func_malloc(malloc_func);
103+
// Free = (free_func == NULL) ? free : free_func;
104+
// set_func_realloc(realloc_func);
105+
// Strdup = (strdup_func == NULL) ? strdup : strdup_func;
106+
// }

src/ctl/ctl.c

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@
66
* the library's internal state
77
*/
88
#include "ctl.h"
9-
#include "alloc.h"
10-
#include "os.h"
9+
// #include "alloc.h"
10+
#include "utils/utils_common.h"
11+
#include "base_alloc/base_alloc.h"
12+
#include "base_alloc/base_alloc_global.h"
13+
// #include "os.h"
1114
#include <ctype.h>
1215
#include <limits.h>
1316
#include <stdint.h>
17+
#include <stdio.h>
18+
#include <stdlib.h>
1419
#include <string.h>
1520

21+
#ifdef _WIN32
22+
#define strtok_r strtok_s
23+
#endif
24+
1625
#define CTL_MAX_ENTRIES 100
1726

1827
#define MAX_CONFIG_FILE_LEN (1 << 20) /* 1 megabyte */
@@ -40,6 +49,32 @@ struct ctl {
4049
int first_free;
4150
};
4251

52+
static umf_ba_pool_t *pool = NULL;
53+
54+
// Implement Zalloc (function that returns zeroed memory)
55+
void *Zalloc(size_t sz) {
56+
void *ptr = umf_ba_global_alloc(sz);
57+
if (ptr) {
58+
memset(ptr, 0, sz);
59+
}
60+
return ptr;
61+
}
62+
63+
// Implement Free (function that frees memory)
64+
void Free(void *ptr) {
65+
umf_ba_global_free(ptr);
66+
}
67+
68+
// Implement Strdup (function that duplicates a string)
69+
char *Strdup(const char *s) {
70+
size_t len = strlen(s) + 1;
71+
char *p = umf_ba_global_alloc(len);
72+
if (p) {
73+
memcpy(p, s, len);
74+
}
75+
return p;
76+
}
77+
4378
/*
4479
* ctl_find_node -- (internal) searches for a matching entry point in the
4580
* provided nodes
@@ -57,7 +92,7 @@ static const struct ctl_node *ctl_find_node(const struct ctl_node *nodes,
5792
return NULL;
5893
}
5994

60-
char *node_name = strtok_r(parse_str, CTL_QUERY_NODE_SEPARATOR, &sptr);
95+
char *node_name = strtok_s(parse_str, CTL_QUERY_NODE_SEPARATOR, &sptr);
6196

6297
/*
6398
* Go through the string and separate tokens that correspond to nodes
@@ -74,7 +109,8 @@ static const struct ctl_node *ctl_find_node(const struct ctl_node *nodes,
74109
errno = tmp_errno;
75110
struct ctl_index *index_entry = NULL;
76111
if (endptr != node_name) { /* a valid index */
77-
index_entry = Malloc(sizeof(*index_entry));
112+
// index_entry = Malloc(sizeof(*index_entry));
113+
index_entry = Zalloc(sizeof(*index_entry));
78114
if (index_entry == NULL) {
79115
goto error;
80116
}
@@ -126,7 +162,8 @@ static void ctl_delete_indexes(struct ctl_indexes *indexes) {
126162
* structure
127163
*/
128164
static void *ctl_parse_args(const struct ctl_argument *arg_proto, char *arg) {
129-
char *dest_arg = Malloc(arg_proto->dest_size);
165+
// char *dest_arg = Malloc(arg_proto->dest_size);
166+
char *dest_arg = Zalloc(arg_proto->dest_size);
130167
if (dest_arg == NULL) {
131168
return NULL;
132169
}
@@ -315,7 +352,7 @@ static int ctl_parse_query(char *qbuf, char **name, char **value) {
315352
return -1;
316353
}
317354

318-
char *sptr;
355+
char *sptr = NULL;
319356
*name = strtok_r(qbuf, CTL_NAME_VALUE_SEPARATOR, &sptr);
320357
if (*name == NULL) {
321358
return -1;
@@ -389,13 +426,14 @@ int ctl_load_config_from_string(struct ctl *ctl, void *ctx,
389426
* This function opens up the config file, allocates a buffer of size equal to
390427
* the size of the file, reads its content and sanitizes it for ctl_load_config.
391428
*/
429+
#ifdef WINDOWS_API_NEEDED
392430
int ctl_load_config_from_file(struct ctl *ctl, void *ctx,
393431
const char *cfg_file) {
394432
int ret = -1;
395433
long fsize = 0;
396434
char *buf = NULL;
397435

398-
FILE *fp = os_fopen(cfg_file, "r");
436+
FILE *fp = utils_file_open(cfg_file, "r");
399437
if (fp == NULL) {
400438
return ret;
401439
}
@@ -446,6 +484,7 @@ int ctl_load_config_from_file(struct ctl *ctl, void *ctx,
446484
(void)fclose(fp);
447485
return ret;
448486
}
487+
#endif
449488

450489
/*
451490
* ctl_new -- allocates and initializes ctl data structures

src/ctl/os.h

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
#include <stdio.h>
1212
#include <sys/stat.h>
13-
#include <unistd.h>
13+
// #include <unistd.h>
1414

1515
#ifdef __cplusplus
1616
extern "C" {
@@ -41,36 +41,36 @@ typedef struct stat os_stat_t;
4141
#define os_close close
4242
#define os_fclose fclose
4343

44-
typedef off_t os_off_t;
45-
int os_open(const char *pathname, int flags, ...);
46-
int os_fsync(int fd);
47-
int os_fsync_dir(const char *dir_name);
48-
int os_stat(const char *pathname, os_stat_t *buf);
49-
int os_unlink(const char *pathname);
50-
int os_access(const char *pathname, int mode);
51-
FILE *os_fopen(const char *pathname, const char *mode);
52-
FILE *os_fdopen(int fd, const char *mode);
53-
int os_chmod(const char *pathname, mode_t mode);
54-
int os_mkstemp(char *temp);
55-
int os_posix_fallocate(int fd, os_off_t offset, os_off_t len);
56-
int os_ftruncate(int fd, os_off_t length);
57-
int os_flock(int fd, int operation);
58-
ssize_t os_writev(int fd, const struct iovec *iov, int iovcnt);
59-
int os_clock_gettime(int id, struct timespec *ts);
60-
unsigned os_rand_r(unsigned *seedp);
61-
int os_unsetenv(const char *name);
62-
int os_setenv(const char *name, const char *value, int overwrite);
63-
char *os_getenv(const char *name);
64-
const char *os_strsignal(int sig);
65-
int os_execv(const char *path, char *const argv[]);
44+
// typedef off_t os_off_t;
45+
// int os_open(const char *pathname, int flags, ...);
46+
// int os_fsync(int fd);
47+
// int os_fsync_dir(const char *dir_name);
48+
// int os_stat(const char *pathname, os_stat_t *buf);
49+
// int os_unlink(const char *pathname);
50+
// int os_access(const char *pathname, int mode);
51+
// FILE *os_fopen(const char *pathname, const char *mode);
52+
// FILE *os_fdopen(int fd, const char *mode);
53+
// int os_chmod(const char *pathname, mode_t mode);
54+
// int os_mkstemp(char *temp);
55+
// int os_posix_fallocate(int fd, os_off_t offset, os_off_t len);
56+
// int os_ftruncate(int fd, os_off_t length);
57+
// int os_flock(int fd, int operation);
58+
// ssize_t os_writev(int fd, const struct iovec *iov, int iovcnt);
59+
// int os_clock_gettime(int id, struct timespec *ts);
60+
// unsigned os_rand_r(unsigned *seedp);
61+
// int os_unsetenv(const char *name);
62+
// int os_setenv(const char *name, const char *value, int overwrite);
63+
// char *os_getenv(const char *name);
64+
// const char *os_strsignal(int sig);
65+
// int os_execv(const char *path, char *const argv[]);
6666

6767
FILE *os_fopen(const char *filename, const char *mode) {
6868
#ifdef _MSC_VER
6969
FILE *file;
7070
if (0 == fopen_s(&file, filename, mode)) {
7171
return file;
7272
} else {
73-
return UBENCH_NULL;
73+
return NULL;
7474
}
7575
#else
7676
return fopen(filename, mode);

src/libumf.def

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,10 @@ EXPORTS
114114
umfScalablePoolParamsCreate
115115
umfScalablePoolParamsDestroy
116116
umfScalablePoolParamsSetGranularity
117-
umfScalablePoolParamsSetKeepAllMemory
117+
umfScalablePoolParamsSetKeepAllMemory
118+
initialize_debug_ctl
119+
get_debug_ctl
120+
ctl_load_config_from_string
121+
ctl_query
122+
debug_ctl_register
123+
deinitialize_debug_ctl

test/CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,12 @@ add_umf_test(
192192
SRCS utils/utils_log.cpp ${UMF_UTILS_SOURCES}
193193
LIBS ${UMF_LOGGER_LIBS})
194194

195-
if(LINUX OR MACOSX)
196-
add_umf_test(
197-
NAME ctl
198-
SRCS ctl/test.cpp
199-
LIBS ${UMF_UTILS_FOR_TEST})
200-
endif()
195+
# if(LINUX OR MACOSX)
196+
add_umf_test(
197+
NAME ctl
198+
SRCS ctl/test.cpp
199+
LIBS ${UMF_UTILS_FOR_TEST})
200+
# endif()
201201

202202
add_umf_test(
203203
NAME utils_common

0 commit comments

Comments
 (0)