don't use global mutable variable!

This commit is contained in:
Yuichi Nishiwaki
2015-06-19 03:06:57 +09:00
parent e43a9c7881
commit 78bd3047f8
7 changed files with 32 additions and 25 deletions
+6 -5
View File
@@ -46,6 +46,9 @@ extern "C" {
#include "picrin/value.h"
typedef struct pic_code pic_code;
typedef struct pic_state pic_state;
#include "picrin/file.h"
typedef struct pic_jmpbuf {
PIC_JMPBUF buf;
@@ -71,9 +74,7 @@ typedef struct {
typedef void *(*pic_allocf)(void *, size_t);
typedef struct xFILE xFILE;
typedef struct {
struct pic_state {
int argc;
char **argv, **envp;
@@ -137,6 +138,7 @@ typedef struct {
struct pic_reg *attrs;
struct pic_reader *reader;
xFILE files[XOPEN_MAX];
bool gc_enable;
struct pic_heap *heap;
@@ -148,7 +150,7 @@ typedef struct {
pic_code *iseq; /* for pic_apply_trampoline */
char *native_stack_start;
} pic_state;
};
typedef pic_value (*pic_func_t)(pic_state *);
@@ -283,7 +285,6 @@ pic_value pic_fdisplay(pic_state *, pic_value, xFILE *);
#include "picrin/read.h"
#include "picrin/vector.h"
#include "picrin/reg.h"
#include "picrin/file.h"
#if defined(__cplusplus)
}
+8 -8
View File
@@ -14,7 +14,7 @@ extern "C" {
#define XBUFSIZ 1024
#define XOPEN_MAX 1024
struct xFILE {
typedef struct {
/* buffer */
char buf[1]; /* fallback buffer */
long cnt; /* characters left */
@@ -29,13 +29,13 @@ struct xFILE {
int (*close)(pic_state *, void *);
} vtable;
int flag; /* mode of the file access */
};
} xFILE;
extern xFILE x_iob[XOPEN_MAX];
#define xstdin (&pic->files[0])
#define xstdout (&pic->files[1])
#define xstderr (&pic->files[2])
#define xstdin (x_iob[0].vtable.cookie || (x_iob[0].vtable.cookie = stdin ), &x_iob[0])
#define xstdout (x_iob[1].vtable.cookie || (x_iob[1].vtable.cookie = stdout), &x_iob[1])
#define xstderr (x_iob[2].vtable.cookie || (x_iob[2].vtable.cookie = stderr), &x_iob[2])
extern const xFILE x_iob[XOPEN_MAX];
enum _flags {
X_READ = 01,
@@ -63,8 +63,8 @@ enum _flags {
#define xputchar(pic, x) xputc((pic), (x), xstdout)
/* resource aquisition */
xFILE *xfunopen(void *cookie, int (*read)(pic_state *, void *, char *, int), int (*write)(pic_state *, void *, const char *, int), long (*seek)(pic_state *, void *, long, int), int (*close)(pic_state *, void *));
xFILE *xfopen(const char *, const char *);
xFILE *xfunopen(pic_state *, void *cookie, int (*read)(pic_state *, void *, char *, int), int (*write)(pic_state *, void *, const char *, int), long (*seek)(pic_state *, void *, long, int), int (*close)(pic_state *, void *));
xFILE *xfopen(pic_state *, const char *, const char *);
int xfclose(pic_state *, xFILE *);
/* buffer management */