mirror of
https://github.com/mirror/tinycc.git
synced 2025-01-01 04:20:09 +08:00
use CH_EOB
This commit is contained in:
parent
63965fc585
commit
2f219d8702
20
tcc.c
20
tcc.c
@ -1150,7 +1150,8 @@ TokenSym *tok_alloc(const char *str, int len)
|
|||||||
ts->sym_identifier = NULL;
|
ts->sym_identifier = NULL;
|
||||||
ts->len = len;
|
ts->len = len;
|
||||||
ts->hash_next = NULL;
|
ts->hash_next = NULL;
|
||||||
memcpy(ts->str, str, len + 1);
|
memcpy(ts->str, str, len);
|
||||||
|
ts->str[len] = '\0';
|
||||||
*pts = ts;
|
*pts = ts;
|
||||||
return ts;
|
return ts;
|
||||||
}
|
}
|
||||||
@ -7557,24 +7558,35 @@ static int tcc_compile(TCCState *s1)
|
|||||||
return s1->nb_errors != 0 ? -1 : 0;
|
return s1->nb_errors != 0 ? -1 : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef LIBTCC
|
||||||
int tcc_compile_string(TCCState *s, const char *str)
|
int tcc_compile_string(TCCState *s, const char *str)
|
||||||
{
|
{
|
||||||
BufferedFile bf1, *bf = &bf1;
|
BufferedFile bf1, *bf = &bf1;
|
||||||
int ret;
|
int ret, len;
|
||||||
|
char *buf;
|
||||||
|
|
||||||
/* init file structure */
|
/* init file structure */
|
||||||
bf->fd = -1;
|
bf->fd = -1;
|
||||||
bf->buf_ptr = (char *)str;
|
/* XXX: avoid copying */
|
||||||
bf->buf_end = (char *)str + strlen(bf->buffer);
|
len = strlen(str);
|
||||||
|
buf = tcc_malloc(len + 1);
|
||||||
|
if (!buf)
|
||||||
|
return -1;
|
||||||
|
buf[len] = CH_EOB;
|
||||||
|
bf->buf_ptr = buf;
|
||||||
|
bf->buf_end = buf + len;
|
||||||
pstrcpy(bf->filename, sizeof(bf->filename), "<string>");
|
pstrcpy(bf->filename, sizeof(bf->filename), "<string>");
|
||||||
bf->line_num = 1;
|
bf->line_num = 1;
|
||||||
file = bf;
|
file = bf;
|
||||||
|
|
||||||
ret = tcc_compile(s);
|
ret = tcc_compile(s);
|
||||||
|
|
||||||
|
tcc_free(buf);
|
||||||
|
|
||||||
/* currently, no need to close */
|
/* currently, no need to close */
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* define a preprocessor symbol. A value can also be provided with the '=' operator */
|
/* define a preprocessor symbol. A value can also be provided with the '=' operator */
|
||||||
void tcc_define_symbol(TCCState *s1, const char *sym, const char *value)
|
void tcc_define_symbol(TCCState *s1, const char *sym, const char *value)
|
||||||
|
Loading…
Reference in New Issue
Block a user