Skip to content

Commit 16d2560

Browse files
authored
Define RUBY_DEBUG macro if undefined (#532)
* Define RUBY_DEBUG macro if undefined Add a check and default definition for RUBY_DEBUG to ensure compatibility when RUBY_DEBUG is not already defined. * Fix TYPED_DATA_EMBEDDED flag for 32/64-bit targets Ensure correct flag type is used for pointer width, preventing mismatched types on 32-bit and 64-bit architectures. * Refine ruby debug and assert header inclusion Replace RUBY_DEBUG guard with HAVE_RUBY_ASSERT_H, include ruby/assert.h when available, and remove manual RUBY_DEBUG definition. * Update Docker workflow and fix RUBY_DEBUG reference - Trigger Docker workflow on docker branches - Fix RUBY_DEBUG path in debug_ruby_assert_type macro * Move ruby/assert.h include after other headers Relocate ruby/assert.h inclusion to the end and add RUBY_DEBUG fallback if not present. Ensures correct header order and macro definition. * Remove ruby/assert.h include and update debug macro Remove conditional inclusion of ruby/assert.h from wrapper.h. Update debug_ruby_assert_type! macro to use cfg(ruby_ruby_debug). * Prevent unused variable warnings in debug macro Add code to use macro arguments when debug is disabled to avoid compiler warnings.
1 parent 68b04c9 commit 16d2560

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

.github/workflows/docker.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66
push:
77
branches:
88
- main
9+
- "*docker*"
910
tags:
1011
- v*
1112

crates/rb-sys/src/stable_api/ruby_3_3.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,8 +292,12 @@ impl StableApiDefinition for Definition {
292292

293293
let rdata = obj as *const crate::internal::RTypedData;
294294
let typed_flag = (*rdata).typed_flag;
295-
// TYPED_DATA_EMBEDDED (2) flag indicates embedded data
296-
(typed_flag & (crate::TYPED_DATA_EMBEDDED as u64)) != 0
295+
#[cfg(target_pointer_width = "64")]
296+
const FLAG: u64 = crate::TYPED_DATA_EMBEDDED as u64;
297+
#[cfg(target_pointer_width = "32")]
298+
const FLAG: u32 = crate::TYPED_DATA_EMBEDDED as u32;
299+
300+
(typed_flag & FLAG) != 0
297301
}
298302

299303
#[inline]

crates/rb-sys/src/stable_api/ruby_3_4.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::{
33
debug_ruby_assert_type,
44
internal::{RArray, RString, RTypedData},
55
ruby_value_type::RUBY_T_DATA,
6-
value_type, TYPED_DATA_EMBEDDED, VALUE,
6+
value_type, VALUE,
77
};
88
use std::{
99
ffi::c_void,
@@ -293,8 +293,12 @@ impl StableApiDefinition for Definition {
293293

294294
let rdata = obj as *const RTypedData;
295295
let typed_flag = (*rdata).typed_flag;
296-
// TYPED_DATA_EMBEDDED (2) flag indicates embedded data
297-
(typed_flag & (TYPED_DATA_EMBEDDED as u64)) != 0
296+
#[cfg(target_pointer_width = "64")]
297+
const FLAG: u64 = crate::TYPED_DATA_EMBEDDED as u64;
298+
#[cfg(target_pointer_width = "32")]
299+
const FLAG: u32 = crate::TYPED_DATA_EMBEDDED as u32;
300+
301+
(typed_flag & FLAG) != 0
298302
}
299303

300304
#[inline]

crates/rb-sys/src/utils.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ pub(crate) unsafe fn is_ruby_vm_started() -> bool {
4343
#[macro_export]
4444
macro_rules! debug_ruby_assert_type {
4545
($obj:expr, $type:expr, $message:expr) => {
46-
if $crate::RUBY_DEBUG != 0 {
46+
#[cfg(ruby_ruby_debug = "true")]
47+
{
4748
#[allow(clippy::macro_metavars_in_unsafe)]
4849
unsafe {
4950
assert!(
@@ -52,6 +53,10 @@ macro_rules! debug_ruby_assert_type {
5253
);
5354
}
5455
}
56+
#[cfg(not(ruby_ruby_debug = "true"))]
57+
{
58+
let _ = ($obj, $type, $message); // Prevent unused variable warnings
59+
}
5560
};
5661
}
5762

0 commit comments

Comments
 (0)