Skip to content

Commit 681b2f1

Browse files
runtime: fix issues with nr_cpus() (#26679)
* Statically link Macport legacy library * Handle error with sysconf() in nr_cpus * Fix formatting issue with runtime.c.v
1 parent 1a9d762 commit 681b2f1

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

GNUmakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ LDFLAGS += -lMacportsLegacySupport
4747
VFLAGS += -cc $(CC)
4848
VFLAGS += -cflags "$(CFLAGS)"
4949
VFLAGS += -ldflags -L$(LEGACYLIBS)/lib
50-
VFLAGS += -ldflags -lMacportsLegacySupport
50+
VFLAGS += -cflags $(LEGACYLIBS)/lib/libMacportsLegacySupport.a
5151
endif
5252
endif
5353

vlib/runtime/runtime_nix.c.v

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ fn C.sysconf(name i32) i64
44

55
// nr_cpus returns the number of virtual CPU cores found on the system.
66
pub fn nr_cpus() int {
7-
return int(C.sysconf(C._SC_NPROCESSORS_ONLN))
7+
mut cpus := int(C.sysconf(C._SC_NPROCESSORS_ONLN))
8+
if cpus < 1 {
9+
eprintln('Warning: sysconf(_SC_NPROCESSORS_ONLN) returned -1, returning CPU count as 1')
10+
cpus = 1
11+
}
12+
return cpus
813
}
914

1015
// total_memory returns total physical memory found on the system.

0 commit comments

Comments
 (0)