Skip to content

Commit

Permalink
Merge branch 'devel'
Browse files Browse the repository at this point in the history
  • Loading branch information
sanpeqf committed May 23, 2024
2 parents 77b1a89 + 55ce8c5 commit d983100
Show file tree
Hide file tree
Showing 91 changed files with 3,295 additions and 2,189 deletions.
1 change: 0 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ jobs:
cmake -B ${{github.workspace}}/build \
-D CMAKE_INSTALL_PREFIX=${{github.workspace}}/build/install \
-D CMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} \
-D CMAKE_C_COMPILER=/usr/local/opt/ccache/libexec/clang \
-D BFDEV_DEVEL=ON
- name: make
Expand Down
11 changes: 2 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#

cmake_minimum_required(VERSION 3.12)
project(bfdev VERSION 1.0.3 LANGUAGES C)
project(bfdev VERSION 1.0.4 LANGUAGES C)

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

include(scripts/hostrule.cmake)
include(scripts/packed-header.cmake)
include(scripts/packed-source.cmake)
include(scripts/commit.cmake)

commit_hash(BFDEV_COMMITID)
Expand All @@ -54,6 +53,7 @@ option(BFDEV_DEBUG_ILIST "Dynamic debug ilist" ON)
option(BFDEV_DEBUG_RBTREE "Dynamic debug rbtree" ON)
option(BFDEV_DEBUG_HEAP "Dynamic debug heap" ON)
option(BFDEV_DEBUG_REFCNT "Dynamic debug refcnt" ON)
option(BFDEV_DEBUG_MEMALLOC "Dynamic debug memalloc" ON)
option(BFDEV_CRC_EXTEND "CRC loop unfolding optimize" ON)

if(BFDEV_DEVEL)
Expand All @@ -74,13 +74,6 @@ packed_header(
${BFDEV_HEADER_PATH}/bfdev
)

packed_source(
${PROJECT_BINARY_DIR}/bfdev.c
"${BFDEV_LIBRARY_SOURCE}"
"#undef MODULE_NAME\n"
"#undef bfdev_log_fmt\n"
)

macro(bfdev_dependencies target)
add_dependencies(
${target}
Expand Down
1 change: 1 addition & 0 deletions cmake/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ BFDEV_BEGIN_DECLS
#cmakedefine BFDEV_DEBUG_RBTREE
#cmakedefine BFDEV_DEBUG_HEAP
#cmakedefine BFDEV_DEBUG_REFCNT
#cmakedefine BFDEV_DEBUG_MEMALLOC
#cmakedefine BFDEV_CRC_EXTEND

#define BFDEV_VERSION_CHECK(major, minor, patch) ( \
Expand Down
2 changes: 1 addition & 1 deletion docs/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

- allocator: Allocation compatibility layer
- allocpool: Mempool optimized for allocation performance
- minpool: Simple memory allocator
- memalloc: Memory allocator algorithm

## String Process

Expand Down
3 changes: 2 additions & 1 deletion examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ add_subdirectory(action)
add_subdirectory(allocator)
add_subdirectory(arc4)
add_subdirectory(array)
add_subdirectory(ascii85)
add_subdirectory(base32)
add_subdirectory(base64)
add_subdirectory(bfdev)
Expand All @@ -28,13 +29,13 @@ add_subdirectory(list)
add_subdirectory(log)
add_subdirectory(log2)
add_subdirectory(matrix)
add_subdirectory(minpool)
add_subdirectory(mpi)
add_subdirectory(notifier)
add_subdirectory(once)
add_subdirectory(prandom)
add_subdirectory(radix)
add_subdirectory(rbtree)
add_subdirectory(respool)
add_subdirectory(ringbuf)
add_subdirectory(segtree)
add_subdirectory(skiplist)
Expand Down
2 changes: 2 additions & 0 deletions examples/ascii85/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SPDX-License-Identifier: GPL-2.0-or-later
/ascii85-bandwidth
28 changes: 28 additions & 0 deletions examples/ascii85/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Copyright(c) 2024 John Sanpe <[email protected]>
#

add_executable(ascii85-bandwidth bandwidth.c)
target_link_libraries(ascii85-bandwidth bfdev)
add_test(ascii85-bandwidth ascii85-bandwidth)

add_executable(ascii85 utils.c)
target_link_libraries(ascii85 bfdev)
add_test(ascii85 ascii85 "helloworld")

if(${CMAKE_PROJECT_NAME} STREQUAL "bfdev")
install(FILES
bandwidth.c
utils.c
DESTINATION
${CMAKE_INSTALL_DOCDIR}/examples/ascii85
)

install(TARGETS
ascii85
ascii85-bandwidth
DESTINATION
${CMAKE_INSTALL_DOCDIR}/bin
)
endif()
69 changes: 69 additions & 0 deletions examples/ascii85/bandwidth.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright(c) 2024 John Sanpe <[email protected]>
*/

#define MODULE_NAME "ascii85-bandwidth"
#define bfdev_log_fmt(fmt) MODULE_NAME ": " fmt

#include <stdio.h>
#include <stdlib.h>
#include <bfdev/ascii85.h>
#include <bfdev/crc.h>
#include <bfdev/log.h>
#include <bfdev/size.h>
#include "../time.h"

#define TEST_SIZE BFDEV_SZ_1MiB
#define TEST_LOOP 3

int main(int argc, char const *argv[])
{
unsigned int count, loop;
uint8_t *dbuff, *sbuff;
size_t dlen, slen, index;
uint32_t cksum, check;

slen = bfdev_ascii85_encode_length(TEST_SIZE);
sbuff = malloc(slen);
if (!sbuff)
return 1;

dlen = bfdev_ascii85_decode_length(slen);
dbuff = malloc(dlen);
if (!dbuff)
return 1;

srand(time(NULL));
for (index = 0; index < dlen; ++index)
dbuff[index] = (uint8_t)rand();

cksum = bfdev_crc32(dbuff, dlen, (uint32_t)~0UL);
bfdev_log_info("start checksum: %#010x\n", cksum);

for (count = 0; count < TEST_LOOP; ++count) {
EXAMPLE_TIME_LOOP(&loop, 1000,
bfdev_ascii85_encode(sbuff, dbuff, &slen, dlen);
0;
);
bfdev_log_info("encode bandwidth %u: %uMiB/s\n", count, loop);

EXAMPLE_TIME_LOOP(&loop, 1000,
bfdev_ascii85_decode(dbuff, sbuff, &dlen, slen);
0;
);
bfdev_log_info("decode bandwidth %u: %uMiB/s\n", count, loop);
}

check = bfdev_crc32(dbuff, dlen, (uint32_t)~0UL);
if (cksum != check) {
bfdev_log_err("verification failed\n");
return 1;
}
bfdev_log_info("verification pass\n");

free(sbuff);
free(dbuff);

return 0;
}
87 changes: 87 additions & 0 deletions examples/ascii85/utils.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* Copyright(c) 2024 John Sanpe <[email protected]>
*/

#define MODULE_NAME "bfdev-ascii85"
#define bfdev_log_fmt(fmt) MODULE_NAME ": " fmt

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <bfdev/log.h>
#include <bfdev/errname.h>
#include <bfdev/ascii85.h>

int
main(int argc, const char *argv[])
{
unsigned int index;
bool decode;
int retval;

decode = false;
for (index = 1; index < argc; ++index) {
const char *para;

para = argv[index];
if (para[0] != '-')
break;

switch (para[1]) {
case 'd':
decode = true;
break;

case 'h': default:
goto usage;
}
}

if (index == argc)
goto usage;

do {
size_t len1, len2, len3;
const char *data;
char *buff;

data = argv[index];
len1 = strlen(data);

if (decode)
len2 = bfdev_ascii85_decode_length(len1);
else
len2 = bfdev_ascii85_encode_length(len1);

buff = malloc(len2);
if (!buff) {
bfdev_log_err("Out of memory.\n");
return 1;
}

if (!decode)
bfdev_ascii85_encode(buff, data, &len3, len1);
else {
retval = bfdev_ascii85_decode(buff, data, &len3, len1);
if (retval) {
const char *ername, *infop;

ername = bfdev_errname(retval, &infop);
bfdev_log_err("Decode error: %s (%s).\n", ername, infop);

return retval;
}
}

fwrite(buff, 1, len3, stdout);
fputc('\n', stdout);
free(buff);
} while (++index < argc);

return 0;

usage:
bfdev_log_err("Usage: %s [-d] data ...\n", argv[0]);
return 1;
}
6 changes: 6 additions & 0 deletions examples/base32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ add_executable(base32-bandwidth bandwidth.c)
target_link_libraries(base32-bandwidth bfdev)
add_test(base32-bandwidth base32-bandwidth)

add_executable(base32 utils.c)
target_link_libraries(base32 bfdev)
add_test(base32 base32 "helloworld")

if(${CMAKE_PROJECT_NAME} STREQUAL "bfdev")
install(FILES
bandwidth.c
utils.c
DESTINATION
${CMAKE_INSTALL_DOCDIR}/examples/base32
)

install(TARGETS
base32
base32-bandwidth
DESTINATION
${CMAKE_INSTALL_DOCDIR}/bin
Expand Down
4 changes: 2 additions & 2 deletions examples/base32/bandwidth.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ int main(int argc, char const *argv[])
return 1;

srand(time(NULL));
for (index = 0; index < TEST_SIZE; ++index)
for (index = 0; index < dlen; ++index)
dbuff[index] = (uint8_t)rand();

cksum = bfdev_crc32(dbuff, dlen, (uint32_t)~0UL);
bfdev_log_info("start checksum: %#010x\n", cksum);

for (count = 0; count < TEST_LOOP; ++count) {
EXAMPLE_TIME_LOOP(&loop, 1000,
bfdev_base32_encode(sbuff, dbuff, TEST_SIZE);
bfdev_base32_encode(sbuff, dbuff, dlen);
0;
);
bfdev_log_info("encode bandwidth %u: %uMiB/s\n", count, loop);
Expand Down
Loading

0 comments on commit d983100

Please sign in to comment.