Actually, I started down this road as well, but thought it would make more
sense to make the opcode_t unsigned. This would allow us to keep it a
consistent size across platforms if we want.
Thoughts?
David
----- Original Message -----
From: "Chip Turner" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, January 01, 2002 8:38 AM
Subject: Re: [patch] Signed correctness, plus other warnings fixes [1/?]
> Dan Sugalski <[EMAIL PROTECTED]> writes:
>
> > At 06:12 AM 1/1/2002 -0500, Chip Turner wrote:
> > >Well, looks like the body of the message I send mysteriously
> > >disappeared, much to my chagrin. Here it is. Patch included inline,
> > >as well.
> >
> > Applied, thanks.
>
> Here's another one, touching encoding a bit, as well as packfile.
>
> Chip
>
> Index: jit.c
> ===================================================================
> RCS file: /cvs/public/parrot/jit.c,v
> retrieving revision 1.5
> diff -u -b -B -r1.5 jit.c
> --- jit.c 31 Dec 2001 19:37:53 -0000 1.5
> +++ jit.c 1 Jan 2002 18:37:49 -0000
> @@ -34,7 +34,8 @@
> build_asm(struct Parrot_Interp *interpreter,opcode_t *pc, opcode_t
*code_start, opcode_t *code_end)
> {
> char *arena, *arena_start;
> - INTVAL *address,ivalue,size,i,k;
> + INTVAL *address,ivalue,i,k;
> + UINTVAL size;
> INTVAL *op_address, prev_address, bytecode_position;
>
> /* temporary variables */
> @@ -160,16 +161,16 @@
> address = (INTVAL *)s->bufstart;
> break;
> case 2:
> - address = &s->buflen;
> + address = (INTVAL *)&s->buflen;
> break;
> case 3:
> - address = &s->flags;
> + address = (INTVAL *)&s->flags;
> break;
> case 4:
> - address = &s->bufused;
> + address = (INTVAL *)&s->bufused;
> break;
> case 5:
> - address = &s->strlen;
> + address = (INTVAL *)&s->strlen;
> break;
> case 6:
> address = (INTVAL *)s->encoding;
> Index: packfile.c
> ===================================================================
> RCS file: /cvs/public/parrot/packfile.c,v
> retrieving revision 1.19
> diff -u -b -B -r1.19 packfile.c
> --- packfile.c 1 Jan 2002 18:17:54 -0000 1.19
> +++ packfile.c 1 Jan 2002 18:37:49 -0000
> @@ -199,7 +199,7 @@
>
> ***************************************/
>
> -opcode_t
> +UINTVAL
> PackFile_get_byte_code_size(struct PackFile * self) {
> return self->byte_code_size;
> }
> @@ -237,7 +237,7 @@
> ***************************************/
>
> void
> -PackFile_set_byte_code(struct PackFile * self, opcode_t byte_code_size,
char * byte_code) {
> +PackFile_set_byte_code(struct PackFile * self, UINTVAL byte_code_size,
char * byte_code) {
> if (self->byte_code) {
> mem_sys_free(self->byte_code);
> self->byte_code = NULL;
> @@ -252,7 +252,7 @@
> return;
> }
>
> - mem_sys_memcopy(self->byte_code, byte_code,
(INTVAL)byte_code_size);
> + mem_sys_memcopy(self->byte_code, byte_code, byte_code_size);
>
> self->byte_code_size = byte_code_size;
> }
> @@ -288,8 +288,8 @@
> ***************************************/
>
> opcode_t
> -PackFile_unpack(struct Parrot_Interp *interpreter, struct PackFile *
self, char * packed, opcode_t packed_size) {
> - opcode_t segment_size;
> +PackFile_unpack(struct Parrot_Interp *interpreter, struct PackFile *
self, char * packed, UINTVAL packed_size) {
> + UINTVAL segment_size;
> char * cursor;
> opcode_t * op_ptr;
>
> @@ -516,9 +516,9 @@
>
> void
> PackFile_dump(struct PackFile * self) {
> - opcode_t i;
> + UINTVAL i;
>
> - printf("MAGIC => 0x%08lx,\n", (long) 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 %08lx: ", (long) i * 4);
> + printf("\n %08lx: ", i * 4);
> }
> - printf("%08lx ", (long) ((opcode_t *)(self->byte_code))[i]);
> + printf("%08lx ", ((opcode_t *)(self->byte_code))[i]);
> }
>
> printf("\n]\n");
> @@ -646,7 +646,7 @@
> ***************************************/
>
> opcode_t
> -PackFile_FixupTable_unpack(struct PackFile_FixupTable * self, char *
packed, opcode_t packed_size) {
> +PackFile_FixupTable_unpack(struct PackFile_FixupTable * self, char *
packed, UINTVAL packed_size) {
> return 1;
> }
>
> @@ -781,7 +781,7 @@
>
> void
> PackFile_ConstTable_clear(struct PackFile_ConstTable * self) {
> - opcode_t i;
> + UINTVAL i;
>
> if (!self) {
> fprintf(stderr, "PackFile_ConstTable_DELETE: self == NULL!\n");
> @@ -837,7 +837,7 @@
> void
> PackFile_ConstTable_push_constant(struct PackFile_ConstTable * self,
struct PackFile_Constant * constant) {
> struct PackFile_Constant ** temp;
> - opcode_t i;
> + UINTVAL i;
>
> if (!self) {
> fprintf(stderr, "PackFile_ConstTable_push_constant: self ==
NULL!\n");
> @@ -849,7 +849,7 @@
> return;
> }
>
> - temp = mem_sys_allocate((self->const_count + 1) *
(INTVAL)sizeof(struct PackFile_Constant *));
> + temp = mem_sys_allocate((self->const_count + 1) * sizeof(struct
PackFile_Constant *));
>
> if (!temp) {
> fprintf(stderr, "Unable to reallocate Constant array to push a
new Constant!\n");
> @@ -887,7 +887,7 @@
> return NULL;
> }
>
> - if (index < 0 || index >= self->const_count) {
> + if (index < 0 || index >= (INTVAL)self->const_count) {
> return NULL;
> }
>
> @@ -911,10 +911,10 @@
> ***************************************/
>
> opcode_t
> -PackFile_ConstTable_unpack(struct Parrot_Interp *interpreter, struct
PackFile_ConstTable * self, char * packed, opcode_t packed_size) {
> +PackFile_ConstTable_unpack(struct Parrot_Interp *interpreter, struct
PackFile_ConstTable * self, char * packed, UINTVAL packed_size) {
> char * cursor;
> opcode_t * op_ptr;
> - opcode_t i;
> + UINTVAL i;
>
> if (!self) {
> fprintf(stderr, "PackFile_ConstTable_unpack: self == NULL!\n");
> @@ -937,7 +937,7 @@
> return 1;
> }
>
> - self->constants = mem_sys_allocate(self->const_count *
(INTVAL)sizeof(struct PackFile_Constant *));
> + self->constants = mem_sys_allocate(self->const_count * sizeof(struct
PackFile_Constant *));
>
> if (!self->constants) {
> fprintf(stderr, "PackFile_ConstTable_unpack: Could not allocate
memory for array!\n");
> @@ -974,7 +974,7 @@
>
> opcode_t
> PackFile_ConstTable_pack_size(struct PackFile_ConstTable * self) {
> - opcode_t i;
> + UINTVAL i;
> opcode_t size = 0;
>
> if (!self) {
> @@ -1009,7 +1009,7 @@
> PackFile_ConstTable_pack(struct PackFile_ConstTable * self, char *
packed) {
> char * cursor;
> opcode_t * op_ptr;
> - opcode_t i;
> + UINTVAL i;
>
> if (!self) {
> fprintf(stderr, "PackFile_ConstTable_pack: self == NULL!\n");
> @@ -1044,7 +1044,7 @@
>
> void
> PackFile_ConstTable_dump(struct PackFile_ConstTable * self) {
> - opcode_t i;
> + UINTVAL i;
>
> if (!self) {
> fprintf(stderr, "PackFile_ConstTable_dump: self == NULL!\n");
> @@ -1052,7 +1052,7 @@
> }
>
> for(i = 0; i < self->const_count; i++) {
> - printf(" # %ld:\n", (long) i);
> + printf(" # %u:\n", (unsigned int)i);
> PackFile_Constant_dump(self->constants[i]);
> }
>
> @@ -1276,10 +1276,10 @@
> ***************************************/
>
> opcode_t
> -PackFile_Constant_unpack(struct Parrot_Interp *interpreter, struct
PackFile_Constant * self, char * packed, opcode_t packed_size) {
> +PackFile_Constant_unpack(struct Parrot_Interp *interpreter, struct
PackFile_Constant * self, char * packed, UINTVAL packed_size) {
> char * cursor;
> - opcode_t type;
> - opcode_t size;
> + UINTVAL type;
> + UINTVAL size;
>
> if (!self) {
> return 0;
> @@ -1287,8 +1287,8 @@
>
> cursor = packed;
>
> - type = *(opcode_t *)cursor;
> - cursor += sizeof(opcode_t);
> + type = *(UINTVAL *)cursor;
> + cursor += sizeof(UINTVAL);
>
> #if TRACE_PACKFILE
> printf("PackFile_Constant_unpack(): Type is %ld ('%c')...\n", type,
(char)type);
> @@ -1330,7 +1330,7 @@
> break;
>
> default:
> - fprintf(stderr, "PackFile_Constant_clear: Unrecognized type
'%c' during unpack!\n", (int) type);
> + fprintf(stderr, "PackFile_Constant_clear: Unrecognized type
'%c' during unpack!\n", (int)type);
> return 0;
> break;
> }
> @@ -1354,7 +1354,7 @@
> ***************************************/
>
> opcode_t
> -PackFile_Constant_unpack_integer(struct PackFile_Constant * self, char *
packed, opcode_t packed_size) {
> +PackFile_Constant_unpack_integer(struct PackFile_Constant * self, char *
packed, UINTVAL packed_size) {
> char * cursor;
> opcode_t value;
>
> @@ -1395,7 +1395,7 @@
> ***************************************/
>
> opcode_t
> -PackFile_Constant_unpack_number(struct PackFile_Constant * self, char *
packed, opcode_t packed_size) {
> +PackFile_Constant_unpack_number(struct PackFile_Constant * self, char *
packed, UINTVAL packed_size) {
> char * cursor;
> FLOATVAL value;
>
> @@ -1439,12 +1439,12 @@
> ***************************************/
>
> opcode_t
> -PackFile_Constant_unpack_string(struct Parrot_Interp *interpreter, struct
PackFile_Constant * self, char * packed, opcode_t packed_size) {
> +PackFile_Constant_unpack_string(struct Parrot_Interp *interpreter, struct
PackFile_Constant * self, char * packed, UINTVAL packed_size) {
> char * cursor;
> - opcode_t flags;
> + UINTVAL flags;
> opcode_t encoding;
> opcode_t type;
> - opcode_t size;
> + UINTVAL size;
>
> if (!self) {
> return 0;
> @@ -1513,7 +1513,7 @@
>
> opcode_t
> PackFile_Constant_pack_size(struct PackFile_Constant * self) {
> - opcode_t packed_size;
> + UINTVAL packed_size;
> opcode_t padded_size;
>
> if (!self) {
> @@ -1578,7 +1578,7 @@
> char * cursor;
> opcode_t * op_ptr;
> FLOATVAL * nv_ptr;
> - opcode_t i;
> + UINTVAL i;
> opcode_t padded_size;
> opcode_t packed_size;
>
> Index: string.c
> ===================================================================
> RCS file: /cvs/public/parrot/string.c,v
> retrieving revision 1.35
> diff -u -b -B -r1.35 string.c
> --- string.c 1 Jan 2002 17:53:50 -0000 1.35
> +++ string.c 1 Jan 2002 18:37:50 -0000
> @@ -182,7 +182,7 @@
> destend = deststart + dest->buflen;
>
> while (srcstart < srcend) {
> - INTVAL c = src->encoding->decode(srcstart);
> + UINTVAL c = src->encoding->decode(srcstart);
>
> if (transcoder1) c = transcoder1(c);
> if (transcoder2) c = transcoder2(c);
> Index: encodings/singlebyte.c
> ===================================================================
> RCS file: /cvs/public/parrot/encodings/singlebyte.c,v
> retrieving revision 1.8
> diff -u -b -B -r1.8 singlebyte.c
> --- encodings/singlebyte.c 1 Jan 2002 18:24:24 -0000 1.8
> +++ encodings/singlebyte.c 1 Jan 2002 18:37:50 -0000
> @@ -30,7 +30,7 @@
> singlebyte_encode (const void *ptr, UINTVAL c) {
> byte_t *bptr = (byte_t*)ptr;
>
> - if (c < 0 || c > 255) {
> + if (c > 255) {
> INTERNAL_EXCEPTION(INVALID_CHARACTER,
> "Invalid character for single byte
encoding\n");
> }
> Index: encodings/utf16.c
> ===================================================================
> RCS file: /cvs/public/parrot/encodings/utf16.c,v
> retrieving revision 1.6
> diff -u -b -B -r1.6 utf16.c
> --- encodings/utf16.c 1 Jan 2002 17:09:52 -0000 1.6
> +++ encodings/utf16.c 1 Jan 2002 18:37:50 -0000
> @@ -60,7 +60,7 @@
> utf16_encode (const void *ptr, UINTVAL c) {
> utf16_t *u16ptr = (utf16_t*)ptr;
>
> - if (c < 0 || c > 0x10FFFF || UNICODE_IS_SURROGATE(c)) {
> + if (c > 0x10FFFF || UNICODE_IS_SURROGATE(c)) {
> INTERNAL_EXCEPTION(INVALID_CHARACTER,
> "Invalid character for UTF-16 encoding\n");
> }
> Index: encodings/utf32.c
> ===================================================================
> RCS file: /cvs/public/parrot/encodings/utf32.c,v
> retrieving revision 1.3
> diff -u -b -B -r1.3 utf32.c
> --- encodings/utf32.c 1 Jan 2002 17:09:52 -0000 1.3
> +++ encodings/utf32.c 1 Jan 2002 18:37:50 -0000
> @@ -33,7 +33,7 @@
> utf32_encode (const void *ptr, UINTVAL c) {
> utf32_t *u32ptr = (utf32_t*)ptr;
>
> - if (c < 0 || c > 0x10FFFF || UNICODE_IS_SURROGATE(c)) {
> + if (c > 0x10FFFF || UNICODE_IS_SURROGATE(c)) {
> INTERNAL_EXCEPTION(INVALID_CHARACTER,
> "Invalid character for UTF-32 encoding\n");
> }
> Index: encodings/utf8.c
> ===================================================================
> RCS file: /cvs/public/parrot/encodings/utf8.c,v
> retrieving revision 1.7
> diff -u -b -B -r1.7 utf8.c
> --- encodings/utf8.c 1 Jan 2002 17:09:52 -0000 1.7
> +++ encodings/utf8.c 1 Jan 2002 18:37:50 -0000
> @@ -82,7 +82,7 @@
> UINTVAL len = UNISKIP(c);
> utf8_t *u8end = u8ptr + len - 1;
>
> - if (c < 0 || c > 0x10FFFF || UNICODE_IS_SURROGATE(c)) {
> + if (c > 0x10FFFF || UNICODE_IS_SURROGATE(c)) {
> INTERNAL_EXCEPTION(INVALID_CHARACTER,
> "Invalid character for UTF-8 encoding\n");
> }
> Index: include/parrot/chartype.h
> ===================================================================
> RCS file: /cvs/public/parrot/include/parrot/chartype.h,v
> retrieving revision 1.3
> diff -u -b -B -r1.3 chartype.h
> --- include/parrot/chartype.h 27 Dec 2001 18:50:28 -0000 1.3
> +++ include/parrot/chartype.h 1 Jan 2002 18:37:50 -0000
> @@ -13,7 +13,7 @@
> #if !defined(PARROT_CHARTYPE_H_GUARD)
> #define PARROT_ENCODING_H_GUARD
>
> -typedef INTVAL (*CHARTYPE_TRANSCODER)(INTVAL c);
> +typedef UINTVAL (*CHARTYPE_TRANSCODER)(UINTVAL c);
>
> typedef struct {
> const char *name;
> Index: include/parrot/jit.h
> ===================================================================
> RCS file: /cvs/public/parrot/include/parrot/jit.h,v
> retrieving revision 1.5
> diff -u -b -B -r1.5 jit.h
> --- include/parrot/jit.h 31 Dec 2001 19:37:53 -0000 1.5
> +++ include/parrot/jit.h 1 Jan 2002 18:37:50 -0000
> @@ -42,7 +42,7 @@
>
> typedef struct {
> const char *assembly;
> - int size;
> + unsigned int size;
> int nargop;
> /* &interpreter->xxx->register[pc[x]] */
> substitution_t intval_register_address;
> Index: include/parrot/packfile.h
> ===================================================================
> RCS file: /cvs/public/parrot/include/parrot/packfile.h,v
> retrieving revision 1.9
> diff -u -b -B -r1.9 packfile.h
> --- include/parrot/packfile.h 22 Oct 2001 21:43:25 -0000 1.9
> +++ include/parrot/packfile.h 1 Jan 2002 18:37:50 -0000
> @@ -34,7 +34,7 @@
>
>
> struct PackFile_ConstTable {
> - opcode_t const_count;
> + UINTVAL const_count;
> struct PackFile_Constant ** constants;
> };
>
> @@ -43,7 +43,7 @@
> opcode_t magic;
> struct PackFile_FixupTable * fixup_table;
> struct PackFile_ConstTable * const_table;
> - opcode_t byte_code_size;
> + UINTVAL byte_code_size;
> char * byte_code;
> };
>
> @@ -67,17 +67,17 @@
> void
> PackFile_set_magic(struct PackFile * self, opcode_t magic);
>
> -opcode_t
> +UINTVAL
> PackFile_get_byte_code_size(struct PackFile * self);
>
> char *
> PackFile_get_byte_code(struct PackFile * self);
>
> void
> -PackFile_set_byte_code(struct PackFile * self, opcode_t byte_code_size,
char * byte_code);
> +PackFile_set_byte_code(struct PackFile * self, UINTVAL byte_code_size,
char * byte_code);
>
> opcode_t
> -PackFile_unpack(struct Parrot_Interp *interpreter, struct PackFile *
self, char * packed, opcode_t packed_size);
> +PackFile_unpack(struct Parrot_Interp *interpreter, struct PackFile *
self, char * packed, UINTVAL packed_size);
>
> opcode_t
> PackFile_pack_size(struct PackFile * self);
> @@ -103,7 +103,7 @@
> PackFile_FixupTable_clear(struct PackFile_FixupTable * self);
>
> opcode_t
> -PackFile_FixupTable_unpack(struct PackFile_FixupTable * self, char *
packed, opcode_t packed_size);
> +PackFile_FixupTable_unpack(struct PackFile_FixupTable * self, char *
packed, UINTVAL packed_size);
>
> opcode_t
> PackFile_FixupTable_pack_size(struct PackFile_FixupTable * self);
> @@ -138,7 +138,7 @@
> PackFile_ConstTable_constant(struct PackFile_ConstTable * self, opcode_t
index);
>
> opcode_t
> -PackFile_ConstTable_unpack(struct Parrot_Interp *interpreter, struct
PackFile_ConstTable * self, char * packed, opcode_t packed_size);
> +PackFile_ConstTable_unpack(struct Parrot_Interp *interpreter, struct
PackFile_ConstTable * self, char * packed, UINTVAL packed_size);
>
> opcode_t
> PackFile_ConstTable_pack_size(struct PackFile_ConstTable * self);
> @@ -185,16 +185,16 @@
> PackFile_Constant_set_string(struct PackFile_Constant * self, STRING *
s);
>
> opcode_t
> -PackFile_Constant_unpack(struct Parrot_Interp *interpreter, struct
PackFile_Constant * self, char * packed, opcode_t packed_size);
> +PackFile_Constant_unpack(struct Parrot_Interp *interpreter, struct
PackFile_Constant * self, char * packed, UINTVAL packed_size);
>
> opcode_t
> -PackFile_Constant_unpack_integer(struct PackFile_Constant * self, char *
packed, opcode_t packed_size);
> +PackFile_Constant_unpack_integer(struct PackFile_Constant * self, char *
packed, UINTVAL packed_size);
>
> opcode_t
> -PackFile_Constant_unpack_number(struct PackFile_Constant * self, char *
packed, opcode_t packed_size);
> +PackFile_Constant_unpack_number(struct PackFile_Constant * self, char *
packed, UINTVAL packed_size);
>
> opcode_t
> -PackFile_Constant_unpack_string(struct Parrot_Interp *interpreter, struct
PackFile_Constant * self, char * packed, opcode_t packed_size);
> +PackFile_Constant_unpack_string(struct Parrot_Interp *interpreter, struct
PackFile_Constant * self, char * packed, UINTVAL packed_size);
>
> opcode_t
> PackFile_Constant_pack_size(struct PackFile_Constant * self);
>
> --
> Chip Turner [EMAIL PROTECTED]
> Red Hat Network