Backed out changeset 5beaad8a185b (bug 662341) for linting failure on a CLOSED TREE

This commit is contained in:
Andreea Pavel 2018-11-15 06:49:53 +02:00
Родитель 6a58f5fcea
Коммит b9b20a60f7
4 изменённых файлов: 47 добавлений и 95 удалений

Просмотреть файл

@ -33,11 +33,8 @@ def attributeParamName(a):
return "a" + firstCap(a.name)
def attributeParamNames(a, getter):
if getter and a.notxpcom:
l = []
else:
l = [attributeParamName(a)]
def attributeParamNames(a):
l = [attributeParamName(a)]
if a.implicit_jscontext:
l.insert(0, "cx")
return ", ".join(l)
@ -48,36 +45,20 @@ def attributeNativeName(a, getter):
return "%s%s" % (getter and 'Get' or 'Set', binaryname)
def attributeReturnType(a, getter, macro):
def attributeReturnType(a, macro):
"""macro should be NS_IMETHOD or NS_IMETHODIMP"""
# Pick the type to be returned from the getter/setter.
if a.notxpcom:
ret = a.realtype.nativeType('in').strip() if getter else "void"
else:
ret = "nsresult"
# Set calling convention and virtual-ness
if a.nostdcall:
if macro == "NS_IMETHOD":
# This is the declaration.
ret = "virtual %s" % ret
ret = macro == "NS_IMETHOD" and "virtual nsresult" or "nsresult"
else:
if ret == "nsresult":
ret = macro
else:
ret = "%s_(%s)" % (macro, ret)
ret = macro
if a.must_use:
ret = "MOZ_MUST_USE " + ret
return ret
def attributeParamlist(a, getter):
if getter and a.notxpcom:
l = []
else:
l = ["%s%s" % (a.realtype.nativeType(getter and 'out' or 'in'),
attributeParamName(a))]
l = ["%s%s" % (a.realtype.nativeType(getter and 'out' or 'in'),
attributeParamName(a))]
if a.implicit_jscontext:
l.insert(0, "JSContext* cx")
@ -85,7 +66,7 @@ def attributeParamlist(a, getter):
def attributeAsNative(a, getter, declType='NS_IMETHOD'):
params = {'returntype': attributeReturnType(a, getter, declType),
params = {'returntype': attributeReturnType(a, declType),
'binaryname': attributeNativeName(a, getter),
'paramlist': attributeParamlist(a, getter)}
return "%(returntype)s %(binaryname)s(%(paramlist)s)" % params
@ -97,22 +78,15 @@ def methodNativeName(m):
def methodReturnType(m, macro):
"""macro should be NS_IMETHOD or NS_IMETHODIMP"""
if m.notxpcom:
ret = m.realtype.nativeType('in').strip()
if m.nostdcall and m.notxpcom:
ret = "%s%s" % (macro == "NS_IMETHOD" and "virtual " or "",
m.realtype.nativeType('in').strip())
elif m.nostdcall:
ret = "%snsresult" % (macro == "NS_IMETHOD" and "virtual " or "")
elif m.notxpcom:
ret = "%s_(%s)" % (macro, m.realtype.nativeType('in').strip())
else:
ret = "nsresult"
# Set calling convention and virtual-ness
if m.nostdcall:
if macro == "NS_IMETHOD":
# This is the declaration
ret = "virtual %s" % ret
else:
if ret == "nsresult":
ret = macro
else:
ret = "%s_(%s)" % (macro, ret)
ret = macro
if m.must_use:
ret = "MOZ_MUST_USE " + ret
return ret
@ -541,14 +515,13 @@ def write_interface(iface, fd):
if forward_infallible and member.infallible:
fd.write("\\\n using %s::%s; " %
(iface.name, attributeNativeName(member, True)))
attr_tmpl = tmpl_notxpcom if member.notxpcom else tmpl
fd.write(attr_tmpl % {'asNative': attributeAsNative(member, True),
'nativeName': attributeNativeName(member, True),
'paramList': attributeParamNames(member, True)})
fd.write(tmpl % {'asNative': attributeAsNative(member, True),
'nativeName': attributeNativeName(member, True),
'paramList': attributeParamNames(member)})
if not member.readonly:
fd.write(attr_tmpl % {'asNative': attributeAsNative(member, False),
'nativeName': attributeNativeName(member, False),
'paramList': attributeParamNames(member, False)})
fd.write(tmpl % {'asNative': attributeAsNative(member, False),
'nativeName': attributeNativeName(member, False),
'paramList': attributeParamNames(member)})
elif isinstance(member, xpidl.Method):
if member.notxpcom:
fd.write(tmpl_notxpcom % {'asNative': methodAsNative(member),

Просмотреть файл

@ -202,21 +202,16 @@ def build_interface(iface):
hasretval=hasretval, symbol=m.symbol))
def build_attr(a):
assert a.realtype.name != 'void'
# Write the getter
getter_params = []
if not a.notxpcom:
getter_params.append(mk_param(get_type(a.realtype, 'out'), out=1))
methods.append(mk_method(a.name, getter_params, getter=1,
notxpcom=a.notxpcom, hidden=a.noscript,
param = mk_param(get_type(a.realtype, 'out'), out=1)
methods.append(mk_method(a.name, [param], getter=1, hidden=a.noscript,
context=a.implicit_jscontext, hasretval=1,
symbol=a.symbol))
# And maybe the setter
if not a.readonly:
param = mk_param(get_type(a.realtype, 'in'), in_=1)
methods.append(mk_method(a.name, [param], setter=1,
notxpcom=a.notxpcom, hidden=a.noscript,
methods.append(mk_method(a.name, [param], setter=1, hidden=a.noscript,
context=a.implicit_jscontext,
symbol=a.symbol))

Просмотреть файл

@ -13,19 +13,19 @@
# documentation for the reasons why we don't generate certain types of bindings,
# so that we don't accidentally start generating them in the future.
# notxpcom methods and attributes return their results directly by value. The x86
# windows stdcall ABI returns aggregates by value differently for methods than
# notxpcom methods return their results directly by value. The x86 windows
# stdcall ABI returns aggregates by value differently for methods than
# functions, and rust only exposes the function ABI, so that's the one we're
# using. The correct ABI can be emulated for notxpcom methods returning aggregates
# by passing an &mut ReturnType parameter as the second parameter. This strategy
# is used by the winapi-rs crate.
# using. The correct ABI can be emulated for notxpcom methods returning
# aggregates by passing an &mut ReturnType parameter as the second parameter.
# This strategy is used by the winapi-rs crate.
# https://github.com/retep998/winapi-rs/blob/7338a5216a6a7abeefcc6bb1bc34381c81d3e247/src/macros.rs#L220-L231
#
# Right now we can generate code for notxpcom methods and attributes, as we don't
# support passing aggregates by value over these APIs ever (the types which are
# allowed in xpidl.py shouldn't include any aggregates), so the code is
# correct. In the future if we want to start supporting returning aggregates by
# value, we will need to use a workaround such as the one used by winapi.rs.
# Right now we can generate code for notxpcom methods, as we don't support
# passing aggregates by value over these APIs ever (the types which are allowed
# in xpidl.py shouldn't include any aggregates), so the code is correct. In the
# future if we want to start supporting returning aggregates by value, we will
# need to use a workaround such as the one used by winapi.rs.
# nostdcall methods on x86 windows will use the thiscall ABI, which is not
# stable in rust right now, so we cannot generate bindings to them.
@ -120,23 +120,13 @@ def attributeNativeName(a, getter):
return "%s%s" % ('Get' if getter else 'Set', binaryname)
def attributeReturnType(a, getter):
if a.notxpcom:
if getter:
return a.realtype.rustType('in').strip()
return "::libc::c_void"
return "::nserror::nsresult"
def attributeParamName(a):
return "a" + firstCap(a.name)
def attributeRawParamList(iface, a, getter):
if getter and a.notxpcom:
l = []
else:
l = [(attributeParamName(a),
a.realtype.rustType('out' if getter else 'in'))]
l = [(attributeParamName(a),
a.realtype.rustType('out' if getter else 'in'))]
if a.implicit_jscontext:
raise xpidl.RustNoncompat("jscontext is unsupported")
if a.nostdcall:
@ -152,10 +142,9 @@ def attributeParamList(iface, a, getter):
def attrAsVTableEntry(iface, m, getter):
try:
return "pub %s: unsafe extern \"system\" fn (%s) -> %s" % \
return "pub %s: unsafe extern \"system\" fn (%s) -> ::nserror::nsresult" % \
(attributeNativeName(m, getter),
attributeParamList(iface, m, getter),
attributeReturnType(m, getter))
attributeParamList(iface, m, getter))
except xpidl.RustNoncompat as reason:
return """\
/// Unable to generate binding because `%s`
@ -264,13 +253,12 @@ def attrAsWrapper(iface, m, getter):
'realtype': m.realtype.rustType('in'),
}
param_list = attributeRawParamList(iface, m, getter)
params = ["%s: %s" % x for x in param_list]
rust_type = m.realtype.rustType('out' if getter else 'in')
return method_impl_tmpl % {
'name': attributeNativeName(m, getter),
'params': ', '.join(params),
'ret_ty': attributeReturnType(m, getter),
'args': '' if getter and m.notxpcom else name,
'params': name + ': ' + rust_type,
'ret_ty': '::nserror::nsresult',
'args': name,
}
except xpidl.RustNoncompat:

Просмотреть файл

@ -682,10 +682,9 @@ class Interface(object):
if not isinstance(m, CDATA):
self.namemap.set(m)
if ((m.kind == 'method' or m.kind == 'attribute') and
m.notxpcom and name != 'nsISupports'):
# An interface cannot be implemented by JS if it has a notxpcom
# method or attribute. Such a type is an "implicit builtinclass".
if m.kind == 'method' and m.notxpcom and name != 'nsISupports':
# An interface cannot be implemented by JS if it has a
# notxpcom method. Such a type is an "implicit builtinclass".
#
# XXX(nika): Why does nostdcall not imply builtinclass?
# It could screw up the shims as well...
@ -993,7 +992,6 @@ class CEnum(object):
class Attribute(object):
kind = 'attribute'
noscript = False
notxpcom = False
readonly = False
symbol = False
implicit_jscontext = False
@ -1024,8 +1022,6 @@ class Attribute(object):
if name == 'noscript':
self.noscript = True
elif name == 'notxpcom':
self.notxpcom = True
elif name == 'symbol':
self.symbol = True
elif name == 'implicit_jscontext':
@ -1063,7 +1059,7 @@ class Attribute(object):
def isScriptable(self):
if not self.iface.attributes.scriptable:
return False
return not (self.noscript or self.notxpcom)
return not self.noscript
def __str__(self):
return "\t%sattribute %s %s\n" % (self.readonly and 'readonly ' or '',