Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/compat2/probes/IR_HASHES.json
Original file line number Diff line number Diff line change
Expand Up @@ -12964,7 +12964,7 @@
"stdlib.unicodedata.east_asian_width": "6ec948e62c433a9ddc05d7bef77a2ba3edf8b7c6c0009aef466040c102f89907",
"stdlib.unicodedata.is_normalized": "fee9b71a96e634c7983077889f248575c03dd27d0ee45d8a95470980960267fe",
"stdlib.unicodedata.lookup": "256b21d78885c2054e0b6db8f39a2094b93c4d88d9a5c478a5312e6a2ee63e5f",
"stdlib.unicodedata.mirrored": "ec2686bf4a1d417adfeff566c72b3d285d5f54aefc6c14102786b19268837e93",
"stdlib.unicodedata.mirrored": "5f5c5472d9aa0a53bbd092a30933bf7fb1e68c350540e08021d253dfde338307",
"stdlib.unicodedata.name": "9cc866afaae198cc2e2d2e80cf0f371f7d7126709638fa79fe38327f50fbbc4d",
"stdlib.unicodedata.normalize": "032eae258b7e27c3f1490f7aace0b5185d4b1a0e0cd600234ada0dc2e38841b2",
"stdlib.unicodedata.numeric": "cd61fbee1099b191303e15d491567cc71f28d298886da9b64ec3792c4865f7df",
Expand Down
41 changes: 37 additions & 4 deletions src/pyscriptc/runtime/ps_osmore.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ are not searched. as_file of one of these paths is the path itself.
#include <sys/utsname.h>
#endif

#if defined(__linux__) && defined(__GLIBC__)
#include <gnu/libc-version.h>
#endif

#ifdef __APPLE__
#include <copyfile.h>
#include <sys/sysctl.h>
#endif

#ifdef __linux__
Expand Down Expand Up @@ -103,10 +108,10 @@ static int ps_temp_ready = 0;
static pthread_mutex_t ps_temp_lock = PTHREAD_MUTEX_INITIALIZER;

/* CPython runs every tempdir candidate through os.path.abspath before it
tests it, and abspath normalizes: a trailing slash goes away and a relative
path is joined to the cwd. macOS launchd sets TMPDIR with a trailing slash
(".../T/"), so returning the raw value would not match CPython's gettempdir.
ps_path_abs is the same normalization the posixpath surface uses. */
tests it, and abspath normalizes: a trailing slash goes away and a relative
path is joined to the cwd. macOS launchd sets TMPDIR with a trailing slash
(".../T/"), so returning the raw value would not match CPython's gettempdir.
ps_path_abs is the same normalization the posixpath surface uses. */
static void ps_temp_abspath(const char *dir, char *out, size_t cap) {
PsBuf abs;
ps_path_abs((int64_t)strlen(dir), dir, &abs);
Expand Down Expand Up @@ -944,9 +949,37 @@ void ps_platform_python_version(PsBuf *out) {
ps_buf_copy(out, "3.14.9", 6);
}

/* CPython 3.14 shapes: macOS is "macOS-<release>-<machine>-<processor>-
<bits>-Mach-O"; glibc Linux appends "-with-glibc<version>". Other targets
keep the plain uname triple. */
void ps_platform_platform(PsBuf *out) {
#if defined(_WIN32)
ps_buf_copy(out, "Windows", 7);
#elif defined(__APPLE__)
struct utsname u;
if (uname(&u) == 0) {
char buf[256];
char product[64];
size_t plen = sizeof(product);
/* CPython reports the product version (mac_ver), not the Darwin
release, and "arm" or "i386" for the processor. */
const char *release = sysctlbyname("kern.osproductversion", product, &plen, NULL, 0) == 0 ? product : u.release;
const char *processor = strcmp(u.machine, "arm64") == 0 ? "arm" : (strcmp(u.machine, "x86_64") == 0 ? "i386" : u.machine);
const char *bits = sizeof(void *) == 8 ? "64bit" : "32bit";
snprintf(buf, sizeof(buf), "macOS-%s-%s-%s-%s-Mach-O", release, u.machine, processor, bits);
ps_buf_copy(out, buf, (int64_t)strlen(buf));
} else {
ps_buf_copy(out, "", 0);
}
#elif defined(__linux__) && defined(__GLIBC__)
struct utsname u;
if (uname(&u) == 0) {
char buf[256];
snprintf(buf, sizeof(buf), "%s-%s-%s-with-glibc%s", u.sysname, u.release, u.machine, gnu_get_libc_version());
ps_buf_copy(out, buf, (int64_t)strlen(buf));
} else {
ps_buf_copy(out, "", 0);
}
#else
struct utsname u;
if (uname(&u) == 0) {
Expand Down
3 changes: 1 addition & 2 deletions tests/test_stdlib_call_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
# a real difference from CPython 3.14 tracked as an issue; the entry is what
# makes the batch an xfail instead of a failure, and it must be removed when
# the row is fixed (the batch then passes on its own).
PLATFORM_DIVERGENCE = "issue #713 (platform.platform output)"
REALPATH_DIVERGENCE = "issue #714 (os.path.realpath on a missing target)"


Expand Down Expand Up @@ -390,7 +389,7 @@ def _p(module: str, member: str, group: str, *lines: str, divergence: str | None
"host",
"print(platform.python_version().startswith('3.14.'))",
),
_p("platform", "platform", "host", "print(platform.platform())", divergence=PLATFORM_DIVERGENCE),
_p("platform", "platform", "host", "print(platform.platform())"),
_p("sys", "stdout.write", "host", "print(sys.stdout.write('dt') == 2)"),
_p("sys", "stderr.write", "host", "print(sys.stderr.write('dt') == 2)"),
_p("socket", "gethostname", "host", "print(len(socket.gethostname()) > 0)"),
Expand Down
Loading