Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(22)

Side by Side Diff: ppapi/generators/idl_c_header.py

Issue 13973011: Pepper IDL: Check for structs in callbacks. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes for mseaborn Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """ Generator for C style prototypes and definitions """ 6 """ Generator for C style prototypes and definitions """
7 7
8 import glob 8 import glob
9 import os 9 import os
10 import re 10 import re
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 form = 'PP_COMPILE_ASSERT_SIZE_IN_BYTES(%s, %s);\n' 132 form = 'PP_COMPILE_ASSERT_SIZE_IN_BYTES(%s, %s);\n'
133 else: 133 else:
134 form = 'PP_COMPILE_ASSERT_SIZE_IN_BYTES(%s, %s);\n' 134 form = 'PP_COMPILE_ASSERT_SIZE_IN_BYTES(%s, %s);\n'
135 item += form % (name, asize[0]) 135 item += form % (name, asize[0])
136 136
137 if item: out.Write(item) 137 if item: out.Write(item)
138 if last_group: 138 if last_group:
139 out.Write(CommentLines(['*',' @}', '']) + '\n') 139 out.Write(CommentLines(['*',' @}', '']) + '\n')
140 140
141 141
142 def CheckTypedefs(filenode, releases):
143 """Checks that typedefs don't specify callbacks that take some structs.
144
145 See http://crbug.com/233439 for details.
146 """
147 cgen = CGen()
148 # TODO(teravest): Allow PP_Var structs to be passed as callback parameters.
Mark Seaborn 2013/04/23 15:08:47 We don't want to allow PP_Var to be passed by valu
149 node_whitelist = ('PP_Ext_Alarms_OnAlarm_Func_Dev_0_1',)
Mark Seaborn 2013/04/23 15:08:47 Nit: '[]' lists are a little neater than '(,)' tup
150 for node in filenode.GetListOf('Typedef'):
151 if node.GetName() in node_whitelist:
152 continue
153 build_list = node.GetUniqueReleases(releases)
154 callnode = node.GetOneOf('Callspec')
155 if callnode:
156 for param in callnode.GetListOf('Param'):
157 if param.GetListOf('Array'):
158 continue
159 if cgen.GetParamMode(param) != 'in':
160 continue
161 t = param.GetType(build_list[0])
162 if t.IsA('Struct'):
Mark Seaborn 2013/04/23 15:08:47 How about: while t.IsA('Typedef'): t = t.GetTyp
163 raise Exception('%s is a struct in callback %s. '
164 'See http://crbug.com/233439' %
165 (t.GetName(), node.GetName()))
166 elif t.IsA('Typedef'):
167 if t.GetType(build_list[0]).IsA('Struct'):
168 raise Exception('%s is a struct in callback %s. '
169 'See http://crbug.com/233439' %
170 (t.GetName(), node.GetName()))
171
142 class HGen(GeneratorByFile): 172 class HGen(GeneratorByFile):
143 def __init__(self): 173 def __init__(self):
144 Generator.__init__(self, 'C Header', 'cgen', 'Generate the C headers.') 174 Generator.__init__(self, 'C Header', 'cgen', 'Generate the C headers.')
145 175
146 def GenerateFile(self, filenode, releases, options): 176 def GenerateFile(self, filenode, releases, options):
177 CheckTypedefs(filenode, releases)
147 savename = GetHeaderFromNode(filenode, GetOption('dstroot')) 178 savename = GetHeaderFromNode(filenode, GetOption('dstroot'))
148 my_min, my_max = filenode.GetMinMax(releases) 179 my_min, my_max = filenode.GetMinMax(releases)
149 if my_min > releases[-1] or my_max < releases[0]: 180 if my_min > releases[-1] or my_max < releases[0]:
150 if os.path.isfile(savename): 181 if os.path.isfile(savename):
151 print "Removing stale %s for this range." % filenode.GetName() 182 print "Removing stale %s for this range." % filenode.GetName()
152 os.remove(os.path.realpath(savename)) 183 os.remove(os.path.realpath(savename))
153 return False 184 return False
154 185
155 out = IDLOutFile(savename) 186 out = IDLOutFile(savename)
156 self.GenerateHead(out, filenode, releases, options) 187 self.GenerateHead(out, filenode, releases, options)
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 print "Golden file for M13-M15 failed." 321 print "Golden file for M13-M15 failed."
291 failed =1 322 failed =1
292 else: 323 else:
293 print "Golden file for M13-M15 passed." 324 print "Golden file for M13-M15 passed."
294 325
295 return failed 326 return failed
296 327
297 if __name__ == '__main__': 328 if __name__ == '__main__':
298 sys.exit(main(sys.argv[1:])) 329 sys.exit(main(sys.argv[1:]))
299 330
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698