Skip to content

Commit

Permalink
Bug 1657609 - statically bound the maximum number of parameters for x…
Browse files Browse the repository at this point in the history
…pidl methods; r=mccr8

We used to not be able to do something like this, and therefore our xpidl
calling code had to  be fully general.  But now that we know all possible
xpidl methods at build time, we can ensure that the number of parameters
does not exceed some bound.  And we choose that bound to be the maximum
number of stack-allocated parameters our calling code supports.

Differential Revision: https://phabricator.services.mozilla.com/D86212
  • Loading branch information
froydnj committed Aug 7, 2020
1 parent fdd22de commit c4c7337
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions xpcom/reflect/xptinfo/xptcodegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,8 @@ def interface_idx(name):
params = []
param_cache = {}
methods = []
max_params = 0
method_with_max_params = None
consts = []
domobjects = []
domobject_cache = {}
Expand Down Expand Up @@ -361,6 +363,10 @@ def lower_method(method, ifacename):
for idx, param in enumerate(method['params']):
lower_param(param, "%s[%d]" % (methodname, idx))

nonlocal max_params, method_with_max_params
if numparams > max_params:
max_params = numparams
method_with_max_params = methodname
methods.append(nsXPTMethodInfo(
"%d = %s" % (len(methods), methodname),

Expand Down Expand Up @@ -508,6 +514,12 @@ def array(ty, name, els):
array("nsXPTType", "sTypes", types)
array("nsXPTParamInfo", "sParams", params)
array("nsXPTMethodInfo", "sMethods", methods)
# Verify that stack-allocated buffers will do for xptcall implementations.
msg = "Too many method arguments in %s. " \
"Either reduce the number of arguments " \
"or increase PARAM_BUFFER_COUNT." % method_with_max_params
fd.write("static_assert(%s <= PARAM_BUFFER_COUNT, \"%s\");\n\n"
% (max_params, msg))
array("nsXPTDOMObjectInfo", "sDOMObjects", domobjects)
array("nsXPTConstantInfo", "sConsts", consts)

Expand Down

0 comments on commit c4c7337

Please sign in to comment.