Skip to content

Commit 29fdb73

Browse files
kateinoigakukunmatzbot
authored andcommitted
[ruby/digest] Fix loading of digest ext libraries with --with-static-linked-ext
`rb_ext_resolve_symbol` is not always available on some platforms including WASI, and we don't need to use it when the extension is built as a static library. This commit prefers to use `rb_digest_wrap_metadata` directly when the extension is built as a static library to avoid the unnecessary use of `rb_ext_resolve_symbol`. ruby/digest@f8ff014622
1 parent 57daed5 commit 29fdb73

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

ext/digest/digest.h

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,17 @@ rb_id_metadata(void)
7676
static inline VALUE
7777
rb_digest_make_metadata(const rb_digest_metadata_t *meta)
7878
{
79-
#ifdef DIGEST_USE_RB_EXT_RESOLVE_SYMBOL
79+
#if EXTSTATIC
80+
// The extension is built as a static library, so safe to refer to
81+
// rb_digest_wrap_metadata directly.
82+
extern VALUE rb_digest_wrap_metadata(const rb_digest_metadata_t *meta);
83+
return rb_digest_wrap_metadata(meta);
84+
#else
85+
// The extension is built as a shared library, so we can't refer to
86+
// rb_digest_wrap_metadata directly.
87+
# ifdef DIGEST_USE_RB_EXT_RESOLVE_SYMBOL
88+
// If rb_ext_resolve_symbol() is available, use it to get the address of
89+
// rb_digest_wrap_metadata.
8090
typedef VALUE (*wrapper_func_type)(const rb_digest_metadata_t *meta);
8191
static wrapper_func_type wrapper;
8292
if (!wrapper) {
@@ -85,9 +95,11 @@ rb_digest_make_metadata(const rb_digest_metadata_t *meta)
8595
if (!wrapper) rb_raise(rb_eLoadError, "rb_digest_wrap_metadata not found");
8696
}
8797
return wrapper(meta);
88-
#else
89-
#undef RUBY_UNTYPED_DATA_WARNING
90-
#define RUBY_UNTYPED_DATA_WARNING 0
98+
# else
99+
// If rb_ext_resolve_symbol() is not available, keep using untyped data.
100+
# undef RUBY_UNTYPED_DATA_WARNING
101+
# define RUBY_UNTYPED_DATA_WARNING 0
91102
return rb_obj_freeze(Data_Wrap_Struct(0, 0, 0, (void *)meta));
103+
# endif
92104
#endif
93105
}

0 commit comments

Comments
 (0)