summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2025-10-19 15:11:39 -0400
committerAlan Wu <XrXr@users.noreply.github.com>2025-10-21 16:48:45 -0400
commit35c2230734e65e8ab55aa718ca6ea02ca9622984 (patch)
treeffb88afff2f7bb787d467d571aa0163a48fbc988
parent193b299b8d1b09de9de695f6fd88314ccfbf884b (diff)
ZJIT: Fix binding to `INVALID_SHAPE_ID` under `-std=c99 -pedantic`
``` /src/jit.c:19:5: error: ISO C restricts enumerator values to range of 'int' (4294967295 is too large) [-Werror,-Wpedantic] 19 | RB_INVALID_SHAPE_ID = INVALID_SHAPE_ID, | ^ ~~~~~~~~~~~~~~~~ ```
-rw-r--r--jit.c5
-rw-r--r--zjit.c4
-rw-r--r--zjit/bindgen/src/main.rs2
-rw-r--r--zjit/src/cruby.rs2
-rw-r--r--zjit/src/cruby_bindings.inc.rs3
5 files changed, 8 insertions, 8 deletions
diff --git a/jit.c b/jit.c
index b7cb05d1c3..db3fe097ef 100644
--- a/jit.c
+++ b/jit.c
@@ -22,6 +22,11 @@ enum robject_offsets {
ROBJECT_OFFSET_AS_ARY = offsetof(struct RObject, as.ary),
};
+// Manually bound in rust since this is out-of-range of `int`,
+// so this can't be in a `enum`, and we avoid `static const`
+// to avoid allocating storage for the constant.
+const shape_id_t rb_invalid_shape_id = INVALID_SHAPE_ID;
+
unsigned int
rb_iseq_encoded_size(const rb_iseq_t *iseq)
{
diff --git a/zjit.c b/zjit.c
index e17abc1b37..fac087a605 100644
--- a/zjit.c
+++ b/zjit.c
@@ -235,10 +235,6 @@ rb_zjit_print_exception(void)
rb_warn("Ruby error: %"PRIsVALUE"", rb_funcall(exception, rb_intern("full_message"), 0));
}
-enum zjit_exported_constants {
- RB_INVALID_SHAPE_ID = INVALID_SHAPE_ID,
-};
-
bool
rb_zjit_singleton_class_p(VALUE klass)
{
diff --git a/zjit/bindgen/src/main.rs b/zjit/bindgen/src/main.rs
index f13b61acf0..60dcb7a69c 100644
--- a/zjit/bindgen/src/main.rs
+++ b/zjit/bindgen/src/main.rs
@@ -100,6 +100,7 @@ fn main() {
.allowlist_function("rb_shape_id_offset")
.allowlist_function("rb_shape_get_iv_index")
.allowlist_function("rb_shape_transition_add_ivar_no_warnings")
+ .allowlist_var("rb_invalid_shape_id")
.allowlist_var("SHAPE_ID_NUM_BITS")
.allowlist_function("rb_obj_is_kind_of")
.allowlist_function("rb_obj_frozen_p")
@@ -295,7 +296,6 @@ fn main() {
.allowlist_function("rb_zjit_insn_leaf")
.allowlist_type("robject_offsets")
.allowlist_type("rstring_offsets")
- .allowlist_type("zjit_exported_constants")
.allowlist_function("rb_assert_holding_vm_lock")
.allowlist_function("rb_jit_shape_too_complex_p")
.allowlist_function("rb_jit_multi_ractor_p")
diff --git a/zjit/src/cruby.rs b/zjit/src/cruby.rs
index a84e408861..09a221b502 100644
--- a/zjit/src/cruby.rs
+++ b/zjit/src/cruby.rs
@@ -273,7 +273,7 @@ pub type IseqPtr = *const rb_iseq_t;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub struct ShapeId(pub u32);
-pub const INVALID_SHAPE_ID: ShapeId = ShapeId(RB_INVALID_SHAPE_ID);
+pub const INVALID_SHAPE_ID: ShapeId = ShapeId(rb_invalid_shape_id);
impl ShapeId {
pub fn is_valid(self) -> bool {
diff --git a/zjit/src/cruby_bindings.inc.rs b/zjit/src/cruby_bindings.inc.rs
index af604661b2..6f2ad37d3b 100644
--- a/zjit/src/cruby_bindings.inc.rs
+++ b/zjit/src/cruby_bindings.inc.rs
@@ -730,11 +730,10 @@ pub const DEFINED_REF: defined_type = 15;
pub const DEFINED_FUNC: defined_type = 16;
pub const DEFINED_CONST_FROM: defined_type = 17;
pub type defined_type = u32;
-pub const RB_INVALID_SHAPE_ID: zjit_exported_constants = 4294967295;
-pub type zjit_exported_constants = u32;
pub const ROBJECT_OFFSET_AS_HEAP_FIELDS: robject_offsets = 16;
pub const ROBJECT_OFFSET_AS_ARY: robject_offsets = 16;
pub type robject_offsets = u32;
+pub const rb_invalid_shape_id: shape_id_t = 4294967295;
pub type rb_iseq_param_keyword_struct = rb_iseq_constant_body__bindgen_ty_1_rb_iseq_param_keyword;
unsafe extern "C" {
pub fn ruby_xfree(ptr: *mut ::std::os::raw::c_void);