fix bugs unveiled by the previous commit

This commit is contained in:
Yuichi Nishiwaki 2015-05-30 19:57:32 +09:00
parent bad14933d2
commit 334ceb9e7c
4 changed files with 21 additions and 16 deletions

View File

@ -7,14 +7,14 @@
void void
pic_panic(pic_state PIC_UNUSED(*pic), const char *msg) pic_panic(pic_state PIC_UNUSED(*pic), const char *msg)
{ {
extern void abort();
#if DEBUG #if DEBUG
fprintf(stderr, "abort: %s\n", msg); fprintf(stderr, "abort: %s\n", msg);
#else #else
(void)msg; (void)msg;
#endif #endif
PIC_ABORT(pic); PIC_ABORT(pic);
PIC_UNREACHABLE();
} }
void void

View File

@ -220,9 +220,8 @@ pic_valid_int(double v)
#else #else
PIC_INLINE bool PIC_INLINE bool
pic_valid_int(int v) pic_valid_int(int PIC_UNUSED(v))
{ {
PIC_UNUSED(v);
return true; return true;
} }
#endif #endif

View File

@ -109,9 +109,9 @@ pic_get_args(pic_state *pic, const char *format, ...)
#if PIC_ENABLE_FLOAT #if PIC_ENABLE_FLOAT
case 'f': { case 'f': {
double *f; double *f;
pic_value v;
f = va_arg(ap, double *); f = va_arg(ap, double *);
pic_value v;
v = GET_OPERAND(pic, i); v = GET_OPERAND(pic, i);
switch (pic_type(v)) { switch (pic_type(v)) {
@ -129,10 +129,10 @@ pic_get_args(pic_state *pic, const char *format, ...)
case 'F': { case 'F': {
double *f; double *f;
bool *e; bool *e;
pic_value v;
f = va_arg(ap, double *); f = va_arg(ap, double *);
e = va_arg(ap, bool *); e = va_arg(ap, bool *);
pic_value v;
v = GET_OPERAND(pic, i); v = GET_OPERAND(pic, i);
switch (pic_type(v)) { switch (pic_type(v)) {
@ -152,10 +152,10 @@ pic_get_args(pic_state *pic, const char *format, ...)
case 'I': { case 'I': {
int *k; int *k;
bool *e; bool *e;
pic_value v;
k = va_arg(ap, int *); k = va_arg(ap, int *);
e = va_arg(ap, bool *); e = va_arg(ap, bool *);
pic_value v;
v = GET_OPERAND(pic, i); v = GET_OPERAND(pic, i);
switch (pic_type(v)) { switch (pic_type(v)) {
@ -175,9 +175,9 @@ pic_get_args(pic_state *pic, const char *format, ...)
#endif #endif
case 'i': { case 'i': {
int *k; int *k;
pic_value v;
k = va_arg(ap, int *); k = va_arg(ap, int *);
pic_value v;
v = GET_OPERAND(pic, i); v = GET_OPERAND(pic, i);
switch (pic_type(v)) { switch (pic_type(v)) {
@ -196,12 +196,12 @@ pic_get_args(pic_state *pic, const char *format, ...)
} }
case 'k': { case 'k': {
size_t *k; size_t *k;
k = va_arg(ap, size_t *);
pic_value v; pic_value v;
int x; int x;
size_t s; size_t s;
k = va_arg(ap, size_t *);
v = GET_OPERAND(pic, i); v = GET_OPERAND(pic, i);
switch (pic_type(v)) { switch (pic_type(v)) {
case PIC_TT_INT: case PIC_TT_INT:

View File

@ -94,6 +94,8 @@ xFILE *xfunopen(void *cookie, int (*read)(void *, char *, int), int (*write)(voi
} }
int xfclose(xFILE *fp) { int xfclose(xFILE *fp) {
extern void free(void *); /* FIXME */
xfflush(fp); xfflush(fp);
fp->flag = 0; fp->flag = 0;
if (fp->base != fp->buf) if (fp->base != fp->buf)
@ -102,6 +104,7 @@ int xfclose(xFILE *fp) {
} }
int x_fillbuf(xFILE *fp) { int x_fillbuf(xFILE *fp) {
extern void *malloc(size_t); /* FIXME */
int bufsize; int bufsize;
if ((fp->flag & (X_READ|X_EOF|X_ERR)) != X_READ) if ((fp->flag & (X_READ|X_EOF|X_ERR)) != X_READ)
@ -136,6 +139,7 @@ int x_fillbuf(xFILE *fp) {
} }
int x_flushbuf(int x, xFILE *fp) { int x_flushbuf(int x, xFILE *fp) {
extern void *malloc(size_t); /* FIXME */
int num_written=0, bufsize=0; int num_written=0, bufsize=0;
char c = x; char c = x;
@ -284,14 +288,15 @@ int xungetc(int c, xFILE *fp) {
} }
size_t xfread(void *ptr, size_t size, size_t count, xFILE *fp) { size_t xfread(void *ptr, size_t size, size_t count, xFILE *fp) {
char *bptr = ptr;
long nbytes; long nbytes;
int c; int c;
nbytes = size * count; nbytes = size * count;
while (nbytes > fp->cnt) { while (nbytes > fp->cnt) {
memcpy((char *)ptr, fp->ptr, fp->cnt); memcpy(bptr, fp->ptr, fp->cnt);
fp->ptr += fp->cnt; fp->ptr += fp->cnt;
ptr += fp->cnt; bptr += fp->cnt;
nbytes -= fp->cnt; nbytes -= fp->cnt;
if ((c = x_fillbuf(fp)) == EOF) { if ((c = x_fillbuf(fp)) == EOF) {
return (size * count - nbytes) / size; return (size * count - nbytes) / size;
@ -299,26 +304,27 @@ size_t xfread(void *ptr, size_t size, size_t count, xFILE *fp) {
xungetc(c, fp); xungetc(c, fp);
} }
} }
memcpy((char *)ptr, fp->ptr, nbytes); memcpy(bptr, fp->ptr, nbytes);
fp->ptr += nbytes; fp->ptr += nbytes;
fp->cnt -= nbytes; fp->cnt -= nbytes;
return count; return count;
} }
size_t xfwrite(const void *ptr, size_t size, size_t count, xFILE *fp) { size_t xfwrite(const void *ptr, size_t size, size_t count, xFILE *fp) {
const char *bptr = ptr;
long nbytes; long nbytes;
nbytes = size * count; nbytes = size * count;
while (nbytes > fp->cnt) { while (nbytes > fp->cnt) {
memcpy(fp->ptr, (char *)ptr, fp->cnt); memcpy(fp->ptr, bptr, fp->cnt);
fp->ptr += fp->cnt; fp->ptr += fp->cnt;
ptr += fp->cnt; bptr += fp->cnt;
nbytes -= fp->cnt; nbytes -= fp->cnt;
if (x_flushbuf(EOF, fp) == EOF) { if (x_flushbuf(EOF, fp) == EOF) {
return (size * count - nbytes) / size; return (size * count - nbytes) / size;
} }
} }
memcpy(fp->ptr, (char *)ptr, nbytes); memcpy(fp->ptr, bptr, nbytes);
fp->ptr += nbytes; fp->ptr += nbytes;
fp->cnt -= nbytes; fp->cnt -= nbytes;
return count; return count;