Skip to content
Permalink
Browse files
Write rb_mem_clear in Rust
This makefile hackery is ridiculous but whatever, it works!
  • Loading branch information
steveklabnik committed Sep 3, 2016
1 parent f3101b4 commit daadce1be678428bd42071c25ed586793b9260fa
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
@@ -30,6 +30,7 @@
.pc
.ppack
.svn
!./Makefile
Makefile
Makefile.old
cygruby*.def
@@ -552,3 +552,11 @@ un-runnable:
$(Q) exit 1

distclean-local::; @$(RM) GNUmakefile uncommon.mk

array.c:

array.o: rubyarray.c rarray.rs
rustc rarray.rs --crate-type=staticlib -Cpanic=abort
@$(ECHO) compiling $<
@$(Q) $(CC) $(CFLAGS) $(XCFLAGS) $(CPPFLAGS) $(COUTFLAG)$@ -c $<
ld -r rubyarray.o librarray.a -o array.o
@@ -0,0 +1,35 @@
#![no_std]
#![feature(lang_items)]

#![feature(libc)]
extern crate libc;

pub type Value = libc::uintptr_t;

#[allow(non_upper_case_globals)]
static Qnil: libc::uintptr_t = 0x08 as libc::uintptr_t;

#[no_mangle]
pub unsafe extern fn rb_mem_clear(mut mem: *mut Value, mut size: libc::c_long) {
while size != 0 {
size -= 1;
*mem = Qnil;

mem = mem.offset(1);
}
}

use core::fmt;

#[lang = "eh_personality"]
#[no_mangle]
pub extern fn eh_personality() {
}

#[lang = "panic_fmt"]
#[no_mangle]
pub extern fn rust_begin_panic(_: fmt::Arguments,
_: &'static str,
_: u32) -> ! {
loop {}
}
@@ -131,14 +131,6 @@ static ID id_cmp, id_div, id_power;

#define ARY_SET(a, i, v) RARRAY_ASET((assert(!ARY_SHARED_P(a)), (a)), (i), (v))

void
rb_mem_clear(register VALUE *mem, register long size)
{
while (size--) {
*mem++ = Qnil;
}
}

static void
ary_mem_clear(VALUE ary, long beg, long size)
{

0 comments on commit daadce1

Please sign in to comment.