Skip to content

Commit 662a1ba

Browse files
committed
Enable Windows build
1 parent 44ec630 commit 662a1ba

File tree

8 files changed

+51
-266
lines changed

8 files changed

+51
-266
lines changed

src/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,8 @@ 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+
set(CTL_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ctl/ctl.c
30+
${CMAKE_CURRENT_SOURCE_DIR}/ctl/ctl_debug.c)
3531

3632
if(LINUX)
3733
set(BA_SOURCES ${BA_SOURCES}

src/ctl/alloc.c

Lines changed: 0 additions & 106 deletions
This file was deleted.

src/ctl/alloc.h

Lines changed: 0 additions & 49 deletions
This file was deleted.

src/ctl/ctl.c

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
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_global.h"
10+
#include "utils/utils_common.h"
11+
1112
#include <ctype.h>
1213
#include <limits.h>
1314
#include <stdint.h>
15+
#include <stdio.h>
16+
#include <stdlib.h>
1417
#include <string.h>
1518

19+
#ifdef _WIN32
20+
#define strtok_r strtok_s
21+
#endif
22+
1623
#define CTL_MAX_ENTRIES 100
1724

1825
#define MAX_CONFIG_FILE_LEN (1 << 20) /* 1 megabyte */
@@ -40,6 +47,27 @@ struct ctl {
4047
int first_free;
4148
};
4249

50+
void *Malloc(size_t sz) { return umf_ba_global_alloc(sz); }
51+
52+
void *Zalloc(size_t sz) {
53+
void *ptr = umf_ba_global_alloc(sz);
54+
if (ptr) {
55+
memset(ptr, 0, sz);
56+
}
57+
return ptr;
58+
}
59+
60+
void Free(void *ptr) { umf_ba_global_free(ptr); }
61+
62+
char *Strdup(const char *s) {
63+
size_t len = strlen(s) + 1;
64+
char *p = umf_ba_global_alloc(len);
65+
if (p) {
66+
memcpy(p, s, len);
67+
}
68+
return p;
69+
}
70+
4371
/*
4472
* ctl_find_node -- (internal) searches for a matching entry point in the
4573
* provided nodes
@@ -315,7 +343,7 @@ static int ctl_parse_query(char *qbuf, char **name, char **value) {
315343
return -1;
316344
}
317345

318-
char *sptr;
346+
char *sptr = NULL;
319347
*name = strtok_r(qbuf, CTL_NAME_VALUE_SEPARATOR, &sptr);
320348
if (*name == NULL) {
321349
return -1;
@@ -389,13 +417,14 @@ int ctl_load_config_from_string(struct ctl *ctl, void *ctx,
389417
* This function opens up the config file, allocates a buffer of size equal to
390418
* the size of the file, reads its content and sanitizes it for ctl_load_config.
391419
*/
420+
#ifdef WINDOWS_API_NEEDED
392421
int ctl_load_config_from_file(struct ctl *ctl, void *ctx,
393422
const char *cfg_file) {
394423
int ret = -1;
395424
long fsize = 0;
396425
char *buf = NULL;
397426

398-
FILE *fp = os_fopen(cfg_file, "r");
427+
FILE *fp = utils_file_open(cfg_file, "r");
399428
if (fp == NULL) {
400429
return ret;
401430
}
@@ -446,6 +475,7 @@ int ctl_load_config_from_file(struct ctl *ctl, void *ctx,
446475
(void)fclose(fp);
447476
return ret;
448477
}
478+
#endif
449479

450480
/*
451481
* ctl_new -- allocates and initializes ctl data structures

src/ctl/ctl_debug.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
/*
55
* ctl_debug.h -- definitions for CTL test
66
*/
7-
#ifndef LIBPMEMOBJ_CTL_DEBUG_H
8-
#define LIBPMEMOBJ_CTL_DEBUG_H 1
7+
#ifndef CTL_DEBUG_H
8+
#define CTL_DEBUG_H 1
99

1010
#include "ctl.h"
1111

src/ctl/os.h

Lines changed: 0 additions & 92 deletions
This file was deleted.

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)