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
This commit is contained in:
Olly Betts 2006-09-23 23:10:49 +00:00
commit 8904cc86c1
5 changed files with 49 additions and 52 deletions

View file

@ -681,7 +681,7 @@ public:
ParmList *l = Getattr(n,"parms"); ParmList *l = Getattr(n,"parms");
Parm *p; Parm *p;
String *proc_name = 0; String *proc_name = 0;
char source[256], target[256]; char source[256];
Wrapper *f = NewWrapper();; Wrapper *f = NewWrapper();;
String *cleanup = NewString(""); String *cleanup = NewString("");
String *outarg = NewString(""); String *outarg = NewString("");
@ -769,7 +769,6 @@ public:
} }
SwigType *pt = Getattr(p,"type"); SwigType *pt = Getattr(p,"type");
String *ln = Getattr(p,"lname");
int opt_p = (i >= numreq); int opt_p = (i >= numreq);
// Produce names of source and target // Produce names of source and target
@ -777,7 +776,7 @@ public:
sprintf(source, "argv[%d]", i); sprintf(source, "argv[%d]", i);
else else
sprintf(source,"s_%d",i); sprintf(source,"s_%d",i);
sprintf(target,"%s", Char(ln)); String *target = Getattr(p,"lname");
if (!args_passed_as_array) { if (!args_passed_as_array) {
if (i!=0) Printf(f->def,", "); if (i!=0) Printf(f->def,", ");

View file

@ -510,7 +510,7 @@ public:
Parm *p; Parm *p;
int i; int i;
Wrapper *f; Wrapper *f;
char source[256],target[256],temp[256]; char source[256],temp[256];
String *tm; String *tm;
String *cleanup, *outarg; String *cleanup, *outarg;
int num_saved = 0; int num_saved = 0;
@ -567,11 +567,10 @@ public:
} }
SwigType *pt = Getattr(p,"type"); SwigType *pt = Getattr(p,"type");
String *ln = Getattr(p,"lname");
/* Produce string representation of source and target arguments */ /* Produce string representation of source and target arguments */
sprintf(source,"ST(%d)",i); sprintf(source,"ST(%d)",i);
sprintf(target,"%s", Char(ln)); String *target = Getattr(p,"lname");
if (i >= num_required) { if (i >= num_required) {
Printf(f->code," if (items > %d) {\n", i); Printf(f->code," if (items > %d) {\n", i);

View file

@ -170,8 +170,8 @@ public:
/* If shadow classing is enabled, we're going to change the module name to "_module" */ /* If shadow classing is enabled, we're going to change the module name to "_module" */
if (itcl) { if (itcl) {
char filen[256]; String *filen;
sprintf(filen,"%s%s.itcl", Swig_file_dirname(outfile), Char(module)); filen = NewStringf("%s%s.itcl", Swig_file_dirname(outfile), module);
Insert( module,0,"_" ); Insert( module,0,"_" );
@ -190,7 +190,8 @@ public:
NIL); NIL);
Printv(f_shadow,"\npackage require Itcl\n\n", NIL); Printv(f_shadow,"\npackage require Itcl\n\n", NIL);
}; Delete(filen);
}
/* Generate some macros used throughout code generation */ /* Generate some macros used throughout code generation */

View file

@ -71,17 +71,13 @@ Swig_warning(int wnum, const String_or_char *filename, int line, const char *fmt
out = NewStringEmpty(); out = NewStringEmpty();
vPrintf(out,fmt,ap); vPrintf(out,fmt,ap);
{
char temp[64], *t;
t = temp;
msg = Char(out); msg = Char(out);
while (isdigit((int) *msg)) { if (isdigit((unsigned char)*msg)) {
*(t++) = *(msg++); unsigned long result = strtoul(msg, &msg, 10);
} if (msg != Char(out)) {
if (t != temp) {
msg++; msg++;
*t = 0; wnum = result;
wnum = atoi(temp);
} }
} }

View file

@ -268,7 +268,7 @@ Swig_require(const char *ns, Node *n, ...) {
va_list ap; va_list ap;
char *name; char *name;
DOH *obj; DOH *obj;
char temp[512]; String *temp = NewStringEmpty();
va_start(ap, n); va_start(ap, n);
name = va_arg(ap, char *); name = va_arg(ap, char *);
@ -292,10 +292,9 @@ Swig_require(const char *ns, Node *n, ...) {
if (!obj) obj = DohNone; if (!obj) obj = DohNone;
if (newref) { if (newref) {
/* Save a copy of the attribute */ /* Save a copy of the attribute */
strcpy(temp,ns); Printf(temp, "%s:%s", ns, name);
strcat(temp,":");
strcat(temp,name);
Setattr(n,temp,obj); Setattr(n,temp,obj);
Clear(temp);
} }
name = va_arg(ap, char *); name = va_arg(ap, char *);
} }
@ -306,16 +305,18 @@ Swig_require(const char *ns, Node *n, ...) {
String *view = Getattr(n,k_view); String *view = Getattr(n,k_view);
if (view) { if (view) {
if (Strcmp(view,ns) != 0) { if (Strcmp(view,ns) != 0) {
strcpy(temp,ns); Printf(temp, "%s:view", ns);
strcat(temp,":view");
Setattr(n,temp,view); Setattr(n,temp,view);
Setattr(n,k_view,ns); Setattr(n,k_view,ns);
Clear(temp);
} }
} else { } else {
Setattr(n,k_view,ns); Setattr(n,k_view,ns);
} }
} }
Delete(temp);
return 1; return 1;
} }
@ -331,7 +332,7 @@ Swig_save(const char *ns, Node *n, ...) {
va_list ap; va_list ap;
char *name; char *name;
DOH *obj; DOH *obj;
char temp[512]; String *temp = NewStringEmpty();
va_start(ap, n); va_start(ap, n);
name = va_arg(ap, char *); name = va_arg(ap, char *);
@ -345,13 +346,12 @@ Swig_save(const char *ns, Node *n, ...) {
if (!obj) obj = DohNone; if (!obj) obj = DohNone;
/* Save a copy of the attribute */ /* Save a copy of the attribute */
strcpy(temp,ns); Printf(temp, "%s:%s", ns, name);
strcat(temp,":");
strcat(temp,name);
if (Setattr(n,temp,obj)) { 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 *); name = va_arg(ap, char *);
Clear(temp);
} }
va_end(ap); va_end(ap);
@ -360,16 +360,18 @@ Swig_save(const char *ns, Node *n, ...) {
String *view = Getattr(n,k_view); String *view = Getattr(n,k_view);
if (view) { if (view) {
if (Strcmp(view,ns) != 0) { if (Strcmp(view,ns) != 0) {
strcpy(temp,ns); Printf(temp, "%s:view", ns);
strcat(temp,":view");
Setattr(n,temp,view); Setattr(n,temp,view);
Setattr(n,k_view,ns); Setattr(n,k_view,ns);
Clear(temp);
} }
} else { } else {
Setattr(n,k_view,ns); Setattr(n,k_view,ns);
} }
} }
Delete(temp);
return 1; return 1;
} }
@ -380,7 +382,7 @@ Swig_save(const char *ns, Node *n, ...) {
void void
Swig_restore(Node *n) { Swig_restore(Node *n) {
char temp[512]; String *temp;
int len; int len;
List *l; List *l;
String *ns; String *ns;
@ -391,12 +393,11 @@ Swig_restore(Node *n) {
l = NewList(); l = NewList();
strcpy(temp,Char(ns)); temp = NewStringf("%s:", ns);
strcat(temp,":"); len = Len(temp);
len = strlen(temp);
for (ki = First(n); ki.key; ki = Next(ki)) { 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); Append(l,ki.key);
} }
} }
@ -406,6 +407,7 @@ Swig_restore(Node *n) {
Delattr(n,ki.item); Delattr(n,ki.item);
} }
Delete(l); Delete(l);
Delete(temp);
} }