Bug 1223142 - make XPIDL set default nullptrs for optional out parameters, r=bz
authorGijs Kruitbosch <gijskruitbosch@gmail.com>
Thu, 05 Nov 2015 22:45:25 +0000
changeset 308251 f9e28bb0ab11512a7fc1c11f017f9eabf9b800c9
parent 308250 55cea35b3cc657886368c1b22f11cf70def6ba0c
child 308252 f1bee32f7e255e79e1a1f36ab2652eb694f6b773
push id7450
push userahalberstadt@mozilla.com
push dateWed, 11 Nov 2015 20:09:05 +0000
reviewersbz
bugs1223142
milestone45.0a1
Bug 1223142 - make XPIDL set default nullptrs for optional out parameters, r=bz
xpcom/idl-parser/xpidl/header.py
--- a/xpcom/idl-parser/xpidl/header.py
+++ b/xpcom/idl-parser/xpidl/header.py
@@ -106,16 +106,29 @@ def paramlistAsNative(m, empty='void'):
     if not m.notxpcom and m.realtype.name != 'void':
         l.append(paramAsNative(xpidl.Param(paramtype='out',
                                            type=None,
                                            name='_retval',
                                            attlist=[],
                                            location=None,
                                            realtype=m.realtype)))
 
+    # Set any optional out params to default to nullptr. Skip if we just added
+    # extra non-optional args to l.
+    if len(l) == len(m.params):
+        paramIter = len(m.params) - 1
+        while (paramIter >= 0 and m.params[paramIter].optional and
+                m.params[paramIter].paramtype == "out"):
+            t = m.params[paramIter].type
+            # Strings can't be optional, so this shouldn't happen, but let's make sure:
+            if t == "AString" or t == "ACString" or t == "DOMString" or t == "AUTF8String":
+                break
+            l[paramIter] += " = nullptr"
+            paramIter -= 1
+
     if len(l) == 0:
         return empty
 
     return ", ".join(l)
 
 
 def paramAsNative(p):
     return "%s%s" % (p.nativeType(),