Skip to content

Commit b732d58

Browse files
sei40krclaude
andcommitted
fix: use manual FFI declarations for pm_line_column_t and pm_newline_list_line_column
Bindgen cannot generate bindings for these symbols on the WASM target, causing CI failures. Replace the bindgen allowlist entries with hand- written repr(C) struct and extern C declarations so they work on all targets (native and WASM). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 50686bc commit b732d58

3 files changed

Lines changed: 27 additions & 11 deletions

File tree

rust/ruby-prism-sys/build/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ fn generate_bindings(ruby_include_path: &Path) -> bindgen::Bindings {
116116
// Structs
117117
.allowlist_type("pm_comment_t")
118118
.allowlist_type("pm_diagnostic_t")
119-
.allowlist_type("pm_line_column_t")
120119
.allowlist_type("pm_list_t")
121120
.allowlist_type("pm_magic_comment_t")
122121
.allowlist_type("pm_node_t")
@@ -141,8 +140,6 @@ fn generate_bindings(ruby_include_path: &Path) -> bindgen::Bindings {
141140
// Functions
142141
.allowlist_function("pm_list_empty_p")
143142
.allowlist_function("pm_list_free")
144-
.allowlist_function("pm_newline_list_line")
145-
.allowlist_function("pm_newline_list_line_column")
146143
.allowlist_function("pm_node_destroy")
147144
.allowlist_function("pm_pack_parse")
148145
.allowlist_function("pm_parse")

rust/ruby-prism-sys/src/lib.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,25 @@ mod bindings {
3535
}
3636

3737
pub use self::bindings::*;
38+
39+
/// Line and column information for a given byte offset relative to the
40+
/// beginning of the source.
41+
#[repr(C)]
42+
#[derive(Debug, Clone, Copy)]
43+
pub struct pm_line_column_t {
44+
/// The 1-indexed line number relative to the start line configured on the
45+
/// parser.
46+
pub line: i32,
47+
/// The 0-indexed column number in bytes.
48+
pub column: u32,
49+
}
50+
51+
extern "C" {
52+
/// Return the line and column number for the given byte offset relative to
53+
/// the beginning of the source.
54+
pub fn pm_newline_list_line_column(
55+
list: *const pm_newline_list_t,
56+
cursor: u32,
57+
start_line: i32,
58+
) -> pm_line_column_t;
59+
}

rust/ruby-prism/src/parse_result/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,22 +104,19 @@ impl<'pr> Location<'pr> {
104104
}
105105
}
106106

107-
fn line_column_at(&self, offset: u32) -> LineColumn {
107+
fn line_column_at(&self, offset: u32) -> ruby_prism_sys::pm_line_column_t {
108+
// SAFETY: `self.parser` is a valid pointer to a `pm_parser_t` that
109+
// outlives `self`, and `pm_newline_list_line_column` only reads from
110+
// the newline list.
108111
unsafe {
109112
let parser = self.parser.as_ptr();
110113
let newline_list = &(*parser).newline_list;
111114
let start_line = (*parser).start_line;
112-
let result = pm_newline_list_line_column(newline_list, offset, start_line);
113-
LineColumn { line: result.line, column: result.column }
115+
pm_newline_list_line_column(newline_list, offset, start_line)
114116
}
115117
}
116118
}
117119

118-
struct LineColumn {
119-
line: i32,
120-
column: u32,
121-
}
122-
123120
impl std::fmt::Debug for Location<'_> {
124121
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
125122
let slice: &[u8] = self.as_slice();

0 commit comments

Comments
 (0)