mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Do not allow unused_unsafe in codegen anymore
This commit is contained in:
parent
89a5e2b3d0
commit
aaa7a86381
2 changed files with 18 additions and 9 deletions
|
@ -890,16 +890,21 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None,
|
||||||
else:
|
else:
|
||||||
handleInvalidEnumValueCode = "return JSTrue;"
|
handleInvalidEnumValueCode = "return JSTrue;"
|
||||||
|
|
||||||
|
transmute = "mem::transmute(index)"
|
||||||
|
if isMember == 'Dictionary':
|
||||||
|
transmute = 'unsafe { ' + transmute + ' }'
|
||||||
|
|
||||||
template = (
|
template = (
|
||||||
"match find_enum_string_index(cx, ${val}, %(values)s) {\n"
|
"match find_enum_string_index(cx, ${val}, %(values)s) {\n"
|
||||||
" Err(_) => { %(exceptionCode)s },\n"
|
" Err(_) => { %(exceptionCode)s },\n"
|
||||||
" Ok(None) => { %(handleInvalidEnumValueCode)s },\n"
|
" Ok(None) => { %(handleInvalidEnumValueCode)s },\n"
|
||||||
" Ok(Some(index)) => {\n"
|
" Ok(Some(index)) => {\n"
|
||||||
" //XXXjdm need some range checks up in here.\n"
|
" //XXXjdm need some range checks up in here.\n"
|
||||||
" unsafe { mem::transmute(index) }\n"
|
" %(transmute)s\n"
|
||||||
" },\n"
|
" },\n"
|
||||||
"}" % {"values": enum + "Values::strings",
|
"}" % {"values": enum + "Values::strings",
|
||||||
"exceptionCode": exceptionCode,
|
"exceptionCode": exceptionCode,
|
||||||
|
"transmute": transmute,
|
||||||
"handleInvalidEnumValueCode": handleInvalidEnumValueCode})
|
"handleInvalidEnumValueCode": handleInvalidEnumValueCode})
|
||||||
|
|
||||||
if defaultValue is not None:
|
if defaultValue is not None:
|
||||||
|
@ -1629,7 +1634,6 @@ class CGImports(CGWrapper):
|
||||||
'unused_parens',
|
'unused_parens',
|
||||||
'unused_imports',
|
'unused_imports',
|
||||||
'unused_variables',
|
'unused_variables',
|
||||||
'unused_unsafe',
|
|
||||||
'unused_mut',
|
'unused_mut',
|
||||||
'unused_assignments',
|
'unused_assignments',
|
||||||
'dead_code',
|
'dead_code',
|
||||||
|
@ -2049,7 +2053,7 @@ class CGAbstractMethod(CGThing):
|
||||||
"""
|
"""
|
||||||
def __init__(self, descriptor, name, returnType, args, inline=False,
|
def __init__(self, descriptor, name, returnType, args, inline=False,
|
||||||
alwaysInline=False, extern=False, pub=False, templateArgs=None,
|
alwaysInline=False, extern=False, pub=False, templateArgs=None,
|
||||||
unsafe=True):
|
unsafe=False):
|
||||||
CGThing.__init__(self)
|
CGThing.__init__(self)
|
||||||
self.descriptor = descriptor
|
self.descriptor = descriptor
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -2165,7 +2169,8 @@ class CGWrapMethod(CGAbstractMethod):
|
||||||
args = [Argument('*mut JSContext', 'cx'),
|
args = [Argument('*mut JSContext', 'cx'),
|
||||||
Argument("Box<%s>" % descriptor.concreteType, 'object', mutable=True)]
|
Argument("Box<%s>" % descriptor.concreteType, 'object', mutable=True)]
|
||||||
retval = 'Root<%s>' % descriptor.concreteType
|
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):
|
def definition_body(self):
|
||||||
if not self.descriptor.isGlobal():
|
if not self.descriptor.isGlobal():
|
||||||
|
@ -2309,6 +2314,7 @@ class CGCreateInterfaceObjectsMethod(CGAbstractMethod):
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
protoChain = self.descriptor.prototypeChain
|
protoChain = self.descriptor.prototypeChain
|
||||||
if len(protoChain) == 1:
|
if len(protoChain) == 1:
|
||||||
|
self.unsafe = True
|
||||||
getParentProto = "parent_proto.ptr = JS_GetObjectPrototype(cx, global)"
|
getParentProto = "parent_proto.ptr = JS_GetObjectPrototype(cx, global)"
|
||||||
else:
|
else:
|
||||||
parentProtoName = self.descriptor.prototypeChain[-2]
|
parentProtoName = self.descriptor.prototypeChain[-2]
|
||||||
|
@ -2382,7 +2388,7 @@ class CGGetPerInterfaceObject(CGAbstractMethod):
|
||||||
Argument('HandleObject', 'receiver'),
|
Argument('HandleObject', 'receiver'),
|
||||||
Argument('MutableHandleObject', 'rval')]
|
Argument('MutableHandleObject', 'rval')]
|
||||||
CGAbstractMethod.__init__(self, descriptor, name,
|
CGAbstractMethod.__init__(self, descriptor, name,
|
||||||
'void', args, pub=pub)
|
'void', args, pub=pub, unsafe=True)
|
||||||
self.id = idPrefix + "ID::" + self.descriptor.name
|
self.id = idPrefix + "ID::" + self.descriptor.name
|
||||||
|
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
|
@ -2452,7 +2458,9 @@ class CGDefineProxyHandler(CGAbstractMethod):
|
||||||
"""
|
"""
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
assert descriptor.proxy
|
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):
|
def define(self):
|
||||||
return CGAbstractMethod.define(self)
|
return CGAbstractMethod.define(self)
|
||||||
|
@ -4021,7 +4029,8 @@ class CGProxyUnwrap(CGAbstractMethod):
|
||||||
def __init__(self, descriptor):
|
def __init__(self, descriptor):
|
||||||
args = [Argument('HandleObject', 'obj')]
|
args = [Argument('HandleObject', 'obj')]
|
||||||
CGAbstractMethod.__init__(self, descriptor, "UnwrapProxy",
|
CGAbstractMethod.__init__(self, descriptor, "UnwrapProxy",
|
||||||
'*const ' + descriptor.concreteType, args, alwaysInline=True)
|
'*const ' + descriptor.concreteType, args,
|
||||||
|
alwaysInline=True, unsafe=True)
|
||||||
|
|
||||||
def definition_body(self):
|
def definition_body(self):
|
||||||
return CGGeneric("""\
|
return CGGeneric("""\
|
||||||
|
|
|
@ -169,13 +169,13 @@ pub mod codegen {
|
||||||
include!(concat!(env!("OUT_DIR"), "/PrototypeList.rs"));
|
include!(concat!(env!("OUT_DIR"), "/PrototypeList.rs"));
|
||||||
}
|
}
|
||||||
#[allow(unreachable_code, non_camel_case_types, non_upper_case_globals, unused_parens,
|
#[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)]
|
dead_code)]
|
||||||
pub mod RegisterBindings {
|
pub mod RegisterBindings {
|
||||||
include!(concat!(env!("OUT_DIR"), "/RegisterBindings.rs"));
|
include!(concat!(env!("OUT_DIR"), "/RegisterBindings.rs"));
|
||||||
}
|
}
|
||||||
#[allow(unreachable_code, non_camel_case_types, non_upper_case_globals, unused_parens,
|
#[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)]
|
dead_code)]
|
||||||
pub mod UnionTypes {
|
pub mod UnionTypes {
|
||||||
include!(concat!(env!("OUT_DIR"), "/UnionTypes.rs"));
|
include!(concat!(env!("OUT_DIR"), "/UnionTypes.rs"));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue