From: Marcelo M. <mar...@us...> - 2005-12-14 07:28:38
|
Update of /cvsroot/swig/SWIG/Source/Modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24973/Source/Modules Modified Files: python.cxx Log Message: add the -fastunpack/-nofastunpack options to avoid using python native UnpackTuple Index: python.cxx =================================================================== RCS file: /cvsroot/swig/SWIG/Source/Modules/python.cxx,v retrieving revision 1.149 retrieving revision 1.150 diff -C2 -d -r1.149 -r1.150 *** python.cxx 11 Dec 2005 10:44:56 -0000 1.149 --- python.cxx 14 Dec 2005 07:28:30 -0000 1.150 *************** *** 67,70 **** --- 67,71 ---- static int dirvtable = 0; static int proxydel = 1; + static int fastunpack = 0; /* flags for the make_autodoc function */ *************** *** 106,111 **** -proxydel - Generate a __del__ method even when now is redundant (default) \n\ -noproxydel - Don't generate the redundant __del__ method \n\ -O - Enable several old and new optimizations options: \n\ ! -modern -fastdispatch -dirvtable -nosafecstrings -fvirtual -noproxydel \n\ \n"; --- 107,114 ---- -proxydel - Generate a __del__ method even when now is redundant (default) \n\ -noproxydel - Don't generate the redundant __del__ method \n\ + -fastunpack - Use fast unpack mechanism to parse the argument functions \n\ + -nofastunpack - Use traditional UnpackTuple method to parse the argument functions (default) \n\ -O - Enable several old and new optimizations options: \n\ ! -modern -fastdispatch -dirvtable -nosafecstrings -fvirtual -noproxydel -fastunpack\n\ \n"; *************** *** 279,282 **** --- 282,291 ---- dirvtable = 0; Swig_mark_arg(i); + } else if (strcmp(argv[i],"-fastunpack") == 0) { + fastunpack = 1; + Swig_mark_arg(i); + } else if (strcmp(argv[i],"-nofastunpack") == 0) { + fastunpack = 0; + Swig_mark_arg(i); } else if (strcmp(argv[i],"-proxydel") == 0) { proxydel = 1; *************** *** 309,312 **** --- 318,322 ---- classptr = 0; proxydel = 0; + fastunpack = 1; Wrapper_fast_dispatch_mode_set(1); Wrapper_virtual_elimination_mode_set(1); *************** *** 1224,1232 **** * ------------------------------------------------------------ */ ! void add_method(String *name, String *function, int kw, Node *n = 0) { ! if (!kw) ! Printf(methods,"\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function); ! else Printf(methods,"\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, ", name, function); if (n && GetFlag(n,"feature:callback")) { --- 1234,1254 ---- * ------------------------------------------------------------ */ ! void add_method(String *name, String *function, int kw, Node *n = 0, ! int funpack = 0, int num_required = -1, int num_arguments = -1) { ! if (!kw) { ! if (n && funpack) { ! if (num_required == 0 && num_arguments == 0) { ! Printf(methods,"\t { (char *)\"%s\", (PyCFunction)%s, METH_NOARGS, ", name, function); ! } else if (num_required == 1 && num_arguments == 1) { ! Printf(methods,"\t { (char *)\"%s\", (PyCFunction)%s, METH_O, ", name, function); ! } else { ! Printf(methods,"\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function); ! } ! } else { ! Printf(methods,"\t { (char *)\"%s\", %s, METH_VARARGS, ", name, function); ! } ! } else { Printf(methods,"\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, ", name, function); + } if (n && GetFlag(n,"feature:callback")) { *************** *** 1251,1255 **** * dispatchFunction() * ------------------------------------------------------------ */ ! void dispatchFunction(Node *n) { /* Last node in overloaded chain */ --- 1273,1277 ---- * dispatchFunction() * ------------------------------------------------------------ */ ! void dispatchFunction(Node *n, int funpack = 0) { /* Last node in overloaded chain */ *************** *** 1258,1262 **** String *tmp = NewString(""); ! String *dispatch = Swig_overload_dispatch(n,"return %s(self,args);",&maxargs); /* Generate a dispatch wrapper for all overloaded functions */ --- 1280,1288 ---- String *tmp = NewString(""); ! ! String *dispatch = funpack ? ! Swig_overload_dispatch(n,"return %s(self, argv);",&maxargs) ! : Swig_overload_dispatch(n,"return %s(self, args);",&maxargs); ! /* Generate a dispatch wrapper for all overloaded functions */ *************** *** 1274,1285 **** Printf(tmp,"PyObject *argv[%d]", maxargs+1); Wrapper_add_local(f,"argv",tmp); - Wrapper_add_local(f,"ii","int ii"); - if (allow_thread) thread_begin_block(n, f->code); ! Printf(f->code,"argc = PyObject_Length(args);\n"); ! Printf(f->code,"for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n",maxargs); ! Printf(f->code,"argv[ii] = PyTuple_GetItem(args,ii);\n"); ! Printf(f->code,"}\n"); Replaceall(dispatch,"$args","self,args"); --- 1300,1317 ---- Printf(tmp,"PyObject *argv[%d]", maxargs+1); Wrapper_add_local(f,"argv",tmp); if (allow_thread) thread_begin_block(n, f->code); ! if (!fastunpack) { ! Wrapper_add_local(f,"ii","int ii"); ! Printf(f->code,"argc = PyObject_Length(args);\n"); ! Printf(f->code,"for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n",maxargs); ! Printf(f->code,"argv[ii] = PyTuple_GetItem(args,ii);\n"); ! Printf(f->code,"}\n"); ! } else { ! String *iname = Getattr(n,"sym:name"); ! Printf(f->code,"argc = SWIG_Python_UnpackTuple(args,\"%s\",0,%d,argv);\n", iname, maxargs); ! Printf(f->code,"if (!argc) { return NULL; } else { --argc; }\n"); ! } ! Replaceall(dispatch,"$args","self,args"); *************** *** 1389,1393 **** num_required = emit_num_required(l); varargs = emit_isvarargs(l); ! String *nw = Swig_name_wrapper(iname); strcpy(wname,Char(nw)); --- 1421,1428 ---- num_required = emit_num_required(l); varargs = emit_isvarargs(l); ! int funpack = fastunpack && !varargs && !allow_kwargs ; ! int noargs = funpack && (num_required == 0 && num_arguments == 0); ! int onearg = funpack && (num_required == 1 && num_arguments == 1); ! String *nw = Swig_name_wrapper(iname); strcpy(wname,Char(nw)); *************** *** 1399,1411 **** if (!allow_kwargs || Getattr(n,"sym:overloaded")) { if (!varargs) { ! Printv(f->def, ! "SWIGINTERN PyObject *", wname, ! "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", ! NIL); } else { ! Printv(f->def, ! "SWIGINTERN PyObject *", wname, "__varargs__", ! "(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *varargs) {", ! NIL); } if (allow_kwargs) { --- 1434,1442 ---- if (!allow_kwargs || Getattr(n,"sym:overloaded")) { if (!varargs) { ! Printv(f->def, "SWIGINTERN PyObject *", wname, ! "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); } else { ! Printv(f->def, "SWIGINTERN PyObject *", wname, "__varargs__", ! "(PyObject *SWIGUNUSEDPARM(self), PyObject *args, PyObject *varargs) {", NIL); } if (allow_kwargs) { *************** *** 1426,1440 **** } if (!allow_kwargs) { ! Printf(parse_args," if(!PyArg_ParseTuple(args,(char *)\""); } else { ! Printf(parse_args," if(!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)\""); Printf(arglist,",kwnames"); } /* Generate code for argument marshalling */ int use_parse = 0; ! Printf(kwargs,"{"); ! for (i = 0, p=l; i < num_arguments; i++) { ! while (checkAttribute(p,"tmap:in:numinputs","0")) { p = Getattr(p,"tmap:in:next"); --- 1457,1477 ---- } if (!allow_kwargs) { ! Printf(parse_args," if (!PyArg_ParseTuple(args,(char *)\""); } else { ! Printf(parse_args," if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)\""); Printf(arglist,",kwnames"); } /* Generate code for argument marshalling */ + if (funpack) { + if (!overname && num_arguments) { + sprintf(source,"obj[%d]",num_arguments); + Wrapper_add_localv(f, "obj", "PyObject *",source, NIL); + } + } + int use_parse = 0; ! Printf(kwargs,"{"); ! for (i = 0, p=l; i < num_arguments; i++) { while (checkAttribute(p,"tmap:in:numinputs","0")) { p = Getattr(p,"tmap:in:next"); *************** *** 1444,1450 **** String *pn = Getattr(p,"name"); String *ln = Getattr(p,"lname"); ! ! sprintf(source,"obj%d",i); ! Putc(',',arglist); if (i == num_required) Putc('|', parse_args); /* Optional argument separator */ --- 1481,1491 ---- String *pn = Getattr(p,"name"); String *ln = Getattr(p,"lname"); ! if (funpack) { ! sprintf(source,"obj[%d]",i); ! } else { ! sprintf(source,"obj%d",i); ! } ! ! Putc(',',arglist); if (i == num_required) Putc('|', parse_args); /* Optional argument separator */ *************** *** 1471,1474 **** --- 1512,1520 ---- String *parse = Getattr(p,"tmap:in:parse"); if (!parse) { + if (funpack) { + Replaceall(tm,"$self","obj[0]"); + } else{ + Replaceall(tm,"$self","obj0"); + } Replaceall(tm,"$source",source); Replaceall(tm,"$target",ln); *************** *** 1483,1488 **** Putc('O',parse_args); ! Wrapper_add_localv(f, source, "PyObject *",source, "= 0", NIL); ! Printf(arglist,"&%s",source); if (i >= num_required) Printv(get_pointers, "if (", source, ") {\n", NIL); --- 1529,1536 ---- Putc('O',parse_args); ! if (!funpack) { ! Wrapper_add_localv(f, source, "PyObject *",source, "= 0", NIL); ! Printf(arglist,"&%s",source); ! } if (i >= num_required) Printv(get_pointers, "if (", source, ") {\n", NIL); *************** *** 1515,1525 **** Printf(parse_args,":%s\"", iname); Printv(parse_args,arglist, ")) goto fail;\n",NIL); } else { Clear(parse_args); ! Printf(parse_args,"if(!PyArg_UnpackTuple(args,(char *)\"%s\",%d,%d", iname, num_required, num_arguments); ! Printv(parse_args,arglist, ")) goto fail;\n",NIL); } - - /* Now piece together the first part of the wrapper function */ --- 1563,1599 ---- Printf(parse_args,":%s\"", iname); Printv(parse_args,arglist, ")) goto fail;\n",NIL); + funpack = 0; } else { Clear(parse_args); ! if (funpack) { ! Clear(f->def); ! if (overname) { ! if (noargs) { ! Printv(f->def, "SWIGINTERN PyObject *", wname, ! "(PyObject *SWIGUNUSEDPARM(self), PyObject **SWIGUNUSEDPARM(obj)) {", NIL); ! } else{ ! Printv(f->def, "SWIGINTERN PyObject *", wname, ! "(PyObject *SWIGUNUSEDPARM(self), PyObject **obj) {", NIL); ! } ! } else { ! if (noargs) { ! Printv(f->def, "SWIGINTERN PyObject *", wname, ! "(PyObject *SWIGUNUSEDPARM(self), PyObject *SWIGUNUSEDPARM(args)) {", NIL); ! } else { ! Printv(f->def, "SWIGINTERN PyObject *", wname, ! "(PyObject *SWIGUNUSEDPARM(self), PyObject *args) {", NIL); ! } ! if (onearg) { ! Printf(parse_args,"if (!args) { goto fail; } else { obj[0] = args; }\n"); ! } else if (!noargs) { ! Printf(parse_args,"if(!SWIG_Python_UnpackTuple(args,\"%s\",%d,%d,obj)) goto fail;\n", ! iname, num_required, num_arguments); ! } ! } ! } else { ! Printf(parse_args,"if(!PyArg_UnpackTuple(args,(char *)\"%s\",%d,%d", iname, num_required, num_arguments); ! Printv(parse_args,arglist, ")) goto fail;\n",NIL); ! } } /* Now piece together the first part of the wrapper function */ *************** *** 1606,1610 **** Printf(f->code, "}\n"); } ! Printf(f->code, "if (director && (director->swig_get_self()==obj0)) director->swig_set_up();\n"); } } --- 1680,1688 ---- Printf(f->code, "}\n"); } ! if (funpack) { ! Printf(f->code, "if (director && (director->swig_get_self()==obj[0])) director->swig_set_up();\n"); ! } else { ! Printf(f->code, "if (director && (director->swig_get_self()==obj0)) director->swig_set_up();\n"); ! } } } *************** *** 1760,1763 **** --- 1838,1847 ---- Replaceall(f->code,"$result","resultobj"); + if (funpack) { + Replaceall(f->code,"$self","obj[0]"); + } else{ + Replaceall(f->code,"$self","obj0"); + } + /* Dump the function out */ Wrapper_print(f,f_wrappers); *************** *** 1788,1792 **** /* Now register the function with the interpreter. */ if (!Getattr(n,"sym:overloaded")) { ! add_method(iname, wname, allow_kwargs, n); /* Create a shadow for this function (if enabled and not in a member function) */ --- 1872,1876 ---- /* Now register the function with the interpreter. */ if (!Getattr(n,"sym:overloaded")) { ! add_method(iname, wname, allow_kwargs, n, funpack, num_required, num_arguments); /* Create a shadow for this function (if enabled and not in a member function) */ *************** *** 1796,1800 **** } else { if (!Getattr(n,"sym:nextSibling")) { ! dispatchFunction(n); } } --- 1880,1884 ---- } else { if (!Getattr(n,"sym:nextSibling")) { ! dispatchFunction(n, funpack); } } |