Use append instead of printf

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@8588 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2006-01-28 05:02:37 +00:00
commit 43a5a07593

View file

@ -683,20 +683,20 @@ public:
Printf(f_wrappers,"#ifdef __cplusplus\n"); Printf(f_wrappers,"#ifdef __cplusplus\n");
Printf(f_wrappers,"extern \"C\" {\n"); Printf(f_wrappers,"extern \"C\" {\n");
Printf(f_wrappers,"#endif\n"); Printf(f_wrappers,"#endif\n");
Printf(const_code,"static swig_const_info swig_const_table[] = {\n"); Append(const_code,"static swig_const_info swig_const_table[] = {\n");
Printf(methods,"static PyMethodDef SwigMethods[] = {\n"); Append(methods,"static PyMethodDef SwigMethods[] = {\n");
/* emit code */ /* emit code */
Language::top(n); Language::top(n);
/* Close language module */ /* Close language module */
Printf(methods,"\t { NULL, NULL, 0, NULL }\n"); Append(methods,"\t { NULL, NULL, 0, NULL }\n");
Printf(methods,"};\n"); Append(methods,"};\n");
Printf(f_wrappers,"%s\n",methods); Printf(f_wrappers,"%s\n",methods);
SwigType_emit_type_table(f_runtime,f_wrappers); SwigType_emit_type_table(f_runtime,f_wrappers);
Printf(const_code, "{0, 0, 0, 0.0, 0, 0}};\n"); Append(const_code, "{0, 0, 0, 0.0, 0, 0}};\n");
Printf(f_wrappers,"%s\n",const_code); Printf(f_wrappers,"%s\n",const_code);
initialize_threads(f_init); initialize_threads(f_init);
Printf(f_init,"}\n"); Printf(f_init,"}\n");
@ -776,7 +776,7 @@ public:
Printf(import, "_%s\n", modname); Printf(import, "_%s\n", modname);
if (!Strstr(f_shadow_imports, import)) { if (!Strstr(f_shadow_imports, import)) {
Printf(f_shadow, "import %s\n", modname); Printf(f_shadow, "import %s\n", modname);
Printf(f_shadow_imports, "%s", import); Printv(f_shadow_imports, import, NULL);
} }
} }
} }
@ -1000,7 +1000,7 @@ public:
int lines = 0; int lines = 0;
const int maxwidth = 50; const int maxwidth = 50;
if (pdocs) Printf(pdocs, "\n"); if (pdocs) Append(pdocs, "\n");
Swig_typemap_attach_parms("in",plist,0); Swig_typemap_attach_parms("in",plist,0);
@ -1032,7 +1032,7 @@ public:
if ( Len(doc) ) { if ( Len(doc) ) {
// add a comma to the previous one if any // add a comma to the previous one if any
Printf(doc, ", "); Append(doc, ", ");
// Do we need to wrap a long line? // Do we need to wrap a long line?
if ((Len(doc) - lines*maxwidth) > maxwidth) { if ((Len(doc) - lines*maxwidth) > maxwidth) {
@ -1050,13 +1050,13 @@ public:
} }
if (name) { if (name) {
Printf(doc, "%s", name); Append(doc, name);
if (pdoc) { if (pdoc) {
if (!pdocs) pdocs = NewString("Parameters:\n"); if (!pdocs) pdocs = NewString("Parameters:\n");
Printf(pdocs, " %s\n", pdoc); Printf(pdocs, " %s\n", pdoc);
} }
} else { } else {
Printf(doc, "?"); Append(doc, "?");
} }
if (value) { if (value) {
@ -1121,7 +1121,7 @@ public:
showTypes = true; showTypes = true;
break; break;
case STRING_AUTODOC: case STRING_AUTODOC:
Printf(doc, "%s", autodoc); Append(doc, autodoc);
skipAuto = true; skipAuto = true;
break; break;
} }
@ -1173,7 +1173,7 @@ public:
break; break;
case AUTODOC_DTOR: case AUTODOC_DTOR:
Printf(doc, "__del__(self)"); Append(doc, "__del__(self)");
break; break;
case AUTODOC_STATICFUNC: case AUTODOC_STATICFUNC:
@ -1207,7 +1207,7 @@ public:
// if it's overloaded then get the next decl and loop around again // if it's overloaded then get the next decl and loop around again
n = Getattr(n, "sym:nextSibling"); n = Getattr(n, "sym:nextSibling");
if (n) if (n)
Printf(doc, "\n"); Append(doc, "\n");
} }
return doc; return doc;
@ -1350,11 +1350,11 @@ public:
Printf(methods,"(char *)\"swig_ptr: %s\"",Getattr(n,"feature:callback:name")); Printf(methods,"(char *)\"swig_ptr: %s\"",Getattr(n,"feature:callback:name"));
} }
} else { } else {
Printf(methods,"NULL"); Append(methods,"NULL");
} }
Printf(methods,"},\n"); Append(methods,"},\n");
} }
/* ------------------------------------------------------------ /* ------------------------------------------------------------
@ -1394,15 +1394,15 @@ public:
if (!fastunpack) { if (!fastunpack) {
Wrapper_add_local(f,"ii","int ii"); Wrapper_add_local(f,"ii","int ii");
Printf(f->code,"if (!PyTuple_Check(args)) SWIG_fail;\n"); Append(f->code,"if (!PyTuple_Check(args)) SWIG_fail;\n");
Printf(f->code,"argc = PyObject_Length(args);\n"); Append(f->code,"argc = PyObject_Length(args);\n");
Printf(f->code,"for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n",maxargs); Printf(f->code,"for (ii = 0; (ii < argc) && (ii < %d); ii++) {\n",maxargs);
Printf(f->code,"argv[ii] = PyTuple_GET_ITEM(args,ii);\n"); Append(f->code,"argv[ii] = PyTuple_GET_ITEM(args,ii);\n");
Printf(f->code,"}\n"); Append(f->code,"}\n");
} else { } else {
String *iname = Getattr(n,"sym:name"); String *iname = Getattr(n,"sym:name");
Printf(f->code,"if (!(argc = SWIG_Python_UnpackTuple(args,\"%s\",0,%d,argv))) SWIG_fail;\n", iname, maxargs); Printf(f->code,"if (!(argc = SWIG_Python_UnpackTuple(args,\"%s\",0,%d,argv))) SWIG_fail;\n", iname, maxargs);
Printf(f->code,"--argc;\n"); Append(f->code,"--argc;\n");
} }
Replaceall(dispatch,"$args","self,args"); Replaceall(dispatch,"$args","self,args");
@ -1420,13 +1420,13 @@ public:
if (allow_thread) thread_end_block(n, f->code); if (allow_thread) thread_end_block(n, f->code);
if (GetFlag(n,"feature:python:maybecall")) { if (GetFlag(n,"feature:python:maybecall")) {
Printf(f->code,"fail:\n"); Append(f->code,"fail:\n");
Printf(f->code,"Py_INCREF(Py_NotImplemented);\n"); Append(f->code,"Py_INCREF(Py_NotImplemented);\n");
Printf(f->code,"return Py_NotImplemented;\n"); Append(f->code,"return Py_NotImplemented;\n");
} else { } else {
Printf(f->code,"fail:\n"); Append(f->code,"fail:\n");
Printf(f->code,"SWIG_SetErrorMsg(PyExc_NotImplementedError,\"No matching function for overloaded '%s'\");\n", symname); Printf(f->code,"SWIG_SetErrorMsg(PyExc_NotImplementedError,\"No matching function for overloaded '%s'\");\n", symname);
Printf(f->code,"return NULL;\n"); Append(f->code,"return NULL;\n");
} }
Printv(f->code,"}\n",NIL); Printv(f->code,"}\n",NIL);
Wrapper_print(f,f_wrappers); Wrapper_print(f,f_wrappers);
@ -1567,10 +1567,10 @@ public:
NIL); NIL);
} }
if (!allow_kwargs) { if (!allow_kwargs) {
Printf(parse_args," if (!PyArg_ParseTuple(args,(char *)\""); Append(parse_args," if (!PyArg_ParseTuple(args,(char *)\"");
} else { } else {
Printf(parse_args," if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)\""); Append(parse_args," if (!PyArg_ParseTupleAndKeywords(args,kwargs,(char *)\"");
Printf(arglist,",kwnames"); Append(arglist,",kwnames");
} }
int funpack = modernargs && fastunpack && !varargs && !allow_kwargs ; int funpack = modernargs && fastunpack && !varargs && !allow_kwargs ;
@ -1581,13 +1581,13 @@ public:
if (funpack) { if (funpack) {
if (overname) { if (overname) {
if (aliasobj0) { if (aliasobj0) {
Printf(f->code, "#define obj0 (swig_obj[0])\n"); Append(f->code, "#define obj0 (swig_obj[0])\n");
} }
} else if (num_arguments) { } else if (num_arguments) {
sprintf(source,"PyObject *swig_obj[%d]",num_arguments); sprintf(source,"PyObject *swig_obj[%d]",num_arguments);
Wrapper_add_localv(f, "swig_obj", source, NIL); Wrapper_add_localv(f, "swig_obj", source, NIL);
if (aliasobj0) { if (aliasobj0) {
Printf(f->code, "#define obj0 (swig_obj[0])\n"); Append(f->code, "#define obj0 (swig_obj[0])\n");
} }
} }
} }
@ -1605,7 +1605,7 @@ public:
} }
int use_parse = 0; int use_parse = 0;
Printf(kwargs,"{"); Append(kwargs,"{");
for (i = 0, p=l; i < num_arguments; i++) { for (i = 0, p=l; i < num_arguments; i++) {
while (checkAttribute(p,"tmap:in:numinputs","0")) { while (checkAttribute(p,"tmap:in:numinputs","0")) {
p = Getattr(p,"tmap:in:next"); p = Getattr(p,"tmap:in:next");
@ -1682,7 +1682,7 @@ public:
} else { } else {
use_parse = 1; use_parse = 1;
Printf(parse_args,"%s",parse); Append(parse_args,parse);
Printf(arglist,"&%s", ln); Printf(arglist,"&%s", ln);
} }
p = Getattr(p,"tmap:in:next"); p = Getattr(p,"tmap:in:next");
@ -1696,7 +1696,7 @@ public:
} }
/* finish argument marshalling */ /* finish argument marshalling */
Printf(kwargs," NULL }"); Append(kwargs," NULL }");
if (allow_kwargs) { if (allow_kwargs) {
Printv(f->locals,tab4, "char * kwnames[] = ", kwargs, ";\n", NIL); Printv(f->locals,tab4, "char * kwnames[] = ", kwargs, ";\n", NIL);
} }
@ -1824,17 +1824,17 @@ public:
&& isVirtual && !Getattr(n,"feature:nodirector")) { && isVirtual && !Getattr(n,"feature:nodirector")) {
director_method = 1; director_method = 1;
Wrapper_add_local(f, "director", "Swig::Director *director = 0"); Wrapper_add_local(f, "director", "Swig::Director *director = 0");
Printf(f->code, "director = SWIG_DIRECTOR_CAST(arg1);\n"); Append(f->code, "director = SWIG_DIRECTOR_CAST(arg1);\n");
if (dirprot_mode() && !is_public(n)) { if (dirprot_mode() && !is_public(n)) {
Printf(f->code, "if (!director || !(director->swig_get_inner(\"%s\"))) {\n", name); Printf(f->code, "if (!director || !(director->swig_get_inner(\"%s\"))) {\n", name);
Printf(f->code, "SWIG_SetErrorMsg(PyExc_RuntimeError,\"accessing protected member %s\");\n", name); Printf(f->code, "SWIG_SetErrorMsg(PyExc_RuntimeError,\"accessing protected member %s\");\n", name);
Printf(f->code, "SWIG_fail;\n"); Append(f->code, "SWIG_fail;\n");
Printf(f->code, "}\n"); Append(f->code, "}\n");
} }
if (funpack) { if (funpack) {
Printf(f->code, "if (director && (director->swig_get_self()==swig_obj[0])) director->swig_set_up();\n"); Append(f->code, "if (director && (director->swig_get_self()==swig_obj[0])) director->swig_set_up();\n");
} else { } else {
Printf(f->code, "if (director && (director->swig_get_self()==obj0)) director->swig_set_up();\n"); Append(f->code, "if (director && (director->swig_get_self()==obj0)) director->swig_set_up();\n");
} }
} }
} }
@ -1847,17 +1847,17 @@ public:
/* /*
if (constructor && (Getattr(n, "wrap:self") != 0)) { if (constructor && (Getattr(n, "wrap:self") != 0)) {
Wrapper_add_local(f, "subclassed", "int subclassed = 0"); Wrapper_add_local(f, "subclassed", "int subclassed = 0");
Printf(f->code, "subclassed = (arg1 != Py_None);\n"); Append(f->code, "subclassed = (arg1 != Py_None);\n");
} }
*/ */
/* Emit the function call */ /* Emit the function call */
if (director_method) { if (director_method) {
Printf(f->code, "try {\n"); Append(f->code, "try {\n");
Printf(f->code, " Swig::UnknownExceptionHandler dh;\n"); Append(f->code, " Swig::UnknownExceptionHandler dh;\n");
} else { } else {
if (allow_thread) { if (allow_thread) {
Printf(f->code, "{\n"); Append(f->code, "{\n");
thread_begin_allow(n, f->code); thread_begin_allow(n, f->code);
} }
} }
@ -1865,13 +1865,13 @@ public:
emit_action(n,f); emit_action(n,f);
if (director_method) { if (director_method) {
Printf(f->code, "} catch (Swig::DirectorException&) {\n"); Append(f->code, "} catch (Swig::DirectorException&) {\n");
Printf(f->code, " SWIG_fail;\n"); Append(f->code, " SWIG_fail;\n");
Printf(f->code, "}\n"); Append(f->code, "}\n");
} else { } else {
if (allow_thread) { if (allow_thread) {
thread_end_allow(n, f->code); thread_end_allow(n, f->code);
Printf(f->code, "}\n"); Append(f->code, "}\n");
} }
} }
@ -1918,13 +1918,13 @@ public:
} }
if (unwrap) { if (unwrap) {
Wrapper_add_local(f, "director", "Swig::Director *director = 0"); Wrapper_add_local(f, "director", "Swig::Director *director = 0");
Printf(f->code, "director = SWIG_DIRECTOR_CAST(result);\n"); Append(f->code, "director = SWIG_DIRECTOR_CAST(result);\n");
Printf(f->code, "if (director) {\n"); Append(f->code, "if (director) {\n");
Printf(f->code, " resultobj = director->swig_get_self();\n"); Append(f->code, " resultobj = director->swig_get_self();\n");
Printf(f->code, " Py_INCREF(resultobj);\n"); Append(f->code, " Py_INCREF(resultobj);\n");
Printf(f->code, "} else {\n"); Append(f->code, "} else {\n");
Printf(f->code,"%s\n", tm); Printf(f->code,"%s\n", tm);
Printf(f->code, "}\n"); Append(f->code, "}\n");
} else { } else {
Printf(f->code,"%s\n", tm); Printf(f->code,"%s\n", tm);
} }
@ -1972,11 +1972,11 @@ public:
} }
if (allow_thread) thread_end_block(n, f->code); if (allow_thread) thread_end_block(n, f->code);
Printf(f->code," return resultobj;\n"); Append(f->code," return resultobj;\n");
/* Error handling code */ /* Error handling code */
Printf(f->code,"fail:\n"); Append(f->code,"fail:\n");
if (need_cleanup) { if (need_cleanup) {
Printv(f->code,cleanup,NIL); Printv(f->code,cleanup,NIL);
} }
@ -1986,14 +1986,14 @@ public:
if (funpack) { if (funpack) {
if (aliasobj0) { if (aliasobj0) {
Printf(f->code, "#if defined(obj0)\n"); Append(f->code, "#if defined(obj0)\n");
Printf(f->code, "#undef obj0\n"); Append(f->code, "#undef obj0\n");
Printf(f->code, "#endif\n"); Append(f->code, "#endif\n");
} }
} }
Printf(f->code,"}\n"); Append(f->code,"}\n");
/* Substitute the cleanup code */ /* Substitute the cleanup code */
Replaceall(f->code,"$cleanup",cleanup); Replaceall(f->code,"$cleanup",cleanup);
@ -2025,10 +2025,10 @@ public:
Printf(f->code,"newargs = PyTuple_GetSlice(args,0,%d);\n", num_arguments); Printf(f->code,"newargs = PyTuple_GetSlice(args,0,%d);\n", num_arguments);
Printf(f->code,"varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args)+1);\n", num_arguments); Printf(f->code,"varargs = PyTuple_GetSlice(args,%d,PyTuple_Size(args)+1);\n", num_arguments);
Printf(f->code,"resultobj = %s__varargs__(self,newargs,varargs);\n", wname); Printf(f->code,"resultobj = %s__varargs__(self,newargs,varargs);\n", wname);
Printf(f->code,"Py_XDECREF(newargs);\n"); Append(f->code,"Py_XDECREF(newargs);\n");
Printf(f->code,"Py_XDECREF(varargs);\n"); Append(f->code,"Py_XDECREF(varargs);\n");
Printf(f->code,"return resultobj;\n"); Append(f->code,"return resultobj;\n");
Printf(f->code,"}\n"); Append(f->code,"}\n");
Wrapper_print(f,f_wrappers); Wrapper_print(f,f_wrappers);
} }
@ -2118,7 +2118,7 @@ public:
"Unable to set variable of type %s.\n", SwigType_str(t,0)); "Unable to set variable of type %s.\n", SwigType_str(t,0));
} }
Printv(setf->code,tab4,"return 0;\n",NULL); Printv(setf->code,tab4,"return 0;\n",NULL);
Printf(setf->code,"fail:\n"); Append(setf->code,"fail:\n");
Printv(setf->code,tab4,"return 1;\n",NULL); Printv(setf->code,tab4,"return 1;\n",NULL);
} else { } else {
/* Is a readonly variable. Issue an error */ /* Is a readonly variable. Issue an error */
@ -2133,7 +2133,7 @@ public:
NIL); NIL);
} }
Printf(setf->code,"}\n"); Append(setf->code,"}\n");
Wrapper_print(setf,f_wrappers); Wrapper_print(setf,f_wrappers);
/* Create a function for getting the value of a variable */ /* Create a function for getting the value of a variable */
@ -2302,7 +2302,7 @@ public:
call = Swig_csuperclass_call(0, basetype, superparms); call = Swig_csuperclass_call(0, basetype, superparms);
Printf(w->def, "%s::%s: %s, Swig::Director(self) { \n", classname, target, call); Printf(w->def, "%s::%s: %s, Swig::Director(self) { \n", classname, target, call);
Printf(w->def, " SWIG_DIRECTOR_RGTR((%s *)this, this); \n", basetype); Printf(w->def, " SWIG_DIRECTOR_RGTR((%s *)this, this); \n", basetype);
Printf(w->def, "}\n"); Append(w->def, "}\n");
Delete(target); Delete(target);
Wrapper_print(w, f_directors); Wrapper_print(w, f_directors);
Delete(call); Delete(call);
@ -2336,7 +2336,7 @@ public:
Wrapper *w = NewWrapper(); Wrapper *w = NewWrapper();
Printf(w->def, "SwigDirector_%s::SwigDirector_%s(PyObject* self) : Swig::Director(self) { \n", classname, classname); Printf(w->def, "SwigDirector_%s::SwigDirector_%s(PyObject* self) : Swig::Director(self) { \n", classname, classname);
Printf(w->def, " SWIG_DIRECTOR_RGTR((%s *)this, this); \n", basetype); Printf(w->def, " SWIG_DIRECTOR_RGTR((%s *)this, this); \n", basetype);
Printf(w->def, "}\n"); Append(w->def, "}\n");
Wrapper_print(w, f_directors); Wrapper_print(w, f_directors);
DelWrapper(w); DelWrapper(w);
} }
@ -2467,7 +2467,7 @@ public:
} }
Printf(importname,"%s.", modname); Printf(importname,"%s.", modname);
} }
Printf(importname,"%s", Getattr(n,"sym:name")); Append(importname,Getattr(n,"sym:name"));
Setattr(n,"python:proxy",importname); Setattr(n,"python:proxy",importname);
} }
} }
@ -3115,7 +3115,7 @@ public:
virtual String *runtimeCode() { virtual String *runtimeCode() {
String *s = Swig_include_sys("pyrun.swg"); String *s = Swig_include_sys("pyrun.swg");
if (!s) { if (!s) {
Printf(stderr, "*** Unable to open 'pyrun.swg'\n"); Append(stderr, "*** Unable to open 'pyrun.swg'\n");
s = NewString(""); s = NewString("");
} }
return s; return s;
@ -3222,8 +3222,8 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
Append(declaration, ", "); Append(declaration, ", ");
} }
String *str = SwigType_str(Getattr(p, "type"),0); String *str = SwigType_str(Getattr(p, "type"),0);
Printf(w->def, "%s", str); Append(w->def, str);
Printf(declaration, "%s", str); Append(declaration, str);
Delete(str); Delete(str);
} }
} }
@ -3280,7 +3280,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
String* parse = Getattr(p, "tmap:directorin:parse"); String* parse = Getattr(p, "tmap:directorin:parse");
if (!parse) { if (!parse) {
sprintf(source, "obj%d", idx++); sprintf(source, "obj%d", idx++);
String *input = NewStringf("%s", source); String *input = NewString(source);
Replaceall(tm, "$input", input); Replaceall(tm, "$input", input);
Delete(input); Delete(input);
Replaceall(tm, "$owner", "0"); Replaceall(tm, "$owner", "0");
@ -3292,11 +3292,11 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
Putc('O', parse_args); Putc('O', parse_args);
} else { } else {
use_parse = 1; use_parse = 1;
Printf(parse_args, "%s", parse); Append(parse_args, parse);
Replaceall(tm, "$input", pname); Replaceall(tm, "$input", pname);
Replaceall(tm, "$owner", "0"); Replaceall(tm, "$owner", "0");
if (Len(tm) == 0) Append(tm, pname); if (Len(tm) == 0) Append(tm, pname);
Printf(arglist, "%s", tm); Append(arglist, tm);
} }
p = Getattr(p, "tmap:directorin:next"); p = Getattr(p, "tmap:directorin:next");
continue; continue;
@ -3345,10 +3345,10 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst); Printf(wrap_args, "%s = SWIG_DIRECTOR_CAST(%s);\n", director, nonconst);
Printf(wrap_args, "if (!%s) {\n", director); Printf(wrap_args, "if (!%s) {\n", director);
Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle); Printf(wrap_args, "%s = SWIG_NewPointerObj(%s, SWIGTYPE%s, 0);\n", source, nonconst, mangle);
Printf(wrap_args, "} else {\n"); Append(wrap_args, "} else {\n");
Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director); Printf(wrap_args, "%s = %s->swig_get_self();\n", source, director);
Printf(wrap_args, "Py_INCREF((PyObject *)%s);\n", source); Printf(wrap_args, "Py_INCREF((PyObject *)%s);\n", source);
Printf(wrap_args, "}\n"); Append(wrap_args, "}\n");
Delete(director); Delete(director);
Printv(arglist, source, NIL); Printv(arglist, source, NIL);
} else { } else {
@ -3380,7 +3380,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
/* direct call to superclass if _up is set */ /* direct call to superclass if _up is set */
if (allow_thread) thread_begin_block(n, w->code); if (allow_thread) thread_begin_block(n, w->code);
Printf(w->code, "if (swig_get_up()) {\n"); Append(w->code, "if (swig_get_up()) {\n");
if (pure_virtual) { if (pure_virtual) {
Printf(w->code, Printf(w->code,
"Swig::DirectorPureVirtualException::raise(\"%s.\");\n",Swig_method_call(super,l)); "Swig::DirectorPureVirtualException::raise(\"%s.\");\n",Swig_method_call(super,l));
@ -3388,13 +3388,13 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
if (allow_thread) thread_begin_allow(n, w->code); if (allow_thread) thread_begin_allow(n, w->code);
if (is_void) { if (is_void) {
Printf(w->code, "%s;\n", Swig_method_call(super,l)); Printf(w->code, "%s;\n", Swig_method_call(super,l));
Printf(w->code, "return;\n"); Append(w->code, "return;\n");
} else { } else {
Printf(w->code, "return %s;\n", Swig_method_call(super,l)); Printf(w->code, "return %s;\n", Swig_method_call(super,l));
} }
if (allow_thread) thread_end_allow(n, w->code); if (allow_thread) thread_end_allow(n, w->code);
} }
Printf(w->code, "}\n"); Append(w->code, "}\n");
/* declare method return value /* declare method return value
* if the return value is a reference or const reference, a specialized typemap must * if the return value is a reference or const reference, a specialized typemap must
@ -3406,7 +3406,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
Delete(cres); Delete(cres);
} }
if (allow_thread) { if (allow_thread) {
Printf(w->code, "{\n"); Append(w->code, "{\n");
} }
/* wrap complex arguments to PyObjects */ /* wrap complex arguments to PyObjects */
@ -3418,14 +3418,14 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
} }
Printf(w->code, "if (!swig_get_self()) {\n"); Append(w->code, "if (!swig_get_self()) {\n");
Printf(w->code, " Swig::DirectorException::raise(\"'self' unitialized, maybe you forgot to call %s.__init__.\");\n", classname); Printf(w->code, " Swig::DirectorException::raise(\"'self' unitialized, maybe you forgot to call %s.__init__.\");\n", classname);
Printf(w->code, "}\n"); Append(w->code, "}\n");
Printf(w->code,"#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n"); Append(w->code,"#if defined(SWIG_PYTHON_DIRECTOR_VTABLE)\n");
Printf(w->code, "const size_t swig_method_index = %d;\n", director_method_index++); Printf(w->code, "const size_t swig_method_index = %d;\n", director_method_index++);
Printf(w->code, "const char * const swig_method_name = \"%s\";\n", pyname); Printf(w->code, "const char * const swig_method_name = \"%s\";\n", pyname);
Printf(w->code, "PyObject* method = swig_get_method(swig_method_index, swig_method_name);\n"); Append(w->code, "PyObject* method = swig_get_method(swig_method_index, swig_method_name);\n");
if (Len(parse_args) > 0) { if (Len(parse_args) > 0) {
if (use_parse || !modernargs) { if (use_parse || !modernargs) {
Printf(w->code, "swig::PyObject_var result = PyObject_CallFunction(method, (char *)\"(%s)\" %s);\n", parse_args, arglist); Printf(w->code, "swig::PyObject_var result = PyObject_CallFunction(method, (char *)\"(%s)\" %s);\n", parse_args, arglist);
@ -3433,10 +3433,10 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
Printf(w->code, "swig::PyObject_var result = PyObject_CallFunctionObjArgs(method %s, NULL);\n", arglist); Printf(w->code, "swig::PyObject_var result = PyObject_CallFunctionObjArgs(method %s, NULL);\n", arglist);
} }
} else { } else {
Printf(w->code, "swig::PyObject_var args = PyTuple_New(0);\n"); Append(w->code, "swig::PyObject_var args = PyTuple_New(0);\n");
Printf(w->code, "swig::PyObject_var result = PyObject_Call(method, (PyObject*) args, NULL);\n"); Append(w->code, "swig::PyObject_var result = PyObject_Call(method, (PyObject*) args, NULL);\n");
} }
Printf(w->code,"#else\n"); Append(w->code,"#else\n");
if (Len(parse_args) > 0) { if (Len(parse_args) > 0) {
if (use_parse || !modernargs) { if (use_parse || !modernargs) {
Printf(w->code, "swig::PyObject_var result = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n", Printf(w->code, "swig::PyObject_var result = PyObject_CallMethod(swig_get_self(), (char *)\"%s\", (char *)\"(%s)\" %s);\n",
@ -3451,10 +3451,10 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
Printf(w->code, "swig::PyObject_var result = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", pyname); Printf(w->code, "swig::PyObject_var result = PyObject_CallMethod(swig_get_self(), (char *) \"%s\", NULL);\n", pyname);
} else { } else {
Printf(w->code, "swig::PyObject_var swig_method_name = PyString_FromString((char *)\"%s\");\n", pyname); Printf(w->code, "swig::PyObject_var swig_method_name = PyString_FromString((char *)\"%s\");\n", pyname);
Printf(w->code, "swig::PyObject_var result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n"); Append(w->code, "swig::PyObject_var result = PyObject_CallMethodObjArgs(swig_get_self(), (PyObject *) swig_method_name, NULL);\n");
} }
} }
Printf(w->code,"#endif\n"); Append(w->code,"#endif\n");
if (dirprot_mode() && !is_public(n)) if (dirprot_mode() && !is_public(n))
Printf(w->code, "swig_set_inner(\"%s\", false);\n", name); Printf(w->code, "swig_set_inner(\"%s\", false);\n", name);
@ -3465,18 +3465,18 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
tm = Getattr(n, "feature:director:except"); tm = Getattr(n, "feature:director:except");
if (tm) tm = Copy(tm); if (tm) tm = Copy(tm);
} }
Printf(w->code, "if (result == NULL) {\n"); Append(w->code, "if (result == NULL) {\n");
Printf(w->code, " PyObject *error = PyErr_Occurred();\n"); Append(w->code, " PyObject *error = PyErr_Occurred();\n");
if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) { if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) {
Replaceall(tm, "$error", "error"); Replaceall(tm, "$error", "error");
Printv(w->code, Str(tm), "\n", NIL); Printv(w->code, Str(tm), "\n", NIL);
} else { } else {
Printf(w->code, " if (error != NULL) {\n"); Append(w->code, " if (error != NULL) {\n");
Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s.%s'\");\n", Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s.%s'\");\n",
classname, pyname); classname, pyname);
Printf(w->code, " }\n"); Append(w->code, " }\n");
} }
Printf(w->code, "}\n"); Append(w->code, "}\n");
Delete(tm); Delete(tm);
/* /*
@ -3493,10 +3493,10 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
if (outputs > 1) { if (outputs > 1) {
Wrapper_add_local(w, "output", "PyObject *output"); Wrapper_add_local(w, "output", "PyObject *output");
Printf(w->code, "if (!PyTuple_Check(result)) {\n"); Append(w->code, "if (!PyTuple_Check(result)) {\n");
Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n", Printf(w->code, " Swig::DirectorTypeMismatchException::raise(\"Python method %s.%sfailed to return a tuple.\");\n",
classname, pyname); classname, pyname);
Printf(w->code, "}\n"); Append(w->code, "}\n");
} }
idx = 0; idx = 0;
@ -3567,7 +3567,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
/* any existing helper functions to handle this? */ /* any existing helper functions to handle this? */
if (allow_thread) { if (allow_thread) {
Printf(w->code, "}\n"); Append(w->code, "}\n");
thread_end_block(n, w->code); thread_end_block(n, w->code);
} }
@ -3580,7 +3580,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
} }
Delete(rettype); Delete(rettype);
} }
Printf(w->code, "}\n"); Append(w->code, "}\n");
/* emit the director method */ /* emit the director method */
if (status == SWIG_OK) { if (status == SWIG_OK) {