The attached patch addresses the non-printf related casting problems between
opcodes (which are currently doubling as PBC chunks in addition to just
being an opcode number) and INTVALs. Handles sizeof(opcode_t) <=>
sizeof(INTVAL). Includes a couple other casting fixes.
Casting between opcode_t entities and INTVALs should now be done via the
macros OP2INT() and INT2OP(). Truncation of INTVALs > opcode_t is untested.
printf formats of entities > long are still unsupported, pending a viable
solution.
<patch.101101.unsigned>
--
Bryan C. Warnock
[EMAIL PROTECTED]
Index: Configure.pl
===================================================================
RCS file: /home/perlcvs/parrot/Configure.pl,v
retrieving revision 1.24
diff -u -r1.24 Configure.pl
--- Configure.pl 2001/10/08 18:30:46 1.24
+++ Configure.pl 2001/10/12 03:44:34
@@ -114,6 +114,11 @@
$c{cc_debug} = ' ';
}
+# Make sure types are signed. We'll mark the unsigned ones as necessary
+foreach my $type (qw(iv nv opcode_t)) {
+ $c{$type} =~ s/^\s*unsigned\s+//;
+}
+
print <<"END";
Okay. Now I'm gonna probe Perl 5's configuration to see
@@ -145,6 +150,25 @@
unlink('test.c', "test_siz$c{exe}", "test$c{o}");
}
+# Validate the sizes, and compute the proper op->int/int->op conversions
+if ($c{intvalsize} < $c{opcode_t_size}) {
+ print <<"END";
+
+Your INTs are smaller than your opcodes, but need to be at
+least the same size. I'll promote them for you.
+END
+ $c{iv} = $c{opcode_t};
+ $c{intvalsize} = $c{opcode_t_size};
+}
+if ($c{intvalsize} == $c{opcode_t_size}) {
+ $c{op2int_conversion} = "(signed $c{iv})";
+ $c{int2op_conversion} = "(unsigned $c{opcode_t})";
+}
+else {
+ $c{op2int_conversion} = "($c{iv})(signed $c{opcode_t})";
+ $c{int2op_conversion} = "(unsigned $c{opcode_t})";
+}
+
print <<"END";
Done. Now I'm figuring out what formats to pass to pack() for the
@@ -299,4 +323,4 @@
sub runtestc {
`./test_siz$c{exe}`
-}
\ No newline at end of file
+}
Index: config_h.in
===================================================================
RCS file: /home/perlcvs/parrot/config_h.in,v
retrieving revision 1.8
diff -u -r1.8 config_h.in
--- config_h.in 2001/10/06 00:57:43 1.8
+++ config_h.in 2001/10/12 03:44:34
@@ -7,11 +7,15 @@
#if !defined(PARROT_CONFIG_H_GUARD)
#define PARROT_CONFIG_H_GUARD
#include <stddef.h>
+
typedef ${iv} INTVAL;
typedef ${nv} FLOATVAL;
-typedef ${opcode_t} opcode_t;
+typedef unsigned ${opcode_t} opcode_t;
typedef size_t ptrcast_t;
+
+#define OP2INT(x) (${op2int_conversion} x )
+#define INT2OP(x) (${int2op_conversion} x )
typedef struct _vtable VTABLE;
typedef void DPOINTER;
Index: packfile.c
===================================================================
RCS file: /home/perlcvs/parrot/packfile.c,v
retrieving revision 1.12
diff -u -r1.12 packfile.c
--- packfile.c 2001/10/08 00:21:02 1.12
+++ packfile.c 2001/10/12 03:44:37
@@ -328,11 +328,11 @@
cursor += sizeof(opcode_t);
#if TRACE_PACKFILE
- printf("PackFile_unpack(): Unpacking %ld bytes for fixup table...\n",
segment_size);
+ printf("PackFile_unpack(): Unpacking %lu bytes for fixup table...\n",
segment_size);
#endif
if (segment_size % sizeof(opcode_t)) {
- fprintf(stderr, "PackFile_unpack: Illegal fixup table segment size
%d (must be multiple of %d)!\n",
+ fprintf(stderr, "PackFile_unpack: Illegal fixup table segment size
%lu (must be multiple of %d)!\n",
segment_size, sizeof(opcode_t));
return 0;
}
@@ -353,11 +353,11 @@
cursor += sizeof(opcode_t);
#if TRACE_PACKFILE
- printf("PackFile_unpack(): Unpacking %ld bytes for constant
table...\n", segment_size);
+ printf("PackFile_unpack(): Unpacking %lu bytes for constant
table...\n", segment_size);
#endif
if (segment_size % sizeof(opcode_t)) {
- fprintf(stderr, "PackFile_unpack: Illegal constant table segment
size %d (must be multiple of %d)!\n",
+ fprintf(stderr, "PackFile_unpack: Illegal constant table segment
size %lu (must be multiple of %d)!\n",
segment_size, sizeof(opcode_t));
return 0;
}
@@ -378,7 +378,7 @@
cursor += sizeof(opcode_t);
#if TRACE_PACKFILE
- printf("PackFile_unpack(): Unpacking %ld bytes for byte code...\n",
segment_size);
+ printf("PackFile_unpack(): Unpacking %lu bytes for byte code...\n",
segment_size);
#endif
self->byte_code_size = segment_size;
@@ -518,7 +518,7 @@
PackFile_dump(struct PackFile * self) {
opcode_t i;
- printf("MAGIC => 0x%08x,\n", self->magic);
+ printf("MAGIC => 0x%08lx,\n", self->magic);
printf("FIXUP => {\n");
@@ -536,9 +536,9 @@
for (i = 0; i < self->byte_code_size / 4; i++) {
if (i % 8 == 0) {
- printf("\n %08x: ", i * 4);
+ printf("\n %08lx: ", i * 4);
}
- printf("%08x ", ((opcode_t *)(self->byte_code))[i]);
+ printf("%08lx ", ((opcode_t *)(self->byte_code))[i]);
}
printf("\n]\n");
@@ -1052,7 +1052,7 @@
}
for(i = 0; i < self->const_count; i++) {
- printf(" # %d:\n", i);
+ printf(" # %ld:\n", i);
PackFile_Constant_dump(self->constants[i]);
}
@@ -1117,7 +1117,7 @@
struct PackFile_Constant * self = mem_sys_allocate(sizeof(struct
PackFile_Constant));
self->type = PFC_INTEGER;
- self->integer = i;
+ self->integer = OP2INT(i);
return self;
}
@@ -1330,7 +1330,7 @@
break;
default:
- fprintf(stderr, "PackFile_Constant_clear: Unrecognized type
'%c' during unpack!\n", type);
+ fprintf(stderr, "PackFile_Constant_clear: Unrecognized type
'%lx' during unpack!\n", type);
return 0;
break;
}
@@ -1356,7 +1356,7 @@
opcode_t
PackFile_Constant_unpack_integer(struct PackFile_Constant * self, char *
packed, opcode_t packed_size) {
char * cursor;
- opcode_t value;
+ INTVAL value;
if (!self) {
return 0;
@@ -1366,7 +1366,7 @@
cursor = packed;
- value = *(opcode_t *)cursor;
+ value = OP2INT(*(opcode_t *)cursor);
cursor += sizeof(opcode_t);
self->type = PFC_INTEGER;
@@ -1597,7 +1597,7 @@
cursor += sizeof(opcode_t);
op_ptr = (opcode_t *)cursor;
- *op_ptr = self->integer;
+ *op_ptr = (opcode_t)self->integer;
cursor += sizeof(opcode_t);
break;
@@ -1694,7 +1694,7 @@
case PFC_STRING:
printf(" [ 'PFC_STRING', {\n");
- printf(" FLAGS => 0x%04x,\n", self->string->flags);
+ printf(" FLAGS => 0x%04lx,\n", self->string->flags);
printf(" ENCODING => %ld,\n",
(long) self->string->encoding->which);
printf(" TYPE => %ld,\n",
@@ -1703,7 +1703,7 @@
(long) self->string->bufused);
/* TODO: Won't do anything reasonable for most encodings */
printf(" DATA => '%.*s'\n",
- self->string->bufused, (char *)
self->string->bufstart);
+ (int) self->string->bufused, (char *)
self->string->bufstart);
printf(" } ],\n");
break;
Index: process_opfunc.pl
===================================================================
RCS file: /home/perlcvs/parrot/process_opfunc.pl,v
retrieving revision 1.24
diff -u -r1.24 process_opfunc.pl
--- process_opfunc.pl 2001/10/07 15:27:42 1.24
+++ process_opfunc.pl 2001/10/12 03:44:37
@@ -85,7 +85,7 @@
s/NUM_CONST\(([^)]+)\)/interpreter->code->const_table->constants[$1]->number/g;
s/STR_CONST\(([^)]+)\)/interpreter->code->const_table->constants[$1]->string/g;
- s/INT_CONST\(([^)]+)\)/$1/g;
+ s/INT_CONST\(([^)]+)\)/OP2INT($1)/g;
if (/^}/) {
print OUTPUT $footer, "\n";
Index: test_main.c
===================================================================
RCS file: /home/perlcvs/parrot/test_main.c,v
retrieving revision 1.16
diff -u -r1.16 test_main.c
--- test_main.c 2001/10/08 00:15:20 1.16
+++ test_main.c 2001/10/12 03:44:38
@@ -60,19 +60,19 @@
time_t foo;
printf("String %p has length %i: %.*s\n", (void *) s,
- (int) string_length(s), s->bufused,
+ (int) string_length(s), (int) s->bufused,
(char *) s->bufstart);
string_concat(s, t, 0);
printf("String %p has length %i: %.*s\n", (void *) s,
- (int) string_length(s), s->bufused,
+ (int) string_length(s), (int) s->bufused,
(char *) s->bufstart);
string_chopn(s, 4);
printf("String %p has length %i: %.*s\n", (void *) s,
- (int) string_length(s), s->bufused,
+ (int) string_length(s), (int) s->bufused,
(char *) s->bufstart);
string_chopn(s, 4);
printf("String %p has length %i: %.*s\n", (void *) s,
- (int) string_length(s), s->bufused,
+ (int) string_length(s), (int) s->bufused,
(char *) s->bufstart);
foo = time(0);
Index: include/parrot/packfile.h
===================================================================
RCS file: /home/perlcvs/parrot/include/parrot/packfile.h,v
retrieving revision 1.8
diff -u -r1.8 packfile.h
--- include/parrot/packfile.h 2001/10/06 01:04:47 1.8
+++ include/parrot/packfile.h 2001/10/12 03:44:38
@@ -27,23 +27,23 @@
struct PackFile_Constant {
opcode_t type;
- opcode_t integer;
+ INTVAL integer;
FLOATVAL number;
STRING * string;
};
struct PackFile_ConstTable {
- opcode_t const_count;
+ opcode_t const_count;
struct PackFile_Constant ** constants;
};
struct PackFile {
- opcode_t magic;
+ opcode_t magic;
struct PackFile_FixupTable * fixup_table;
struct PackFile_ConstTable * const_table;
- opcode_t byte_code_size;
+ opcode_t byte_code_size;
char * byte_code;
};