# HG changeset patch # User Mike Becker # Date 1525290352 -7200 # Node ID c3b6ff227481e105f6e563a76a95f18032ccd2a2 # Parent 39e69d78b01db72f1b5638d315d796bda188563a adds more convenience macros for sstr This commit also increases the UCX version number towards the next release. - New product version: 1.1 - New library version: 2.0.1 - we are backwards, but not forward compatible. diff -r 39e69d78b01d -r c3b6ff227481 configure.ac --- a/configure.ac Wed May 02 20:55:23 2018 +0200 +++ b/configure.ac Wed May 02 21:45:52 2018 +0200 @@ -27,8 +27,9 @@ # # the package version must match the macros in ucx.h -# if you change the package version, don't forget to adjust the library version -AC_INIT([ucx], [1.0.1], [olaf.wintermann@gmail.com]) +# if you change the version, don't forget to adjust the +# libtool version-info in src/Makefile.am accordingly +AC_INIT([ucx], [1.1.0], [olaf.wintermann@gmail.com]) # don't place everything in the project root AC_CONFIG_AUX_DIR([build-aux]) diff -r 39e69d78b01d -r c3b6ff227481 src/Makefile.am --- a/src/Makefile.am Wed May 02 20:55:23 2018 +0200 +++ b/src/Makefile.am Wed May 02 21:45:52 2018 +0200 @@ -27,7 +27,7 @@ # lib_LTLIBRARIES = libucx.la -libucx_la_LDFLAGS = -version-info 1:0:0 +libucx_la_LDFLAGS = -version-info 2:0:1 libucx_la_SOURCES = utils.c libucx_la_SOURCES += list.c libucx_la_SOURCES += map.c diff -r 39e69d78b01d -r c3b6ff227481 src/ucx/string.h --- a/src/ucx/string.h Wed May 02 20:55:23 2018 +0200 +++ b/src/ucx/string.h Wed May 02 21:45:52 2018 +0200 @@ -58,6 +58,12 @@ /** Shortcut for the conversion of a C string to a sstr_t. */ #define S(s) sstrn((char*)s, sizeof(s)-1) +/** Expands a sstr_t to printf arguments. */ +#define SFMT(s) (int) (s).length, (s).ptr + +/** Format specifier for a sstr_t. */ +#define PRIsstr ".*s" + #ifdef __cplusplus extern "C" { #endif diff -r 39e69d78b01d -r c3b6ff227481 src/ucx/ucx.h --- a/src/ucx/ucx.h Wed May 02 20:55:23 2018 +0200 +++ b/src/ucx/ucx.h Wed May 02 21:45:52 2018 +0200 @@ -40,7 +40,7 @@ #define UCX_VERSION_MAJOR 1 /** Minor UCX version as integer constant. */ -#define UCX_VERSION_MINOR 0 +#define UCX_VERSION_MINOR 1 /** Version constant which ensures to increase monotonically. */ #define UCX_VERSION (((UCX_VERSION_MAJOR)<<16)|UCX_VERSION_MINOR) diff -r 39e69d78b01d -r c3b6ff227481 test/main.c --- a/test/main.c Wed May 02 20:55:23 2018 +0200 +++ b/test/main.c Wed May 02 21:45:52 2018 +0200 @@ -125,6 +125,7 @@ ucx_test_register(suite, test_ucx_default_allocator); /* sstring Tests */ + ucx_test_register(suite, test_sstr_macros); ucx_test_register(suite, test_sstr); ucx_test_register(suite, test_sstr_len); ucx_test_register(suite, test_sstrcmp); diff -r 39e69d78b01d -r c3b6ff227481 test/string_tests.c --- a/test/string_tests.c Wed May 02 20:55:23 2018 +0200 +++ b/test/string_tests.c Wed May 02 21:45:52 2018 +0200 @@ -28,6 +28,19 @@ #include "string_tests.h" +UCX_TEST(test_sstr_macros) { + sstr_t hello = ST("Hello"); + sstr_t world = S("World"); + + char buf[20]; + snprintf(buf, sizeof(buf), "%" PRIsstr ", %" PRIsstr "!", SFMT(hello), SFMT(world)); + + UCX_TEST_BEGIN + const char* cmp = "Hello, World!"; + UCX_TEST_ASSERT(!strcmp(cmp, buf), "Something weird happened."); + UCX_TEST_END +} + UCX_TEST(test_sstr) { sstr_t s1 = sstr((char*)"1234"); sstr_t s2 = sstrn((char*)"ab", 2); diff -r 39e69d78b01d -r c3b6ff227481 test/string_tests.h --- a/test/string_tests.h Wed May 02 20:55:23 2018 +0200 +++ b/test/string_tests.h Wed May 02 21:45:52 2018 +0200 @@ -36,6 +36,7 @@ extern "C" { #endif +UCX_TEST(test_sstr_macros); UCX_TEST(test_sstr); UCX_TEST(test_sstr_len); UCX_TEST(test_sstrcmp);