8000 Convert rb_builtin_func to use bindgen, which requires adding a FILE … · kddnewton/ruby@a7ad647 · GitHub
[go: up one dir, main page]

Skip to content

Commit a7ad647

Browse files
authored
Convert rb_builtin_func to use bindgen, which requires adding a FILE opaque type. (ruby#194)
1 parent c0ebe07 commit a7ad647

File tree

5 files changed

+20
-23
lines changed

5 files changed

+20
-23
lines changed

yjit.c

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -328,18 +328,6 @@ rb_get_mct_func(rb_method_cfunc_t *mct)
328328
return (void*)mct->func; // this field is defined as type VALUE (*func)(ANYARGS)
329329
}
330330

331-
int
332-
rb_get_builtin_argc(struct rb_builtin_function* bi)
333-
{
334-
return bi->argc;
335-
}
336-
337-
void*
338-
rb_get_builtin_func_ptr(struct rb_builtin_function* bi)
339-
{
340-
return bi->func_ptr;
341-
}
342-
343331
const rb_iseq_t*
344332
rb_def_iseq_ptr(rb_method_definition_t *def)
345333
{

yjit/bindgen/src/main.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ fn main() {
131131
.allowlist_function("rb_yjit_get_page_size")
132132
.allowlist_function("rb_leaf_invokebuiltin_iseq_p")
133133
.allowlist_function("rb_leaf_builtin_function")
134-
.blocklist_type("rb_builtin_function")
135134

136135
// Not sure why it's picking these up, but don't.
137136
.blocklist_type("FILE")

yjit/src/codegen.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3898,7 +3898,7 @@ fn gen_send_iseq(jit: &mut JITState, ctx: &mut Context, cb: &mut CodeBlock, ocb:
38983898
let leaf_builtin: Option<*const rb_builtin_function> = if leaf_builtin_raw == (0 as *const rb_builtin_function) { None } else { Some(leaf_builtin_raw) };
38993899
match (block, leaf_builtin) {
39003900
(None, Some(builtin_info)) => {
3901-
let builtin_argc = unsafe { get_builtin_argc(builtin_info) };
3901+
let builtin_argc = unsafe { (*builtin_info).argc };
39023902
if builtin_argc + 1 /* for self */ + 1 /* for ec */ <= (C_ARG_REGS.len() as i32) {
39033903
add_comment(cb, "inlined leaf builtin");
39043904

@@ -3913,7 +3913,7 @@ fn gen_send_iseq(jit: &mut JITState, ctx: &mut Context, cb: &mut CodeBlock, ocb:
39133913
mov(cb, c_arg_reg, stack_opnd);
39143914
}
39153915
ctx.stack_pop((builtin_argc + 1).try_into().unwrap());
3916-
let builtin_func_ptr = unsafe { get_builtin_func_ptr(builtin_info) };
3916+
let builtin_func_ptr = unsafe { (*builtin_info).func_ptr as *const u8 };
39173917
call_ptr(cb, REG0, builtin_func_ptr);
39183918

39193919
// Push the return value

yjit/src/cruby.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,6 @@ extern "C" {
158158
#[link_name = "rb_get_mct_func"]
159159
pub fn get_mct_func(mct: * const rb_method_cfunc_t) -> *const u8;
160160

161-
#[link_name="rb_get_builtin_argc"]
162-
pub fn get_builtin_argc(bi: * const rb_builtin_function) -> c_int;
163-
164-
#[link_name="rb_get_builtin_func_ptr"]
165-
pub fn get_builtin_func_ptr(bi: * const rb_builtin_function) -> *mut u8;
166-
167161
#[link_name = "rb_def_iseq_ptr"]
168162
pub fn def_iseq_ptr(def: *const rb_method_definition_t) -> IseqPtr;
169163

@@ -317,9 +311,9 @@ pub struct rb_method_cfunc_t {
317311
core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
318312
}
319313

320-
/// Ruby built-in C function info
314+
/// Opaque FILE type
321315
#[repr(C)]
322-
pub struct rb_builtin_function {
316+
pub struct FILE {
323317
_data: [u8; 0],
324318
_marker:
325319
core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,

yjit/src/cruby_bindings.inc.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,22 @@ extern "C" {
421421
extern "C" {
422422
pub fn rb_ec_str_resurrect(ec: *mut rb_execution_context_struct, str_: VALUE) -> VALUE;
423423
}
424+
#[repr(C)]
425+
#[derive(Debug, Copy, Clone)]
426+
pub struct rb_builtin_function {
427+
pub func_ptr: *const ::std::os::raw::c_void,
428+
pub argc: ::std::os::raw::c_int,
429+
pub index: ::std::os::raw::c_int,
430+
pub name: *const ::std::os::raw::c_char,
431+
pub compiler: ::std::option::Option<
432+
unsafe extern "C" fn(
433+
arg1: *mut FILE,
434+
arg2: ::std::os::raw::c_long,
435+
arg3: ::std::os::raw::c_uint,
436+
arg4: bool,
437+
),
438+
>,
439+
}
424440
extern "C" {
425441
pub fn rb_vm_insn_addr2opcode(addr: *const ::std::os::raw::c_void) -> ::std::os::raw::c_int;
426442
}

0 commit comments

Comments
 (0)
0