summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Zhu <[email protected]>2024-10-10 11:09:53 -0400
committerPeter Zhu <[email protected]>2024-10-11 08:56:36 -0400
commitd641b7d172a715b4407218de250d93e6a2f5e158 (patch)
tree9dcfc8b23fde776b58ce620e8bda9185f30062dd
parent047a7750d1064c9d13811f3498325f4d2101b681 (diff)
Improve RUBY_GC_LIBRARY
Instead of passing the full GC SO file name to RUBY_GC_LIBRARY, we now only need to pass the GC name. For example, before we needed to pass `RUBY_GC_LIBRARY=librubygc.default.so` but now we only need to pass `RUBY_GC_LIBRARY=default`.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11866
-rw-r--r--.github/workflows/ubuntu.yml2
-rw-r--r--configure.ac2
-rw-r--r--gc.c22
3 files changed, 19 insertions, 7 deletions
diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml
index 750944e754..7587762d8c 100644
--- a/.github/workflows/ubuntu.yml
+++ b/.github/workflows/ubuntu.yml
@@ -99,7 +99,7 @@ jobs:
- name: Build shared GC
run: |
- echo "RUBY_GC_LIBRARY=librubygc.default.so" >> $GITHUB_ENV
+ echo "RUBY_GC_LIBRARY=default" >> $GITHUB_ENV
make shared-gc SHARED_GC=default
if: ${{ matrix.shared_gc }}
diff --git a/configure.ac b/configure.ac
index ca578f8e9f..21fa34e307 100644
--- a/configure.ac
+++ b/configure.ac
@@ -3403,6 +3403,8 @@ AC_DEFINE_UNQUOTED(DLEXT_MAXLEN, `expr $len + 1`)
test ".$DLEXT" = "." || AC_DEFINE_UNQUOTED(DLEXT, ".$DLEXT")
AC_SUBST(DLEXT)
+AC_DEFINE_UNQUOTED(SOEXT, ".$SOEXT")
+
: "strip" && {
AC_MSG_CHECKING([for $STRIP flags])
AC_LINK_IFELSE([AC_LANG_PROGRAM], [AS_IF(
diff --git a/gc.c b/gc.c
index 7b6decf3d2..c2889a78c2 100644
--- a/gc.c
+++ b/gc.c
@@ -659,7 +659,7 @@ ruby_external_gc_init(void)
char *gc_so_path = NULL;
void *handle = NULL;
if (gc_so_file) {
- /* Check to make sure that gc_so_file matches /[\w-_.]+/ so that it does
+ /* Check to make sure that gc_so_file matches /[\w-_]+/ so that it does
* not load a shared object outside of the directory. */
for (size_t i = 0; i < strlen(gc_so_file); i++) {
char c = gc_so_file[i];
@@ -667,17 +667,27 @@ ruby_external_gc_init(void)
switch (c) {
case '-':
case '_':
- case '.':
break;
default:
- fprintf(stderr, "Only alphanumeric, dash, underscore, and period is allowed in "RUBY_GC_LIBRARY"\n");
+ fprintf(stderr, "Only alphanumeric, dash, and underscore is allowed in "RUBY_GC_LIBRARY"\n");
exit(1);
}
}
- gc_so_path = alloca(strlen(SHARED_GC_DIR) + strlen(gc_so_file) + 1);
- strcpy(gc_so_path, SHARED_GC_DIR);
- strcpy(gc_so_path + strlen(SHARED_GC_DIR), gc_so_file);
+ size_t gc_so_path_size = strlen(SHARED_GC_DIR "librubygc." SOEXT) + strlen(gc_so_file) + 1;
+ gc_so_path = alloca(gc_so_path_size);
+ {
+ size_t gc_so_path_idx = 0;
+#define GC_SO_PATH_APPEND(str) do { \
+ gc_so_path_idx += strlcpy(gc_so_path + gc_so_path_idx, str, gc_so_path_size - gc_so_path_idx); \
+} while (0)
+ GC_SO_PATH_APPEND(SHARED_GC_DIR);
+ GC_SO_PATH_APPEND("librubygc.");
+ GC_SO_PATH_APPEND(gc_so_file);
+ GC_SO_PATH_APPEND(SOEXT);
+ GC_ASSERT(gc_so_path_idx == gc_so_path_size - 1);
+#undef GC_SO_PATH_APPEND
+ }
handle = dlopen(gc_so_path, RTLD_LAZY | RTLD_GLOBAL);
if (!handle) {