Fix Strcmp - it didn't have consistent null pointer handling - revert to what it used to be - a lightweight wrapper around strcmp which means functions once again must not pass in null to it.

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13943 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2012-12-02 13:36:13 +00:00
commit 89052f3b0a
8 changed files with 18 additions and 17 deletions

View file

@ -3138,7 +3138,7 @@ c_declaration : c_decl {
appendChild($$,n); appendChild($$,n);
while (n) { while (n) {
SwigType *decl = Getattr(n,"decl"); SwigType *decl = Getattr(n,"decl");
if (SwigType_isfunction(decl) && Strcmp(Getattr(n, "storage"), "typedef") != 0) { if (SwigType_isfunction(decl) && !Equal(Getattr(n, "storage"), "typedef")) {
Setattr(n,"storage","externc"); Setattr(n,"storage","externc");
} }
n = nextSibling(n); n = nextSibling(n);

View file

@ -1153,11 +1153,7 @@ DOHString *DohNewStringf(const DOHString_or_char *fmt, ...) {
int DohStrcmp(const DOHString_or_char *s1, const DOHString_or_char *s2) { int DohStrcmp(const DOHString_or_char *s1, const DOHString_or_char *s2) {
const char *c1 = Char(s1); const char *c1 = Char(s1);
const char *c2 = Char(s2); const char *c2 = Char(s2);
if (c1 && c2) { return strcmp(c1, c2);
return strcmp(c1, c2);
} else {
return c1 < c2;
}
} }
int DohStrncmp(const DOHString_or_char *s1, const DOHString_or_char *s2, int n) { int DohStrncmp(const DOHString_or_char *s1, const DOHString_or_char *s2, int n) {

View file

@ -1225,7 +1225,7 @@ void emit_full_class(Node *n) {
// hack. why would decl have a value of "variableHandler" and now "0"? // hack. why would decl have a value of "variableHandler" and now "0"?
String *childDecl = Getattr(c, "decl"); String *childDecl = Getattr(c, "decl");
// Printf(stderr,"childDecl = '%s' (%s)\n", childDecl, Getattr(c,"view")); // Printf(stderr,"childDecl = '%s' (%s)\n", childDecl, Getattr(c,"view"));
if (!Strcmp(childDecl, "0")) if (!childDecl || !Strcmp(childDecl, "0"))
childDecl = NewString(""); childDecl = NewString("");
SwigType *childType; SwigType *childType;

View file

@ -835,7 +835,7 @@ void CFFI::emit_struct_union(Node *n, bool un = false) {
String *typespec = tm ? NewString(tm) : NewString(""); String *typespec = tm ? NewString(tm) : NewString("");
String *slot_name = lispify_name(c, Getattr(c, "sym:name"), "'slotname"); String *slot_name = lispify_name(c, Getattr(c, "sym:name"), "'slotname");
if (Strcmp(slot_name, "t") == 0 || Strcmp(slot_name, "T") == 0) if (slot_name && (Strcmp(slot_name, "t") == 0 || Strcmp(slot_name, "T") == 0))
slot_name = NewStringf("t_var"); slot_name = NewStringf("t_var");
Printf(f_cl, "\n\t(%s %s)", slot_name, typespec); Printf(f_cl, "\n\t(%s %s)", slot_name, typespec);

View file

@ -4418,10 +4418,14 @@ private:
// so we can progress up the inheritance hierachy even if there have been // so we can progress up the inheritance hierachy even if there have been
// new overloads introduced after the topmost class. // new overloads introduced after the topmost class.
Node *base_function = NULL; Node *base_function = NULL;
for (Node *tmp = firstChild(base_class); tmp; tmp = nextSibling(tmp)) { String *symname = Getattr(n, "sym:name");
if (Strcmp(Getattr(tmp, "sym:name"), Getattr(n, "sym:name")) == 0) { if (symname) {
base_function = tmp; for (Node *tmp = firstChild(base_class); tmp; tmp = nextSibling(tmp)) {
break; String *child_symname = Getattr(tmp, "sym:name");
if (child_symname && (Strcmp(child_symname, symname) == 0)) {
base_function = tmp;
break;
}
} }
} }

View file

@ -1990,7 +1990,7 @@ private:
continue; continue;
} }
String *storage = Getattr(ni, "storage"); String *storage = Getattr(ni, "storage");
if (Strcmp(storage, "typedef") == 0 || Strcmp(storage, "friend") == 0) { if (storage && (Strcmp(storage, "typedef") == 0 || Strcmp(storage, "friend") == 0)) {
continue; continue;
} }
@ -4792,7 +4792,7 @@ private:
return Copy(ret); return Copy(ret);
} }
if (Strcmp(Getattr(n, "type"), "enum ") == 0) { if (Equal(Getattr(n, "type"), "enum ")) {
return NewString("int"); return NewString("int");
} }

View file

@ -1577,7 +1577,8 @@ public:
while (i.item) { while (i.item) {
Node *j = firstChild(i.item); Node *j = firstChild(i.item);
while (j) { while (j) {
if (Strcmp(Getattr(j, "name"), Getattr(n, "name")) != 0) { String *jname = Getattr(j, "name");
if (!jname || Strcmp(jname, Getattr(n, "name")) != 0) {
j = nextSibling(j); j = nextSibling(j);
continue; continue;
} }

View file

@ -2351,7 +2351,7 @@ int R::classDeclaration(Node *n) {
elName = Getattr(c, "name"); elName = Getattr(c, "name");
String *elKind = Getattr(c, "kind"); String *elKind = Getattr(c, "kind");
if (Strcmp(elKind, "variable") != 0) { if (!Equal(elKind, "variable")) {
c = nextSibling(c); c = nextSibling(c);
continue; continue;
} }
@ -2453,7 +2453,7 @@ int R::generateCopyRoutines(Node *n) {
continue; continue;
} }
String *elKind = Getattr(c, "kind"); String *elKind = Getattr(c, "kind");
if (Strcmp(elKind, "variable") != 0) { if (!Equal(elKind, "variable")) {
continue; continue;
} }