Skip to content

Commit fc47b87

Browse files
committed
Merge branch 'devel'
2 parents d185a51 + 4043cef commit fc47b87

91 files changed

Lines changed: 3295 additions & 2189 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/macos.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ jobs:
3535
cmake -B ${{github.workspace}}/build \
3636
-D CMAKE_INSTALL_PREFIX=${{github.workspace}}/build/install \
3737
-D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
38-
-D CMAKE_C_COMPILER=/usr/local/opt/ccache/libexec/clang \
3938
-D BFDEV_DEVEL=ON
4039
4140
- name: make

CMakeLists.txt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#
66

77
cmake_minimum_required(VERSION 3.12)
8-
project(bfdev VERSION 1.0.3 LANGUAGES C)
8+
project(bfdev VERSION 1.0.4 LANGUAGES C)
99

1010
include(GNUInstallDirs)
1111
include(CheckIncludeFiles)
@@ -32,7 +32,6 @@ set(BFDEV_CONFIGURE ${BFDEV_GENERATED_PATH}/bfdev-config.cmake)
3232

3333
include(scripts/hostrule.cmake)
3434
include(scripts/packed-header.cmake)
35-
include(scripts/packed-source.cmake)
3635
include(scripts/commit.cmake)
3736

3837
commit_hash(BFDEV_COMMITID)
@@ -54,6 +53,7 @@ option(BFDEV_DEBUG_ILIST "Dynamic debug ilist" ON)
5453
option(BFDEV_DEBUG_RBTREE "Dynamic debug rbtree" ON)
5554
option(BFDEV_DEBUG_HEAP "Dynamic debug heap" ON)
5655
option(BFDEV_DEBUG_REFCNT "Dynamic debug refcnt" ON)
56+
option(BFDEV_DEBUG_MEMALLOC "Dynamic debug memalloc" ON)
5757
option(BFDEV_CRC_EXTEND "CRC loop unfolding optimize" ON)
5858

5959
if(BFDEV_DEVEL)
@@ -74,13 +74,6 @@ packed_header(
7474
${BFDEV_HEADER_PATH}/bfdev
7575
)
7676

77-
packed_source(
78-
${PROJECT_BINARY_DIR}/bfdev.c
79-
"${BFDEV_LIBRARY_SOURCE}"
80-
"#undef MODULE_NAME\n"
81-
"#undef bfdev_log_fmt\n"
82-
)
83-
8477
macro(bfdev_dependencies target)
8578
add_dependencies(
8679
${target}

cmake/config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ BFDEV_BEGIN_DECLS
3333
#cmakedefine BFDEV_DEBUG_RBTREE
3434
#cmakedefine BFDEV_DEBUG_HEAP
3535
#cmakedefine BFDEV_DEBUG_REFCNT
36+
#cmakedefine BFDEV_DEBUG_MEMALLOC
3637
#cmakedefine BFDEV_CRC_EXTEND
3738

3839
#define BFDEV_VERSION_CHECK(major, minor, patch) ( \

docs/components.md

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

5757
- allocator: Allocation compatibility layer
5858
- allocpool: Mempool optimized for allocation performance
59-
- minpool: Simple memory allocator
59+
- memalloc: Memory allocator algorithm
6060

6161
## String Process
6262

examples/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ add_subdirectory(action)
77
add_subdirectory(allocator)
88
add_subdirectory(arc4)
99
add_subdirectory(array)
10+
add_subdirectory(ascii85)
1011
add_subdirectory(base32)
1112
add_subdirectory(base64)
1213
add_subdirectory(bfdev)
@@ -28,13 +29,13 @@ add_subdirectory(list)
2829
add_subdirectory(log)
2930
add_subdirectory(log2)
3031
add_subdirectory(matrix)
31-
add_subdirectory(minpool)
3232
add_subdirectory(mpi)
3333
add_subdirectory(notifier)
3434
add_subdirectory(once)
3535
add_subdirectory(prandom)
3636
add_subdirectory(radix)
3737
add_subdirectory(rbtree)
38+
add_subdirectory(respool)
3839
add_subdirectory(ringbuf)
3940
add_subdirectory(segtree)
4041
add_subdirectory(skiplist)

examples/ascii85/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SPDX-License-Identifier: GPL-2.0-or-later
2+
/ascii85-bandwidth

examples/ascii85/CMakeLists.txt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# SPDX-License-Identifier: GPL-2.0-or-later
2+
#
3+
# Copyright(c) 2024 John Sanpe <sanpeqf@gmail.com>
4+
#
5+
6+
add_executable(ascii85-bandwidth bandwidth.c)
7+
target_link_libraries(ascii85-bandwidth bfdev)
8+
add_test(ascii85-bandwidth ascii85-bandwidth)
9+
10+
add_executable(ascii85 utils.c)
11+
target_link_libraries(ascii85 bfdev)
12+
add_test(ascii85 ascii85 "helloworld")
13+
14+
if(${CMAKE_PROJECT_NAME} STREQUAL "bfdev")
15+
install(FILES
16+
bandwidth.c
17+
utils.c
18+
DESTINATION
19+
${CMAKE_INSTALL_DOCDIR}/examples/ascii85
20+
)
21+
22+
install(TARGETS
23+
ascii85
24+
ascii85-bandwidth
25+
DESTINATION
26+
${CMAKE_INSTALL_DOCDIR}/bin
27+
)
28+
endif()

examples/ascii85/bandwidth.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copyright(c) 2024 John Sanpe <sanpeqf@gmail.com>
4+
*/
5+
6+
#define MODULE_NAME "ascii85-bandwidth"
7+
#define bfdev_log_fmt(fmt) MODULE_NAME ": " fmt
8+
9+
#include <stdio.h>
10+
#include <stdlib.h>
11+
#include <bfdev/ascii85.h>
12+
#include <bfdev/crc.h>
13+
#include <bfdev/log.h>
14+
#include <bfdev/size.h>
15+
#include "../time.h"
16+
17+
#define TEST_SIZE BFDEV_SZ_1MiB
18+
#define TEST_LOOP 3
19+
20+
int main(int argc, char const *argv[])
21+
{
22+
unsigned int count, loop;
23+
uint8_t *dbuff, *sbuff;
24+
size_t dlen, slen, index;
25+
uint32_t cksum, check;
26+
27+
slen = bfdev_ascii85_encode_length(TEST_SIZE);
28+
sbuff = malloc(slen);
29+
if (!sbuff)
30+
return 1;
31+
32+
dlen = bfdev_ascii85_decode_length(slen);
33+
dbuff = malloc(dlen);
34+
if (!dbuff)
35+
return 1;
36+
37+
srand(time(NULL));
38+
for (index = 0; index < dlen; ++index)
39+
dbuff[index] = (uint8_t)rand();
40+
41+
cksum = bfdev_crc32(dbuff, dlen, (uint32_t)~0UL);
42+
bfdev_log_info("start checksum: %#010x\n", cksum);
43+
44+
for (count = 0; count < TEST_LOOP; ++count) {
45+
EXAMPLE_TIME_LOOP(&loop, 1000,
46+
bfdev_ascii85_encode(sbuff, dbuff, &slen, dlen);
47+
0;
48+
);
49+
bfdev_log_info("encode bandwidth %u: %uMiB/s\n", count, loop);
50+
51+
EXAMPLE_TIME_LOOP(&loop, 1000,
52+
bfdev_ascii85_decode(dbuff, sbuff, &dlen, slen);
53+
0;
54+
);
55+
bfdev_log_info("decode bandwidth %u: %uMiB/s\n", count, loop);
56+
}
57+
58+
check = bfdev_crc32(dbuff, dlen, (uint32_t)~0UL);
59+
if (cksum != check) {
60+
bfdev_log_err("verification failed\n");
61+
return 1;
62+
}
63+
bfdev_log_info("verification pass\n");
64+
65+
free(sbuff);
66+
free(dbuff);
67+
68+
return 0;
69+
}

examples/ascii85/utils.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/* SPDX-License-Identifier: GPL-2.0-or-later */
2+
/*
3+
* Copyright(c) 2024 John Sanpe <sanpeqf@gmail.com>
4+
*/
5+
6+
#define MODULE_NAME "bfdev-ascii85"
7+
#define bfdev_log_fmt(fmt) MODULE_NAME ": " fmt
8+
9+
#include <stdio.h>
10+
#include <stdlib.h>
11+
#include <string.h>
12+
#include <bfdev/log.h>
13+
#include <bfdev/errname.h>
14+
#include <bfdev/ascii85.h>
15+
16+
int
17+
main(int argc, const char *argv[])
18+
{
19+
unsigned int index;
20+
bool decode;
21+
int retval;
22+
23+
decode = false;
24+
for (index = 1; index < argc; ++index) {
25+
const char *para;
26+
27+
para = argv[index];
28+
if (para[0] != '-')
29+
break;
30+
31+
switch (para[1]) {
32+
case 'd':
33+
decode = true;
34+
break;
35+
36+
case 'h': default:
37+
goto usage;
38+
}
39+
}
40+
41+
if (index == argc)
42+
goto usage;
43+
44+
do {
45+
size_t len1, len2, len3;
46+
const char *data;
47+
char *buff;
48+
49+
data = argv[index];
50+
len1 = strlen(data);
51+
52+
if (decode)
53+
len2 = bfdev_ascii85_decode_length(len1);
54+
else
55+
len2 = bfdev_ascii85_encode_length(len1);
56+
57+
buff = malloc(len2);
58+
if (!buff) {
59+
bfdev_log_err("Out of memory.\n");
60+
return 1;
61+
}
62+
63+
if (!decode)
64+
bfdev_ascii85_encode(buff, data, &len3, len1);
65+
else {
66+
retval = bfdev_ascii85_decode(buff, data, &len3, len1);
67+
if (retval) {
68+
const char *ername, *infop;
69+
70+
ername = bfdev_errname(retval, &infop);
71+
bfdev_log_err("Decode error: %s (%s).\n", ername, infop);
72+
73+
return retval;
74+
}
75+
}
76+
77+
fwrite(buff, 1, len3, stdout);
78+
fputc('\n', stdout);
79+
free(buff);
80+
} while (++index < argc);
81+
82+
return 0;
83+
84+
usage:
85+
bfdev_log_err("Usage: %s [-d] data ...\n", argv[0]);
86+
return 1;
87+
}

examples/base32/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,20 @@ add_executable(base32-bandwidth bandwidth.c)
77
target_link_libraries(base32-bandwidth bfdev)
88
add_test(base32-bandwidth base32-bandwidth)
99

10+
add_executable(base32 utils.c)
11+
target_link_libraries(base32 bfdev)
12+
add_test(base32 base32 "helloworld")
13+
1014
if(${CMAKE_PROJECT_NAME} STREQUAL "bfdev")
1115
install(FILES
1216
bandwidth.c
17+
utils.c
1318
DESTINATION
1419
${CMAKE_INSTALL_DOCDIR}/examples/base32
1520
)
1621

1722
install(TARGETS
23+
base32
1824
base32-bandwidth
1925
DESTINATION
2026
${CMAKE_INSTALL_DOCDIR}/bin

0 commit comments

Comments
 (0)