From aaa7a86381e1755eaf04a898e09989bce17b3221 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sun, 30 Aug 2015 16:30:25 +0200 Subject: [PATCH] Do not allow unused_unsafe in codegen anymore --- .../dom/bindings/codegen/CodegenRust.py | 23 +++++++++++++------ components/script/dom/bindings/mod.rs | 4 ++-- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/components/script/dom/bindings/codegen/CodegenRust.py b/components/script/dom/bindings/codegen/CodegenRust.py index 003ee83c170..e2db9510d1b 100644 --- a/components/script/dom/bindings/codegen/CodegenRust.py +++ b/components/script/dom/bindings/codegen/CodegenRust.py @@ -890,16 +890,21 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, else: handleInvalidEnumValueCode = "return JSTrue;" + transmute = "mem::transmute(index)" + if isMember == 'Dictionary': + transmute = 'unsafe { ' + transmute + ' }' + template = ( "match find_enum_string_index(cx, ${val}, %(values)s) {\n" " Err(_) => { %(exceptionCode)s },\n" " Ok(None) => { %(handleInvalidEnumValueCode)s },\n" " Ok(Some(index)) => {\n" " //XXXjdm need some range checks up in here.\n" - " unsafe { mem::transmute(index) }\n" + " %(transmute)s\n" " },\n" "}" % {"values": enum + "Values::strings", "exceptionCode": exceptionCode, + "transmute": transmute, "handleInvalidEnumValueCode": handleInvalidEnumValueCode}) if defaultValue is not None: @@ -1629,7 +1634,6 @@ class CGImports(CGWrapper): 'unused_parens', 'unused_imports', 'unused_variables', - 'unused_unsafe', 'unused_mut', 'unused_assignments', 'dead_code', @@ -2049,7 +2053,7 @@ class CGAbstractMethod(CGThing): """ def __init__(self, descriptor, name, returnType, args, inline=False, alwaysInline=False, extern=False, pub=False, templateArgs=None, - unsafe=True): + unsafe=False): CGThing.__init__(self) self.descriptor = descriptor self.name = name @@ -2165,7 +2169,8 @@ class CGWrapMethod(CGAbstractMethod): args = [Argument('*mut JSContext', 'cx'), Argument("Box<%s>" % descriptor.concreteType, 'object', mutable=True)] retval = 'Root<%s>' % descriptor.concreteType - CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args, pub=True) + CGAbstractMethod.__init__(self, descriptor, 'Wrap', retval, args, + pub=True, unsafe=True) def definition_body(self): if not self.descriptor.isGlobal(): @@ -2309,6 +2314,7 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod): def definition_body(self): protoChain = self.descriptor.prototypeChain if len(protoChain) == 1: + self.unsafe = True getParentProto = "parent_proto.ptr = JS_GetObjectPrototype(cx, global)" else: parentProtoName = self.descriptor.prototypeChain[-2] @@ -2382,7 +2388,7 @@ class CGGetPerInterfaceObject(CGAbstractMethod): Argument('HandleObject', 'receiver'), Argument('MutableHandleObject', 'rval')] CGAbstractMethod.__init__(self, descriptor, name, - 'void', args, pub=pub) + 'void', args, pub=pub, unsafe=True) self.id = idPrefix + "ID::" + self.descriptor.name def definition_body(self): @@ -2452,7 +2458,9 @@ class CGDefineProxyHandler(CGAbstractMethod): """ def __init__(self, descriptor): assert descriptor.proxy - CGAbstractMethod.__init__(self, descriptor, 'DefineProxyHandler', '*const libc::c_void', [], pub=True) + CGAbstractMethod.__init__(self, descriptor, 'DefineProxyHandler', + '*const libc::c_void', [], + pub=True, unsafe=True) def define(self): return CGAbstractMethod.define(self) @@ -4021,7 +4029,8 @@ class CGProxyUnwrap(CGAbstractMethod): def __init__(self, descriptor): args = [Argument('HandleObject', 'obj')] CGAbstractMethod.__init__(self, descriptor, "UnwrapProxy", - '*const ' + descriptor.concreteType, args, alwaysInline=True) + '*const ' + descriptor.concreteType, args, + alwaysInline=True, unsafe=True) def definition_body(self): return CGGeneric("""\ diff --git a/components/script/dom/bindings/mod.rs b/components/script/dom/bindings/mod.rs index 283dc9b08c9..aa44ba40fea 100644 --- a/components/script/dom/bindings/mod.rs +++ b/components/script/dom/bindings/mod.rs @@ -169,13 +169,13 @@ pub mod codegen { include!(concat!(env!("OUT_DIR"), "/PrototypeList.rs")); } #[allow(unreachable_code, non_camel_case_types, non_upper_case_globals, unused_parens, - unused_imports, unused_variables, unused_unsafe, unused_mut, unused_assignments, + unused_imports, unused_variables, unused_mut, unused_assignments, dead_code)] pub mod RegisterBindings { include!(concat!(env!("OUT_DIR"), "/RegisterBindings.rs")); } #[allow(unreachable_code, non_camel_case_types, non_upper_case_globals, unused_parens, - unused_imports, unused_variables, unused_unsafe, unused_mut, unused_assignments, + unused_imports, unused_variables, unused_mut, unused_assignments, dead_code)] pub mod UnionTypes { include!(concat!(env!("OUT_DIR"), "/UnionTypes.rs"));