Module: wine Branch: master Commit: 506bdf4249025e6d786c976e88b06a66a442dfa5 URL: https://source.winehq.org/git/wine.git/?a=commit;h=506bdf4249025e6d786c976e8...
Author: Alexandre Julliard julliard@winehq.org Date: Thu Dec 3 13:27:15 2020 +0100
wpp: Use standard Wine lists where possible.
Signed-off-by: Alexandre Julliard julliard@winehq.org
---
libs/wpp/ppl.l | 10 +++---- libs/wpp/preproc.c | 72 ++++++++++++++++---------------------------------- libs/wpp/wpp.c | 15 +++++------ libs/wpp/wpp_private.h | 9 +++---- 4 files changed, 37 insertions(+), 69 deletions(-)
diff --git a/libs/wpp/ppl.l b/libs/wpp/ppl.l index a1d54029c7c..4fc23384dff 100644 --- a/libs/wpp/ppl.l +++ b/libs/wpp/ppl.l @@ -302,7 +302,7 @@ include_state_t pp_incl_state = 0 /* seen_junk */ };
-includelogicentry_t *pp_includelogiclist = NULL; +struct list pp_includelogiclist = LIST_INIT( pp_includelogiclist );
#define YY_INPUT(buf,result,max_size) \ { \ @@ -1350,11 +1350,7 @@ static bufferstackentry_t *pop_buffer(void) iep->ppp = ppp; ppp->iep = iep; iep->filename = bufferstack[bufferstackidx].include_filename; - iep->prev = NULL; - iep->next = pp_includelogiclist; - if(iep->next) - iep->next->prev = iep; - pp_includelogiclist = iep; + list_add_head( &pp_includelogiclist, &iep->entry ); if(pp_status.debug) fprintf(stderr, "pop_buffer: %s:%d: includelogic added, include_ppp='%s', file='%s'\n", bufferstack[bufferstackidx].filename, bufferstack[bufferstackidx].line_number, pp_incl_state.ppp, iep->filename); @@ -1557,7 +1553,7 @@ void pp_do_include(char *fname, int type) if(!fname) return;
- for(iep = pp_includelogiclist; iep; iep = iep->next) + LIST_FOR_EACH_ENTRY( iep, &pp_includelogiclist, includelogicentry_t, entry ) { if(!strcmp(iep->filename, fname)) { diff --git a/libs/wpp/preproc.c b/libs/wpp/preproc.c index 8b9b8b05375..2106b811e83 100644 --- a/libs/wpp/preproc.c +++ b/libs/wpp/preproc.c @@ -39,10 +39,11 @@ struct pp_status pp_status;
typedef struct pp_def_state { - struct pp_def_state *next; - pp_entry_t *defines[HASHKEY]; + struct list entry; + struct list defines[HASHKEY]; } pp_def_state_t;
+static struct list pp_states = LIST_INIT( pp_states ); static pp_def_state_t *pp_def_state;
#define MAXIFSTACK 64 @@ -56,14 +57,11 @@ void pp_print_status(void) int i; int sum; int total = 0; - pp_entry_t *ppp;
fprintf(stderr, "Defines statistics:\n"); for(i = 0; i < HASHKEY; i++) { - sum = 0; - for(ppp = pp_def_state->defines[i]; ppp; ppp = ppp->next) - sum++; + sum = list_count( &pp_def_state->defines[i] ); total += sum; if (sum) fprintf(stderr, "%4d, %3d\n", i, sum); } @@ -188,7 +186,7 @@ pp_entry_t *pplookup(const char *ident) if(!ident) return NULL; idx = pphash(ident); - for(ppp = pp_def_state->defines[idx]; ppp; ppp = ppp->next) + LIST_FOR_EACH_ENTRY( ppp, &pp_def_state->defines[idx], pp_entry_t, entry ) { if(!strcmp(ident, ppp->ident)) return ppp; @@ -200,35 +198,11 @@ static void free_pp_entry( pp_entry_t *ppp, int idx ) { if(ppp->iep) { - if(ppp->iep == pp_includelogiclist) - { - pp_includelogiclist = ppp->iep->next; - if(pp_includelogiclist) - pp_includelogiclist->prev = NULL; - } - else - { - ppp->iep->prev->next = ppp->iep->next; - if(ppp->iep->next) - ppp->iep->next->prev = ppp->iep->prev; - } + list_remove( &ppp->iep->entry ); free(ppp->iep->filename); free(ppp->iep); } - - if(pp_def_state->defines[idx] == ppp) - { - pp_def_state->defines[idx] = ppp->next; - if(pp_def_state->defines[idx]) - pp_def_state->defines[idx]->prev = NULL; - } - else - { - ppp->prev->next = ppp->next; - if(ppp->next) - ppp->next->prev = ppp->prev; - } - + list_remove( &ppp->entry ); free(ppp); }
@@ -236,9 +210,10 @@ static void free_pp_entry( pp_entry_t *ppp, int idx ) void pp_push_define_state(void) { pp_def_state_t *state = pp_xmalloc( sizeof(*state) ); + int i;
- memset( state->defines, 0, sizeof(state->defines) ); - state->next = pp_def_state; + for (i = 0; i < HASHKEY; i++) list_init( &state->defines[i] ); + list_add_head( &pp_states, &state->entry ); pp_def_state = state; }
@@ -246,16 +221,22 @@ void pp_push_define_state(void) void pp_pop_define_state(void) { int i; - pp_entry_t *ppp; - pp_def_state_t *state; + pp_entry_t *ppp, *ppp2; + pp_def_state_t *state = pp_def_state;
for (i = 0; i < HASHKEY; i++) { - while ((ppp = pp_def_state->defines[i]) != NULL) pp_del_define( ppp->ident ); + LIST_FOR_EACH_ENTRY_SAFE( ppp, ppp2, &state->defines[i], pp_entry_t, entry ) + { + free( ppp->ident ); + free( ppp->subst.text ); + free( ppp->filename ); + free_pp_entry( ppp, i ); + } } - state = pp_def_state; - pp_def_state = state->next; + list_remove( &state->entry ); free( state ); + pp_def_state = LIST_ENTRY( list_head( &pp_states ), pp_def_state_t, entry ); }
void pp_del_define(const char *name) @@ -300,10 +281,7 @@ pp_entry_t *pp_add_define(const char *def, const char *text) ppp->subst.text = text ? pp_xstrdup(text) : NULL; ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>"); ppp->linenumber = pp_status.input ? pp_status.line_number : 0; - ppp->next = pp_def_state->defines[idx]; - pp_def_state->defines[idx] = ppp; - if(ppp->next) - ppp->next->prev = ppp; + list_add_head( &pp_def_state->defines[idx], &ppp->entry ); if(ppp->subst.text) { /* Strip trailing white space from subst text */ @@ -345,11 +323,7 @@ pp_entry_t *pp_add_macro(char *id, marg_t *args[], int nargs, mtext_t *exp) ppp->subst.mtext= exp; ppp->filename = pp_xstrdup(pp_status.input ? pp_status.input : "<internal or cmdline>"); ppp->linenumber = pp_status.input ? pp_status.line_number : 0; - ppp->next = pp_def_state->defines[idx]; - pp_def_state->defines[idx] = ppp; - if(ppp->next) - ppp->next->prev = ppp; - + list_add_head( &pp_def_state->defines[idx], &ppp->entry ); if(pp_status.debug) { fprintf(stderr, "Added macro (%s, %d) <%s(%d)> to <", pp_status.input, pp_status.line_number, ppp->ident, nargs); diff --git a/libs/wpp/wpp.c b/libs/wpp/wpp.c index c17289c8923..de7f7f761a2 100644 --- a/libs/wpp/wpp.c +++ b/libs/wpp/wpp.c @@ -32,18 +32,18 @@ int ppy_debug, pp_flex_debug;
struct define { - struct define *next; + struct list entry; char *name; char *value; };
-static struct define *cmdline_defines; +static struct list cmdline_defines = LIST_INIT( cmdline_defines );
static void add_cmdline_defines(void) { struct define *def;
- for (def = cmdline_defines; def; def = def->next) + LIST_FOR_EACH_ENTRY( def, &cmdline_defines, struct define, entry ) { if (def->value) pp_add_define( def->name, def->value ); } @@ -53,7 +53,7 @@ static void del_cmdline_defines(void) { struct define *def;
- for (def = cmdline_defines; def; def = def->next) + LIST_FOR_EACH_ENTRY( def, &cmdline_defines, struct define, entry ) { if (def->value) pp_del_define( def->name ); } @@ -94,7 +94,7 @@ void wpp_add_define( const char *name, const char *value )
if (!value) value = "";
- for (def = cmdline_defines; def; def = def->next) + LIST_FOR_EACH_ENTRY( def, &cmdline_defines, struct define, entry ) { if (!strcmp( def->name, name )) { @@ -105,10 +105,9 @@ void wpp_add_define( const char *name, const char *value ) }
def = pp_xmalloc( sizeof(*def) ); - def->next = cmdline_defines; def->name = pp_xstrdup(name); def->value = pp_xstrdup(value); - cmdline_defines = def; + list_add_head( &cmdline_defines, &def->entry ); }
@@ -117,7 +116,7 @@ void wpp_del_define( const char *name ) { struct define *def;
- for (def = cmdline_defines; def; def = def->next) + LIST_FOR_EACH_ENTRY( def, &cmdline_defines, struct define, entry ) { if (!strcmp( def->name, name )) { diff --git a/libs/wpp/wpp_private.h b/libs/wpp/wpp_private.h index 3f395e528bb..2598ad77223 100644 --- a/libs/wpp/wpp_private.h +++ b/libs/wpp/wpp_private.h @@ -22,6 +22,7 @@
#include <stdio.h> #include <string.h> +#include "wine/list.h"
struct pp_entry; /* forward */ /* @@ -30,8 +31,7 @@ struct pp_entry; /* forward */ * are protected in the #ifndef/#endif way. */ typedef struct includelogicentry { - struct includelogicentry *next; - struct includelogicentry *prev; + struct list entry; struct pp_entry *ppp; /* The define which protects the file */ char *filename; /* The filename of the include */ } includelogicentry_t; @@ -81,8 +81,7 @@ typedef enum { } def_type_t;
typedef struct pp_entry { - struct pp_entry *next; - struct pp_entry *prev; + struct list entry; def_type_t type; /* Define or macro */ char *ident; /* The key */ marg_t **margs; /* Macro arguments array or NULL if none */ @@ -217,7 +216,7 @@ struct pp_status
extern struct pp_status pp_status; extern include_state_t pp_incl_state; -extern includelogicentry_t *pp_includelogiclist; +extern struct list pp_includelogiclist;
/* * From ppl.l