MCPcopy Create free account
hub / github.com/CppCXY/EmmyLuaCodeStyle / mi_option_init

Function mi_option_init

3rd/mimalloc-2.0.9/src/options.c:575–642  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

573#endif // !MI_NO_GETENV
574
575static void mi_option_init(mi_option_desc_t* desc) {
576 // Read option value from the environment
577 char s[64+1];
578 char buf[64+1];
579 mi_strlcpy(buf, "mimalloc_", sizeof(buf));
580 mi_strlcat(buf, desc->name, sizeof(buf));
581 bool found = mi_getenv(buf,s,sizeof(s));
582 if (!found && desc->legacy_name != NULL) {
583 mi_strlcpy(buf, "mimalloc_", sizeof(buf));
584 mi_strlcat(buf, desc->legacy_name, sizeof(buf));
585 found = mi_getenv(buf,s,sizeof(s));
586 if (found) {
587 _mi_warning_message("environment option \"mimalloc_%s\" is deprecated -- use \"mimalloc_%s\" instead.\n", desc->legacy_name, desc->name );
588 }
589 }
590
591 if (found) {
592 size_t len = strlen(s);
593 if (len >= sizeof(buf)) len = sizeof(buf) - 1;
594 for (size_t i = 0; i < len; i++) {
595 buf[i] = (char)toupper(s[i]);
596 }
597 buf[len] = 0;
598 if (buf[0]==0 || strstr("1;TRUE;YES;ON", buf) != NULL) {
599 desc->value = 1;
600 desc->init = INITIALIZED;
601 }
602 else if (strstr("0;FALSE;NO;OFF", buf) != NULL) {
603 desc->value = 0;
604 desc->init = INITIALIZED;
605 }
606 else {
607 char* end = buf;
608 long value = strtol(buf, &end, 10);
609 if (desc->option == mi_option_reserve_os_memory) {
610 // this option is interpreted in KiB to prevent overflow of `long`
611 if (*end == 'K') { end++; }
612 else if (*end == 'M') { value *= MI_KiB; end++; }
613 else if (*end == 'G') { value *= MI_MiB; end++; }
614 else { value = (value + MI_KiB - 1) / MI_KiB; }
615 if (end[0] == 'I' && end[1] == 'B') { end += 2; }
616 else if (*end == 'B') { end++; }
617 }
618 if (*end == 0) {
619 desc->value = value;
620 desc->init = INITIALIZED;
621 }
622 else {
623 // set `init` first to avoid recursion through _mi_warning_message on mimalloc_verbose.
624 desc->init = DEFAULTED;
625 if (desc->option == mi_option_verbose && desc->value == 0) {
626 // if the 'mimalloc_verbose' env var has a bogus value we'd never know
627 // (since the value defaults to 'off') so in that case briefly enable verbose
628 desc->value = 1;
629 _mi_warning_message("environment option mimalloc_%s has an invalid value.\n", desc->name );
630 desc->value = 0;
631 }
632 else {

Callers 1

mi_option_getFunction · 0.85

Calls 5

mi_strlcpyFunction · 0.85
mi_strlcatFunction · 0.85
mi_getenvFunction · 0.85
_mi_warning_messageFunction · 0.85
_mi_preloadingFunction · 0.85

Tested by

no test coverage detected