cvsuser 03/11/22 07:32:39
Modified: src packfile.c
Log:
PackFile-23: cleanup
Revision Changes Path
1.124 +73 -96 parrot/src/packfile.c
Index: packfile.c
===================================================================
RCS file: /cvs/public/parrot/src/packfile.c,v
retrieving revision 1.123
retrieving revision 1.124
diff -u -w -r1.123 -r1.124
--- packfile.c 22 Nov 2003 12:13:05 -0000 1.123
+++ packfile.c 22 Nov 2003 15:32:39 -0000 1.124
@@ -7,7 +7,7 @@
** This program is free software. It is subject to the same
** license as Parrot itself.
**
-** $Id: packfile.c,v 1.123 2003/11/22 12:13:05 leo Exp $
+** $Id: packfile.c,v 1.124 2003/11/22 15:32:39 leo Exp $
**
** History:
** Rework by Melvin; new bytecode format, make bytecode portable.
@@ -75,10 +75,6 @@
struct PackFile_Segment *self, opcode_t *);
static void pf_debug_destroy (struct PackFile_Segment *self);
-/*
- * round val up to whole opcode_t, return result in opcodes
- */
-#define ROUND_UP(val,size) (((val) + ((size) - 1))/(size))
/******************************************************************************
@@ -173,60 +169,6 @@
}
}
-/***************************************
-
-=item unpack
-
-Unpack a PackFile from a block of memory. The format is:
-
- byte wordsize
- byte byteorder
- byte major
- byte minor
- byte intvalsize
- byte floattype
- byte pad[10] = fingerprint
-
- opcode_t magic
- opcode_t language type
-
- opcode_t segment_length
- * fixup_segment
-
- if fixup segment_length != 0, a directory is here and used for
- the rest of the file
- directory segment
- * segment
- ....
-
- All new segments have this common header:
- - op_count ... total segment size incl. this count
- - itype ... internal type of data
- - id ... id of data e.g. byte code nr.
- - size ... size of data oparray
- - data[size] ... data array e.g. bytecode
- segment specific data follow here
-
-
- else:
-
- opcode_t segment_length
- * const_segment
-
- opcode_t segment_length
- * byte_code
-
-
-Checks to see if the magic matches the Parrot magic number for
-Parrot PackFiles.
-
-Returns one (1) if everything is OK, else zero (0).
-
-=back
-
-=cut
-
-***************************************/
static void
fixup_subs(struct Parrot_Interp *interpreter, struct PackFile *self)
{
@@ -279,6 +221,49 @@
}
}
+/***************************************
+
+=item unpack
+
+Unpack a PackFile from a block of memory. The format is:
+
+ byte wordsize
+ byte byteorder
+ byte major
+ byte minor
+ byte intvalsize
+ byte floattype
+ byte pad[10] = fingerprint
+
+ opcode_t magic
+ opcode_t language type
+
+ opcode_t dir_format
+ opcode_t padding
+
+ directory segment
+ * segment
+ ....
+
+ All segments have this common header:
+ - op_count ... total segment size incl. this count
+ - itype ... internal type of data
+ - id ... id of data e.g. byte code nr.
+ - size ... size of data oparray
+ - data[size] ... data array e.g. bytecode
+ segment specific data follow here
+
+Checks to see if the magic matches the Parrot magic number for
+Parrot PackFiles.
+
+Returns size of unpacked if everything is OK, else zero (0).
+
+=back
+
+=cut
+
+***************************************/
+
opcode_t
PackFile_unpack(struct Parrot_Interp *interpreter, struct PackFile *self,
opcode_t *packed, size_t packed_size)
@@ -351,18 +336,12 @@
#endif
/*
- * Unpack the Fixup Table Segment:
+ * Unpack the dir_format
*/
header->dir_format = PF_fetch_opcode(self, &cursor);
- if (header->dir_format == 0) {
- PIO_eprintf(NULL,
- "PackFile_unpack: Dir format 0 no longer supported!\n");
- return 0;
- }
- else {
- /* new format use directory */
+ /* dir_format 1 use directory */
if (header->dir_format != PF_DIR_FORMAT ) {
PIO_eprintf(NULL,
"PackFile_unpack: Unknowm dir format found %d!\n",
@@ -371,6 +350,9 @@
}
(void)PF_fetch_opcode(self, &cursor); /* pad */
self->directory.base.file_offset = (size_t)(cursor - self->src);
+ /*
+ * now unpack dir, which unpacks its contents ...
+ */
cursor = PackFile_Segment_unpack(interpreter,
&self->directory.base, cursor);
/* shortcut */
@@ -380,10 +362,10 @@
*/
fixup_subs(interpreter, self);
/*
- * TODO JIT and/or prederef the sub/the bytecode
+ * JITting and/or prederefing the sub/the bytecode is done
+ * in switch_to_cs before actual usage of the segment
*/
- }
#ifdef PARROT_HAS_HEADER_SYSMMAN
if (self->is_mmap_ped && (
self->need_endianize || self->need_wordsize)) {
@@ -667,8 +649,8 @@
return cursor;
}
-void default_dump_header (struct Parrot_Interp *interpreter,
- struct PackFile_Segment *self)
+void
+default_dump_header (Parrot_Interp interpreter, struct PackFile_Segment *self)
{
PIO_printf(interpreter, "%s => [ # offs 0x%x(%d)",
self->name, (int)self->file_offset, (int)self->file_offset);
@@ -677,8 +659,8 @@
(int)self->id, (int)self->size);
}
-static void default_dump (struct Parrot_Interp *interpreter,
- struct PackFile_Segment *self)
+static void
+default_dump (Parrot_Interp interpreter, struct PackFile_Segment *self)
{
size_t i;
@@ -1023,10 +1005,8 @@
/* number of segments + default, we need it for the offsets */
size = 1 + default_packed_size(self);
for (i = 0; i < dir->num_segments; i++) {
- UINTVAL str_len;
size += 3; /* type, offset, size */
- str_len = strlen (dir->segments[i]->name);
- size += ROUND_UP(str_len + 1, sizeof(opcode_t));
+ size += PF_size_cstring(dir->segments[i]->name);
}
if (align && size % align)
size += (align - size % align); /* pad/align it */
@@ -1057,10 +1037,8 @@
for (i = 0; i < num_segs; i++) {
struct PackFile_Segment *seg = dir->segments[i];
- size_t str_len = strlen (seg->name);
*cursor++ = seg->type;
- strcpy ((char *)cursor, seg->name);
- cursor += ROUND_UP(str_len + 1, sizeof(opcode_t));
+ cursor = PF_store_cstring(cursor, seg->name);
*cursor++ = seg->file_offset;
*cursor++ = seg->op_count;
}
@@ -1432,8 +1410,7 @@
switch (ft->fixups[i]->type) {
case enum_fixup_label:
case enum_fixup_sub:
- strcpy ((char *)cursor, ft->fixups[i]->name);
- cursor += PF_size_cstring(ft->fixups[i]->name);
+ cursor = PF_store_cstring(cursor, ft->fixups[i]->name);
*cursor++ = ft->fixups[i]->offset;
break;
default: