# HG changeset patch # User Mike Becker # Date 1759947654 -7200 # Node ID b97faf8b7ab7b30fb70ee56d4850897ab415a425 # Parent e67caa21d5a707d74f71495825415302c2917c1b replace all remaining generics with cx_strcast() - resolves #700 diff -r e67caa21d5a7 -r b97faf8b7ab7 src/cx/json.h --- a/src/cx/json.h Wed Oct 08 20:09:32 2025 +0200 +++ b/src/cx/json.h Wed Oct 08 20:20:54 2025 +0200 @@ -575,36 +575,20 @@ cx_attr_export int cxJsonFilln(CxJson *json, const char *buf, size_t len); -#ifdef __cplusplus -} // extern "C" +/** + * Internal function, do not use. + * + * @param json the json interface + * @param str the string + * @retval zero success + * @retval non-zero internal allocation error + */ cx_attr_nonnull -static inline int cxJsonFill( - CxJson *json, - cxstring str -) { +static inline int cx_json_fill(CxJson *json, cxstring str) { return cxJsonFilln(json, str.ptr, str.length); } -cx_attr_nonnull -static inline int cxJsonFill( - CxJson *json, - cxmutstr str -) { - return cxJsonFilln(json, str.ptr, str.length); -} - -cx_attr_nonnull -cx_attr_cstr_arg(2) -static inline int cxJsonFill( - CxJson *json, - const char *str -) { - return cxJsonFilln(json, str, strlen(str)); -} - -extern "C" { -#else // __cplusplus /** * Fills the input buffer. * @@ -622,47 +606,7 @@ * @retval non-zero internal allocation error * @see cxJsonFilln() */ -#define cxJsonFill(json, str) _Generic((str), \ - cxstring: cx_json_fill_cxstr, \ - cxmutstr: cx_json_fill_mutstr, \ - char*: cx_json_fill_str, \ - const char*: cx_json_fill_str) \ - (json, str) - -/** - * @copydoc cxJsonFill() - */ -cx_attr_nonnull -static inline int cx_json_fill_cxstr( - CxJson *json, - cxstring str -) { - return cxJsonFilln(json, str.ptr, str.length); -} - -/** - * @copydoc cxJsonFill() - */ -cx_attr_nonnull -static inline int cx_json_fill_mutstr( - CxJson *json, - cxmutstr str -) { - return cxJsonFilln(json, str.ptr, str.length); -} - -/** - * @copydoc cxJsonFill() - */ -cx_attr_nonnull -cx_attr_cstr_arg(2) -static inline int cx_json_fill_str( - CxJson *json, - const char *str -) { - return cxJsonFilln(json, str, strlen(str)); -} -#endif +#define cxJsonFill(json, str) cx_json_fill(json, cx_strcast(str)) /** * Creates a new (empty) JSON object. @@ -1334,49 +1278,16 @@ CxIterator cxJsonObjIter(const CxJsonValue *value); /** - * @copydoc cxJsonObjGet() + * Internal function, do not use. + * @param value the JSON object + * @param name the key to look up + * @return the value corresponding to the key */ cx_attr_nonnull cx_attr_returns_nonnull cx_attr_export -CxJsonValue *cx_json_obj_get_cxstr(const CxJsonValue *value, cxstring name); - -/** - * @copydoc cxJsonObjRemove() - */ -cx_attr_nonnull -cx_attr_export -CxJsonValue *cx_json_obj_remove_cxstr(CxJsonValue *value, cxstring name); - -#ifdef __cplusplus -} // extern "C" - -static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxstring name) { - return cx_json_obj_get_cxstr(value, name); -} +CxJsonValue *cx_json_obj_get(const CxJsonValue *value, cxstring name); -static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxmutstr name) { - return cx_json_obj_get_cxstr(value, cx_strcast(name)); -} - -static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, const char *name) { - return cx_json_obj_get_cxstr(value, cx_str(name)); -} - -static inline CxJsonValue *cxJsonObjRemove(CxJsonValue *value, cxstring name) { - return cx_json_obj_remove_cxstr(value, name); -} - -static inline CxJsonValue *cxJsonObjRemove(CxJsonValue *value, cxmutstr name) { - return cx_json_obj_remove_cxstr(value, cx_strcast(name)); -} - -static inline CxJsonValue *cxJsonObjRemove(CxJsonValue *value, const char *name) { - return cx_json_obj_remove_cxstr(value, cx_str(name)); -} - -extern "C" { -#else /** * Returns a value corresponding to a key in a JSON object. * @@ -1391,31 +1302,17 @@ * @return the value corresponding to the key * @see cxJsonIsObject() */ -#define cxJsonObjGet(value, name) _Generic((name), \ - cxstring: cx_json_obj_get_cxstr, \ - cxmutstr: cx_json_obj_get_mutstr, \ - char*: cx_json_obj_get_str, \ - const char*: cx_json_obj_get_str) \ - (value, name) +#define cxJsonObjGet(value, name) cx_json_obj_get(value, cx_strcast(name)) /** - * @copydoc cxJsonObjGet() + * Internal function, do not use. + * @param value the JSON object + * @param name the key to look up + * @return the value corresponding to the key or @c NULL when the key is not part of the object */ cx_attr_nonnull -cx_attr_returns_nonnull -static inline CxJsonValue *cx_json_obj_get_mutstr(const CxJsonValue *value, cxmutstr name) { - return cx_json_obj_get_cxstr(value, cx_strcast(name)); -} - -/** - * @copydoc cxJsonObjGet() - */ -cx_attr_nonnull -cx_attr_returns_nonnull -cx_attr_cstr_arg(2) -static inline CxJsonValue *cx_json_obj_get_str(const CxJsonValue *value, const char *name) { - return cx_json_obj_get_cxstr(value, cx_str(name)); -} +cx_attr_export +CxJsonValue *cx_json_obj_remove(CxJsonValue *value, cxstring name); /** * Removes and returns a value corresponding to a key in a JSON object. @@ -1430,30 +1327,7 @@ * @return the value corresponding to the key or @c NULL when the key is not part of the object * @see cxJsonIsObject() */ -#define cxJsonObjRemove(value, name) _Generic((name), \ - cxstring: cx_json_obj_remove_cxstr, \ - cxmutstr: cx_json_obj_remove_mutstr, \ - char*: cx_json_obj_remove_str, \ - const char*: cx_json_obj_remove_str) \ - (value, name) - -/** - * @copydoc cxJsonObjRemove() - */ -cx_attr_nonnull -static inline CxJsonValue *cx_json_obj_remove_mutstr(CxJsonValue *value, cxmutstr name) { - return cx_json_obj_remove_cxstr(value, cx_strcast(name)); -} - -/** - * @copydoc cxJsonObjRemove() - */ -cx_attr_nonnull -cx_attr_cstr_arg(2) -static inline CxJsonValue *cx_json_obj_remove_str(CxJsonValue *value, const char *name) { - return cx_json_obj_remove_cxstr(value, cx_str(name)); -} -#endif +#define cxJsonObjRemove(value, name) cx_json_obj_remove(value, cx_strcast(name)) #ifdef __cplusplus } diff -r e67caa21d5a7 -r b97faf8b7ab7 src/cx/properties.h --- a/src/cx/properties.h Wed Oct 08 20:09:32 2025 +0200 +++ b/src/cx/properties.h Wed Oct 08 20:20:54 2025 +0200 @@ -403,35 +403,22 @@ size_t len ); -#ifdef __cplusplus -} // extern "C" +/** + * Internal function, do not use. + * + * @param prop the properties interface + * @param str the text to fill in + * @retval zero success + * @retval non-zero a memory allocation was necessary but failed + */ cx_attr_nonnull -static inline int cxPropertiesFill( +static inline int cx_properties_fill( CxProperties *prop, cxstring str ) { return cxPropertiesFilln(prop, str.ptr, str.length); } -cx_attr_nonnull -static inline int cxPropertiesFill( - CxProperties *prop, - cxmutstr str -) { - return cxPropertiesFilln(prop, str.ptr, str.length); -} - -cx_attr_nonnull -cx_attr_cstr_arg(2) -static inline int cxPropertiesFill( - CxProperties *prop, - const char *str -) { - return cxPropertiesFilln(prop, str, strlen(str)); -} - -extern "C" { -#else // __cplusplus /** * Fills the input buffer with data. * @@ -452,47 +439,7 @@ * @retval non-zero a memory allocation was necessary but failed * @see cxPropertiesFilln() */ -#define cxPropertiesFill(prop, str) _Generic((str), \ - cxstring: cx_properties_fill_cxstr, \ - cxmutstr: cx_properties_fill_mutstr, \ - char*: cx_properties_fill_str, \ - const char*: cx_properties_fill_str) \ - (prop, str) - -/** - * @copydoc cxPropertiesFill() - */ -cx_attr_nonnull -static inline int cx_properties_fill_cxstr( - CxProperties *prop, - cxstring str -) { - return cxPropertiesFilln(prop, str.ptr, str.length); -} - -/** - * @copydoc cxPropertiesFill() - */ -cx_attr_nonnull -static inline int cx_properties_fill_mutstr( - CxProperties *prop, - cxmutstr str -) { - return cxPropertiesFilln(prop, str.ptr, str.length); -} - -/** - * @copydoc cxPropertiesFill() - */ -cx_attr_nonnull -cx_attr_cstr_arg(2) -static inline int cx_properties_fill_str( - CxProperties *prop, - const char *str -) { - return cxPropertiesFilln(prop, str, strlen(str)); -} -#endif +#define cxPropertiesFill(prop, str) cx_properties_fill(prop, cx_strcast(str)) /** * Specifies stack memory that shall be used as internal buffer. diff -r e67caa21d5a7 -r b97faf8b7ab7 src/json.c --- a/src/json.c Wed Oct 08 20:09:32 2025 +0200 +++ b/src/json.c Wed Oct 08 20:20:54 2025 +0200 @@ -1141,7 +1141,7 @@ ); } -CxJsonValue *cx_json_obj_get_cxstr(const CxJsonValue *value, cxstring name) { +CxJsonValue *cx_json_obj_get(const CxJsonValue *value, cxstring name) { size_t index = json_find_objvalue(value, name); if (index >= value->value.object.values_size) { return &cx_json_value_nothing; @@ -1150,7 +1150,7 @@ } } -CxJsonValue *cx_json_obj_remove_cxstr(CxJsonValue *value, cxstring name) { +CxJsonValue *cx_json_obj_remove(CxJsonValue *value, cxstring name) { size_t index = json_find_objvalue(value, name); if (index >= value->value.object.values_size) { return NULL;