auto merge of #10439 : brson/rust/rmcxx, r=bstrie

This commit is contained in:
bors 2013-11-12 08:01:20 -08:00
commit 2ee72ba5c6
5 changed files with 10 additions and 141 deletions

View File

@ -10,7 +10,6 @@
/* Foreign builtins. */
#include "rust_util.h"
#include "sync/lock_and_signal.h"
#include "vg/valgrind.h"
@ -234,6 +233,16 @@ precise_time_ns(uint64_t *ns) {
#endif
}
struct
rust_vec
{
size_t fill; // in bytes; if zero, heapified
size_t alloc; // in bytes
uint8_t data[0];
};
typedef rust_vec rust_str;
struct rust_tm {
int32_t tm_sec;
int32_t tm_min;

View File

@ -10,7 +10,6 @@
// Helper functions used only in tests
#include "rust_util.h"
#include "sync/lock_and_signal.h"
// These functions are used in the unit tests for C ABI calls.

View File

@ -1,81 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#ifndef RUST_TYPE_H
#define RUST_TYPE_H
#include "rust_globals.h"
struct rust_opaque_box;
// The type of functions that we spawn, which fall into two categories:
// - the main function: has a NULL environment, but uses the void* arg
// - unique closures of type fn~(): have a non-NULL environment, but
// no arguments (and hence the final void*) is harmless
typedef void (*CDECL spawn_fn)(rust_opaque_box*, void *);
struct type_desc;
typedef void CDECL (glue_fn)(void *,
void *);
typedef unsigned long ref_cnt_t;
// Corresponds to the boxed data in the @ region. The body follows the
// header; you can obtain a ptr via box_body() below.
struct rust_opaque_box {
ref_cnt_t ref_count;
type_desc *td;
rust_opaque_box *prev;
rust_opaque_box *next;
};
// corresponds to the layout of a &fn(), @fn(), ~fn() etc
struct fn_env_pair {
spawn_fn f;
rust_opaque_box *env;
};
static inline void *box_body(rust_opaque_box *box) {
// Here we take advantage of the fact that the size of a box in 32
// (resp. 64) bit is 16 (resp. 32) bytes, and thus always 16-byte aligned.
// If this were to change, we would have to update the method
// rustc::middle::trans::base::opaque_box_body() as well.
return (void*)(box + 1);
}
struct slice {
void *data;
size_t length;
};
struct type_desc {
size_t size;
size_t align;
glue_fn *take_glue;
glue_fn *drop_glue;
glue_fn *free_glue;
glue_fn *visit_glue;
size_t borrow_offset;
slice name;
};
#endif
//
// Local Variables:
// mode: C++
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// End:
//

View File

@ -17,7 +17,6 @@
*/
#include "rust_globals.h"
#include "rust_util.h"
//Unwinding ABI declarations.
typedef int _Unwind_Reason_Code;

View File

@ -1,57 +0,0 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#ifndef RUST_UTIL_H
#define RUST_UTIL_H
#include <limits.h>
#include "rust_type.h"
// Inline fn used regularly elsewhere.
// Rounds |size| to the nearest |alignment|. Invariant: |alignment| is a power
// of two.
template<typename T>
static inline T
align_to(T size, size_t alignment) {
assert(alignment);
T x = (T)(((uintptr_t)size + alignment - 1) & ~(alignment - 1));
return x;
}
// Interior vectors (rust-user-code level).
struct
rust_vec
{
size_t fill; // in bytes; if zero, heapified
size_t alloc; // in bytes
uint8_t data[0];
};
typedef rust_vec rust_str;
inline size_t get_box_size(size_t body_size, size_t body_align) {
size_t header_size = sizeof(rust_opaque_box);
size_t total_size = align_to(header_size, body_align) + body_size;
return total_size;
}
//
// Local Variables:
// mode: C++
// fill-column: 78;
// indent-tabs-mode: nil
// c-basic-offset: 4
// buffer-file-coding-system: utf-8-unix
// End:
//
#endif