Commit 636ac4de

636ac4de0853Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 7 files · +4 added · ~3 modified

Description

codegen,runtime: RUBY_VERSION/PLATFORM/ENGINE + Process.pid/ppid

Four built-in identifiers that used to fall through to warn_unresolved_const / warn_unresolved_call (emitting 0):

RUBY_VERSION -> "4.0.0" (string literal) RUBY_ENGINE -> "spinel" RUBY_PLATFORM -> sp_ruby_platform_str() -- detected at C compile time from x86_64/aarch64/linux/etc. macros so cross-builds report the target. Process.pid -> getpid() (unistd.h already included) Process.ppid -> getppid()

Refs #890 #893

Co-Authored-By: Claude Opus 4.7 [email protected]

Details

Commit
636ac4de0853
Parent
d55c86b47ed4

lib/sp_runtime.hmodifiedView file

@@ -362,6 +362,33 @@
362362 static const char sp_str_empty_data[] = "\xff";
363363 #define sp_str_empty (sp_str_empty_data + 1)
364364
365+/* RUBY_PLATFORM string -- host arch + OS. Detected at C compile time
366+ so cross-builds report the target platform. Issue #890. */
367+#if defined(__x86_64__) || defined(_M_X64)
368+# define SP_RUBY_ARCH "x86_64"
369+#elif defined(__aarch64__) || defined(_M_ARM64)
370+# define SP_RUBY_ARCH "aarch64"
371+#elif defined(__i386__) || defined(_M_IX86)
372+# define SP_RUBY_ARCH "i686"
373+#elif defined(__arm__)
374+# define SP_RUBY_ARCH "arm"
375+#else
376+# define SP_RUBY_ARCH "unknown"
377+#endif
378+#if defined(__linux__)
379+# define SP_RUBY_OS "linux"
380+#elif defined(__APPLE__)
381+# define SP_RUBY_OS "darwin"
382+#elif defined(_WIN32) || defined(_WIN64)
383+# define SP_RUBY_OS "mingw32"
384+#elif defined(__FreeBSD__)
385+# define SP_RUBY_OS "freebsd"
386+#else
387+# define SP_RUBY_OS "unknown"
388+#endif
389+static const char sp_ruby_platform_data[] = "\xff" SP_RUBY_ARCH "-" SP_RUBY_OS;
390+static inline const char *sp_ruby_platform_str(void) { return sp_ruby_platform_data + 1; }
391+
365392 static void sp_oom_die(void);
366393 static char *sp_str_alloc(size_t len) {
367394 size_t total = sizeof(sp_str_hdr) + 1 + len + 1;