void ruby_set_debug_option(const char *str) { const char *end; int len; if (!str) return; for (; *str; str = end) { while (ISSPACE(*str) || *str == ',') str++; if (!*str) break; end = str; while (*end && !ISSPACE(*end) && *end != ',') end++; len = end - str; #define SET_WHEN(name, var) \ if (len == sizeof(name) - 1 && \ strncmp(str, name, len) == 0) { \ extern int ruby_##var; \ ruby_##var = 1; \ continue; \ } SET_WHEN("gc_stress", gc_stress); SET_WHEN("core", enable_coredump); fprintf(stderr, "unexpected debug option: %.*s\n", len, str); } }
static void set_debug_option(const char *str, int len, void *arg) { #define SET_WHEN(name, var) do { \ if (len == sizeof(name) - 1 && \ strncmp(str, name, len) == 0) { \ extern int var; \ var = 1; \ return; \ } \ } while (0) SET_WHEN("gc_stress", *ruby_initial_gc_stress_ptr); SET_WHEN("core", ruby_enable_coredump); fprintf(stderr, "unexpected debug option: %.*s\n", len, str); }