diff --git a/xpcom/typelib/xpidl/xpidl_header.c b/xpcom/typelib/xpidl/xpidl_header.c index 57672472b481..c576acb33e0e 100644 --- a/xpcom/typelib/xpidl/xpidl_header.c +++ b/xpcom/typelib/xpidl/xpidl_header.c @@ -83,12 +83,15 @@ interface(TreeState *state) { IDL_tree iface = state->tree, iter, orig; char *className = IDL_IDENT(IDL_INTERFACE(iface).ident).str; - char *classNameUpper; + char *classNameUpper = NULL, *cp; + gboolean ok = TRUE; const char *iid; const char *name_space; struct nsID id; char iid_parsed[UUID_LENGTH]; +#define FAIL do {ok = FALSE; goto out;} while(0) + orig = state->tree; fprintf(state->file, "\n/* starting interface: %s */\n", @@ -108,7 +111,7 @@ interface(TreeState *state) /* Redundant, but a better error than 'cannot parse.' */ if (strlen(iid) != 36) { IDL_tree_error(state->tree, "IID %s is the wrong length\n", iid); - return FALSE; + FAIL; } /* @@ -117,11 +120,11 @@ interface(TreeState *state) */ if (!xpidl_parse_iid(&id, iid)) { IDL_tree_error(state->tree, "cannot parse IID %s\n", iid); - return FALSE; + FAIL; } if (!xpidl_sprint_iid(&id, iid_parsed)) { IDL_tree_error(state->tree, "error formatting IID %s\n", iid); - return FALSE; + FAIL; } /* #define NS_ISUPPORTS_IID_STR "00000000-0000-0000-c000-000000000046" */ @@ -166,7 +169,7 @@ interface(TreeState *state) state->tree = IDL_INTERFACE(iface).body; if (state->tree && !xpidl_process_node(state)) - return FALSE; + FAIL; fputs("};\n", state->file); fputc('\n', state->file); @@ -182,10 +185,10 @@ interface(TreeState *state) fputs("/* Use this macro when declaring classes that implement this " "interface. */\n", state->file); fputs("#define NS_DECL_", state->file); - classNameUpper = className; - while (*classNameUpper != '\0') - fputc(toupper(*classNameUpper++), state->file); - fputs(" \\\n", state->file); + classNameUpper = xpidl_strdup(className); + for (cp = classNameUpper; *cp != '\0'; cp++) + *cp = toupper(*cp); + fprintf(state->file, "%s \\\n", classNameUpper); if (IDL_INTERFACE(state->tree).body == NULL) { write_indent(state->file); fputs("/* no methods! */\n", state->file); @@ -206,12 +209,12 @@ interface(TreeState *state) case IDLN_ATTR_DCL: write_indent(state->file); if (!write_attr_accessor(data, state->file, TRUE, FALSE)) - return FALSE; + FAIL; if (!IDL_ATTR_DCL(data).f_readonly) { fputs("; \\\n", state->file); /* Terminate the previous one. */ write_indent(state->file); if (!write_attr_accessor(data, state->file, FALSE, FALSE)) - return FALSE; + FAIL; /* '; \n' at end will clean up. */ } break; @@ -223,10 +226,10 @@ interface(TreeState *state) case IDLN_CODEFRAG: XPIDL_WARNING((iter, IDL_WARNING1, "%%{ .. %%} code fragment within interface " - "ignored when generating NS_DECL_IFOO macro; " + "ignored when generating NS_DECL_%s macro; " "if the code fragment contains method " "declarations, the macro probably isn't " - "complete.")); + "complete.", classNameUpper)); continue; default: @@ -234,7 +237,7 @@ interface(TreeState *state) "unexpected node type %d! " "Please file a bug against the xpidl component.", IDL_NODE_TYPE(data)); - return FALSE; + FAIL; } if (IDL_LIST(iter).next != NULL) { @@ -251,13 +254,11 @@ interface(TreeState *state) * behavior from in implementation to another object. As generated by * idlc. */ - fputs("/* Use this macro to declare functions that forward the behavior of " - "this interface to another object. */\n", state->file); - fputs("#define NS_FORWARD_", state->file); - classNameUpper = className; - while (*classNameUpper != '\0') - fputc(toupper(*classNameUpper++), state->file); - fputs("(_to) \\\n", state->file); + fprintf(state->file, + "/* Use this macro to declare functions that forward the " + "behavior of this interface to another object. */\n" + "#define NS_FORWARD_%s(_to) \\\n", + classNameUpper); if (IDL_INTERFACE(state->tree).body == NULL) { write_indent(state->file); fputs("/* no methods! */\n", state->file); @@ -280,18 +281,18 @@ interface(TreeState *state) case IDLN_ATTR_DCL: write_indent(state->file); if (!write_attr_accessor(data, state->file, TRUE, FALSE)) - return FALSE; + FAIL; fputs(" { return _to ## ", state->file); if (!write_attr_accessor(data, state->file, TRUE, TRUE)) - return FALSE; + FAIL; if (!IDL_ATTR_DCL(data).f_readonly) { fputs("; } \\\n", state->file); /* Terminate the previous one. */ write_indent(state->file); if (!write_attr_accessor(data, state->file, FALSE, FALSE)) - return FALSE; + FAIL; fputs(" { return _to ## ", state->file); if (!write_attr_accessor(data, state->file, FALSE, TRUE)) - return FALSE; + FAIL; /* '; } \n' at end will clean up. */ } break; @@ -301,7 +302,7 @@ interface(TreeState *state) continue; default: - return FALSE; + FAIL; } if (IDL_LIST(iter).next != NULL) { @@ -312,7 +313,12 @@ interface(TreeState *state) } fputc('\n', state->file); - return TRUE; +#undef FAIL + +out: + if (classNameUpper) + free(classNameUpper); + return ok; } static gboolean