Skip to content

Commit 581ae08

Browse files
committed
fixup port: fixed compatibility on 32-bit machines
Signed-off-by: John Sanpe <sanpeqf@gmail.com>
1 parent 0b25e50 commit 581ae08

22 files changed

Lines changed: 254 additions & 115 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ set(BFDEV_ARCH_PATH ${PROJECT_SOURCE_DIR}/arch/${BFDEV_ARCH})
3434
set(BFDEV_ARCH_HEADER_PATH ${BFDEV_ARCH_PATH}/include)
3535
set(BFDEV_CONFIGURE ${BFDEV_GENERATED_PATH}/bfdev-config.cmake)
3636

37-
include(scripts/hostrule.cmake)
38-
include(scripts/packed-header.cmake)
39-
include(scripts/commit.cmake)
37+
include(${PROJECT_SOURCE_DIR}/scripts/hostrule.cmake)
38+
include(${PROJECT_SOURCE_DIR}/scripts/packed-header.cmake)
39+
include(${PROJECT_SOURCE_DIR}/scripts/commit.cmake)
4040

4141
commit_hash(BFDEV_COMMITID)
4242
commit_branch(BFDEV_BRANCH)
@@ -129,6 +129,11 @@ macro(bfdev_dependencies target)
129129
)
130130
endmacro()
131131

132+
set(CMAKE_C_FLAGS
133+
"${CMAKE_C_FLAGS} \
134+
${BFDEV_C_FLAGS}"
135+
)
136+
132137
add_library(bfdev_object OBJECT ${BFDEV_LIBRARY})
133138
bfdev_dependencies(bfdev_object)
134139
add_library(bfdev ALIAS bfdev_object)

build.cmake

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,31 @@
33
# Copyright(c) 2023 John Sanpe <sanpeqf@gmail.com>
44
#
55

6-
add_compile_options(
7-
-std=gnu11
8-
-Wall
9-
-Wextra
10-
-Wno-override-init
11-
-Wno-unused-parameter
12-
-Wno-sign-compare
13-
-Wno-pointer-sign
14-
-Wno-null-pointer-arithmetic
15-
-Wmissing-prototypes
16-
-Wmissing-declarations
17-
-fvisibility=hidden
6+
set(CMAKE_C_FLAGS
7+
"${CMAKE_C_FLAGS} \
8+
-std=gnu11 \
9+
-Wall \
10+
-Wextra \
11+
-Wno-override-init \
12+
-Wno-unused-parameter \
13+
-Wno-sign-compare \
14+
-Wno-pointer-sign \
15+
-Wno-null-pointer-arithmetic \
16+
-Wmissing-prototypes \
17+
-Wmissing-declarations \
18+
-fvisibility=hidden "
1819
)
1920

20-
if(BFDEV_STRICT)
21+
if(CMAKE_C_FLAGS)
2122
set(CMAKE_C_FLAGS
2223
"${CMAKE_C_FLAGS} \
2324
-Werror"
2425
)
2526
endif()
2627

27-
include(scripts/check.cmake)
28-
include(scripts/sanitize.cmake)
29-
include(scripts/asm-generic.cmake)
28+
include(${PROJECT_SOURCE_DIR}/scripts/check.cmake)
29+
include(${PROJECT_SOURCE_DIR}/scripts/asm-generic.cmake)
30+
include(${PROJECT_SOURCE_DIR}/scripts/sanitize.cmake)
3031

3132
asm_generic(
3233
bfdev/asm-generic/
@@ -35,16 +36,6 @@ asm_generic(
3536
${BFDEV_HEADER_PATH}/bfdev/asm-generic
3637
)
3738

38-
configure_file(
39-
${BFDEV_MODULE_PATH}/config.h.in
40-
${BFDEV_GENERATED_PATH}/bfdev/config.h
41-
)
42-
43-
configure_file(
44-
${BFDEV_MODULE_PATH}/bfdev-config.cmake.in
45-
${BFDEV_CONFIGURE}
46-
)
47-
4839
file(GLOB_RECURSE BFDEV_HEADER
4940
${BFDEV_HEADER_PATH}/*.h
5041
)
@@ -64,9 +55,21 @@ set(BFDEV_INCLUDE_DIRS
6455
)
6556

6657
include_directories(${BFDEV_INCLUDE_DIRS})
58+
include(${PROJECT_SOURCE_DIR}/scripts/platform.cmake)
59+
include(${BFDEV_PORT_PATH}/build.cmake)
60+
6761
include(${BFDEV_ARCH_PATH}/build.cmake)
6862
include(${BFDEV_SOURCE_PATH}/build.cmake)
69-
include(${BFDEV_PORT_PATH}/build.cmake)
63+
64+
configure_file(
65+
${BFDEV_MODULE_PATH}/config.h.in
66+
${BFDEV_GENERATED_PATH}/bfdev/config.h
67+
)
68+
69+
configure_file(
70+
${BFDEV_MODULE_PATH}/bfdev-config.cmake.in
71+
${BFDEV_CONFIGURE}
72+
)
7073

7174
set(BFDEV_LIBRARY_HEADER
7275
${BFDEV_HEADER}

cmake/config.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ BFDEV_BEGIN_DECLS
2424
#define BFDEV_VERSION ${BFDEV_VERSION}
2525
#define BFDEV_RELEASE "${BFDEV_RELEASE}"
2626

27+
#define BFDEV_TYPE_ADDR ${BFDEV_TYPE_ADDR}
28+
#define BFDEV_TYPE_W64 ${BFDEV_TYPE_W64}
29+
#define BFDEV_TYPE_MAX ${BFDEV_TYPE_MAX}
30+
2731
#cmakedefine BFDEV_DEBUG_LIST
2832
#cmakedefine BFDEV_DEBUG_SLIST
2933
#cmakedefine BFDEV_DEBUG_HLIST

include/bfdev/asm-generic/types.h

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define _BFDEV_ASM_GENERIC_TYPES_H_
88

99
#include <bfdev/config.h>
10+
#include <bfdev/asm/bitsperlong.h>
1011

1112
BFDEV_BEGIN_DECLS
1213

@@ -19,20 +20,20 @@ typedef unsigned short bfdev_u16;
1920
typedef unsigned int bfdev_u32;
2021

2122
#ifdef __GNUC__
22-
__extension__ typedef __signed__ long long bfdev_s64;
23-
__extension__ typedef unsigned long long bfdev_u64;
23+
__extension__ typedef __signed__ BFDEV_TYPE_W64 bfdev_s64;
24+
__extension__ typedef unsigned BFDEV_TYPE_W64 bfdev_u64;
2425
#else
25-
typedef __signed__ long long bfdev_s64;
26-
typedef unsigned long long bfdev_u64;
26+
typedef __signed__ BFDEV_TYPE_W64 bfdev_s64;
27+
typedef unsigned BFDEV_TYPE_W64 bfdev_u64;
2728
#endif
2829

29-
typedef unsigned long bfdev_size_t;
30-
typedef bfdev_s64 bfdev_intmax_t;
31-
typedef bfdev_u64 bfdev_uintmax_t;
30+
typedef unsigned BFDEV_TYPE_ADDR bfdev_size_t;
31+
typedef unsigned BFDEV_TYPE_ADDR bfdev_uintptr_t;
32+
typedef __signed__ BFDEV_TYPE_ADDR bfdev_intptr_t;
33+
typedef __signed__ BFDEV_TYPE_ADDR bfdev_ptrdiff_t;
3234

33-
typedef unsigned long bfdev_uintptr_t;
34-
typedef __signed__ long bfdev_intptr_t;
35-
typedef __signed__ long bfdev_ptrdiff_t;
35+
typedef BFDEV_TYPE_MAX bfdev_intmax_t;
36+
typedef BFDEV_TYPE_MAX bfdev_uintmax_t;
3637

3738
BFDEV_END_DECLS
3839

include/bfdev/hash.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ bfdev_hash64(bfdev_u64 value, unsigned int bits)
6969
# define BFDEV_GOLDEN_RATIO_LONG BFDEV_GOLDEN_RATIO_64
7070
# define bfdev_hashvl(value) bfdev_hashv64(value)
7171
# define bfdev_hashl(value, bits) bfdev_hash64(value, bits)
72-
#endif /* BFDEV_BITS_PER_LONG == 64 */
72+
#endif
7373

7474
BFDEV_END_DECLS
7575

port/build.cmake

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,10 @@
33
# Copyright(c) 2025 John Sanpe <sanpeqf@gmail.com>
44
#
55

6-
if(CMAKE_SYSTEM_NAME MATCHES "Linux|Darwin|GNU")
7-
set(BFDEV_PORT_TYPE "posix")
8-
endif()
9-
10-
if(CMAKE_SYSTEM_NAME MATCHES "MSYS|CYGWIN")
11-
set(BFDEV_PORT_TYPE "posix")
12-
endif()
13-
14-
if(CMAKE_SYSTEM_NAME MATCHES "kFreeBSD|FreeBSD|NetBSD|OpenBSD|DragonFly")
15-
set(BFDEV_PORT_TYPE "posix")
16-
endif()
17-
18-
if(CMAKE_SYSTEM_NAME MATCHES "Generic")
19-
set(BFDEV_PORT_TYPE "generic")
20-
endif()
21-
226
if(BFDEV_PORT_TYPE)
237
include(${BFDEV_PORT_PATH}/${BFDEV_PORT_TYPE}/build.cmake)
248
else()
259
message(FATAL_ERROR "Unsupported system: ${CMAKE_SYSTEM_NAME}")
2610
endif()
11+
12+
include(${CMAKE_CURRENT_LIST_DIR}/tests/build.cmake)

port/generic/log.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
/* TODO: PORTME */
1111

12-
hidden int
12+
int
1313
bfport_log_write(bfdev_log_message_t *msg)
1414
{
1515
return 0;

port/generic/stdio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/* TODO: PORTME */
1010

11-
hidden int
11+
int
1212
bfport_vsnprintf(char *s, bfdev_size_t maxlen, const char *fmt,
1313
bfdev_va_list arg)
1414
{

port/generic/stdlib.c

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

99
/* TODO: PORTME */
1010

11-
hidden __bfdev_malloc void *
11+
__bfdev_malloc void *
1212
bfport_malloc(bfdev_size_t size)
1313
{
1414
return BFDEV_NULL;
1515
}
1616

17-
hidden __bfdev_malloc void *
17+
__bfdev_malloc void *
1818
bfport_calloc(bfdev_size_t nmemb, bfdev_size_t size)
1919
{
2020
return BFDEV_NULL;
2121
}
2222

23-
hidden __bfdev_malloc void *
23+
__bfdev_malloc void *
2424
bfport_realloc(void *ptr, bfdev_size_t size)
2525
{
2626
return BFDEV_NULL;
2727
}
2828

29-
hidden void
29+
void
3030
bfport_free(void *ptr)
3131
{
3232
return;
3333
}
3434

35-
hidden int
35+
int
3636
bfport_rand(void)
3737
{
3838
return 0;
3939
}
4040

41-
hidden __bfdev_noreturn void
41+
__bfdev_noreturn void
4242
bfport_abort(void)
4343
{
4444
for (;;);

port/generic/string.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
#include <port/string.h>
77
#include <export.h>
88

9-
hidden void *
9+
void *
1010
bfport_memcpy(void *dest, const void *src, bfdev_size_t n)
1111
{
1212
const unsigned char *nsrc;
@@ -21,7 +21,7 @@ bfport_memcpy(void *dest, const void *src, bfdev_size_t n)
2121
return dest;
2222
}
2323

24-
hidden void *
24+
void *
2525
bfport_memset(void *s, int c, bfdev_size_t n)
2626
{
2727
unsigned char *xs;
@@ -33,7 +33,7 @@ bfport_memset(void *s, int c, bfdev_size_t n)
3333
return s;
3434
}
3535

36-
hidden int
36+
int
3737
bfport_memcmp(const void *s1, const void *s2, bfdev_size_t n)
3838
{
3939
const unsigned char *su1, *su2;
@@ -48,7 +48,7 @@ bfport_memcmp(const void *s1, const void *s2, bfdev_size_t n)
4848
return res;
4949
}
5050

51-
hidden int
51+
int
5252
bfport_strcmp(const char *s1, const char *s2)
5353
{
5454
int cp;
@@ -62,7 +62,7 @@ bfport_strcmp(const char *s1, const char *s2)
6262
return cp;
6363
}
6464

65-
hidden char *
65+
char *
6666
bfport_strchr(const char *s, int c)
6767
{
6868
for (; *s != (char)c; ++s) {
@@ -73,7 +73,7 @@ bfport_strchr(const char *s, int c)
7373
return (char *)s;
7474
}
7575

76-
hidden bfdev_size_t
76+
bfdev_size_t
7777
bfport_strspn(const char *s, const char *accept)
7878
{
7979
const unsigned char *p, *a;
@@ -93,7 +93,7 @@ bfport_strspn(const char *s, const char *accept)
9393
return count;
9494
}
9595

96-
hidden bfdev_size_t
96+
bfdev_size_t
9797
bfport_strcspn(const char *s, const char *reject)
9898
{
9999
const unsigned char *p, *r;
@@ -111,7 +111,7 @@ bfport_strcspn(const char *s, const char *reject)
111111
return count;
112112
}
113113

114-
hidden char *
114+
char *
115115
bfport_strcpy(char *dest, const char *src)
116116
{
117117
unsigned char *tmp;
@@ -123,7 +123,7 @@ bfport_strcpy(char *dest, const char *src)
123123
return dest;
124124
}
125125

126-
hidden char *
126+
char *
127127
bfport_strncpy(char *dest, const char *src, bfdev_size_t n)
128128
{
129129
unsigned char *tmp;
@@ -136,7 +136,7 @@ bfport_strncpy(char *dest, const char *src, bfdev_size_t n)
136136
return dest;
137137
}
138138

139-
hidden bfdev_size_t
139+
bfdev_size_t
140140
bfport_strlen(const char *s)
141141
{
142142
const unsigned char *len;
@@ -148,7 +148,7 @@ bfport_strlen(const char *s)
148148
return (char *)len - s;
149149
}
150150

151-
hidden bfdev_size_t
151+
bfdev_size_t
152152
bfport_strnlen(const char *s, bfdev_size_t len)
153153
{
154154
const unsigned char *sc;

0 commit comments

Comments
 (0)