This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch to have java dir make use of libiberty calls
- To: apbianco at cygnus dot com
- Subject: Patch to have java dir make use of libiberty calls
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- Date: Mon, 6 Sep 1999 11:23:36 -0400 (EDT)
- Cc: egcs-patches at egcs dot cygnus dot com
This patch converts the java directory to use libiberty calls.
Bootstrapped on Irix6, okay to install?
Thanks,
--Kaveh
1999-09-06 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* gjavah.c (get_field_name): Use concat, not malloc/memcpy/strcpy.
(print_method_info, print_include, add_namelet): Use xmalloc, not
malloc.
* jcf-depend.c (add_entry): Likewise. Use xstrdup, not strdup.
(munge): Use xrealloc, not realloc, trust xrealloc to handle a
NULL pointer.
* jcf-io.c (open_in_zip, find_class): Use xstrdup, not strdup.
* jcf-parse.c (jcf_out_of_synch, yyparse): Likewise.
* jcf-path.c (add_entry): Likewise.
* jcf.h (ALLOC, REALLOC): Use xmalloc/xrealloc, not malloc/realloc.
* jv-scan.c (xmalloc): Remove definition.
* jvgenmain.c (xmalloc): Likewise.
* jvspec.c (lang_specific_driver): Use xcalloc, not xmalloc/bzero.
* lex.c (java_store_unicode): Use xrealloc, not realloc.
* parse-scan.y: Use concat, not of xmalloc/assign/strcpy. Use
concat, not xmalloc/sprintf.
(java_push_parser_context): Use xcalloc, not xmalloc/bzero.
(xstrdup): Remove definition.
* parse.y (duplicate_declaration_error_p,
constructor_circularity_msg, verify_constructor_circularity,
check_abstract_method_definitions, java_check_regular_methods,
java_check_abstract_methods, patch_method_invocation,
check_for_static_method_reference, patch_assignment, patch_binop,
patch_cast, array_constructor_check_entry, patch_return,
patch_conditional_expr): Use xstrdup, not strdup.
* zextract.c (ALLOC): Use xmalloc, not malloc.
diff -rup orig/egcs-CVS19990904/gcc/java/gjavah.c egcs-CVS19990904/gcc/java/gjavah.c
--- orig/egcs-CVS19990904/gcc/java/gjavah.c Fri Sep 3 01:04:38 1999
+++ egcs-CVS19990904/gcc/java/gjavah.c Sat Sep 4 11:04:59 1999
@@ -385,9 +385,7 @@ get_field_name (jcf, name_index, flags)
return NULL;
}
- override = (char *) malloc (length + 3);
- memcpy (override, name, length);
- strcpy (override + length, "__");
+ override = concat (name, "__", NULL);
}
else if ((tmpconstptr = cxx_keyword_subst (name, length)) != NULL)
{
@@ -568,8 +566,8 @@ DEFUN(print_method_info, (stream, jcf, n
{
struct method_name *nn;
- nn = (struct method_name *) malloc (sizeof (struct method_name));
- nn->name = (char *) malloc (length);
+ nn = (struct method_name *) xmalloc (sizeof (struct method_name));
+ nn->name = (char *) xmalloc (length);
memcpy (nn->name, str, length);
nn->length = length;
nn->next = method_name_list;
@@ -1072,8 +1070,8 @@ print_include (out, utf8, len)
return;
}
- incl = (struct include *) malloc (sizeof (struct include));
- incl->name = malloc (len + 1);
+ incl = (struct include *) xmalloc (sizeof (struct include));
+ incl->name = xmalloc (len + 1);
strncpy (incl->name, utf8, len);
incl->name[len] = '\0';
incl->next = all_includes;
@@ -1157,8 +1155,8 @@ add_namelet (name, name_limit, parent)
if (n == NULL)
{
- n = (struct namelet *) malloc (sizeof (struct namelet));
- n->name = malloc (p - name + 1);
+ n = (struct namelet *) xmalloc (sizeof (struct namelet));
+ n->name = xmalloc (p - name + 1);
strncpy (n->name, name, p - name);
n->name[p - name] = '\0';
n->is_class = (p == name_limit || *p == '$');
diff -rup orig/egcs-CVS19990904/gcc/java/jcf-depend.c egcs-CVS19990904/gcc/java/jcf-depend.c
--- orig/egcs-CVS19990904/gcc/java/jcf-depend.c Tue Aug 10 12:48:57 1999
+++ egcs-CVS19990904/gcc/java/jcf-depend.c Sat Sep 4 11:06:04 1999
@@ -90,8 +90,8 @@ add_entry (entp, name)
if (! strcmp (ent->file, name))
return;
- ent = (struct entry *) malloc (sizeof (struct entry));
- ent->file = strdup (name);
+ ent = (struct entry *) xmalloc (sizeof (struct entry));
+ ent->file = xstrdup (name);
ent->next = *entp;
*entp = ent;
}
@@ -177,10 +177,7 @@ munge (filename)
if (buflen < len)
{
buflen = len;
- if (buffer == NULL)
- buffer = malloc (buflen);
- else
- buffer = realloc (buffer, buflen);
+ buffer = xrealloc (buffer, buflen);
}
dst = buffer;
diff -rup orig/egcs-CVS19990904/gcc/java/jcf-io.c egcs-CVS19990904/gcc/java/jcf-io.c
--- orig/egcs-CVS19990904/gcc/java/jcf-io.c Tue Aug 10 12:48:57 1999
+++ egcs-CVS19990904/gcc/java/jcf-io.c Sat Sep 4 11:07:03 1999
@@ -169,8 +169,8 @@ DEFUN(open_in_zip, (jcf, zipfile, zipmem
jcf->read_ptr = jcf->buffer;
jcf->read_end = jcf->buffer_end;
jcf->filbuf = jcf_unexpected_eof;
- jcf->filename = strdup (zipfile);
- jcf->classname = strdup (zipmember);
+ jcf->filename = xstrdup (zipfile);
+ jcf->classname = xstrdup (zipmember);
jcf->zipd = (void *)zipd;
if (lseek (zipf->fd, zipd->filestart, 0) < 0
|| read (zipf->fd, jcf->buffer, zipd->size) != zipd->size)
@@ -414,14 +414,14 @@ DEFUN(find_class, (classname, classname_
{
JCF_ZERO (jcf); /* JCF_FINISH relies on this */
jcf->java_source = 1;
- jcf->filename = (char *) strdup (buffer);
+ jcf->filename = xstrdup (buffer);
close (fd); /* We use STDIO for source file */
}
else
buffer = open_class (buffer, jcf, fd, dep_file);
jcf->classname = (char *) ALLOC (classname_length + 1);
strncpy (jcf->classname, classname, classname_length + 1);
- jcf->classname = (char *) strdup (classname);
+ jcf->classname = xstrdup (classname);
return buffer;
#endif
}
diff -rup orig/egcs-CVS19990904/gcc/java/jcf-parse.c egcs-CVS19990904/gcc/java/jcf-parse.c
--- orig/egcs-CVS19990904/gcc/java/jcf-parse.c Thu Sep 2 17:47:07 1999
+++ egcs-CVS19990904/gcc/java/jcf-parse.c Sat Sep 4 11:07:21 1999
@@ -449,7 +449,7 @@ void
DEFUN(jcf_out_of_synch, (jcf),
JCF *jcf)
{
- char *source = strdup (jcf->filename);
+ char *source = xstrdup (jcf->filename);
int i = strlen (source);
while (source[i] != '.')
@@ -778,7 +778,7 @@ int
yyparse ()
{
int several_files = 0;
- char *list = strdup (input_filename), *next;
+ char *list = xstrdup (input_filename), *next;
tree node, current_file_list = NULL_TREE;
do
diff -rup orig/egcs-CVS19990904/gcc/java/jcf-path.c egcs-CVS19990904/gcc/java/jcf-path.c
--- orig/egcs-CVS19990904/gcc/java/jcf-path.c Tue Aug 10 12:48:57 1999
+++ egcs-CVS19990904/gcc/java/jcf-path.c Sat Sep 4 11:07:32 1999
@@ -167,11 +167,11 @@ add_entry (entp, filename, is_system)
strcpy (f2, filename);
f2[len] = DIR_SEPARATOR;
f2[len + 1] = '\0';
- n->name = strdup (f2);
+ n->name = xstrdup (f2);
++len;
}
else
- n->name = strdup (filename);
+ n->name = xstrdup (filename);
if (len > longest_path)
longest_path = len;
diff -rup orig/egcs-CVS19990904/gcc/java/jcf.h egcs-CVS19990904/gcc/java/jcf.h
--- orig/egcs-CVS19990904/gcc/java/jcf.h Thu Sep 2 17:47:07 1999
+++ egcs-CVS19990904/gcc/java/jcf.h Sat Sep 4 11:10:14 1999
@@ -53,8 +53,8 @@ The Free Software Foundation is independ
#define JCF_u2 unsigned short
#endif
-#define ALLOC (void*)malloc
-#define REALLOC (void*)realloc
+#define ALLOC xmalloc
+#define REALLOC xrealloc
#ifndef FREE
#define FREE(PTR) free(PTR)
#endif
diff -rup orig/egcs-CVS19990904/gcc/java/jv-scan.c egcs-CVS19990904/gcc/java/jv-scan.c
--- orig/egcs-CVS19990904/gcc/java/jv-scan.c Thu Sep 2 17:47:08 1999
+++ egcs-CVS19990904/gcc/java/jv-scan.c Sat Sep 4 10:22:55 1999
@@ -200,14 +200,3 @@ gcc_obstack_init (obstack)
(void *(*) (long)) OBSTACK_CHUNK_ALLOC,
(void (*) (void *)) OBSTACK_CHUNK_FREE);
}
-
-PTR
-xmalloc (size)
- size_t size;
-{
- register PTR val = (PTR) malloc (size);
-
- if (val == 0)
- fatal ("virtual memory exhausted");
- return val;
-}
diff -rup orig/egcs-CVS19990904/gcc/java/jvgenmain.c egcs-CVS19990904/gcc/java/jvgenmain.c
--- orig/egcs-CVS19990904/gcc/java/jvgenmain.c Wed Aug 11 07:42:28 1999
+++ egcs-CVS19990904/gcc/java/jvgenmain.c Sat Sep 4 10:23:27 1999
@@ -127,17 +127,3 @@ main (int argc, const char **argv)
}
return 0;
}
-
-PTR
-xmalloc (size)
- size_t size;
-{
- register PTR val = (PTR) malloc (size);
-
- if (val == 0)
- {
- fprintf(stderr, "jvgenmain: virtual memory exhausted");
- exit(FATAL_EXIT_CODE);
- }
- return val;
-}
diff -rup orig/egcs-CVS19990904/gcc/java/jvspec.c egcs-CVS19990904/gcc/java/jvspec.c
--- orig/egcs-CVS19990904/gcc/java/jvspec.c Wed Aug 25 15:54:41 1999
+++ egcs-CVS19990904/gcc/java/jvspec.c Sat Sep 4 13:09:41 1999
@@ -200,8 +200,7 @@ lang_specific_driver (fn, in_argc, in_ar
argv = *in_argv;
added_libraries = *in_added_libraries;
- args = (int *) xmalloc (argc * sizeof (int));
- bzero ((char *) args, argc * sizeof (int));
+ args = (int *) xcalloc (argc, sizeof (int));
for (i = 1; i < argc; i++)
{
diff -rup orig/egcs-CVS19990904/gcc/java/lex.c egcs-CVS19990904/gcc/java/lex.c
--- orig/egcs-CVS19990904/gcc/java/lex.c Wed Aug 25 09:48:41 1999
+++ egcs-CVS19990904/gcc/java/lex.c Sat Sep 4 11:10:36 1999
@@ -252,9 +252,9 @@ java_store_unicode (l, c, unicode_escape
if (l->size == l->max)
{
l->max += JAVA_LINE_MAX;
- l->line = (unicode_t *)realloc (l->line, sizeof (unicode_t)*l->max);
- l->unicode_escape_p = (char *)realloc (l->unicode_escape_p,
- sizeof (char)*l->max);
+ l->line = (unicode_t *) xrealloc (l->line, sizeof (unicode_t)*l->max);
+ l->unicode_escape_p = (char *) xrealloc (l->unicode_escape_p,
+ sizeof (char)*l->max);
}
l->line [l->size] = c;
l->unicode_escape_p [l->size++] = unicode_escape_p;
diff -rup orig/egcs-CVS19990904/gcc/java/parse-scan.y egcs-CVS19990904/gcc/java/parse-scan.y
--- orig/egcs-CVS19990904/gcc/java/parse-scan.y Wed Aug 25 09:48:42 1999
+++ egcs-CVS19990904/gcc/java/parse-scan.y Sat Sep 4 13:16:55 1999
@@ -231,17 +231,11 @@ array_type:
primitive_type OSB_TK CSB_TK
| name OSB_TK CSB_TK
{
- char *n = xmalloc (strlen ($1)+2);
- n [0] = '[';
- strcpy (n+1, $1);
- $$ = n;
+ $$ = concat ("[", $1, NULL);
}
| array_type OSB_TK CSB_TK
{
- char *n = xmalloc (strlen ($1)+2);
- n [0] = '[';
- strcpy (n+1, $1);
- $$ = n;
+ $$ = concat ("[", $1, NULL);
}
;
@@ -258,9 +252,7 @@ simple_name:
qualified_name:
name DOT_TK identifier
{
- char *n = xmalloc (strlen ($1)+strlen ($3)+2);
- sprintf (n, "%s.%s", $1, $3);
- $$ = n;
+ $$ = concat ($1, ".", $3, NULL);
}
;
@@ -456,9 +448,7 @@ formal_parameter_list:
formal_parameter
| formal_parameter_list C_TK formal_parameter
{
- char *n = xmalloc (strlen ($1)+strlen($3)+2);
- sprintf (n, "%s,%s", $1, $3);
- $$ = n;
+ $$ = concat ($1, ",", $3, NULL);
}
;
@@ -1114,9 +1104,8 @@ void
java_push_parser_context ()
{
struct parser_ctxt *new =
- (struct parser_ctxt *)xmalloc(sizeof (struct parser_ctxt));
+ (struct parser_ctxt *) xcalloc (1, sizeof (struct parser_ctxt));
- bzero ((PTR) new, sizeof (struct parser_ctxt));
new->next = ctxp;
ctxp = new;
}
@@ -1185,15 +1174,4 @@ void
yyerror (msg)
const char *msg ATTRIBUTE_UNUSED;
{
-}
-
-char *
-xstrdup (s)
- const char *s;
-{
- char *ret;
-
- ret = xmalloc (strlen (s) + 1);
- strcpy (ret, s);
- return ret;
}
diff -rup orig/egcs-CVS19990904/gcc/java/parse.y egcs-CVS19990904/gcc/java/parse.y
--- orig/egcs-CVS19990904/gcc/java/parse.y Fri Sep 3 15:01:07 1999
+++ egcs-CVS19990904/gcc/java/parse.y Sat Sep 4 11:12:01 1999
@@ -3123,14 +3123,14 @@ duplicate_declaration_error_p (new_field
new_field_name);
if (decl)
{
- char *t1 = strdup (purify_type_name
+ char *t1 = xstrdup (purify_type_name
((TREE_CODE (new_type) == POINTER_TYPE
&& TREE_TYPE (new_type) == NULL_TREE) ?
IDENTIFIER_POINTER (TYPE_NAME (new_type)) :
lang_printable_name (new_type, 1)));
/* The type may not have been completed by the time we report
the error */
- char *t2 = strdup (purify_type_name
+ char *t2 = xstrdup (purify_type_name
((TREE_CODE (TREE_TYPE (decl)) == POINTER_TYPE
&& TREE_TYPE (TREE_TYPE (decl)) == NULL_TREE) ?
IDENTIFIER_POINTER (TYPE_NAME (TREE_TYPE (decl))) :
@@ -3604,7 +3604,7 @@ constructor_circularity_msg (from, to)
tree from, to;
{
static char string [4096];
- char *t = strdup (lang_printable_name (from, 0));
+ char *t = xstrdup (lang_printable_name (from, 0));
sprintf (string, "`%s' invokes `%s'", t, lang_printable_name (to, 0));
free (t);
return string;
@@ -3637,7 +3637,7 @@ verify_constructor_circularity (meth, cu
java_error_count--;
}
}
- t = strdup (lang_printable_name (meth, 0));
+ t = xstrdup (lang_printable_name (meth, 0));
parse_error_context (TREE_PURPOSE (c),
"%s: recursive invocation of constructor `%s'",
constructor_circularity_msg (current, meth), t);
@@ -4640,7 +4640,7 @@ check_abstract_method_definitions (do_in
that CLASS can use. */
if (!found)
{
- char *t = strdup (lang_printable_name
+ char *t = xstrdup (lang_printable_name
(TREE_TYPE (TREE_TYPE (method)), 0));
tree ccn = DECL_NAME (TYPE_NAME (DECL_CONTEXT (method)));
tree saved_wfl = NULL_TREE;
@@ -4790,7 +4790,7 @@ java_check_regular_methods (class_decl)
types. */
if (TREE_TYPE (TREE_TYPE (found)) != TREE_TYPE (TREE_TYPE (method)))
{
- char *t = strdup (lang_printable_name (TREE_TYPE (TREE_TYPE (found)),
+ char *t = xstrdup (lang_printable_name (TREE_TYPE (TREE_TYPE (found)),
0));
parse_error_context
(method_wfl,
@@ -4981,7 +4981,7 @@ java_check_abstract_methods (interface_d
char *t;
tree saved_found_wfl = DECL_NAME (found);
reset_method_name (found);
- t = strdup (lang_printable_name (TREE_TYPE (TREE_TYPE (found)), 0));
+ t = xstrdup (lang_printable_name (TREE_TYPE (TREE_TYPE (found)), 0));
parse_error_context
(method_wfl,
"Method `%s' was defined with return type `%s' in class `%s'",
@@ -7171,7 +7171,7 @@ patch_method_invocation (patch, primary,
list = lookup_method_invoke (0, wfl, type, identifier, args);
if (list && !METHOD_STATIC (list))
{
- char *fct_name = strdup (lang_printable_name (list, 0));
+ char *fct_name = xstrdup (lang_printable_name (list, 0));
parse_error_context
(identifier_wfl,
"Can't make static reference to method `%s %s' in class `%s'",
@@ -7317,7 +7317,7 @@ patch_method_invocation (patch, primary,
return the call */
if (not_accessible_p (DECL_CONTEXT (current_function_decl), list, 0))
{
- char *fct_name = strdup (lang_printable_name (list, 0));
+ char *fct_name = xstrdup (lang_printable_name (list, 0));
parse_error_context
(wfl, "Can't access %s method `%s %s.%s' from `%s'",
java_accstring_lookup (get_access_flags_from_decl (list)),
@@ -7382,7 +7382,7 @@ check_for_static_method_reference (wfl,
if (METHOD_STATIC (current_function_decl)
&& !METHOD_STATIC (method) && !primary && !CALL_CONSTRUCTOR_P (node))
{
- char *fct_name = strdup (lang_printable_name (method, 0));
+ char *fct_name = xstrdup (lang_printable_name (method, 0));
parse_error_context
(wfl, "Can't make static reference to method `%s %s' in class `%s'",
lang_printable_name (TREE_TYPE (TREE_TYPE (method)), 0), fct_name,
@@ -9101,8 +9101,8 @@ patch_assignment (node, wfl_op1, wfl_op2
/* Explicit cast required. This is an error */
if (!new_rhs)
{
- char *t1 = strdup (lang_printable_name (TREE_TYPE (rhs), 0));
- char *t2 = strdup (lang_printable_name (lhs_type, 0));
+ char *t1 = xstrdup (lang_printable_name (TREE_TYPE (rhs), 0));
+ char *t2 = xstrdup (lang_printable_name (lhs_type, 0));
tree wfl;
char operation [32]; /* Max size known */
@@ -9837,7 +9837,7 @@ patch_binop (node, wfl_op1, wfl_op2)
the type operand. This is a compile time error. */
else
{
- char *t1 = strdup (lang_printable_name (op1_type, 0));
+ char *t1 = xstrdup (lang_printable_name (op1_type, 0));
SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
parse_error_context
(wfl_operator, "Impossible for `%s' to be instance of `%s'",
@@ -9946,7 +9946,7 @@ patch_binop (node, wfl_op1, wfl_op2)
else
{
char *t1;
- t1 = strdup (lang_printable_name (op1_type, 0));
+ t1 = xstrdup (lang_printable_name (op1_type, 0));
parse_error_context
(wfl_operator, "Incompatible type for `%s'. Can't convert `%s' "
"to `%s'", operator_string (node), t1,
@@ -10541,7 +10541,7 @@ patch_cast (node, wfl_operator)
}
/* Any other casts are proven incorrect at compile time */
- t1 = strdup (lang_printable_name (op_type, 0));
+ t1 = xstrdup (lang_printable_name (op_type, 0));
parse_error_context (wfl_operator, "Invalid cast from `%s' to `%s'",
t1, lang_printable_name (cast_type, 0));
free (t1);
@@ -10882,7 +10882,7 @@ array_constructor_check_entry (type, ent
const char *msg = (!valid_cast_to_p (type_value, type) ?
"Can't" : "Explicit cast needed to");
if (!array_type_string)
- array_type_string = strdup (lang_printable_name (type, 1));
+ array_type_string = xstrdup (lang_printable_name (type, 1));
parse_error_context
(wfl_operator, "Incompatible type for array. %s convert `%s' to `%s'",
msg, lang_printable_name (type_value, 1), array_type_string);
@@ -10961,7 +10961,7 @@ patch_return (node)
else if (!DECL_CONSTRUCTOR_P (meth))
{
- char *t = strdup (lang_printable_name (mtype, 0));
+ char *t = xstrdup (lang_printable_name (mtype, 0));
parse_error_context (wfl_operator,
"`return' with%s value from `%s %s'",
(error_found == 1 ? "" : "out"),
@@ -11937,7 +11937,7 @@ patch_conditional_expr (node, wfl_cond,
/* If we don't have any resulting type, we're in trouble */
if (!resulting_type)
{
- char *t = strdup (lang_printable_name (t1, 0));
+ char *t = xstrdup (lang_printable_name (t1, 0));
SET_WFL_OPERATOR (wfl_operator, node, wfl_op1);
parse_error_context (wfl_operator, "Incompatible type for `?:'. Can't "
"convert `%s' to `%s'", t,
diff -rup orig/egcs-CVS19990904/gcc/java/zextract.c egcs-CVS19990904/gcc/java/zextract.c
--- orig/egcs-CVS19990904/gcc/java/zextract.c Tue Aug 10 12:48:59 1999
+++ egcs-CVS19990904/gcc/java/zextract.c Sat Sep 4 11:12:51 1999
@@ -262,7 +262,7 @@ read_zip_archive (zipf)
return -2;
zipf->count = makeword(&buffer[TOTAL_ENTRIES_CENTRAL_DIR]);
zipf->dir_size = makelong(&buffer[SIZE_CENTRAL_DIRECTORY]);
-#define ALLOC malloc
+#define ALLOC xmalloc
/* Allocate 1 more to allow appending '\0' to last filename. */
zipf->central_directory = ALLOC (zipf->dir_size+1);
if (lseek (zipf->fd, -(zipf->dir_size+ECREC_SIZE+4), SEEK_CUR) < 0)