Skip to content

Commit

Permalink
🛠 Only run extension function code if preprocessor okays it
Browse files Browse the repository at this point in the history
  • Loading branch information
ThePhD committed Nov 22, 2023
1 parent a272f45 commit 7275b99
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 37 deletions.
6 changes: 6 additions & 0 deletions examples/extensions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,10 @@ foreach(extensions_source_file ${ztd.cuneicode.examples.extensions.stmt-exprs.so
target_compile_features(${extensions_target_name}
PRIVATE
c_std_23)
target_compile_features(${extensions_target_name}
PRIVATE
c_std_23)
set_property(TARGET ${extensions_target_name}
PROPERTY
C_EXTENSIONS ON)
endforeach()
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <string.h>

int main() {
#if ZTD_IS_ON(ZTD_CUNEICODE_EXTENSION_FUNCTIONS)
// This only works if we support extension functions!
const ztd_char32_t input_data[] = U"Bark Bark Bark \xFFFFFFFF🐕‍🦺!";
ztd_char8_t output_data[ztdc_c_array_size(input_data) * CNC_C8_MAX] = { 0 };
cnc_mcstate_t state = { 0 };
Expand Down Expand Up @@ -66,4 +68,7 @@ int main() {
// won't show the last line even if you manually call fflush(…) !
fwrite("\n", sizeof(char), 1, stdout);
return has_err ? 1 : 0;
#else
return 0;
#endif
}
5 changes: 5 additions & 0 deletions examples/extensions/source/special_functionality.stmt_exprs.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <limits.h>

int main() {
#if ZTD_IS_ON(ZTD_CUNEICODE_EXTENSION_FUNCTIONS)
// This only works if we support extension functions!
const ztd_char8_t str[]
= u8"\"Saw a \U0001F9DC \u2014"
u8"didn't catch her\u2026 \U0001F61E\"\n\t- Sniff";
Expand All @@ -61,4 +63,7 @@ int main() {
return 3;
}
return 0;
#else
return 0;
#endif
}
2 changes: 1 addition & 1 deletion examples/extensions/source/utf32_to_utf8.stmt_exprs.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
#include <string.h>

int main() {
// Check if we support the extension functions...
#if ZTD_IS_ON(ZTD_CUNEICODE_EXTENSION_FUNCTIONS)
// This only works if we support extension functions!
const ztd_char32_t input_data[] = U"Bark Bark Bark 🐕‍🦺!";
char output_data[ztdc_c_array_size(input_data) * 4] = { 0 };
cnc_mcstate_t state = { 0 };
Expand Down
53 changes: 27 additions & 26 deletions include/ztd/cuneicode/mcchar_extension.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include <ztd/idk/size.h>
#include <ztd/idk/null.h>
#include <ztd/idk/auto.h>
#include <ztd/idk/typeof.h>

#if ZTD_IS_ON(ZTD_C)
#include <stdlib.h>
Expand Down Expand Up @@ -74,10 +75,10 @@
#define cnc_cxsnrtocysn_into_with_handler( \
_TO_N, _TO, _FROM_N, _FROM, _P_STATE, _ERROR_HANDLER, _USER_DATA) \
ZTD_STMT_EXPR_BEGIN() \
typedef typeof(*(_FROM)) __from_t; \
typedef typeof(*(_TO)) __to_t; \
typedef ztd_typeof(*(_FROM)) __from_t; \
typedef ztd_typeof(*(_TO)) __to_t; \
typedef cnc_error_result(__from_t, __to_t) __result_t; \
typedef typeof(*_P_STATE) __state_t; \
typedef ztd_typeof(*_P_STATE) __state_t; \
__from_t const* const __start_from = (_FROM); \
__from_t const* __from = __start_from; \
const size_t __start_from_n = (_FROM_N); \
Expand Down Expand Up @@ -146,10 +147,10 @@
/// @param[in] _USER_DATA The user data that is passed along to the error handler.
#define cnc_cxsrtocysn_into_with_handler(_TO_N, _TO, _FROM, _P_STATE, _ERROR_HANDLER, _USER_DATA) \
ZTD_STMT_EXPR_BEGIN() \
typedef typeof(*(_FROM)) __from_t; \
typedef typeof(*(_TO)) __to_t; \
typedef ztd_typeof(*(_FROM)) __from_t; \
typedef ztd_typeof(*(_TO)) __to_t; \
typedef cnc_error_result(__from_t, __to_t) __result_t; \
typedef typeof(*_P_STATE) __state_t; \
typedef ztd_typeof(*_P_STATE) __state_t; \
__from_t const* const __start_from = (_FROM); \
__from_t const* __from = __start_from; \
const size_t __start_from_n = ztdc_c_string_ptr_size(__from); \
Expand Down Expand Up @@ -208,10 +209,10 @@
/// @param[in] _P_STATE A pointer to the state to use for this conversion.
#define cnc_cxsnrtocysn_into(_TO_N, _TO, _FROM_N, _FROM, _P_STATE) \
ZTD_STMT_EXPR_BEGIN() \
typedef typeof(*(_FROM)) __from_t; \
typedef typeof(*(_TO)) __to_t; \
typedef ztd_typeof(*(_FROM)) __from_t; \
typedef ztd_typeof(*(_TO)) __to_t; \
typedef cnc_result(__from_t, __to_t) __result_t; \
typedef typeof(*(_P_STATE)) __state_t; \
typedef ztd_typeof(*(_P_STATE)) __state_t; \
__from_t const* const __start_from = (_FROM); \
__from_t const* __from = __start_from; \
const size_t __start_from_n = (_FROM_N); \
Expand Down Expand Up @@ -250,10 +251,10 @@
/// @param[in] _P_STATE A pointer to the state to use for this conversion.
#define cnc_cxsrtocysn_into(_TO_N, _TO, _FROM, _P_STATE) \
ZTD_STMT_EXPR_BEGIN() \
typedef typeof(*(_FROM)) __from_t; \
typedef typeof(*(_TO)) __to_t; \
typedef ztd_typeof(*(_FROM)) __from_t; \
typedef ztd_typeof(*(_TO)) __to_t; \
typedef cnc_result(__from_t, __to_t) __result_t; \
typedef typeof(*(_P_STATE)) __state_t; \
typedef ztd_typeof(*(_P_STATE)) __state_t; \
__from_t const* const __start_from = (_FROM); \
__from_t const* __from = __start_from; \
const size_t __start_from_n = ztdc_c_string_ptr_size(__from); \
Expand Down Expand Up @@ -291,9 +292,9 @@
/// @param[in] _P_STATE A pointer to the state to use for this conversion.
#define cnc_cxsnrtocysn_into_is_valid(_TO_PREFIX, _FROM_N, _FROM, _P_STATE) \
ZTD_STMT_EXPR_BEGIN() \
typedef typeof(*(_FROM)) __from_t; \
typedef ztd_typeof(*(_FROM)) __from_t; \
typedef cnc_prefix_to_type(_TO_PREFIX) __to_t; \
typedef typeof(*(_P_STATE)) __state_t; \
typedef ztd_typeof(*(_P_STATE)) __state_t; \
__from_t const* const __start_from = (_FROM); \
__from_t const* __from = __start_from; \
const size_t __start_from_n = (_FROM_N); \
Expand Down Expand Up @@ -326,9 +327,9 @@
/// @param[in] _P_STATE A pointer to the state to use for this conversion.
#define cnc_cxsrtocysn_into_is_valid(_TO_PREFIX, _FROM, _P_STATE) \
ZTD_STMT_EXPR_BEGIN() \
typedef typeof(*(_FROM)) __from_t; \
typedef ztd_typeof(*(_FROM)) __from_t; \
typedef cnc_prefix_to_type(_TO_PREFIX) __to_t; \
typedef typeof(*(_P_STATE)) __state_t; \
typedef ztd_typeof(*(_P_STATE)) __state_t; \
__from_t const* const __start_from = (_FROM); \
__from_t const* __from = __start_from; \
const size_t __start_from_n = ztdc_c_string_ptr_size(__from); \
Expand Down Expand Up @@ -360,9 +361,9 @@
/// @param[in] _P_STATE A pointer to the state to use for this conversion.
#define cnc_cxsnrtocysn_into_count(_TO_PREFIX, _FROM_N, _FROM, _P_STATE) \
ZTD_STMT_EXPR_BEGIN() \
typedef typeof(*(_FROM)) __from_t; \
typedef ztd_typeof(*(_FROM)) __from_t; \
typedef cnc_prefix_to_type(_TO_PREFIX) __to_t; \
typedef typeof(*(_P_STATE)) __state_t; \
typedef ztd_typeof(*(_P_STATE)) __state_t; \
typedef cnc_count_result_t __result_t; \
__from_t const* const __start_from = (_FROM); \
__from_t const* __from = __start_from; \
Expand Down Expand Up @@ -399,9 +400,9 @@
/// @param[in] _P_STATE A pointer to the state to use for this conversion.
#define cnc_cxsrtocysn_into_count(_TO_PREFIX, _FROM, _P_STATE) \
ZTD_STMT_EXPR_BEGIN() \
typedef typeof(*(_FROM)) __from_t; \
typedef ztd_typeof(*(_FROM)) __from_t; \
typedef cnc_prefix_to_type(_TO_PREFIX) __to_t; \
typedef typeof(*(_P_STATE)) __state_t; \
typedef ztd_typeof(*(_P_STATE)) __state_t; \
typedef cnc_count_result_t __result_t; \
__from_t const* const __start_from = (_FROM); \
__from_t const* __from = __start_from; \
Expand Down Expand Up @@ -436,10 +437,10 @@
/// @param[in] _P_STATE A pointer to the state to use for this conversion.
#define cnc_cxsnrtocys_into_unbounded(_TO, _FROM_N, _FROM, _P_STATE) \
ZTD_STMT_EXPR_BEGIN() \
typedef typeof(*(_FROM)) __from_t; \
typedef typeof(*(_TO)) __to_t; \
typedef ztd_typeof(*(_FROM)) __from_t; \
typedef ztd_typeof(*(_TO)) __to_t; \
typedef cnc_result(__from_t, __to_t) __result_t; \
typedef typeof(*(_P_STATE)) __state_t; \
typedef ztd_typeof(*(_P_STATE)) __state_t; \
__from_t const* const __start_from = (_FROM); \
__from_t const* __from = __start_from; \
const size_t __start_from_n = (_FROM_N); \
Expand Down Expand Up @@ -479,10 +480,10 @@
/// @param[in] _P_STATE A pointer to the state to use for this conversion.
#define cnc_cxsrtocys_into_unbounded(_TO, _FROM, _P_STATE) \
ZTD_STMT_EXPR_BEGIN() \
typedef typeof(*(_FROM)) __from_t; \
typedef typeof(*(_TO)) __to_t; \
typedef ztd_typeof(*(_FROM)) __from_t; \
typedef ztd_typeof(*(_TO)) __to_t; \
typedef cnc_result(__from_t, __to_t) __result_t; \
typedef typeof(*(_P_STATE)) __state_t; \
typedef ztd_typeof(*(_P_STATE)) __state_t; \
__from_t const* const __start_from = (_FROM); \
__from_t const* __from = __start_from; \
const size_t __start_from_n = ztdc_c_string_ptr_size(__from); \
Expand Down
Loading

0 comments on commit 7275b99

Please sign in to comment.