Skip to content

Commit 0897129

Browse files
committed
Enable Windows build
1 parent 44ec630 commit 0897129

File tree

6 files changed

+92
-56
lines changed

6 files changed

+92
-56
lines changed

src/CMakeLists.txt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ 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 # ${CMAKE_CURRENT_SOURCE_DIR}/ctl/alloc.c
31+
${CMAKE_CURRENT_SOURCE_DIR}/ctl/ctl.c
32+
${CMAKE_CURRENT_SOURCE_DIR}/ctl/ctl_debug.c)
33+
# endif()
3534

3635
if(LINUX)
3736
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: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@
66
* the library's internal state
77
*/
88
#include "ctl.h"
9-
#include "alloc.h"
10-
#include "os.h"
9+
#include "base_alloc/base_alloc.h"
10+
#include "base_alloc/base_alloc_global.h"
11+
#include "utils/utils_common.h"
12+
1113
#include <ctype.h>
1214
#include <limits.h>
1315
#include <stdint.h>
16+
#include <stdio.h>
17+
#include <stdlib.h>
1418
#include <string.h>
1519

20+
#ifdef _WIN32
21+
#define strtok_r strtok_s
22+
#endif
23+
1624
#define CTL_MAX_ENTRIES 100
1725

1826
#define MAX_CONFIG_FILE_LEN (1 << 20) /* 1 megabyte */
@@ -40,6 +48,25 @@ struct ctl {
4048
int first_free;
4149
};
4250

51+
void *Zalloc(size_t sz) {
52+
void *ptr = umf_ba_global_alloc(sz);
53+
if (ptr) {
54+
memset(ptr, 0, sz);
55+
}
56+
return ptr;
57+
}
58+
59+
void Free(void *ptr) { umf_ba_global_free(ptr); }
60+
61+
char *Strdup(const char *s) {
62+
size_t len = strlen(s) + 1;
63+
char *p = umf_ba_global_alloc(len);
64+
if (p) {
65+
memcpy(p, s, len);
66+
}
67+
return p;
68+
}
69+
4370
/*
4471
* ctl_find_node -- (internal) searches for a matching entry point in the
4572
* provided nodes
@@ -74,7 +101,8 @@ static const struct ctl_node *ctl_find_node(const struct ctl_node *nodes,
74101
errno = tmp_errno;
75102
struct ctl_index *index_entry = NULL;
76103
if (endptr != node_name) { /* a valid index */
77-
index_entry = Malloc(sizeof(*index_entry));
104+
// index_entry = Malloc(sizeof(*index_entry));
105+
index_entry = Zalloc(sizeof(*index_entry));
78106
if (index_entry == NULL) {
79107
goto error;
80108
}
@@ -126,7 +154,8 @@ static void ctl_delete_indexes(struct ctl_indexes *indexes) {
126154
* structure
127155
*/
128156
static void *ctl_parse_args(const struct ctl_argument *arg_proto, char *arg) {
129-
char *dest_arg = Malloc(arg_proto->dest_size);
157+
// char *dest_arg = Malloc(arg_proto->dest_size);
158+
char *dest_arg = Zalloc(arg_proto->dest_size);
130159
if (dest_arg == NULL) {
131160
return NULL;
132161
}
@@ -315,7 +344,7 @@ static int ctl_parse_query(char *qbuf, char **name, char **value) {
315344
return -1;
316345
}
317346

318-
char *sptr;
347+
char *sptr = NULL;
319348
*name = strtok_r(qbuf, CTL_NAME_VALUE_SEPARATOR, &sptr);
320349
if (*name == NULL) {
321350
return -1;
@@ -389,13 +418,14 @@ int ctl_load_config_from_string(struct ctl *ctl, void *ctx,
389418
* This function opens up the config file, allocates a buffer of size equal to
390419
* the size of the file, reads its content and sanitizes it for ctl_load_config.
391420
*/
421+
#ifdef WINDOWS_API_NEEDED
392422
int ctl_load_config_from_file(struct ctl *ctl, void *ctx,
393423
const char *cfg_file) {
394424
int ret = -1;
395425
long fsize = 0;
396426
char *buf = NULL;
397427

398-
FILE *fp = os_fopen(cfg_file, "r");
428+
FILE *fp = utils_file_open(cfg_file, "r");
399429
if (fp == NULL) {
400430
return ret;
401431
}
@@ -446,6 +476,7 @@ int ctl_load_config_from_file(struct ctl *ctl, void *ctx,
446476
(void)fclose(fp);
447477
return ret;
448478
}
479+
#endif
449480

450481
/*
451482
* 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)