From: Marcelo M. <mar...@us...> - 2004-10-01 21:45:42
|
Update of /cvsroot/swig/SWIG/Source/Modules In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv7512/Modules Modified Files: python.cxx lang.cxx Log Message: fix %callback and add %pythoncallback Index: lang.cxx =================================================================== RCS file: /cvsroot/swig/SWIG/Source/Modules/lang.cxx,v retrieving revision 1.69 retrieving revision 1.70 diff -C2 -d -r1.69 -r1.70 *** lang.cxx 3 Sep 2004 22:13:41 -0000 1.69 --- lang.cxx 1 Oct 2004 21:44:26 -0000 1.70 *************** *** 955,959 **** String *cb = Getattr(n,"feature:callback"); if (cb) { ! String *cbname = NewStringf(cb,symname); callbackfunctionHandler(n); if (Cmp(cbname, symname) == 0) { --- 955,964 ---- String *cb = Getattr(n,"feature:callback"); if (cb) { ! String *cbname = Getattr(n,"feature:callback:name"); ! if (!cbname) { ! cbname = NewStringf(cb,symname); ! Setattr(n,"feature:callback:name",cbname); ! } ! callbackfunctionHandler(n); if (Cmp(cbname, symname) == 0) { *************** *** 984,995 **** String *parms = Getattr(n,"parms"); String *cb = Getattr(n,"feature:callback"); ! String *cbname = NewStringf(cb,symname); SwigType *cbty = Copy(type); SwigType_add_function(cbty,parms); SwigType_add_pointer(cbty); Setattr(n,"sym:name", cbname); Setattr(n,"type", cbty); ! Setattr(n,"value", name); constantWrapper(n); --- 989,1006 ---- String *parms = Getattr(n,"parms"); String *cb = Getattr(n,"feature:callback"); ! String *cbname = Getattr(n,"feature:callback:name"); ! String *calltype= NewStringf("(%s (*)(%s))(%s)", SwigType_str(type,0), ParmList_str(parms), SwigType_namestr(name)); SwigType *cbty = Copy(type); SwigType_add_function(cbty,parms); SwigType_add_pointer(cbty); + if (!cbname) { + cbname = NewStringf(cb,symname); + Setattr(n,"feature:callback:name",cbname); + } + Setattr(n,"sym:name", cbname); Setattr(n,"type", cbty); ! Setattr(n,"value", calltype); constantWrapper(n); *************** *** 1016,1020 **** String *value = Getattr(n,"value"); ParmList *parms = Getattr(n,"parms"); ! String *cb; if (Cmp(storage,"virtual") == 0) { --- 1027,1031 ---- String *value = Getattr(n,"value"); ParmList *parms = Getattr(n,"parms"); ! String *cb = Getattr(n,"feature:callback"); if (Cmp(storage,"virtual") == 0) { *************** *** 1027,1047 **** IsVirtual = 0; } - cb = Getattr(n,"feature:callback"); if (cb) { ! Node *cb = NewHash(); ! String *cbname = NewStringf(cb,symname); ! String *cbvalue; SwigType *cbty = Copy(type); SwigType_add_function(cbty,parms); SwigType_add_memberpointer(cbty,ClassName); ! cbvalue = NewStringf("&%s::%s",ClassName,name); ! Setattr(cb,"sym:name", cbname); ! Setattr(cb,"type", cbty); ! Setattr(cb,"value", cbvalue); ! Setattr(cb,"name", name); ! memberconstantHandler(n); Delete(cb); Delete(cbvalue); Delete(cbty); --- 1038,1062 ---- IsVirtual = 0; } if (cb) { ! Node *cbn = NewHash(); ! String *cbname = Getattr(n,"feature:callback:name"); ! if (!cbname) { ! cbname = NewStringf(cb,symname); ! } ! SwigType *cbty = Copy(type); SwigType_add_function(cbty,parms); SwigType_add_memberpointer(cbty,ClassName); ! String *cbvalue = NewStringf("&%s::%s",ClassName,name); ! Setattr(cbn,"sym:name", cbname); ! Setattr(cbn,"type", cbty); ! Setattr(cbn,"value", cbvalue); ! Setattr(cbn,"name", name); ! memberconstantHandler(cbn); ! Setattr(n,"feature:callback:name",Swig_name_member(ClassPrefix, cbname)); Delete(cb); + Delete(cbn); Delete(cbvalue); Delete(cbty); *************** *** 1079,1082 **** --- 1094,1098 ---- ParmList *parms = Getattr(n,"parms"); String *code = Getattr(n,"code"); + String *cb = Getattr(n,"feature:callback"); String *cname, *mrename; *************** *** 1105,1109 **** --- 1121,1131 ---- Delete(wrap); } + if (cb) { + String *cbname = NewStringf(cb,symname); + Setattr(n,"feature:callback:name", Swig_name_member(ClassPrefix, cbname)); + Setattr(n,"feature:callback:staticname", name); + } Delattr(n,"storage"); + globalfunctionHandler(n); Index: python.cxx =================================================================== RCS file: /cvsroot/swig/SWIG/Source/Modules/python.cxx,v retrieving revision 1.51 retrieving revision 1.52 diff -C2 -d -r1.51 -r1.52 *** python.cxx 26 Sep 2004 00:49:41 -0000 1.51 --- python.cxx 1 Oct 2004 21:44:26 -0000 1.52 *************** *** 427,430 **** --- 427,439 ---- + int functionHandler(Node *n) { + if (checkAttribute(n,"feature:python:callback","1")) { + Setattr(n,"feature:callback","%s_cb_ptr"); + } + + return Language::functionHandler(n); + } + + /* ------------------------------------------------------------ * emitFunctionShadowHelper() *************** *** 435,439 **** void emitFunctionShadowHelper(Node *n, File *f_dest, String *name, int kw) { ! if ( ! have_addtofunc(n) ) { /* If there is no addtofunc directive then just assign from the extension module */ Printv(f_dest, "\n", name, " = ", module, ".", name, "\n", NIL); --- 444,448 ---- void emitFunctionShadowHelper(Node *n, File *f_dest, String *name, int kw) { ! if (checkAttribute(n,"feature:python:callback","1") || ! have_addtofunc(n) ) { /* If there is no addtofunc directive then just assign from the extension module */ Printv(f_dest, "\n", name, " = ", module, ".", name, "\n", NIL); *************** *** 487,495 **** * ------------------------------------------------------------ */ ! void add_method(String *name, String *function, int kw) { ! if (!kw) ! Printf(methods,"\t { (char *)\"%s\", %s, METH_VARARGS, NULL },\n", name, function); else ! Printf(methods,"\t { (char *)\"%s\", (PyCFunction) %s, METH_VARARGS | METH_KEYWORDS, NULL },\n", name, function); } --- 496,513 ---- * ------------------------------------------------------------ */ ! 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 && Getattr(n,"feature:callback")) { ! Printf(methods,"\"swig_ptr: %s\"", Getattr(n,"feature:callback:name")); ! } else { ! Printf(methods,"NULL"); ! } ! ! ! Printf(methods,"},\n"); } *************** *** 902,906 **** /* Now register the function with the interpreter. */ if (!Getattr(n,"sym:overloaded")) { ! add_method(iname, wname, allow_kwargs); /* Create a shadow for this function (if enabled and not in a member function) */ --- 920,924 ---- /* 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) */ *************** *** 955,960 **** Replaceall(dispatch,"$args","self,args"); Printv(f->code,dispatch,"\n",NIL); ! Printf(f->code,"PyErr_SetString(PyExc_TypeError,\"No matching function for overloaded '%s'\");\n", symname); ! Printf(f->code,"return NULL;\n"); Printv(f->code,"}\n",NIL); Wrapper_print(f,f_wrappers); --- 973,983 ---- Replaceall(dispatch,"$args","self,args"); Printv(f->code,dispatch,"\n",NIL); ! if (checkAttribute(n,"feature:python:maybecall","1")) { ! Printf(f->code,"Py_INCREF(Py_NotImplemented);\n"); ! Printf(f->code,"return Py_NotImplemented;\n"); ! } else { ! Printf(f->code,"PyErr_SetString(PyExc_NotImplementedError,\"No matching function for overloaded '%s'\");\n", symname); ! Printf(f->code,"return NULL;\n"); ! } Printv(f->code,"}\n",NIL); Wrapper_print(f,f_wrappers); *************** *** 1000,1007 **** } } ! if ((shadow) && (!SwigType_ismutable(t))) { ! if (!in_class) { ! Printf(f_shadow_stubs,"%s = %s.%s\n", iname, global_name, iname); ! } } --- 1023,1030 ---- } } ! if ((shadow) && (checkAttribute(n,"feature:immutable","1"))) { ! if (!in_class) { ! Printf(f_shadow_stubs,"%s = %s.%s\n", iname, global_name, iname); ! } } *************** *** 1108,1112 **** Printv(f_shadow,iname, " = ", module, ".", iname, "\n", NIL); } else { ! Printv(f_shadow_stubs,iname, " = ", module, ".", iname, "\n", NIL); } } --- 1131,1137 ---- Printv(f_shadow,iname, " = ", module, ".", iname, "\n", NIL); } else { ! if (!(Getattr(n,"feature:python:callback"))) { ! Printv(f_shadow_stubs,iname, " = ", module, ".", iname, "\n", NIL); ! } } } *************** *** 1478,1481 **** --- 1503,1510 ---- Replaceall(tm, "$input", "result"); } + char temp[24]; + sprintf(temp,"%d",idx); + Replaceall(tm,"$argnum",temp); + /* TODO check this */ if (Getattr(n,"wrap:disown")) { *************** *** 1940,1955 **** Printv(f_shadow,pycode,"\n",NIL); } else { ! ! Printv(f_shadow, tab4, "def ", symname, "(*args", (allow_kwargs ? ", **kwargs" : ""), "): ", NIL); ! if ( have_addtofunc(n) ) { ! Printv(f_shadow, "\n", NIL); ! Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL); ! Printv(f_shadow, tab8, addtofunc(n), "\n", NIL); ! Printv(f_shadow, tab8, "return val\n", NIL); ! } else { ! Printv(f_shadow, "return ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL); ! } } - } } --- 1969,1981 ---- Printv(f_shadow,pycode,"\n",NIL); } else { ! Printv(f_shadow, tab4, "def ", symname, "(*args", (allow_kwargs ? ", **kwargs" : ""), "): ", NIL); ! if (have_addtofunc(n)) { ! Printv(f_shadow, "\n", NIL); ! Printv(f_shadow, tab8, "val = ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL); ! Printv(f_shadow, tab8, addtofunc(n), "\n", NIL); ! } else { ! Printv(f_shadow, "return ", funcCallHelper(Swig_name_member(class_name,symname), allow_kwargs), "\n", NIL); ! } } } } *************** *** 1983,1990 **** } if (!classic) { ! Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, ! " = staticmethod(", module, ".", ! Swig_name_member(class_name, symname), ")\n", NIL); ! } } } --- 2009,2016 ---- } if (!classic) { ! Printv(f_shadow, tab4, modern ? "" : "if _newclass:", symname, ! " = staticmethod(", module, ".", ! Swig_name_member(class_name, symname), ")\n", NIL); ! } } } |