From 8904cc86c1ca9c161d0989e2682198356a6246a5 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Sat, 23 Sep 2006 23:10:49 +0000 Subject: [PATCH] Use DOH String instead of static char buffers. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@9339 626c5289-ae23-0410-ae9c-e8d60b6d4f22 --- Source/Modules/guile.cxx | 7 ++--- Source/Modules/perl5.cxx | 5 ++-- Source/Modules/tcl8.cxx | 9 +++--- Source/Swig/error.c | 20 ++++++-------- Source/Swig/tree.c | 60 +++++++++++++++++++++------------------- 5 files changed, 49 insertions(+), 52 deletions(-) diff --git a/Source/Modules/guile.cxx b/Source/Modules/guile.cxx index 759645976..c3e6a4079 100644 --- a/Source/Modules/guile.cxx +++ b/Source/Modules/guile.cxx @@ -681,7 +681,7 @@ public: ParmList *l = Getattr(n,"parms"); Parm *p; String *proc_name = 0; - char source[256], target[256]; + char source[256]; Wrapper *f = NewWrapper();; String *cleanup = NewString(""); String *outarg = NewString(""); @@ -769,7 +769,6 @@ public: } SwigType *pt = Getattr(p,"type"); - String *ln = Getattr(p,"lname"); int opt_p = (i >= numreq); // Produce names of source and target @@ -777,8 +776,8 @@ public: sprintf(source, "argv[%d]", i); else sprintf(source,"s_%d",i); - sprintf(target,"%s", Char(ln)); - + String *target = Getattr(p,"lname"); + if (!args_passed_as_array) { if (i!=0) Printf(f->def,", "); Printf(f->def,"SCM s_%d", i); diff --git a/Source/Modules/perl5.cxx b/Source/Modules/perl5.cxx index 051c23a9b..382ac7244 100644 --- a/Source/Modules/perl5.cxx +++ b/Source/Modules/perl5.cxx @@ -510,7 +510,7 @@ public: Parm *p; int i; Wrapper *f; - char source[256],target[256],temp[256]; + char source[256],temp[256]; String *tm; String *cleanup, *outarg; int num_saved = 0; @@ -567,11 +567,10 @@ public: } SwigType *pt = Getattr(p,"type"); - String *ln = Getattr(p,"lname"); /* Produce string representation of source and target arguments */ sprintf(source,"ST(%d)",i); - sprintf(target,"%s", Char(ln)); + String *target = Getattr(p,"lname"); if (i >= num_required) { Printf(f->code," if (items > %d) {\n", i); diff --git a/Source/Modules/tcl8.cxx b/Source/Modules/tcl8.cxx index 7996a427f..4dd04cd0f 100644 --- a/Source/Modules/tcl8.cxx +++ b/Source/Modules/tcl8.cxx @@ -170,8 +170,8 @@ public: /* If shadow classing is enabled, we're going to change the module name to "_module" */ if (itcl) { - char filen[256]; - sprintf(filen,"%s%s.itcl", Swig_file_dirname(outfile), Char(module)); + String *filen; + filen = NewStringf("%s%s.itcl", Swig_file_dirname(outfile), module); Insert( module,0,"_" ); @@ -190,8 +190,9 @@ public: NIL); Printv(f_shadow,"\npackage require Itcl\n\n", NIL); - }; - + Delete(filen); + } + /* Generate some macros used throughout code generation */ Printf(f_header,"#define SWIG_init %s\n", init_name); diff --git a/Source/Swig/error.c b/Source/Swig/error.c index d8b9e133d..365ea92c3 100644 --- a/Source/Swig/error.c +++ b/Source/Swig/error.c @@ -66,28 +66,24 @@ Swig_warning(int wnum, const String_or_char *filename, int line, const char *fmt va_list ap; if (silence) return; if (!init_fmt) Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT); - + va_start(ap,fmt); out = NewStringEmpty(); vPrintf(out,fmt,ap); - { - char temp[64], *t; - t = temp; - msg = Char(out); - while (isdigit((int) *msg)) { - *(t++) = *(msg++); - } - if (t != temp) { + + msg = Char(out); + if (isdigit((unsigned char)*msg)) { + unsigned long result = strtoul(msg, &msg, 10); + if (msg != Char(out)) { msg++; - *t = 0; - wnum = atoi(temp); + wnum = result; } } /* Check in the warning filter */ if (filter) { - char temp[32]; + char temp[32]; char *c; char *f = Char(filter); sprintf(temp,"%d",wnum); diff --git a/Source/Swig/tree.c b/Source/Swig/tree.c index 6aeab3a2d..12d5ed2ef 100644 --- a/Source/Swig/tree.c +++ b/Source/Swig/tree.c @@ -1,10 +1,10 @@ -/* ----------------------------------------------------------------------------- +/* ----------------------------------------------------------------------------- * See the LICENSE file for information on copyright, usage and redistribution * of SWIG, and the README file for authors - http://www.swig.org/release.html. * * tree.c * - * This file provides some general purpose functions for manipulating + * This file provides some general purpose functions for manipulating * parse trees. * ----------------------------------------------------------------------------- */ @@ -21,7 +21,7 @@ char cvsroot_tree_c[] = "$Header$"; * Dump the tag structure of a parse tree to standard output * ----------------------------------------------------------------------------- */ -void +void Swig_print_tags(DOH *obj, DOH *root) { DOH *croot, *newroot; DOH *cobj; @@ -65,7 +65,7 @@ void Swig_print_node(Node *obj) { Iterator ki; Node *cobj; - + print_indent(0); Printf(stdout,"+++ %s ----------------------------------------\n", nodeType(obj)); ki = First(obj); @@ -113,7 +113,7 @@ Swig_print_node(Node *obj) { * Dump the tree structure of a parse tree to standard output * ----------------------------------------------------------------------------- */ -void +void Swig_print_tree(DOH *obj) { while (obj) { Swig_print_node(obj); @@ -258,17 +258,17 @@ checkAttribute(Node *n, const String_or_char *name, const String_or_char *value) * not. Assert will only occur unless the attribute is optional. An attribute is * optional if it is prefixed by ?, eg "?value". If the attribute name is prefixed * by * or ?, eg "*value" then a copy of the attribute is saved. The saved - * attributes will be restored on a subsequent call to Swig_restore(). All the + * attributes will be restored on a subsequent call to Swig_restore(). All the * saved attributes are saved in the view namespace (prefixed by ns). * This function can be called more than once with different namespaces. * ----------------------------------------------------------------------------- */ -int +int Swig_require(const char *ns, Node *n, ...) { va_list ap; char *name; DOH *obj; - char temp[512]; + String *temp = NewStringEmpty(); va_start(ap, n); name = va_arg(ap, char *); @@ -285,18 +285,17 @@ Swig_require(const char *ns, Node *n, ...) { } obj = Getattr(n,name); if (!opt && !obj) { - Printf(stderr,"%s:%d. Fatal error (Swig_require). Missing attribute '%s' in node '%s'.\n", + Printf(stderr,"%s:%d. Fatal error (Swig_require). Missing attribute '%s' in node '%s'.\n", Getfile(n), Getline(n), name, nodeType(n)); assert(obj); } if (!obj) obj = DohNone; if (newref) { /* Save a copy of the attribute */ - strcpy(temp,ns); - strcat(temp,":"); - strcat(temp,name); + Printf(temp, "%s:%s", ns, name); Setattr(n,temp,obj); - } + Clear(temp); + } name = va_arg(ap, char *); } va_end(ap); @@ -306,16 +305,18 @@ Swig_require(const char *ns, Node *n, ...) { String *view = Getattr(n,k_view); if (view) { if (Strcmp(view,ns) != 0) { - strcpy(temp,ns); - strcat(temp,":view"); + Printf(temp, "%s:view", ns); Setattr(n,temp,view); Setattr(n,k_view,ns); + Clear(temp); } } else { Setattr(n,k_view,ns); } } + Delete(temp); + return 1; } @@ -326,12 +327,12 @@ Swig_require(const char *ns, Node *n, ...) { * are saved, ie behaves as if all the attribute names were prefixed by ?. * ----------------------------------------------------------------------------- */ -int +int Swig_save(const char *ns, Node *n, ...) { va_list ap; char *name; DOH *obj; - char temp[512]; + String *temp = NewStringEmpty(); va_start(ap, n); name = va_arg(ap, char *); @@ -345,13 +346,12 @@ Swig_save(const char *ns, Node *n, ...) { if (!obj) obj = DohNone; /* Save a copy of the attribute */ - strcpy(temp,ns); - strcat(temp,":"); - strcat(temp,name); + Printf(temp, "%s:%s", ns, name); if (Setattr(n,temp,obj)) { - Printf(stderr,"Swig_save('%s','%s'): Warning, attribute '%s' was already saved.\n", ns, nodeType(n), name); + Printf(stderr,"Swig_save('%s','%s'): Warning, attribute '%s' was already saved. [%s]\n", ns, nodeType(n), name); } name = va_arg(ap, char *); + Clear(temp); } va_end(ap); @@ -360,16 +360,18 @@ Swig_save(const char *ns, Node *n, ...) { String *view = Getattr(n,k_view); if (view) { if (Strcmp(view,ns) != 0) { - strcpy(temp,ns); - strcat(temp,":view"); + Printf(temp, "%s:view", ns); Setattr(n,temp,view); Setattr(n,k_view,ns); + Clear(temp); } } else { Setattr(n,k_view,ns); } } + Delete(temp); + return 1; } @@ -378,9 +380,9 @@ Swig_save(const char *ns, Node *n, ...) { * Restores attributes saved by a previous call to Swig_require() or Swig_save(). * ----------------------------------------------------------------------------- */ -void +void Swig_restore(Node *n) { - char temp[512]; + String *temp; int len; List *l; String *ns; @@ -391,12 +393,11 @@ Swig_restore(Node *n) { l = NewList(); - strcpy(temp,Char(ns)); - strcat(temp,":"); - len = strlen(temp); + temp = NewStringf("%s:", ns); + len = Len(temp); for (ki = First(n); ki.key; ki = Next(ki)) { - if (strncmp(temp,Char(ki.key),len) == 0) { + if (strncmp(Char(temp),Char(ki.key),len) == 0) { Append(l,ki.key); } } @@ -406,6 +407,7 @@ Swig_restore(Node *n) { Delattr(n,ki.item); } Delete(l); + Delete(temp); }