From 819e76b711c400b936e394ba1fa4159789a8b51c Mon Sep 17 00:00:00 2001 From: CPunch Date: Sat, 27 May 2023 23:15:12 -0500 Subject: [PATCH] cdump.c: fix instruction and line info dumping --- src/cdump.c | 11 ++++++----- src/cdump.h | 2 -- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/cdump.c b/src/cdump.c index 3f37e25..a2f6258 100644 --- a/src/cdump.c +++ b/src/cdump.c @@ -3,6 +3,7 @@ #include "cmem.h" #include "cobj.h" #include "cvalue.h" +#include "cdebug.h" typedef struct { @@ -45,10 +46,10 @@ static void writeSize(DumpState *dstate, size_t d) writeBlock(dstate, &d, sizeof(size_t)); } -static void writeVector(DumpState *dstate, const void *data, size_t size) +static void writeVector(DumpState *dstate, const void *data, size_t size, size_t count) { - writeSize(dstate, size); - writeBlock(dstate, data, size); + writeSize(dstate, count); + writeBlock(dstate, data, size * count); } static void writeHeader(DumpState *dstate) @@ -86,10 +87,10 @@ static void writeCObjFunction(DumpState *dstate, CObjFunction *obj) writeu8(dstate, obj->variadic); /* write chunk info */ - writeVector(dstate, obj->chunk.buf, sizeof(uint8_t) * obj->chunk.count); + writeVector(dstate, obj->chunk.buf, sizeof(uint8_t), obj->chunk.count); /* write line info */ - writeVector(dstate, obj->chunk.lineInfo, sizeof(int) * obj->chunk.count); + writeVector(dstate, obj->chunk.lineInfo, sizeof(int), obj->chunk.count); /* write constants */ writeSize(dstate, obj->chunk.constants.count); diff --git a/src/cdump.h b/src/cdump.h index 43a10dc..15bb745 100644 --- a/src/cdump.h +++ b/src/cdump.h @@ -9,8 +9,6 @@ #define COSMO_MAGIC "COS\x12" #define COSMO_MAGIC_LEN 4 -typedef int (*cosmo_Writer)(CState *state, const void *data, size_t size, const void *ud); - bool cosmoD_isBigEndian(); /* returns non-zero on error */