Skip to content

Remove more C++ #8705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions mk/rt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ endif
endif

RUNTIME_CXXS_$(1)_$(2) := \
rt/sync/timer.cpp \
rt/sync/lock_and_signal.cpp \
rt/sync/rust_thread.cpp \
rt/rust_builtin.cpp \
Expand All @@ -72,13 +71,9 @@ RUNTIME_CXXS_$(1)_$(2) := \
rt/rust_upcall.cpp \
rt/rust_uv.cpp \
rt/rust_crate_map.cpp \
rt/rust_gc_metadata.cpp \
rt/rust_util.cpp \
rt/rust_log.cpp \
rt/rust_exchange_alloc.cpp \
rt/isaac/randport.cpp \
rt/miniz.cpp \
rt/rust_abi.cpp \
rt/memory_region.cpp \
rt/boxed_region.cpp \
rt/arch/$$(HOST_$(1))/context.cpp \
Expand Down
5 changes: 4 additions & 1 deletion src/libextra/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ pub struct Tm {
}

pub fn empty_tm() -> Tm {
// 64 is the max size of the timezone buffer allocated on windows
// in rust_localtime. In glibc the max timezone size is supposedly 3.
let zone = str::with_capacity(64);
Tm {
tm_sec: 0_i32,
tm_min: 0_i32,
Expand All @@ -132,7 +135,7 @@ pub fn empty_tm() -> Tm {
tm_yday: 0_i32,
tm_isdst: 0_i32,
tm_gmtoff: 0_i32,
tm_zone: ~"",
tm_zone: zone,
tm_nsec: 0_i32,
}
}
Expand Down
7 changes: 2 additions & 5 deletions src/libstd/rt/local_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@ impl LocalHeap {
#[fixed_stack_segment] #[inline(never)]
pub fn new() -> LocalHeap {
unsafe {
// Don't need synchronization for the single-threaded local heap
let synchronized = false as uintptr_t;
// XXX: These usually come from the environment
let detailed_leaks = false as uintptr_t;
let poison_on_free = false as uintptr_t;
let region = rust_new_memory_region(synchronized, detailed_leaks, poison_on_free);
let region = rust_new_memory_region(detailed_leaks, poison_on_free);
assert!(region.is_not_null());
let boxed = rust_new_boxed_region(region, poison_on_free);
assert!(boxed.is_not_null());
Expand Down Expand Up @@ -109,8 +107,7 @@ pub fn live_allocs() -> *raw::Box<()> {

extern {
#[fast_ffi]
fn rust_new_memory_region(synchronized: uintptr_t,
detailed_leaks: uintptr_t,
fn rust_new_memory_region(detailed_leaks: uintptr_t,
poison_on_free: uintptr_t) -> *MemoryRegion;
#[fast_ffi]
fn rust_delete_memory_region(region: *MemoryRegion);
Expand Down
3 changes: 0 additions & 3 deletions src/libstd/rt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,7 @@ pub fn init(argc: int, argv: **u8, crate_map: *u8) {
args::init(argc, argv);
env::init();
logging::init(crate_map);
rust_update_gc_metadata(crate_map);
}

externfn!(fn rust_update_gc_metadata(crate_map: *u8));
}

/// One-time runtime cleanup.
Expand Down
21 changes: 5 additions & 16 deletions src/libstd/rt/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use libc;
use option::{Some, None};
use os;
use str::StrSlice;
use unstable::atomics::{AtomicInt, INIT_ATOMIC_INT, SeqCst};

#[cfg(target_os="macos")]
use unstable::running_on_valgrind;
Expand Down Expand Up @@ -129,24 +130,12 @@ memory and partly incapable of presentation to others.",
}
}

pub fn set_exit_status(code: int) {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
return rust_set_exit_status_newrt(code as libc::uintptr_t);
}
static mut EXIT_STATUS: AtomicInt = INIT_ATOMIC_INT;

extern {
fn rust_set_exit_status_newrt(code: libc::uintptr_t);
}
pub fn set_exit_status(code: int) {
unsafe { EXIT_STATUS.store(code, SeqCst) }
}

pub fn get_exit_status() -> int {
#[fixed_stack_segment]; #[inline(never)];
unsafe {
return rust_get_exit_status_newrt() as int;
}

extern {
fn rust_get_exit_status_newrt() -> libc::uintptr_t;
}
unsafe { EXIT_STATUS.load(SeqCst) }
}
25 changes: 5 additions & 20 deletions src/rt/memory_region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.


#include "sync/sync.h"
#include "memory_region.h"

#if RUSTRT_TRACK_ALLOCATIONS >= 3
Expand Down Expand Up @@ -42,30 +41,25 @@ inline void memory_region::maybe_print_backtrace(const alloc_header *header) con
# endif
}

memory_region::memory_region(bool synchronized,
bool detailed_leaks,
memory_region::memory_region(bool detailed_leaks,
bool poison_on_free) :
_parent(NULL), _live_allocations(0),
_detailed_leaks(detailed_leaks),
_poison_on_free(poison_on_free),
_synchronized(synchronized) {
_poison_on_free(poison_on_free) {
}

memory_region::memory_region(memory_region *parent) :
_parent(parent), _live_allocations(0),
_detailed_leaks(parent->_detailed_leaks),
_poison_on_free(parent->_poison_on_free),
_synchronized(parent->_synchronized) {
_poison_on_free(parent->_poison_on_free) {
}

void memory_region::add_alloc() {
//_live_allocations++;
sync::increment(_live_allocations);
_live_allocations++;
}

void memory_region::dec_alloc() {
//_live_allocations--;
sync::decrement(_live_allocations);
_live_allocations--;
}

void memory_region::free(void *mem) {
Expand Down Expand Up @@ -112,7 +106,6 @@ memory_region::realloc(void *mem, size_t orig_size) {
# endif

# if RUSTRT_TRACK_ALLOCATIONS >= 2
if (_synchronized) { _lock.lock(); }
if (_allocation_list[newMem->index] != alloc) {
printf("at index %d, found %p, expected %p\n",
alloc->index, _allocation_list[alloc->index], alloc);
Expand All @@ -125,7 +118,6 @@ memory_region::realloc(void *mem, size_t orig_size) {
// printf("realloc: stored %p at index %d, replacing %p\n",
// newMem, index, mem);
}
if (_synchronized) { _lock.unlock(); }
# endif

return get_data(newMem);
Expand Down Expand Up @@ -160,9 +152,7 @@ memory_region::malloc(size_t size, const char *tag) {
}

memory_region::~memory_region() {
if (_synchronized) { _lock.lock(); }
if (_live_allocations == 0 && !_detailed_leaks) {
if (_synchronized) { _lock.unlock(); }
return;
}
char msg[128];
Expand Down Expand Up @@ -193,7 +183,6 @@ memory_region::~memory_region() {
fprintf(stderr, "%s\n", msg);
assert(false);
}
if (_synchronized) { _lock.unlock(); }
}

void
Expand All @@ -204,7 +193,6 @@ memory_region::release_alloc(void *mem) {
# endif

# if RUSTRT_TRACK_ALLOCATIONS >= 2
if (_synchronized) { _lock.lock(); }
if (((size_t) alloc->index) >= _allocation_list.size()) {
printf("free: ptr 0x%" PRIxPTR " (%s) index %d is beyond allocation_list of size %zu\n",
(uintptr_t) get_data(alloc), alloc->tag, alloc->index, _allocation_list.size());
Expand All @@ -222,7 +210,6 @@ memory_region::release_alloc(void *mem) {
_allocation_list[alloc->index] = NULL;
alloc->index = -1;
}
if (_synchronized) { _lock.unlock(); }
# endif

dec_alloc();
Expand All @@ -236,9 +223,7 @@ memory_region::claim_alloc(void *mem) {
# endif

# if RUSTRT_TRACK_ALLOCATIONS >= 2
if (_synchronized) { _lock.lock(); }
alloc->index = _allocation_list.append(alloc);
if (_synchronized) { _lock.unlock(); }
# endif

# if RUSTRT_TRACK_ALLOCATIONS >= 3
Expand Down
4 changes: 1 addition & 3 deletions src/rt/memory_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class memory_region {
array_list<alloc_header *> _allocation_list;
const bool _detailed_leaks;
const bool _poison_on_free;
const bool _synchronized;
lock_and_signal _lock;

void add_alloc();
Expand All @@ -77,8 +76,7 @@ class memory_region {
memory_region& operator=(const memory_region& rhs);

public:
memory_region(bool synchronized,
bool detailed_leaks, bool poison_on_free);
memory_region(bool detailed_leaks, bool poison_on_free);
memory_region(memory_region *parent);
void *malloc(size_t size, const char *tag);
void *realloc(void *mem, size_t size);
Expand Down
88 changes: 0 additions & 88 deletions src/rt/rust_abi.cpp

This file was deleted.

Loading