Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
04ae435f
Commit
04ae435f
authored
Sep 24, 2021
by
Alexandre Julliard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wrc: Use the standard memory allocation wrappers in the preprocessor.
Signed-off-by:
Alexandre Julliard
<
julliard@winehq.org
>
parent
b69ce347
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
91 deletions
+38
-91
ppl.l
tools/wrc/ppl.l
+0
-0
ppy.y
tools/wrc/ppy.y
+14
-17
wpp.c
tools/wrc/wpp.c
+24
-60
wpp_private.h
tools/wrc/wpp_private.h
+0
-14
No files found.
tools/wrc/ppl.l
View file @
04ae435f
This diff is collapsed.
Click to expand it.
tools/wrc/ppy.y
View file @
04ae435f
...
...
@@ -30,6 +30,7 @@
#include <ctype.h>
#include <string.h>
#include "utils.h"
#include "wpp_private.h"
...
...
@@ -270,27 +271,23 @@ preprocessor
| tMACRO res_arg allmargs tMACROEND opt_mtexts tNL {
pp_add_macro($1, macro_args, nmacro_args, $5);
}
| tLINE tSINT tDQSTRING tNL { if($3)
pp_writestring(
"# %d %s\n", $2 , $3); free($3); }
| tGCCLINE tSINT tDQSTRING tNL { if($3)
pp_writestring(
"# %d %s\n", $2 , $3); free($3); }
| tLINE tSINT tDQSTRING tNL { if($3)
fprintf(ppy_out,
"# %d %s\n", $2 , $3); free($3); }
| tGCCLINE tSINT tDQSTRING tNL { if($3)
fprintf(ppy_out,
"# %d %s\n", $2 , $3); free($3); }
| tGCCLINE tSINT tDQSTRING tSINT tNL
{ if($3) pp_writestring(
"# %d %s %d\n", $2, $3, $4); free($3); }
{ if($3) fprintf(ppy_out,
"# %d %s %d\n", $2, $3, $4); free($3); }
| tGCCLINE tSINT tDQSTRING tSINT tSINT tNL
{ if($3)
pp_writestring(
"# %d %s %d %d\n", $2 ,$3, $4, $5); free($3); }
{ if($3)
fprintf(ppy_out,
"# %d %s %d %d\n", $2 ,$3, $4, $5); free($3); }
| tGCCLINE tSINT tDQSTRING tSINT tSINT tSINT tNL
{ if($3) pp_writestring(
"# %d %s %d %d %d\n", $2 ,$3 ,$4 ,$5, $6); free($3); }
{ if($3) fprintf(ppy_out,
"# %d %s %d %d %d\n", $2 ,$3 ,$4 ,$5, $6); free($3); }
| tGCCLINE tSINT tDQSTRING tSINT tSINT tSINT tSINT tNL
{ if($3)
pp_writestring(
"# %d %s %d %d %d %d\n", $2 ,$3 ,$4 ,$5, $6, $7); free($3); }
{ if($3)
fprintf(ppy_out,
"# %d %s %d %d %d %d\n", $2 ,$3 ,$4 ,$5, $6, $7); free($3); }
| tGCCLINE tNL /* The null-token */
| tERROR opt_text tNL { ppy_error("#error directive: '%s'", $2); free($2); }
| tWARNING opt_text tNL { ppy_warning("#warning directive: '%s'", $2); free($2); }
| tPRAGMA opt_text tNL {
pp_writestring(
"#pragma %s\n", $2 ? $2 : ""); free($2); }
| tPRAGMA opt_text tNL {
fprintf(ppy_out,
"#pragma %s\n", $2 ? $2 : ""); free($2); }
| tPPIDENT opt_text tNL { if(pp_status.pedantic) ppy_warning("#ident ignored (arg: '%s')", $2); free($2); }
| tRCINCLUDE tRCINCLUDEPATH {
int nl=strlen($2) +3;
char *fn=pp_xmalloc(nl);
sprintf(fn,"\"%s\"",$2);
pp_do_include(fn,1);
free($2);
pp_do_include(strmake( "\"%s\"", $2 ),1);
}
| tRCINCLUDE tDQSTRING {
pp_do_include($2,1);
...
...
@@ -538,8 +535,8 @@ static int boolean(cval_t *v)
static char *add_new_marg(char *str)
{
char *ma;
macro_args =
pp_
xrealloc(macro_args, (nmacro_args+1) * sizeof(macro_args[0]));
macro_args[nmacro_args++] = ma =
pp_
xstrdup(str);
macro_args = xrealloc(macro_args, (nmacro_args+1) * sizeof(macro_args[0]));
macro_args[nmacro_args++] = ma = xstrdup(str);
return ma;
}
...
...
@@ -558,7 +555,7 @@ static int marg_index(char *id)
static mtext_t *new_mtext(char *str, int idx, def_exp_t type)
{
mtext_t *mt =
pp_
xmalloc(sizeof(mtext_t));
mtext_t *mt = xmalloc(sizeof(mtext_t));
if(str == NULL)
mt->subst.argidx = idx;
...
...
@@ -579,7 +576,7 @@ static mtext_t *combine_mtext(mtext_t *tail, mtext_t *mtp)
if(tail->type == exp_text && mtp->type == exp_text)
{
tail->subst.text =
pp_
xrealloc(tail->subst.text, strlen(tail->subst.text)+strlen(mtp->subst.text)+1);
tail->subst.text = xrealloc(tail->subst.text, strlen(tail->subst.text)+strlen(mtp->subst.text)+1);
strcat(tail->subst.text, mtp->subst.text);
free(mtp->subst.text);
free(mtp);
...
...
@@ -645,7 +642,7 @@ static char *merge_text(char *s1, char *s2)
{
int l1 = strlen(s1);
int l2 = strlen(s2);
s1 =
pp_
xrealloc(s1, l1+l2+1);
s1 = xrealloc(s1, l1+l2+1);
memcpy(s1+l1, s2, l2+1);
free(s2);
return s1;
...
...
tools/wrc/wpp.c
View file @
04ae435f
...
...
@@ -34,6 +34,7 @@
# include <unistd.h>
#endif
#include "utils.h"
#include "wpp_private.h"
struct
pp_status
pp_status
;
...
...
@@ -57,42 +58,8 @@ struct define
static
struct
list
cmdline_defines
=
LIST_INIT
(
cmdline_defines
);
void
*
pp_xmalloc
(
size_t
size
)
{
void
*
res
;
assert
(
size
>
0
);
res
=
malloc
(
size
);
if
(
res
==
NULL
)
{
fprintf
(
stderr
,
"Virtual memory exhausted
\n
"
);
exit
(
1
);
}
return
res
;
}
void
*
pp_xrealloc
(
void
*
p
,
size_t
size
)
{
void
*
res
;
assert
(
size
>
0
);
res
=
realloc
(
p
,
size
);
if
(
res
==
NULL
)
{
fprintf
(
stderr
,
"Virtual memory exhausted
\n
"
);
exit
(
1
);
}
return
res
;
}
char
*
pp_xstrdup
(
const
char
*
str
)
{
int
len
=
strlen
(
str
)
+
1
;
return
memcpy
(
pp_xmalloc
(
len
),
str
,
len
);
}
char
*
wpp_lookup
(
const
char
*
name
,
int
type
,
const
char
*
parent_name
,
char
**
include_path
,
int
include_path_count
)
static
char
*
wpp_lookup
(
const
char
*
name
,
int
type
,
const
char
*
parent_name
,
char
**
include_path
,
int
include_path_count
)
{
char
*
cpy
;
char
*
cptr
;
...
...
@@ -100,7 +67,7 @@ char *wpp_lookup(const char *name, int type, const char *parent_name,
const
char
*
ccptr
;
int
i
,
fd
;
cpy
=
pp_
xmalloc
(
strlen
(
name
)
+
1
);
cpy
=
xmalloc
(
strlen
(
name
)
+
1
);
cptr
=
cpy
;
for
(
ccptr
=
name
;
*
ccptr
;
ccptr
++
)
...
...
@@ -125,7 +92,7 @@ char *wpp_lookup(const char *name, int type, const char *parent_name,
if
((
p
=
strrchr
(
parent_name
,
'/'
)))
p
++
;
else
p
=
parent_name
;
path
=
pp_
xmalloc
(
(
p
-
parent_name
)
+
strlen
(
cpy
)
+
1
);
path
=
xmalloc
(
(
p
-
parent_name
)
+
strlen
(
cpy
)
+
1
);
memcpy
(
path
,
parent_name
,
p
-
parent_name
);
strcpy
(
path
+
(
p
-
parent_name
),
cpy
);
fd
=
open
(
path
,
O_RDONLY
);
...
...
@@ -140,10 +107,7 @@ char *wpp_lookup(const char *name, int type, const char *parent_name,
/* Search -I path */
for
(
i
=
0
;
i
<
include_path_count
;
i
++
)
{
path
=
pp_xmalloc
(
strlen
(
include_path
[
i
])
+
strlen
(
cpy
)
+
2
);
strcpy
(
path
,
include_path
[
i
]);
strcat
(
path
,
"/"
);
strcat
(
path
,
cpy
);
path
=
strmake
(
"%s/%s"
,
include_path
[
i
],
cpy
);
fd
=
open
(
path
,
O_RDONLY
);
if
(
fd
!=
-
1
)
{
...
...
@@ -195,7 +159,7 @@ static void free_pp_entry( pp_entry_t *ppp, int idx )
}
/* initialize the define state */
void
pp_init_define_state
(
void
)
static
void
pp_init_define_state
(
void
)
{
int
i
;
...
...
@@ -203,7 +167,7 @@ void pp_init_define_state(void)
}
/* free the current define state */
void
pp_free_define_state
(
void
)
static
void
pp_free_define_state
(
void
)
{
int
i
;
pp_entry_t
*
ppp
,
*
ppp2
;
...
...
@@ -255,12 +219,12 @@ pp_entry_t *pp_add_define(const char *def, const char *text)
ppy_warning
(
"Redefinition of %s
\n\t
Previous definition: %s:%d"
,
def
,
ppp
->
filename
,
ppp
->
linenumber
);
pp_del_define
(
def
);
}
ppp
=
pp_
xmalloc
(
sizeof
(
pp_entry_t
));
ppp
=
xmalloc
(
sizeof
(
pp_entry_t
));
memset
(
ppp
,
0
,
sizeof
(
*
ppp
)
);
ppp
->
ident
=
pp_
xstrdup
(
def
);
ppp
->
ident
=
xstrdup
(
def
);
ppp
->
type
=
def_define
;
ppp
->
subst
.
text
=
text
?
pp_
xstrdup
(
text
)
:
NULL
;
ppp
->
filename
=
pp_
xstrdup
(
pp_status
.
input
?
pp_status
.
input
:
"<internal or cmdline>"
);
ppp
->
subst
.
text
=
text
?
xstrdup
(
text
)
:
NULL
;
ppp
->
filename
=
xstrdup
(
pp_status
.
input
?
pp_status
.
input
:
"<internal or cmdline>"
);
ppp
->
linenumber
=
pp_status
.
input
?
pp_status
.
line_number
:
0
;
list_add_head
(
&
pp_defines
[
idx
],
&
ppp
->
entry
);
if
(
ppp
->
subst
.
text
)
...
...
@@ -295,14 +259,14 @@ pp_entry_t *pp_add_macro(char *id, char *args[], int nargs, mtext_t *exp)
ppy_warning
(
"Redefinition of %s
\n\t
Previous definition: %s:%d"
,
id
,
ppp
->
filename
,
ppp
->
linenumber
);
pp_del_define
(
id
);
}
ppp
=
pp_
xmalloc
(
sizeof
(
pp_entry_t
));
ppp
=
xmalloc
(
sizeof
(
pp_entry_t
));
memset
(
ppp
,
0
,
sizeof
(
*
ppp
)
);
ppp
->
ident
=
id
;
ppp
->
type
=
def_macro
;
ppp
->
margs
=
args
;
ppp
->
nargs
=
nargs
;
ppp
->
subst
.
mtext
=
exp
;
ppp
->
filename
=
pp_
xstrdup
(
pp_status
.
input
?
pp_status
.
input
:
"<internal or cmdline>"
);
ppp
->
filename
=
xstrdup
(
pp_status
.
input
?
pp_status
.
input
:
"<internal or cmdline>"
);
ppp
->
linenumber
=
pp_status
.
input
?
pp_status
.
line_number
:
0
;
list_add_head
(
&
pp_defines
[
idx
],
&
ppp
->
entry
);
if
(
pp_status
.
debug
)
...
...
@@ -349,7 +313,7 @@ static int nincludepath = 0;
void
wpp_add_include_path
(
const
char
*
path
)
{
char
*
tok
;
char
*
cpy
=
pp_
xstrdup
(
path
);
char
*
cpy
=
xstrdup
(
path
);
tok
=
strtok
(
cpy
,
INCLUDESEPARATOR
);
while
(
tok
)
...
...
@@ -358,7 +322,7 @@ void wpp_add_include_path(const char *path)
char
*
dir
;
char
*
cptr
;
dir
=
pp_
xstrdup
(
tok
);
dir
=
xstrdup
(
tok
);
for
(
cptr
=
dir
;
*
cptr
;
cptr
++
)
{
/* Convert to forward slash */
...
...
@@ -370,7 +334,7 @@ void wpp_add_include_path(const char *path)
*
cptr
=
'\0'
;
/* Add to list */
includepath
=
pp_
xrealloc
(
includepath
,
(
nincludepath
+
1
)
*
sizeof
(
*
includepath
));
includepath
=
xrealloc
(
includepath
,
(
nincludepath
+
1
)
*
sizeof
(
*
includepath
));
includepath
[
nincludepath
]
=
dir
;
nincludepath
++
;
}
...
...
@@ -633,14 +597,14 @@ static void wpp_add_define( const char *name, const char *value )
if
(
!
strcmp
(
def
->
name
,
name
))
{
free
(
def
->
value
);
def
->
value
=
pp_
xstrdup
(
value
);
def
->
value
=
xstrdup
(
value
);
return
;
}
}
def
=
pp_
xmalloc
(
sizeof
(
*
def
)
);
def
->
name
=
pp_
xstrdup
(
name
);
def
->
value
=
pp_
xstrdup
(
value
);
def
=
xmalloc
(
sizeof
(
*
def
)
);
def
->
name
=
xstrdup
(
name
);
def
->
value
=
xstrdup
(
value
);
list_add_head
(
&
cmdline_defines
,
&
def
->
entry
);
}
...
...
@@ -666,7 +630,7 @@ void wpp_del_define( const char *name )
void
wpp_add_cmdline_define
(
const
char
*
value
)
{
char
*
p
;
char
*
str
=
pp_
xstrdup
(
value
);
char
*
str
=
xstrdup
(
value
);
p
=
strchr
(
str
,
'='
);
if
(
p
)
*
p
++
=
0
;
...
...
@@ -708,10 +672,10 @@ int wpp_parse( const char *input, FILE *output )
else
if
(
!
(
pp_status
.
file
=
fopen
(
input
,
"rt"
)))
ppy_error
(
"Could not open %s
\n
"
,
input
);
pp_status
.
input
=
input
?
pp_
xstrdup
(
input
)
:
NULL
;
pp_status
.
input
=
input
?
xstrdup
(
input
)
:
NULL
;
ppy_out
=
output
;
pp_writestring
(
"# 1
\"
%s
\"
1
\n
"
,
input
?
input
:
""
);
fprintf
(
ppy_out
,
"# 1
\"
%s
\"
1
\n
"
,
input
?
input
:
""
);
ret
=
ppy_parse
();
...
...
tools/wrc/wpp_private.h
View file @
04ae435f
...
...
@@ -155,12 +155,7 @@ typedef struct cval {
void
*
pp_xmalloc
(
size_t
);
void
*
pp_xrealloc
(
void
*
,
size_t
);
char
*
pp_xstrdup
(
const
char
*
str
);
pp_entry_t
*
pplookup
(
const
char
*
ident
);
void
pp_init_define_state
(
void
);
void
pp_free_define_state
(
void
);
pp_entry_t
*
pp_add_define
(
const
char
*
def
,
const
char
*
text
);
pp_entry_t
*
pp_add_macro
(
char
*
ident
,
char
*
args
[],
int
nargs
,
mtext_t
*
exp
);
void
pp_del_define
(
const
char
*
name
);
...
...
@@ -170,12 +165,6 @@ void pp_next_if_state(int);
pp_if_state_t
pp_pop_if
(
void
);
pp_if_state_t
pp_if_state
(
void
);
int
pp_get_if_depth
(
void
);
char
*
wpp_lookup
(
const
char
*
name
,
int
type
,
const
char
*
parent_name
,
char
**
include_path
,
int
include_path_count
);
#ifndef __GNUC__
#define __attribute__(x)
/*nothing*/
#endif
int
ppy_error
(
const
char
*
s
,
...)
__attribute__
((
format
(
printf
,
1
,
2
)));
int
ppy_warning
(
const
char
*
s
,
...)
__attribute__
((
format
(
printf
,
1
,
2
)));
...
...
@@ -195,7 +184,6 @@ struct pp_status
extern
struct
pp_status
pp_status
;
extern
include_state_t
pp_incl_state
;
extern
struct
list
pp_includelogiclist
;
/*
* From ppl.l
...
...
@@ -210,8 +198,6 @@ void pp_do_include(char *fname, int type);
void
pp_push_ignore_state
(
void
);
void
pp_pop_ignore_state
(
void
);
void
pp_writestring
(
const
char
*
format
,
...)
__attribute__
((
format
(
printf
,
1
,
2
)));
/*
* From ppy.y
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment