Changeset 4879
- Timestamp:
- 12/23/08 10:24:23 (4 years ago)
- Location:
- trunk/src/host/pye17
- Files:
-
- 7 edited
-
Makefile (modified) (1 diff)
-
codegen/argtypes.py (modified) (33 diffs)
-
codegen/codegen.py (modified) (10 diffs)
-
codegen/definitions.py (modified) (3 diffs)
-
codegen/h2def.py (modified) (4 diffs)
-
ecore_evas/ecore_evas.override (modified) (1 diff)
-
examples/ecore_evas/simple_window.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/host/pye17/Makefile
r4720 r4879 3 3 ifeq ($(wildcard $(E_PATH)),) 4 4 5 E_PATH_TMP=~/openmoko/e 175 E_PATH_TMP=~/openmoko/e 6 6 ifneq ($(wildcard $(E_PATH_TMP)),) 7 7 E_PATH = $(E_PATH_TMP) -
trunk/src/host/pye17/codegen/argtypes.py
r4694 r4879 77 77 78 78 class ArgType: 79 def write_param(self, ptype, pname, pdflt, pnull, info ):79 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 80 80 """Add code to the WrapperInfo instance to handle 81 81 parameter.""" … … 95 95 96 96 class StringArg(ArgType): 97 def write_param(self, ptype, pname, pdflt, pnull, info ):97 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 98 98 if pdflt != None: 99 99 if pdflt != 'NULL': pdflt = '"' + pdflt + '"' … … 125 125 126 126 class StringPtrArg(ArgType): 127 def write_param(self, ptype, pname, pdflt, pnull, info ):127 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 128 128 if pdflt != None: 129 129 if pdflt != 'NULL': pdflt = '"' + pdflt + '"' … … 156 156 class UCharArg(ArgType): 157 157 # allows strings with embedded NULLs. 158 def write_param(self, ptype, pname, pdflt, pnull, info ):158 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 159 159 if pdflt: 160 160 info.varlist.add('guchar', '*' + pname + ' = "' + pdflt + '"') … … 174 174 175 175 class CharArg(ArgType): 176 def write_param(self, ptype, pname, pdflt, pnull, info ):176 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 177 177 if pdflt: 178 178 info.varlist.add('char', pname + " = '" + pdflt + "'") … … 193 193 ' py_ret = (Py_UNICODE)ret;\n' 194 194 ' return PyUnicode_FromUnicode(&py_ret, 1);\n') 195 def write_param(self, ptype, pname, pdflt, pnull, info ):195 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 196 196 if pdflt: 197 197 info.varlist.add('gunichar', pname + " = '" + pdflt + "'") … … 207 207 208 208 class IntArg(ArgType): 209 def write_param(self, ptype, pname, pdflt, pnull, info ):209 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 210 210 if pdflt: 211 211 info.varlist.add('int', pname + ' = ' + pdflt) … … 237 237 ' if (PyErr_Occurred())\n' 238 238 ' return NULL;\n') 239 def write_param(self, ptype, pname, pdflt, pnull, info ):239 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 240 240 if not pdflt: 241 241 pdflt = '0'; … … 260 260 llp64 = False 261 261 262 def write_param(self, ptype, pname, pdflt, pnull, info ):262 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 263 263 if pdflt: 264 264 info.varlist.add(ptype, pname + ' = ' + pdflt) … … 284 284 llp64 = False 285 285 286 def write_param(self, ptype, pname, pdflt, pnull, info ):286 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 287 287 if pdflt: 288 288 info.varlist.add(ptype, pname + ' = ' + pdflt) … … 302 302 303 303 class LongArg(ArgType): 304 def write_param(self, ptype, pname, pdflt, pnull, info ):304 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 305 305 if pdflt: 306 306 info.varlist.add(ptype, pname + ' = ' + pdflt) … … 319 319 320 320 class TimeTArg(ArgType): 321 def write_param(self, ptype, pname, pdflt, pnull, info ):321 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 322 322 if pdflt: 323 323 info.varlist.add('time_t', pname + ' = ' + pdflt) … … 331 331 332 332 class ULongArg(ArgType): 333 def write_param(self, ptype, pname, pdflt, pnull, info ):333 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 334 334 if pdflt: 335 335 info.varlist.add('unsigned long', pname + ' = ' + pdflt) … … 343 343 344 344 class UInt32Arg(ULongArg): 345 def write_param(self, ptype, pname, pdflt, pnull, info ):345 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 346 346 ULongArg.write_param(self, ptype, pname, pdflt, pnull, info) 347 347 ## if sizeof(unsigned long) > sizeof(unsigned int), we need to … … 357 357 358 358 class Int64Arg(ArgType): 359 def write_param(self, ptype, pname, pdflt, pnull, info ):359 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 360 360 if pdflt: 361 361 info.varlist.add('gint64', pname + ' = ' + pdflt) … … 372 372 ' %(name)s = PyLong_AsUnsignedLongLong(py_%(name)s);\n' 373 373 before = ' %(name)s = PyLong_AsUnsignedLongLong(py_%(name)s);\n' 374 def write_param(self, ptype, pname, pdflt, pnull, info ):374 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 375 375 if pdflt: 376 376 info.varlist.add('guint64', pname + ' = ' + pdflt) … … 388 388 389 389 class DoubleArg(ArgType): 390 def write_param(self, ptype, pname, pdflt, pnull, info ):390 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 391 391 if pdflt: 392 392 info.varlist.add('double', pname + ' = ' + pdflt) … … 416 416 dflt = (' if (py_%(name)s)\n' 417 417 ' %(name)s = PyFile_AsFile(py_%(name)s);\n') 418 def write_param(self, ptype, pname, pdflt, pnull, info ):418 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 419 419 if pnull: 420 420 if pdflt: … … 451 451 self.enumname = enumname 452 452 self.typecode = typecode 453 def write_param(self, ptype, pname, pdflt, pnull, info ):453 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 454 454 if pdflt: 455 455 info.varlist.add(self.enumname, pname + ' = ' + pdflt) … … 471 471 self.flagname = flagname 472 472 self.typecode = typecode 473 def write_param(self, ptype, pname, pdflt, pnull, info ):473 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 474 474 if pdflt: 475 475 info.varlist.add(self.flagname, pname + ' = ' + pdflt) … … 511 511 self.cast = string.replace(typecode, '_TYPE_', '_', 1) 512 512 self.parent = parent 513 def write_param(self, ptype, pname, pdflt, pnull, info ):513 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 514 514 if pnull: 515 515 if pdflt: … … 591 591 self.typename = ptype 592 592 self.typecode = typecode 593 def write_param(self, ptype, pname, pdflt, pnull, info ):593 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 594 594 if pnull: 595 595 info.varlist.add(self.typename, '*' + pname + ' = NULL') … … 646 646 self.checker = 'Py' + ptype + '_Check' 647 647 self.new = new 648 def write_param(self, ptype, pname, pdflt, pnull, info ):648 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 649 649 if pnull: 650 650 info.varlist.add(ptype[:-1], '*' + pname + ' = NULL') … … 681 681 ' return NULL;\n' 682 682 ' }\n') 683 cb = (' if (!PyCallable_Check(py_%(name)s)) {\n' 684 ' PyErr_SetString(PyExc_TypeError, "parameter must be callable");\n' 685 ' return NULL;\n' 686 ' }\n\n' 687 ' /* Py_XINCREF & Py_XDECREF are NULL safe */\n' 688 ' Py_XINCREF(py_%(name)s); /* Add a reference to new callback */\n' 689 ' Py_XDECREF(%(cb_name)s_obj); /* Dispose of previous callback */\n' 690 ' %(cb_name)s_obj = py_%(name)s; /* Remember new callback */\n') 683 691 def __init__(self, ptype, typecode): 684 692 self.typename = ptype 685 693 self.typecode = typecode 686 def write_param(self, ptype, pname, pdflt, pnull, info ):694 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 687 695 if self.typename == "unsigned-int": 688 696 local_typename = "unsigned int" … … 690 698 local_typename = self.typename 691 699 692 if pnull: 700 if piscb: 701 info.varlist.add(local_typename, '*' + pname + ' = NULL') 702 info.varlist.add('PyObject', '*py_' + pname + ' = Py_None') 703 info.codebefore.append(self.cb % {'name': pname, 704 'cb_name': info.function_c_name}) 705 706 elif pnull: 693 707 info.varlist.add(local_typename, '*' + pname + ' = NULL') 694 708 info.varlist.add('PyObject', '*py_' + pname + ' = Py_None') … … 723 737 ' if (PyErr_Occurred())\n' 724 738 ' return NULL;\n') 725 def write_param(self, ptype, pname, pdflt, pnull, info ):739 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 726 740 if pdflt: 727 741 info.varlist.add('GdkAtom', pname + ' = ' + pdflt) … … 746 760 gtype = (' if ((%(name)s = pyg_type_from_object(py_%(name)s)) == 0)\n' 747 761 ' return NULL;\n') 748 def write_param(self, ptype, pname, pdflt, pnull, info ):762 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 749 763 info.varlist.add('GType', pname) 750 764 info.varlist.add('PyObject', '*py_' + pname + ' = NULL') … … 760 774 handleerror = (' if (pyg_error_check(&%(name)s))\n' 761 775 ' return NULL;\n') 762 def write_param(self, ptype, pname, pdflt, pnull, info ):776 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 763 777 info.varlist.add('GError', '*' + pname + ' = NULL') 764 778 info.arglist.append('&' + pname) … … 783 797 def __init__(self): 784 798 pass 785 def write_param(self, ptype, pname, pdflt, pnull, info ):799 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 786 800 if pnull: 787 801 info.varlist.add('GtkTreePath', '*' + pname + ' = NULL') … … 824 838 ' else\n' 825 839 ' return NULL;\n') 826 def write_param(self, ptype, pname, pdflt, pnull, info ):840 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 827 841 if pnull: 828 842 info.varlist.add('GdkRectangle', pname + '_rect = { 0, 0, 0, 0 }') … … 845 859 846 860 class PyObjectArg(ArgType): 847 def write_param(self, ptype, pname, pdflt, pnull, info ):861 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 848 862 info.varlist.add('PyObject', '*' + pname) 849 863 info.add_parselist('O', ['&' + pname], [pname]) … … 863 877 864 878 class CairoArg(ArgType): 865 def write_param(self, ptype, pname, pdflt, pnull, info ):879 def write_param(self, ptype, pname, pdflt, pnull, info, piscb): 866 880 info.varlist.add('PycairoContext', '*' + pname) 867 881 info.add_parselist('O!', ['&PycairoContext_Type', '&' + pname], [pname]) … … 902 916 self.register(ptype, FlagsArg(ptype, typecode)) 903 917 def register_object(self, ptype, parent, typecode): 904 #fd = open("/tmp/debug.log","a") 905 #fd.write("ptype: " + str(ptype) + ", parent:" + str(parent) + ", typecode: " + str(typecode) + "\n") 906 #fd.close() 918 #import sys 919 #sys.stderr.write("ptype: " + str(ptype) + ", parent:" + str(parent) + ", typecode: " + str(typecode) + "\n") 907 920 oa = ObjectArg(ptype, parent, typecode) 908 921 self.register(ptype, oa) # in case I forget the * in the .defs -
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, -
trunk/src/host/pye17/codegen/definitions.py
r4658 r4879 15 15 # New Parameter class, wich emulates a tuple for compatibility reasons 16 16 class Parameter(object): 17 def __init__(self, ptype, pname, pdflt, pnull, pdir=None ):17 def __init__(self, ptype, pname, pdflt, pnull, pdir=None, piscb=0): 18 18 self.ptype = ptype 19 19 self.pname = pname … … 21 21 self.pnull = pnull 22 22 self.pdir = pdir 23 self.piscb = piscb 23 24 24 25 def __len__(self): return 4 … … 310 311 pnull = 0 311 312 pdir = None 313 piscb = 0 312 314 for farg in parg[2:]: 313 assert isinstance(farg, tuple) 314 if farg[0] == 'default': 315 pdflt = farg[1] 316 elif farg[0] == 'null-ok': 317 pnull = 1 318 elif farg[0] == 'direction': 319 pdir = farg[1] 320 self.params.append(Parameter(ptype, pname, pdflt, pnull, pdir)) 315 if farg == 'is_callback': 316 piscb = 1 317 continue 318 assert isinstance(farg, tuple) 319 if farg[0] == 'default': 320 pdflt = farg[1] 321 elif farg[0] == 'null-ok': 322 pnull = 1 323 elif farg[0] == 'direction': 324 pdir = farg[1] 325 self.params.append(Parameter(ptype, pname, pdflt, pnull, pdir, piscb)) 321 326 elif arg[0] == 'varargs': 322 327 self.varargs = arg[1] in ('t', '#t') -
trunk/src/host/pye17/codegen/h2def.py
r4691 r4879 483 483 if callback > -1: 484 484 func_name_end = argument.find(')') 485 argument = 'void* callback_' + argument[callback+1:func_name_end].lstrip("* ") 486 spaces = string.count(argument, ' ') 487 if spaces > 1: 488 argument = string.replace(argument, ' ', '-', spaces - 1) 489 #print "argument: " + argument + "; num spaces: " + str(spaces) 485 argument = 'void* cb_' + argument[callback+1:func_name_end].lstrip("* ") + ' *is_callback*' 486 else: 487 spaces = string.count(argument, ' ') 488 if spaces > 1: 489 argument = string.replace(argument, ' ', '-', spaces - 1) 490 #print "argument: " + argument + "; num spaces: " + str(spaces) 491 492 #sys.stderr.write('append argument: ' + argument + '\n') 490 493 arguments.append(argument) 491 494 … … 553 556 if mname[:l] == self.prefix and mname[l+1] == '_': 554 557 mname = mname[l+1:] 558 559 if mname.find("callback") > -1: 560 mname = mname.replace("callback", "cb") 561 555 562 self.fp.write('(define-method ' + mname + '\n') 556 563 self.fp.write(' (of-object "' + obj + '")\n') … … 577 584 for arg in args: 578 585 if arg != '...': 579 tupleArg = tuple(string.split(arg)) 580 if len(tupleArg) == 2: 586 tupleArg = tuple(string.split(arg)) 587 is_callback = 0 588 if len(tupleArg) == 3 and tupleArg[2] == "*is_callback*": 589 is_callback = 1 590 if len(tupleArg) == 2 or is_callback: 581 591 var_type = tupleArg[0] 582 592 # some variable types are not supported … … 584 594 #var_type = "guint" # see gtypes.h 585 595 #print "var type: " + var_type 586 self.fp.write(' \'("%s" "%s")\n' % (var_type, tupleArg[1])) 596 self.fp.write(' \'("%s" "%s"' % (var_type, tupleArg[1])) 597 if is_callback: 598 self.fp.write(' "is_callback"') 599 self.fp.write(')\n') 587 600 self.fp.write(' )\n') 588 601 if is_varargs: -
trunk/src/host/pye17/ecore_evas/ecore_evas.override
r4720 r4879 87 87 return (PyObject *)new_self; 88 88 } 89 %% -
trunk/src/host/pye17/examples/ecore_evas/simple_window.py
r4719 r4879 3 3 import ecore 4 4 import ecore_evas 5 6 7 def on_resize(): 8 print "resizing window" 5 9 6 10 try: … … 10 14 11 15 window.title_set("TestWindow") 16 window.cb_resize_set(on_resize) 12 17 window.show() 13 18
Note: See TracChangeset
for help on using the changeset viewer.
