Mon, 21 Jul 2025 22:22:46 +0200
update ucx
| src/ucx/cx/string.h | file | annotate | diff | comparison | revisions | |
| src/ucx/mempool.c | file | annotate | diff | comparison | revisions | |
| src/ucx/string.c | file | annotate | diff | comparison | revisions |
--- a/src/ucx/cx/string.h Wed Jun 25 21:00:29 2025 +0200 +++ b/src/ucx/cx/string.h Mon Jul 21 22:22:46 2025 +0200 @@ -167,6 +167,8 @@ * * The length is implicitly inferred by using a call to @c strlen(). * + * When @c NULL is passed, the length will be set to zero. + * * @note the wrapped string will share the specified pointer to the string. * If you do want a copy, use cx_strdup() on the return value of this function. * @@ -177,7 +179,6 @@ * * @see cx_mutstrn() */ -cx_attr_nonnull cx_attr_nodiscard cx_attr_cstr_arg(1) cx_attr_export @@ -212,6 +213,8 @@ * * The length is implicitly inferred by using a call to @c strlen(). * + * When @c NULL is passed, the length will be set to zero. + * * @note the wrapped string will share the specified pointer to the string. * If you do want a copy, use cx_strdup() on the return value of this function. * @@ -222,7 +225,6 @@ * * @see cx_strn() */ -cx_attr_nonnull cx_attr_nodiscard cx_attr_cstr_arg(1) cx_attr_export @@ -263,6 +265,10 @@ static inline cxstring cx_strcast(cxstring str) { return str; } +cx_attr_nodiscard +static inline cxstring cx_strcast(const char *str) { + return cx_str(str); +} extern "C" { #else /** @@ -287,6 +293,17 @@ } /** + * Internal function, do not use. + * @param str + * @return + * @see cx_strcast() + */ +cx_attr_nodiscard +static inline cxstring cx_strcast_z(const char *str) { + return cx_str(str); +} + +/** * Casts a mutable string to an immutable string. * * Does nothing for already immutable strings. @@ -300,8 +317,9 @@ */ #define cx_strcast(str) _Generic((str), \ cxmutstr: cx_strcast_m, \ - cxstring: cx_strcast_c) \ - (str) + cxstring: cx_strcast_c, \ + const char*: cx_strcast_z, \ + char *: cx_strcast_z) (str) #endif /**
--- a/src/ucx/mempool.c Wed Jun 25 21:00:29 2025 +0200 +++ b/src/ucx/mempool.c Mon Jul 21 22:22:46 2025 +0200 @@ -633,13 +633,19 @@ new_source_allocator->data = source; // transfer all the data - memcpy(&dest->data[dest->size], source->data, sizeof(void*)*source->size); - dest->size += source->size; + if (source->size > 0) { + memcpy(&dest->data[dest->size], source->data, + sizeof(void*)*source->size); + dest->size += source->size; + } // transfer all registered memory - memcpy(&dest->registered[dest->registered_size], source->registered, - sizeof(struct cx_mempool_foreign_memory_s) * source->size); - dest->registered_size += source->registered_size; + if (source->registered_size > 0) { + memcpy(&dest->registered[dest->registered_size], source->registered, + sizeof(struct cx_mempool_foreign_memory_s) + * source->registered_size); + dest->registered_size += source->registered_size; + } // register the old allocator with the new pool // we have to remove const-ness for this, but that's okay here
--- a/src/ucx/string.c Wed Jun 25 21:00:29 2025 +0200 +++ b/src/ucx/string.c Mon Jul 21 22:22:46 2025 +0200 @@ -42,7 +42,7 @@ #endif cxmutstr cx_mutstr(char *cstring) { - return (cxmutstr) {cstring, strlen(cstring)}; + return (cxmutstr) {cstring, cstring == NULL ? 0 : strlen(cstring)}; } cxmutstr cx_mutstrn( @@ -53,7 +53,7 @@ } cxstring cx_str(const char *cstring) { - return (cxstring) {cstring, strlen(cstring)}; + return (cxstring) {cstring, cstring == NULL ? 0 : strlen(cstring)}; } cxstring cx_strn(