__pragma: Check if the option string is packed/unpacked in a more reliable way

This commit is contained in:
Stanislav Gromov 2020-11-14 20:41:45 +07:00
parent 4a4ba1e8b9
commit 3a9cfd8e46
4 changed files with 8 additions and 7 deletions

View File

@ -1009,6 +1009,7 @@ SC_VDECL int pc_retexpr; /* true if the current expression is a part of a "
SC_VDECL int pc_retheap; /* heap space (in bytes) to be manually freed when returning an array returned by another function */
SC_VDECL int pc_nestlevel; /* number of active (open) compound statements */
SC_VDECL unsigned int pc_attributes;/* currently set attribute flags (for the "__pragma" operator) */
SC_VDECL int pc_ispackedstr; /* true if the last tokenized string is packed */
SC_VDECL char *sc_tokens[];

View File

@ -8308,8 +8308,11 @@ static void dopragma(void)
do {
/* read the option string */
tok=lex(&val,&str);
if (tok!=tSTRING) {
if (tok!=tSTRING || !pc_ispackedstr) {
/* either not a string, or the user prepended "!" to the option string */
char tokstr[2];
if (tok==tSTRING)
tok='!';
if (tok<tFIRST) {
sprintf(tokstr,"%c",tok);
str=tokstr;
@ -8321,12 +8324,6 @@ static void dopragma(void)
} /* if */
assert(litidx>bck_litidx);
/* the user shouldn't prepend "!" to the option string */
if (litq[val]<=UNPACKEDMAX && litq[val]!=0) {
error(1,sc_tokens[tSTRING-tFIRST],"!");
goto next;
} /* if */
/* swap the cell bytes if we're on a Little Endian platform */
#if BYTE_ORDER==LITTLE_ENDIAN
{ /* local */

View File

@ -2415,6 +2415,7 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym)
if ((stringflags & RAWMODE)!=0)
lptr+=1; /* skip "escape" character too */
lptr=sc_packstr ? packedstring(lptr,&stringflags) : unpackedstring(lptr,&stringflags);
pc_ispackedstr=sc_packstr;
if (*lptr=='\"')
lptr+=1; /* skip final quote */
else if (!(stringflags & STRINGIZE))
@ -2441,6 +2442,7 @@ SC_FUNC int lex(cell *lexvalue,char **lexsym)
if ((stringflags & RAWMODE)!=0)
lptr+=1; /* skip "escape" character too */
lptr=sc_packstr ? unpackedstring(lptr,&stringflags) : packedstring(lptr,&stringflags);
pc_ispackedstr=!sc_packstr;
if (*lptr=='\"')
lptr+=1; /* skip final quote */
else if (!(stringflags & STRINGIZE))

View File

@ -102,6 +102,7 @@ SC_VDEFINE int pc_retexpr=FALSE; /* true if the current expression is
SC_VDEFINE int pc_retheap=0; /* heap space (in bytes) to be manually freed when returning an array returned by another function */
SC_VDEFINE int pc_nestlevel=0; /* number of active (open) compound statements */
SC_VDEFINE unsigned int pc_attributes=0; /* currently set attribute flags (for the "__pragma" operator) */
SC_VDEFINE int pc_ispackedstr=FALSE; /* true if the last tokenized string is packed */
SC_VDEFINE char *sc_tokens[] = {
"*=", "/=", "%=", "+=", "-=", "<<=", ">>>=", ">>=", "&=", "^=", "|=",