aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Green <green@cygnus.com>1999-10-07 13:26:01 +0000
committerAnthony Green <green@gcc.gnu.org>1999-10-07 13:26:01 +0000
commitab150fb1894fda0eab14187338834d656de2a52a (patch)
treeeb83f5d7b9f27044c9864936e569e3d22225c475
parent81bf3d9ed3ef013962d6913294fa6fdf6c140fee (diff)
downloadgcc-ab150fb1894fda0eab14187338834d656de2a52a.zip
gcc-ab150fb1894fda0eab14187338834d656de2a52a.tar.gz
gcc-ab150fb1894fda0eab14187338834d656de2a52a.tar.bz2
During class file generation...
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. From-SVN: r29854
-rw-r--r--gcc/java/ChangeLog8
-rw-r--r--gcc/java/jcf-write.c19
2 files changed, 21 insertions, 6 deletions
diff --git a/gcc/java/ChangeLog b/gcc/java/ChangeLog
index 18030fc..00ea759 100644
--- a/gcc/java/ChangeLog
+++ b/gcc/java/ChangeLog
@@ -1,3 +1,11 @@
+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.
+
1999-10-04 Tom Tromey <tromey@cygnus.com>
* lex.h (BUILD_OPERATOR2): Return ASSIGN_ANY_TK in `lite' case as
diff --git a/gcc/java/jcf-write.c b/gcc/java/jcf-write.c
index 91567d0..5918757 100644
--- a/gcc/java/jcf-write.c
+++ b/gcc/java/jcf-write.c
@@ -358,6 +358,13 @@ CHECK_PUT(ptr, state, i)
#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 @@ generate_classfile (clas, state)
}
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 @@ generate_classfile (clas, state)
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 @@ generate_classfile (clas, state)
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++)