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,8 +776,8 @@ 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,", ");
Printf(f->def,"SCM s_%d", i); Printf(f->def,"SCM s_%d", i);

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,8 +190,9 @@ 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 */
Printf(f_header,"#define SWIG_init %s\n", init_name); Printf(f_header,"#define SWIG_init %s\n", init_name);

View file

@ -66,28 +66,24 @@ Swig_warning(int wnum, const String_or_char *filename, int line, const char *fmt
va_list ap; va_list ap;
if (silence) return; if (silence) return;
if (!init_fmt) Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT); if (!init_fmt) Swig_error_msg_format(DEFAULT_ERROR_MSG_FORMAT);
va_start(ap,fmt); va_start(ap,fmt);
out = NewStringEmpty(); out = NewStringEmpty();
vPrintf(out,fmt,ap); vPrintf(out,fmt,ap);
{
char temp[64], *t; msg = Char(out);
t = temp; if (isdigit((unsigned char)*msg)) {
msg = Char(out); unsigned long result = strtoul(msg, &msg, 10);
while (isdigit((int) *msg)) { if (msg != Char(out)) {
*(t++) = *(msg++);
}
if (t != temp) {
msg++; msg++;
*t = 0; wnum = result;
wnum = atoi(temp);
} }
} }
/* Check in the warning filter */ /* Check in the warning filter */
if (filter) { if (filter) {
char temp[32]; char temp[32];
char *c; char *c;
char *f = Char(filter); char *f = Char(filter);
sprintf(temp,"%d",wnum); sprintf(temp,"%d",wnum);

View file

@ -1,10 +1,10 @@
/* ----------------------------------------------------------------------------- /* -----------------------------------------------------------------------------
* See the LICENSE file for information on copyright, usage and redistribution * 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. * of SWIG, and the README file for authors - http://www.swig.org/release.html.
* *
* tree.c * tree.c
* *
* This file provides some general purpose functions for manipulating * This file provides some general purpose functions for manipulating
* parse trees. * parse trees.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
@ -21,7 +21,7 @@ char cvsroot_tree_c[] = "$Header$";
* Dump the tag structure of a parse tree to standard output * Dump the tag structure of a parse tree to standard output
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void void
Swig_print_tags(DOH *obj, DOH *root) { Swig_print_tags(DOH *obj, DOH *root) {
DOH *croot, *newroot; DOH *croot, *newroot;
DOH *cobj; DOH *cobj;
@ -65,7 +65,7 @@ void
Swig_print_node(Node *obj) { Swig_print_node(Node *obj) {
Iterator ki; Iterator ki;
Node *cobj; Node *cobj;
print_indent(0); print_indent(0);
Printf(stdout,"+++ %s ----------------------------------------\n", nodeType(obj)); Printf(stdout,"+++ %s ----------------------------------------\n", nodeType(obj));
ki = First(obj); ki = First(obj);
@ -113,7 +113,7 @@ Swig_print_node(Node *obj) {
* Dump the tree structure of a parse tree to standard output * Dump the tree structure of a parse tree to standard output
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
void void
Swig_print_tree(DOH *obj) { Swig_print_tree(DOH *obj) {
while (obj) { while (obj) {
Swig_print_node(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 * 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 * 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 * 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). * saved attributes are saved in the view namespace (prefixed by ns).
* This function can be called more than once with different namespaces. * This function can be called more than once with different namespaces.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
int int
Swig_require(const char *ns, Node *n, ...) { 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 *);
@ -285,18 +285,17 @@ Swig_require(const char *ns, Node *n, ...) {
} }
obj = Getattr(n,name); obj = Getattr(n,name);
if (!opt && !obj) { 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)); Getfile(n), Getline(n), name, nodeType(n));
assert(obj); assert(obj);
} }
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 *);
} }
va_end(ap); va_end(ap);
@ -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;
} }
@ -326,12 +327,12 @@ Swig_require(const char *ns, Node *n, ...) {
* are saved, ie behaves as if all the attribute names were prefixed by ?. * are saved, ie behaves as if all the attribute names were prefixed by ?.
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
int int
Swig_save(const char *ns, Node *n, ...) { 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;
} }
@ -378,9 +380,9 @@ Swig_save(const char *ns, Node *n, ...) {
* Restores attributes saved by a previous call to Swig_require() or Swig_save(). * Restores attributes saved by a previous call to Swig_require() or Swig_save().
* ----------------------------------------------------------------------------- */ * ----------------------------------------------------------------------------- */
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);
} }