|
1 | | -/* nob - v3.8.1 - Public Domain - https://github.com/tsoding/nob.h |
| 1 | +/* nob - v3.8.2 - Public Domain - https://github.com/tsoding/nob.h |
2 | 2 |
|
3 | 3 | This library is the next generation of the [NoBuild](https://github.com/tsoding/nobuild) idea. |
4 | 4 |
|
@@ -660,9 +660,19 @@ NOBDEF void nob_cmd_render(Nob_Cmd cmd, Nob_String_Builder *render); |
660 | 660 | #define NOB_CLIT(type) (type) |
661 | 661 | #endif |
662 | 662 |
|
663 | | -NOBDEF void nob__cmd_append(Nob_Cmd *cmd, ...); |
664 | | -#define nob_cmd_append(cmd, ...) \ |
665 | | - nob__cmd_append(cmd, __VA_ARGS__, (const char*)-1) |
| 663 | +NOBDEF void nob__cmd_append(Nob_Cmd *cmd, size_t n, const char **args); |
| 664 | +#if defined(__cplusplus) |
| 665 | + template <typename... Args> |
| 666 | + static inline void nob__cpp_cmd_append_wrapper(Nob_Cmd *cmd, Args... strs) |
| 667 | + { |
| 668 | + const char* args[] = { strs... }; |
| 669 | + nob__cmd_append(cmd, sizeof(args)/sizeof(args[0]), args); |
| 670 | + } |
| 671 | + #define nob_cmd_append(cmd, ...) nob__cpp_cmd_append_wrapper(cmd, __VA_ARGS__) |
| 672 | +#else |
| 673 | + #define nob_cmd_append(cmd, ...) \ |
| 674 | + nob__cmd_append(cmd, sizeof((const char*[]){__VA_ARGS__})/sizeof(const char*), (const char*[]){__VA_ARGS__}) |
| 675 | +#endif // __cplusplus |
666 | 676 |
|
667 | 677 | // TODO: nob_cmd_extend() evaluates other_cmd twice |
668 | 678 | // It can be fixed by turning nob_cmd_extend() call into a statement. |
@@ -959,16 +969,11 @@ static Nob_Proc nob__cmd_start_process(Nob_Cmd cmd, Nob_Fd *fdin, Nob_Fd *fdout, |
959 | 969 | // Any messages with the level below nob_minimal_log_level are going to be suppressed. |
960 | 970 | Nob_Log_Level nob_minimal_log_level = NOB_INFO; |
961 | 971 |
|
962 | | -NOBDEF void nob__cmd_append(Nob_Cmd *cmd, ...) |
| 972 | +NOBDEF void nob__cmd_append(Nob_Cmd *cmd, size_t n, const char **args) |
963 | 973 | { |
964 | | - va_list args; |
965 | | - va_start(args, cmd); |
966 | | - for (;;) { |
967 | | - const char *arg = va_arg(args, const char *); |
968 | | - if (arg == (const char*)-1) break; |
969 | | - nob_da_append(cmd, arg); |
| 974 | + for (size_t i = 0; i < n; ++i) { |
| 975 | + nob_da_append(cmd, args[i]); |
970 | 976 | } |
971 | | - va_end(args); |
972 | 977 | } |
973 | 978 |
|
974 | 979 | #ifdef _WIN32 |
@@ -1529,7 +1534,7 @@ static Nob_Proc nob__cmd_start_process(Nob_Cmd cmd, Nob_Fd *fdin, Nob_Fd *fdout, |
1529 | 1534 | // But do we actually care? It's a one off leak anyway... |
1530 | 1535 | Nob_Cmd cmd_null = {0}; |
1531 | 1536 | nob_da_append_many(&cmd_null, cmd.items, cmd.count); |
1532 | | - nob_cmd_append(&cmd_null, NULL); |
| 1537 | + nob_cmd_append(&cmd_null, (const char*)NULL); |
1533 | 1538 |
|
1534 | 1539 | if (execvp(cmd.items[0], (char * const*) cmd_null.items) < 0) { |
1535 | 1540 | nob_log(NOB_ERROR, "Could not exec child process for %s: %s", cmd.items[0], strerror(errno)); |
@@ -3023,6 +3028,7 @@ NOBDEF char *nob_temp_running_executable_path(void) |
3023 | 3028 | /* |
3024 | 3029 | Revision history: |
3025 | 3030 |
|
| 3031 | + 3.8.2 (2026-04-01) Fix the broken type safety of nob_cmd_append() (by @aalmkainzi) |
3026 | 3032 | 3.8.1 (2026-04-01) Fix annoying clang warning |
3027 | 3033 | 3.8.0 (2026-03-24) Add NOB_CLIT() |
3028 | 3034 | Fix compliation on MSVC with /TP |
|
0 commit comments