Replace our rust_box with std::unstable::raw::Box

This will keep us in sync with compiler changes.  In fact we had the 'prev' and
'next' fields in the wrong order (but we aren't using them).
This commit is contained in:
Keegan McAllister 2013-09-18 14:57:12 -07:00
parent 68ddc6b4ab
commit 4b0680a136
4 changed files with 32 additions and 38 deletions

View file

@ -3190,7 +3190,7 @@ class CGAbstractBindingMethod(CGAbstractExternMethod):
" return false as JSBool;\n" " return false as JSBool;\n"
"}\n" "}\n"
"\n" "\n"
"let this: *rust_box<%s>;" % self.descriptor.concreteType)) "let this: *Box<%s>;" % self.descriptor.concreteType))
def generate_code(self): def generate_code(self):
assert(False) # Override me assert(False) # Override me
@ -3230,7 +3230,7 @@ class CGSpecializedMethod(CGAbstractExternMethod):
self.method = method self.method = method
name = method.identifier.name name = method.identifier.name
args = [Argument('*JSContext', 'cx'), Argument('JSHandleObject', 'obj'), args = [Argument('*JSContext', 'cx'), Argument('JSHandleObject', 'obj'),
Argument('*mut rust_box<%s>' % descriptor.concreteType, 'this'), Argument('*mut Box<%s>' % descriptor.concreteType, 'this'),
Argument('libc::c_uint', 'argc'), Argument('*mut JSVal', 'vp')] Argument('libc::c_uint', 'argc'), Argument('*mut JSVal', 'vp')]
CGAbstractExternMethod.__init__(self, descriptor, name, 'JSBool', args) CGAbstractExternMethod.__init__(self, descriptor, name, 'JSBool', args)
@ -3247,7 +3247,7 @@ class CGSpecializedMethod(CGAbstractExternMethod):
self.descriptor, self.method), self.descriptor, self.method),
pre=extraPre + pre=extraPre +
" let obj = (*obj.unnamed);\n" + " let obj = (*obj.unnamed);\n" +
" let this = &mut (*this).payload;\n").define() " let this = &mut (*this).data;\n").define()
class CGGenericGetter(CGAbstractBindingMethod): class CGGenericGetter(CGAbstractBindingMethod):
""" """
@ -3283,7 +3283,7 @@ class CGSpecializedGetter(CGAbstractExternMethod):
name = 'get_' + attr.identifier.name name = 'get_' + attr.identifier.name
args = [ Argument('*JSContext', 'cx'), args = [ Argument('*JSContext', 'cx'),
Argument('JSHandleObject', 'obj'), Argument('JSHandleObject', 'obj'),
Argument('*mut rust_box<%s>' % descriptor.concreteType, 'this'), Argument('*mut Box<%s>' % descriptor.concreteType, 'this'),
Argument('*mut JSVal', 'vp') ] Argument('*mut JSVal', 'vp') ]
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args) CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
@ -3309,7 +3309,7 @@ class CGSpecializedGetter(CGAbstractExternMethod):
self.descriptor, self.attr)), self.descriptor, self.attr)),
pre=extraPre + pre=extraPre +
" let obj = (*obj.unnamed);\n" + " let obj = (*obj.unnamed);\n" +
" let this = &mut (*this).payload;\n").define() " let this = &mut (*this).data;\n").define()
class CGGenericSetter(CGAbstractBindingMethod): class CGGenericSetter(CGAbstractBindingMethod):
""" """
@ -3350,7 +3350,7 @@ class CGSpecializedSetter(CGAbstractExternMethod):
name = 'set_' + attr.identifier.name name = 'set_' + attr.identifier.name
args = [ Argument('*JSContext', 'cx'), args = [ Argument('*JSContext', 'cx'),
Argument('JSHandleObject', 'obj'), Argument('JSHandleObject', 'obj'),
Argument('*mut rust_box<%s>' % descriptor.concreteType, 'this'), Argument('*mut Box<%s>' % descriptor.concreteType, 'this'),
Argument('*mut JSVal', 'argv')] Argument('*mut JSVal', 'argv')]
CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args) CGAbstractExternMethod.__init__(self, descriptor, name, "JSBool", args)
@ -3367,7 +3367,7 @@ class CGSpecializedSetter(CGAbstractExternMethod):
self.descriptor, self.attr)), self.descriptor, self.attr)),
pre=extraPre + pre=extraPre +
" let obj = (*obj.unnamed);\n" + " let obj = (*obj.unnamed);\n" +
" let this = &mut (*this).payload;\n").define() " let this = &mut (*this).data;\n").define()
def infallibleForMember(member, type, descriptorProvider): def infallibleForMember(member, type, descriptorProvider):
""" """
@ -3642,8 +3642,8 @@ class CGProxyUnwrap(CGAbstractMethod):
obj = js::UnwrapObject(obj); obj = js::UnwrapObject(obj);
}*/ }*/
//MOZ_ASSERT(IsProxy(obj)); //MOZ_ASSERT(IsProxy(obj));
let box: *rust_box<%s> = cast::transmute(RUST_JSVAL_TO_PRIVATE(GetProxyPrivate(obj))); let box: *Box<%s> = cast::transmute(RUST_JSVAL_TO_PRIVATE(GetProxyPrivate(obj)));
return ptr::to_unsafe_ptr(&(*box).payload);""" % (self.descriptor.concreteType) return ptr::to_unsafe_ptr(&(*box).data);""" % (self.descriptor.concreteType)
class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod): class CGDOMJSProxyHandler_getOwnPropertyDescriptor(CGAbstractExternMethod):
def __init__(self, descriptor): def __init__(self, descriptor):
@ -3997,7 +3997,7 @@ class CGAbstractClassHook(CGAbstractExternMethod):
def definition_body_prologue(self): def definition_body_prologue(self):
return """ return """
let this: *%s = &(*unwrap::<*rust_box<%s>>(obj)).payload; let this: *%s = &(*unwrap::<*Box<%s>>(obj)).data;
""" % (self.descriptor.concreteType, self.descriptor.concreteType) """ % (self.descriptor.concreteType, self.descriptor.concreteType)
def definition_body(self): def definition_body(self):
@ -4686,6 +4686,7 @@ class CGBindingRoot(CGThing):
'std::vec', 'std::vec',
'std::str', 'std::str',
'std::num', 'std::num',
'std::unstable::raw::Box',
], ],
[], [],
curr) curr)

View file

@ -14,7 +14,7 @@ use std::libc;
use std::ptr; use std::ptr;
use std::ptr::{null, to_unsafe_ptr}; use std::ptr::{null, to_unsafe_ptr};
use std::str; use std::str;
use std::unstable::intrinsics; use std::unstable::raw::Box;
use js::glue::*; use js::glue::*;
use js::glue::{DefineFunctionWithReserved, GetObjectJSClass, RUST_OBJECT_TO_JSVAL}; use js::glue::{DefineFunctionWithReserved, GetObjectJSClass, RUST_OBJECT_TO_JSVAL};
use js::glue::{js_IsObjectProxyClass, js_IsFunctionProxyClass, IsProxyHandlerFamily}; use js::glue::{js_IsObjectProxyClass, js_IsFunctionProxyClass, IsProxyHandlerFamily};
@ -106,14 +106,6 @@ pub fn null_str_as_empty_ref<'a>(s: &'a DOMString) -> &'a str {
} }
} }
pub struct rust_box<T> {
rc: uint,
td: *intrinsics::TyDesc,
next: *(),
prev: *(),
payload: T
}
fn is_dom_class(clasp: *JSClass) -> bool { fn is_dom_class(clasp: *JSClass) -> bool {
unsafe { unsafe {
((*clasp).flags & js::JSCLASS_IS_DOMJSCLASS) != 0 ((*clasp).flags & js::JSCLASS_IS_DOMJSCLASS) != 0
@ -180,8 +172,8 @@ pub fn unwrap_value<T>(val: *JSVal, proto_id: PrototypeList::id::ID, proto_depth
} }
} }
pub unsafe fn squirrel_away<T>(x: @mut T) -> *rust_box<T> { pub unsafe fn squirrel_away<T>(x: @mut T) -> *Box<T> {
let y: *rust_box<T> = cast::transmute(x); let y: *Box<T> = cast::transmute(x);
cast::forget(x); cast::forget(x);
y y
} }
@ -523,7 +515,7 @@ pub fn initialize_global(global: *JSObject) {
unsafe { unsafe {
//XXXjdm we should be storing the box pointer instead of the inner //XXXjdm we should be storing the box pointer instead of the inner
let box = squirrel_away(protoArray); let box = squirrel_away(protoArray);
let inner = ptr::to_unsafe_ptr(&(*box).payload); let inner = ptr::to_unsafe_ptr(&(*box).data);
JS_SetReservedSlot(global, JS_SetReservedSlot(global,
DOM_PROTOTYPE_SLOT, DOM_PROTOTYPE_SLOT,
RUST_PRIVATE_TO_JSVAL(inner as *libc::c_void)); RUST_PRIVATE_TO_JSVAL(inner as *libc::c_void));

View file

@ -4,7 +4,7 @@
use dom::bindings::codegen::DocumentBinding; use dom::bindings::codegen::DocumentBinding;
use dom::bindings::utils::{DOMString, WrapperCache, ErrorResult}; use dom::bindings::utils::{DOMString, WrapperCache, ErrorResult};
use dom::bindings::utils::{BindingObject, CacheableWrapper, rust_box, DerivedWrapper}; use dom::bindings::utils::{BindingObject, CacheableWrapper, DerivedWrapper};
use dom::bindings::utils::{is_valid_element_name, InvalidCharacter, Traceable, null_str_as_empty}; use dom::bindings::utils::{is_valid_element_name, InvalidCharacter, Traceable, null_str_as_empty};
use dom::element::{Element}; use dom::element::{Element};
use dom::element::{HTMLHtmlElementTypeId, HTMLHeadElementTypeId, HTMLTitleElementTypeId}; use dom::element::{HTMLHtmlElementTypeId, HTMLHeadElementTypeId, HTMLTitleElementTypeId};
@ -29,6 +29,7 @@ use std::ptr;
use std::str::eq_slice; use std::str::eq_slice;
use std::libc; use std::libc;
use std::ascii::StrAsciiExt; use std::ascii::StrAsciiExt;
use std::unstable::raw::Box;
pub trait WrappableDocument { pub trait WrappableDocument {
fn init_wrapper(@mut self, cx: *JSContext); fn init_wrapper(@mut self, cx: *JSContext);
@ -48,13 +49,13 @@ impl AbstractDocument {
} }
unsafe fn transmute<T, R>(&self, f: &fn(&T) -> R) -> R { unsafe fn transmute<T, R>(&self, f: &fn(&T) -> R) -> R {
let box: *rust_box<T> = cast::transmute(self.document); let box: *Box<T> = cast::transmute(self.document);
f(&(*box).payload) f(&(*box).data)
} }
unsafe fn transmute_mut<T, R>(&self, f: &fn(&mut T) -> R) -> R { unsafe fn transmute_mut<T, R>(&self, f: &fn(&mut T) -> R) -> R {
let box: *mut rust_box<T> = cast::transmute(self.document); let box: *mut Box<T> = cast::transmute(self.document);
f(&mut (*box).payload) f(&mut (*box).data)
} }
pub fn with_base<R>(&self, callback: &fn(&Document) -> R) -> R { pub fn with_base<R>(&self, callback: &fn(&Document) -> R) -> R {

View file

@ -6,8 +6,7 @@
use dom::bindings::node; use dom::bindings::node;
use dom::bindings::utils::{WrapperCache, DOMString, ErrorResult, NotFound, HierarchyRequest}; use dom::bindings::utils::{WrapperCache, DOMString, ErrorResult, NotFound, HierarchyRequest};
use dom::bindings::utils::{BindingObject, CacheableWrapper, rust_box, null_str_as_empty}; use dom::bindings::utils::{BindingObject, CacheableWrapper, null_str_as_empty};
use dom::bindings;
use dom::characterdata::CharacterData; use dom::characterdata::CharacterData;
use dom::document::AbstractDocument; use dom::document::AbstractDocument;
use dom::element::{Element, ElementTypeId, HTMLImageElementTypeId, HTMLIframeElementTypeId}; use dom::element::{Element, ElementTypeId, HTMLImageElementTypeId, HTMLIframeElementTypeId};
@ -19,6 +18,7 @@ use dom::text::Text;
use std::cast; use std::cast;
use std::cast::transmute; use std::cast::transmute;
use std::libc::c_void; use std::libc::c_void;
use std::unstable::raw::Box;
use extra::arc::Arc; use extra::arc::Arc;
use js::jsapi::{JSObject, JSContext}; use js::jsapi::{JSObject, JSContext};
use netsurfcss::util::VoidPtrLike; use netsurfcss::util::VoidPtrLike;
@ -170,7 +170,7 @@ impl<'self, View> AbstractNode<View> {
/// Allow consumers to recreate an AbstractNode from the raw boxed type. /// Allow consumers to recreate an AbstractNode from the raw boxed type.
/// Must only be used in situations where the boxed type is in the inheritance /// Must only be used in situations where the boxed type is in the inheritance
/// chain for nodes. /// chain for nodes.
pub fn from_box<T>(ptr: *mut rust_box<T>) -> AbstractNode<View> { pub fn from_box<T>(ptr: *mut Box<T>) -> AbstractNode<View> {
AbstractNode { AbstractNode {
obj: ptr as *mut Node<View> obj: ptr as *mut Node<View>
} }
@ -219,12 +219,12 @@ impl<'self, View> AbstractNode<View> {
pub fn transmute<T, R>(self, f: &fn(&T) -> R) -> R { pub fn transmute<T, R>(self, f: &fn(&T) -> R) -> R {
unsafe { unsafe {
let node_box: *mut bindings::utils::rust_box<Node<View>> = transmute(self.obj); let node_box: *mut Box<Node<View>> = transmute(self.obj);
let node = &mut (*node_box).payload; let node = &mut (*node_box).data;
let old = node.abstract; let old = node.abstract;
node.abstract = Some(self); node.abstract = Some(self);
let box: *bindings::utils::rust_box<T> = transmute(self.obj); let box: *Box<T> = transmute(self.obj);
let rv = f(&(*box).payload); let rv = f(&(*box).data);
node.abstract = old; node.abstract = old;
rv rv
} }
@ -232,12 +232,12 @@ impl<'self, View> AbstractNode<View> {
pub fn transmute_mut<T, R>(self, f: &fn(&mut T) -> R) -> R { pub fn transmute_mut<T, R>(self, f: &fn(&mut T) -> R) -> R {
unsafe { unsafe {
let node_box: *mut bindings::utils::rust_box<Node<View>> = transmute(self.obj); let node_box: *mut Box<Node<View>> = transmute(self.obj);
let node = &mut (*node_box).payload; let node = &mut (*node_box).data;
let old = node.abstract; let old = node.abstract;
node.abstract = Some(self); node.abstract = Some(self);
let box: *bindings::utils::rust_box<T> = transmute(self.obj); let box: *Box<T> = transmute(self.obj);
let rv = f(cast::transmute(&(*box).payload)); let rv = f(cast::transmute(&(*box).data));
node.abstract = old; node.abstract = old;
rv rv
} }