Java patch: enable checking for class file generation

Anthony Green green@cygnus.com
Thu Oct 7 06:26:00 GMT 1999


I'm committing the following patch to the trunk.

During class file generation, generate_classfile occasionally writes
out a bunch of data and then skips backwards to fill in blanks.  When
configured with --enable-checking, this patching up will often trip
the checking code.  This change introduces UNSAFE_PUTx macros which
never use CHECK_PUT.  These should only be used in cases we know
CHECK_PUT will fail.

1999-10-07  Anthony Green  <green@cygnus.com>

        * jcf-write.c (generate_classfile): Use UNSAFE_PUTx in cases
        where CHECK_PUT may fail for valid reasons.

        * jcf-write.c (UNSAFE_PUT1, UNSAFE_PUT2, UNSAFE_PUT3,
        UNSAFE_PUTN): New macros.

Index: gcc/java/jcf-write.c
===================================================================
RCS file: /cvs/egcs/egcs/gcc/java/jcf-write.c,v
retrieving revision 1.34
diff -u -r1.34 jcf-write.c
--- jcf-write.c	1999/08/28 05:33:02	1.34
+++ jcf-write.c	1999/10/07 13:11:23
@@ -358,6 +358,13 @@
 #define PUT4(X)  (PUT2((X) >> 16), PUT2((X) & 0xFFFF))
 #define PUTN(P, N)  (CHECK_PUT(ptr, state, N), memcpy(ptr, P, N), ptr += (N))
 
+/* There are some cases below where CHECK_PUT is guaranteed to fail.
+   Use the following macros in those specific cases.  */
+#define UNSAFE_PUT1(X)  (*ptr++ = (X))
+#define UNSAFE_PUT2(X)  (UNSAFE_PUT1((X) >> 8), UNSAFE_PUT1((X) & 0xFF))
+#define UNSAFE_PUT4(X)  (UNSAFE_PUT2((X) >> 16), UNSAFE_PUT2((X) & 0xFFFF))
+#define UNSAFE_PUTN(P, N)  (memcpy(ptr, P, N), ptr += (N))
+
 
 /* Allocate a new chunk on obstack WORK, and link it in after LAST.
    Set the data and size fields to DATA and SIZE, respectively.
@@ -2807,7 +2814,7 @@
 	}
       fields_count++;
     }
-  ptr = fields_count_ptr;  PUT2 (fields_count);
+  ptr = fields_count_ptr;  UNSAFE_PUT2 (fields_count);
 
   ptr = methods_count_ptr = append_chunk (NULL, 2, state);
   PUT2 (0);
@@ -2873,10 +2880,10 @@
 	      code_attributes_count++;
 	      i += 8 + 10 * state->lvar_count;
 	    }
-	  PUT4 (i); /* attribute_length */
-	  PUT2 (state->code_SP_max);  /* max_stack */
-	  PUT2 (localvar_max);  /* max_locals */
-	  PUT4 (state->code_length);
+	  UNSAFE_PUT4 (i); /* attribute_length */
+	  UNSAFE_PUT2 (state->code_SP_max);  /* max_stack */
+	  UNSAFE_PUT2 (localvar_max);  /* max_locals */
+	  UNSAFE_PUT4 (state->code_length);
 
 	  /* Emit the exception table. */
 	  ptr = append_chunk (NULL, 2 + 8 * state->num_handlers, state);
@@ -2966,7 +2973,7 @@
       methods_count++;
       current_function_decl = save_function;
     }
-  ptr = methods_count_ptr;  PUT2 (methods_count);
+  ptr = methods_count_ptr;  UNSAFE_PUT2 (methods_count);
 
   source_file = DECL_SOURCE_FILE (TYPE_NAME (clas));
   for (ptr = source_file;  ;  ptr++)

-- 
Anthony Green                                               Cygnus Solutions
                                                       Sunnyvale, California


More information about the Gcc-patches mailing list