Changeset 4879 for trunk/src/host/pye17/codegen/codegen.py
- Timestamp:
- 12/23/08 10:24:23 (4 years ago)
- File:
-
- 1 edited
-
trunk/src/host/pye17/codegen/codegen.py (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/host/pye17/codegen/codegen.py
r4694 r4879 205 205 ) 206 206 207 cb_function_tmpl = ( 208 'static PyObject *%(cb_name)s_obj = NULL;\n\n' 209 'void %(c_name)s_cb(void)\n' 210 '{\n' 211 ' PyObject *arglist = NULL;\n\n' 212 ' if (%(cb_name)s_obj != NULL)\n' 213 ' PyEval_CallObject(%(cb_name)s_obj, arglist);\n' 214 '}\n\n' 215 ) 216 207 217 virtual_accessor_tmpl = ( 208 218 'static PyObject *\n' … … 278 288 # Maybe this could be done in a nicer way, but I'll leave it as it is 279 289 # for now: -- Johan 280 if not self.overrides.slot_is_overriden('%s.tp_init' % 281 self.objinfo.c_name): 282 substdict['tp_init'] = self.write_constructor() 290 if not self.overrides.slot_is_overriden('%s.tp_init' % self.objinfo.c_name): 291 #import sys 292 #sys.stderr.write("tp_init: " + str(self.objinfo.c_name) + "\n") 293 substdict['tp_init'] = self.write_constructor() 283 294 substdict['tp_methods'] = self.write_methods() 284 295 substdict['tp_getset'] = self.write_getsets() … … 303 314 self.write_virtuals() 304 315 305 def write_function_wrapper(self, function_obj, template, 316 def write_function_wrapper(self, function_obj, template, cb_template, 306 317 handle_return=0, is_method=0, kwargs_needed=0, 307 318 substdict=None): … … 311 322 312 323 info = argtypes.WrapperInfo() 324 info.function_c_name = function_obj.c_name 325 info.piscb = 0 313 326 314 327 substdict.setdefault('errorreturn', 'NULL') … … 329 342 info.add_parselist('|', [], []) 330 343 handler = argtypes.matcher.get(param.ptype) 344 if param.piscb: 345 info.piscb += 1 331 346 #fd.write("pname: " + param.pname + "; ptype: " + str(param.ptype) + "; pdflt: " + str(param.pdflt) + "; pnull: " + str(param.pnull) + "; handler: " + str(handler) + "\n") 332 347 handler.write_param(param.ptype, param.pname, param.pdflt, 333 param.pnull, info )348 param.pnull, info, param.piscb) 334 349 335 350 #fd.write("arglist 2: " + str(info.get_arglist()) + "\n") … … 368 383 substdict['typecodes'] = info.parsestr 369 384 substdict['parselist'] = info.get_parselist() 385 370 386 substdict['arglist'] = info.get_arglist() 387 388 substdict['cb_code'] = "" 389 390 # TODO: deal with more arguments 391 if info.piscb > 0: 392 substdict['arglist'] = ", &" + function_obj.c_name + "_cb" 393 substdict['cb_code'] = cb_template % {'c_name': function_obj.c_name, 394 'cb_name': function_obj.c_name} 395 template = substdict['cb_code'] + template 396 sys.stderr.write("cb_code: %s\n" % substdict['cb_code']) 397 371 398 substdict['codebefore'] = deprecated + ( 372 399 string.replace(info.get_codebefore(), … … 390 417 flags = 'METH_NOARGS' 391 418 392 #fd.write("arglist: " + str(info.get_arglist()) + "\n")393 419 #for key,item in substdict.iteritems(): 394 # fd.write("key: " + str(key) + ", item: " + str(item) + "\n") 395 #fd.close() 396 420 #sys.stderr.write("key: " + str(key) + ", item: " + str(item) + "\n") 421 422 if info.piscb > 0: 423 sys.stderr.write("template: %s\n" % (template % substdict)) 424 #sys.stderr.write("cb_code (again): %s\n" % substdict['cb_code']) 425 #substdict['callback_code'] = 'balbla' 426 #for key,item in substdict.iteritems(): 427 #sys.stderr.write("key: " + str(key) + ", item: " + str(item) + "\n") 397 428 return template % substdict, flags 398 429 399 430 def write_constructor(self): 400 431 initfunc = '0' 432 #import sys 433 #sys.stderr.write("searching constructor ...\n") 401 434 constructor = self.parser.find_constructor(self.objinfo,self.overrides) 402 435 if not constructor: 403 436 return self.write_default_constructor() 404 437 438 #sys.stderr.write("constructor: " + str(constructor.c_name) + "\n") 405 439 funcname = constructor.c_name 406 440 try: … … 431 465 432 466 # write constructor from template ... 467 #sys.stderr.write("constructor: " + str(funcname) + ", tmpl:" + str(self.constructor_tmpl) + "\n") 433 468 code = self.write_function_wrapper(constructor, 434 469 self.constructor_tmpl, … … 506 541 # write constructor from template ... 507 542 code, methflags = self.write_function_wrapper(meth, 508 self.method_tmpl, handle_return=1, is_method=1,509 substdict=self.get_initial_method_substdict(meth))543 self.method_tmpl, self.cb_function_tmpl, handle_return=1, 544 is_method=1, substdict=self.get_initial_method_substdict(meth)) 510 545 self.fp.write(code) 511 546 methods.append(self.methdef_tmpl % … … 857 892 # write constructor from template ... 858 893 code, methflags = self.write_function_wrapper(func, 859 self.function_tmpl, handle_return=1, is_method=0)894 self.function_tmpl, self.cb_function_tmpl, handle_return=1, is_method=0) 860 895 self.fp.write(code) 861 896 functions.append((func.name, '_wrap_' + funcname,
Note: See TracChangeset
for help on using the changeset viewer.
