diff options
author | Takashi Kokubun <[email protected]> | 2022-10-17 10:45:59 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2022-10-17 10:45:59 -0700 |
commit | 64c52c428285e7930aed62740cc9c54ee483178e (patch) | |
tree | 818515b6cc1909e98cdcdca93f0a3ac3b2b8cd5a /yjit/src/utils.rs | |
parent | e7c71c6c9271b0c29f210769159090e17128e740 (diff) |
YJIT: Interleave inline and outlined code blocks (#6460)
Co-authored-by: Alan Wu <[email protected]>
Co-authored-by: Maxime Chevalier-Boisvert <[email protected]>
Notes
Notes:
Merged-By: k0kubun <[email protected]>
Diffstat (limited to 'yjit/src/utils.rs')
-rw-r--r-- | yjit/src/utils.rs | 9 |
1 files changed, 4 insertions, 5 deletions
diff --git a/yjit/src/utils.rs b/yjit/src/utils.rs index cabebb7dcc..b156c9d5ed 100644 --- a/yjit/src/utils.rs +++ b/yjit/src/utils.rs @@ -74,14 +74,13 @@ pub(crate) use offset_of; // This should work fine on ASCII strings and anything else // that is considered legal UTF-8, including embedded nulls. fn ruby_str_to_rust(v: VALUE) -> String { - // Make sure the CRuby encoding is UTF-8 compatible - let encoding = unsafe { rb_ENCODING_GET(v) } as u32; - assert!(encoding == RUBY_ENCINDEX_ASCII_8BIT || encoding == RUBY_ENCINDEX_UTF_8 || encoding == RUBY_ENCINDEX_US_ASCII); - let str_ptr = unsafe { rb_RSTRING_PTR(v) } as *mut u8; let str_len: usize = unsafe { rb_RSTRING_LEN(v) }.try_into().unwrap(); let str_slice: &[u8] = unsafe { slice::from_raw_parts(str_ptr, str_len) }; - String::from_utf8(str_slice.to_vec()).unwrap() // does utf8 validation + match String::from_utf8(str_slice.to_vec()) { + Ok(utf8) => utf8, + Err(_) => String::new(), + } } // Location is the file defining the method, colon, method name. |