aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/embedding/mem.rs
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2014-02-18 09:44:25 -0500
committerMike Blumenkrantz <zmike@samsung.com>2014-05-26 16:43:10 -0400
commitfaa7f1885cc0aa830b2c917cf6a1dba17d523013 (patch)
tree8f4cacaf6b5e3019a38f21c996eb43a634bb3fdf /src/components/embedding/mem.rs
parent4d188e2ccdc382566d794c808ab6a08ab6171966 (diff)
downloadservo-faa7f1885cc0aa830b2c917cf6a1dba17d523013.tar.gz
servo-faa7f1885cc0aa830b2c917cf6a1dba17d523013.zip
serious mode engaged: start of embedding crate using FFI
current status ============= [ ] Successfully crashing CEF [X] Successfully not crashing CEF
Diffstat (limited to 'src/components/embedding/mem.rs')
-rw-r--r--src/components/embedding/mem.rs54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/components/embedding/mem.rs b/src/components/embedding/mem.rs
new file mode 100644
index 00000000000..032d13783d5
--- /dev/null
+++ b/src/components/embedding/mem.rs
@@ -0,0 +1,54 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+use libc::{c_void, size_t};
+use std::mem;
+use std::ptr::set_memory;
+
+extern "C" {
+ fn tc_new(size: size_t) -> *mut c_void;
+ fn tc_delete(mem: *mut c_void);
+ fn tc_newarray(size: size_t) -> *mut c_void;
+ fn tc_deletearray(mem: *mut c_void);
+}
+
+pub fn newarray0<T>(nmem: size_t) -> *mut T {
+ let mem = newarray::<T>(nmem) as *mut T;
+ unsafe {
+ set_memory(mem, 0 as u8, nmem as uint);
+ }
+ mem
+}
+
+pub fn newarray<T>(nmem: size_t) -> *mut T {
+ unsafe {
+ tc_newarray(nmem * mem::size_of::<T>() as u64) as *mut T
+ }
+}
+
+pub fn new0<T>(nmem: size_t) -> *mut T {
+ let mem = new(nmem * mem::size_of::<T>() as u64) as *mut T;
+ unsafe {
+ set_memory(mem, 0 as u8, nmem as uint);
+ }
+ mem
+}
+
+pub fn new(size: size_t) -> *mut c_void {
+ unsafe {
+ tc_new(size)
+ }
+}
+
+pub fn delete(mem: *mut c_void) {
+ unsafe {
+ tc_delete(mem)
+ }
+}
+
+pub fn deletearray(mem: *mut c_void) {
+ unsafe {
+ tc_deletearray(mem)
+ }
+}