summaryrefslogtreecommitdiff
path: root/libguile/dump.c
diff options
context:
space:
mode:
Diffstat (limited to 'libguile/dump.c')
-rw-r--r--libguile/dump.c48
1 files changed, 30 insertions, 18 deletions
diff --git a/libguile/dump.c b/libguile/dump.c
index 69af7ebb0..de0b46d63 100644
--- a/libguile/dump.c
+++ b/libguile/dump.c
@@ -246,22 +246,21 @@ scm_store_pad (SCM dstate)
}
void
-scm_store_string (const char *addr, scm_sizet size, SCM dstate)
+scm_store_word (const scm_bits_t word, SCM dstate)
{
struct scm_dstate *p = SCM_DSTATE_DATA (dstate);
- while (p->image_index + size + 1 >= p->image_size)
+ while (p->image_index + sizeof (scm_bits_t) >= p->image_size)
dstate_extend (p);
- memcpy (p->image_base + p->image_index, addr, size);
- memcpy (p->image_base + p->image_index + size, "\0", 1);
- p->image_index += size + 1;
- scm_store_pad (dstate);
+ memcpy (p->image_base + p->image_index, &word, sizeof (scm_bits_t));
+ p->image_index += sizeof (scm_bits_t);
}
void
scm_store_bytes (const void *addr, scm_sizet size, SCM dstate)
{
struct scm_dstate *p = SCM_DSTATE_DATA (dstate);
- while (p->image_index + size >= p->image_size)
+ scm_store_word (size, dstate);
+ while (p->image_index + size + sizeof (scm_bits_t) >= p->image_size)
dstate_extend (p);
memcpy (p->image_base + p->image_index, addr, size);
p->image_index += size;
@@ -269,9 +268,15 @@ scm_store_bytes (const void *addr, scm_sizet size, SCM dstate)
}
void
-scm_store_word (const scm_bits_t word, SCM dstate)
+scm_store_string (const char *addr, scm_sizet size, SCM dstate)
{
- scm_store_bytes (&word, sizeof (scm_bits_t), dstate);
+ struct scm_dstate *p = SCM_DSTATE_DATA (dstate);
+ while (p->image_index + size + 1 >= p->image_size)
+ dstate_extend (p);
+ memcpy (p->image_base + p->image_index, addr, size);
+ memcpy (p->image_base + p->image_index + size, "\0", 1);
+ p->image_index += size + 1;
+ scm_store_pad (dstate);
}
void
@@ -302,30 +307,37 @@ scm_restore_pad (struct scm_dstate *p)
}
void
-scm_restore_string (const char **pp, scm_sizet *sizep, SCM dstate)
+scm_restore_word (scm_bits_t *wordp, SCM dstate)
{
struct scm_dstate *p = SCM_DSTATE_DATA (dstate);
- *pp = p->image_base + p->image_index;
- *sizep = strlen (*pp);
- p->image_index += *sizep + 1;
- scm_restore_pad (p);
+ *wordp = *(scm_bits_t *) (p->image_base + p->image_index);
+ p->image_index += sizeof (scm_bits_t);
}
void
-scm_restore_bytes (const void **pp, scm_sizet size, SCM dstate)
+scm_restore_bytes (const void **pp, scm_sizet *sizep, SCM dstate)
{
+ scm_bits_t size;
struct scm_dstate *p = SCM_DSTATE_DATA (dstate);
+ scm_restore_word (&size, dstate);
+ if (sizep)
+ *sizep = size;
*pp = p->image_base + p->image_index;
p->image_index += size;
scm_restore_pad (p);
}
void
-scm_restore_word (scm_bits_t *wordp, SCM dstate)
+scm_restore_string (const char **pp, scm_sizet *sizep, SCM dstate)
{
+ int len;
struct scm_dstate *p = SCM_DSTATE_DATA (dstate);
- *wordp = *(scm_bits_t *) (p->image_base + p->image_index);
- p->image_index += sizeof (scm_bits_t);
+ *pp = p->image_base + p->image_index;
+ len = strlen (*pp);
+ if (sizep)
+ *sizep = len;
+ p->image_index += len + 1;
+ scm_restore_pad (p);
}
void