From 3e1b13b13a044c8a9fedf6ec5b033a8c6e9fee6d Mon Sep 17 00:00:00 2001 From: Nathan Hjelm Date: Fri, 7 Dec 2012 00:12:43 +0000 Subject: [PATCH] Re-add support for old flex (2.5.4a and earlier) while still cleaning up properly in new flex. This commit was SVN r27657. --- autogen.pl | 4 ---- ompi/mca/btl/openib/btl_openib_lex.l | 18 +++++++++++++++++ ompi/mca/coll/ml/coll_ml_lex.l | 18 +++++++++++++++++ opal/util/keyval/keyval_lex.l | 19 ++++++++++++++++++ opal/util/show_help.c | 14 ++++++------- opal/util/show_help.h | 11 ---------- opal/util/show_help_lex.h | 1 + opal/util/show_help_lex.l | 16 +++++++-------- .../mca/rmaps/rank_file/rmaps_rank_file_lex.l | 20 +++++++++++++++++++ 9 files changed, 90 insertions(+), 31 deletions(-) diff --git a/autogen.pl b/autogen.pl index 67abbc33f6..f53b495a93 100755 --- a/autogen.pl +++ b/autogen.pl @@ -56,13 +56,11 @@ my $exclude_list; my $ompi_automake_version = "1.11.1"; my $ompi_autoconf_version = "2.65"; my $ompi_libtool_version = "2.2.6b"; -my $ompi_flex_version = "2.5.4"; # Search paths my $ompi_autoconf_search = "autoconf"; my $ompi_automake_search = "automake"; my $ompi_libtoolize_search = "libtoolize;glibtoolize"; -my $ompi_flex_search = "flex"; # One-time setup my $username; @@ -809,7 +807,6 @@ tools: GNU Autoconf: $ompi_autoconf_version GNU Automake: $ompi_automake_version GNU Libtool: $ompi_libtool_version - Flex: $ompi_flex_version =================================================================\n"; my_exit(1); } @@ -1028,7 +1025,6 @@ $step. Checking tool versions\n\n"; &find_and_check("autoconf", $ompi_autoconf_search, $ompi_autoconf_version); &find_and_check("libtool", $ompi_libtoolize_search, $ompi_libtool_version); &find_and_check("automake", $ompi_automake_search, $ompi_automake_version); -&find_and_check("flex", $ompi_flex_search, $ompi_flex_version); #--------------------------------------------------------------------------- diff --git a/ompi/mca/btl/openib/btl_openib_lex.l b/ompi/mca/btl/openib/btl_openib_lex.l index 8d784a9e70..2aa6059e56 100644 --- a/ompi/mca/btl/openib/btl_openib_lex.l +++ b/ompi/mca/btl/openib/btl_openib_lex.l @@ -100,7 +100,25 @@ NAME_CHAR [A-Za-z0-9_\-\.\\\/] %% +/* Old flex (2.5.4a? and older) does not define a destroy function */ +#if !defined(YY_FLEX_SUBMINOR_VERSION) +#define YY_FLEX_SUBMINOR_VERSION 0 +#endif +#if (YY_FLEX_MAJOR_VERSION < 2) || (YY_FLEX_MAJOR_VERSION == 2 && (YY_FLEX_MINOR_VERSION < 5 || (YY_FLEX_MINOR_VERSION == 5 && YY_FLEX_SUBMINOR_VERSION < 5))) +int btl_openib_ini_yylex_destroy(void) +{ + if (NULL != YY_CURRENT_BUFFER) { + yy_delete_buffer(YY_CURRENT_BUFFER); +#if defined(YY_CURRENT_BUFFER_LVALUE) + YY_CURRENT_BUFFER_LVALUE = NULL; +#else + YY_CURRENT_BUFFER = NULL; +#endif /* YY_CURRENT_BUFFER_LVALUE */ + } + return YY_NULL; +} +#endif static int btl_openib_ini_yywrap(void) { diff --git a/ompi/mca/coll/ml/coll_ml_lex.l b/ompi/mca/coll/ml/coll_ml_lex.l index 73098bb4b1..30daaae255 100644 --- a/ompi/mca/coll/ml/coll_ml_lex.l +++ b/ompi/mca/coll/ml/coll_ml_lex.l @@ -95,7 +95,25 @@ NAME_CHAR [A-Za-z0-9_\-\.\\\/] . { return COLL_ML_CONFIG_PARSE_ERROR; } %% +/* Old flex (2.5.4a? and older) does not define a destroy function */ +#if !defined(YY_FLEX_SUBMINOR_VERSION) +#define YY_FLEX_SUBMINOR_VERSION 0 +#endif +#if (YY_FLEX_MAJOR_VERSION < 2) || (YY_FLEX_MAJOR_VERSION == 2 && (YY_FLEX_MINOR_VERSION < 5 || (YY_FLEX_MINOR_VERSION == 5 && YY_FLEX_SUBMINOR_VERSION < 5))) +int coll_ml_config_yylex_destroy(void) +{ + if (NULL != YY_CURRENT_BUFFER) { + yy_delete_buffer(YY_CURRENT_BUFFER); +#if defined(YY_CURRENT_BUFFER_LVALUE) + YY_CURRENT_BUFFER_LVALUE = NULL; +#else + YY_CURRENT_BUFFER = NULL; +#endif /* YY_CURRENT_BUFFER_LVALUE */ + } + return YY_NULL; +} +#endif static int coll_ml_config_yywrap(void) { diff --git a/opal/util/keyval/keyval_lex.l b/opal/util/keyval/keyval_lex.l index 1281c22cd2..816caffe2f 100644 --- a/opal/util/keyval/keyval_lex.l +++ b/opal/util/keyval/keyval_lex.l @@ -81,6 +81,25 @@ CHAR [A-Za-z0-9_\-\.] %% +/* Old flex (2.5.4a? and older) does not define a destroy function */ +#if !defined(YY_FLEX_SUBMINOR_VERSION) +#define YY_FLEX_SUBMINOR_VERSION 0 +#endif + +#if (YY_FLEX_MAJOR_VERSION < 2) || (YY_FLEX_MAJOR_VERSION == 2 && (YY_FLEX_MINOR_VERSION < 5 || (YY_FLEX_MINOR_VERSION == 5 && YY_FLEX_SUBMINOR_VERSION < 5))) +int opal_util_keyval_yylex_destroy(void) +{ + if (NULL != YY_CURRENT_BUFFER) { + yy_delete_buffer(YY_CURRENT_BUFFER); +#if defined(YY_CURRENT_BUFFER_LVALUE) + YY_CURRENT_BUFFER_LVALUE = NULL; +#else + YY_CURRENT_BUFFER = NULL; +#endif /* YY_CURRENT_BUFFER_LVALUE */ + } + return YY_NULL; +} +#endif int opal_util_keyval_yywrap(void) { diff --git a/opal/util/show_help.c b/opal/util/show_help.c index bc89ddc935..4430a6cae9 100644 --- a/opal/util/show_help.c +++ b/opal/util/show_help.c @@ -274,20 +274,20 @@ static int load_array(char ***array, const char *filename, const char *topic) if (OPAL_SUCCESS != (ret = open_file(filename, topic))) { return ret; } - if (OPAL_SUCCESS != (ret = find_topic(filename, topic))) { - fclose(opal_show_help_yyin); - return ret; + + ret = find_topic(filename, topic); + if (OPAL_SUCCESS == ret) { + ret = read_topic(array); } - ret = read_topic(array); - opal_show_help_finish_parsing(); fclose(opal_show_help_yyin); + opal_show_help_yylex_destroy (); + if (OPAL_SUCCESS != ret) { opal_argv_free(*array); - return ret; } - return OPAL_SUCCESS; + return ret; } char *opal_show_help_vstring(const char *filename, const char *topic, diff --git a/opal/util/show_help.h b/opal/util/show_help.h index e5c1015e00..7d96d4305f 100644 --- a/opal/util/show_help.h +++ b/opal/util/show_help.h @@ -171,17 +171,6 @@ OPAL_DECLSPEC char* opal_show_help_vstring(const char *filename, */ OPAL_DECLSPEC int opal_show_help_add_dir(const char *directory); -/** - * \internal - * - * Internal function to help clean up the flex parser. - * - * This function is called internally by the SHS to shut down the - * flex parser since we may not hit the <> rule and call this - * function automatically. - */ -OPAL_DECLSPEC int opal_show_help_finish_parsing(void); - END_C_DECLS #endif diff --git a/opal/util/show_help_lex.h b/opal/util/show_help_lex.h index 4d9f8fc39f..0be537de9f 100644 --- a/opal/util/show_help_lex.h +++ b/opal/util/show_help_lex.h @@ -36,6 +36,7 @@ BEGIN_C_DECLS int opal_show_help_yylex(void); int opal_show_help_init_buffer(FILE *file); +int opal_show_help_yylex_destroy(void); extern FILE *opal_show_help_yyin; extern bool opal_show_help_parse_done; diff --git a/opal/util/show_help_lex.l b/opal/util/show_help_lex.l index 4474cfd75d..c39a106f62 100644 --- a/opal/util/show_help_lex.l +++ b/opal/util/show_help_lex.l @@ -48,9 +48,6 @@ END_C_DECLS int opal_show_help_yynewlines = 1; bool opal_show_help_parse_done = false; -#define yyterminate() \ - return opal_show_help_finish_parsing() - %} WHITE [\f\t\v ] @@ -70,12 +67,13 @@ CHAR [A-Za-z0-9_\-\.] %% +/* Old flex (2.5.4a? and older) does not define a destroy function */ +#if !defined(YY_FLEX_SUBMINOR_VERSION) +#define YY_FLEX_SUBMINOR_VERSION 0 +#endif -/* - * This cleans up at the end of the parse (since, in this case, we - * always parse the entire file) and prevents a memory leak. - */ -int opal_show_help_finish_parsing(void) +#if (YY_FLEX_MAJOR_VERSION < 2) || (YY_FLEX_MAJOR_VERSION == 2 && (YY_FLEX_MINOR_VERSION < 5 || (YY_FLEX_MINOR_VERSION == 5 && YY_FLEX_SUBMINOR_VERSION < 5))) +int opal_show_help_yylex_destroy(void) { if (NULL != YY_CURRENT_BUFFER) { yy_delete_buffer(YY_CURRENT_BUFFER); @@ -87,7 +85,7 @@ int opal_show_help_finish_parsing(void) } return YY_NULL; } - +#endif static int opal_show_help_yywrap(void) { diff --git a/orte/mca/rmaps/rank_file/rmaps_rank_file_lex.l b/orte/mca/rmaps/rank_file/rmaps_rank_file_lex.l index 5cde533661..6c50578fcf 100644 --- a/orte/mca/rmaps/rank_file/rmaps_rank_file_lex.l +++ b/orte/mca/rmaps/rank_file/rmaps_rank_file_lex.l @@ -119,6 +119,26 @@ username { orte_rmaps_rank_file_value.sval = yytext; %% +/* Old flex (2.5.4a? and older) does not define a destroy function */ +#if !defined(YY_FLEX_SUBMINOR_VERSION) +#define YY_FLEX_SUBMINOR_VERSION 0 +#endif + +#if (YY_FLEX_MAJOR_VERSION < 2) || (YY_FLEX_MAJOR_VERSION == 2 && (YY_FLEX_MINOR_VERSION < 5 || (YY_FLEX_MINOR_VERSION == 5 && YY_FLEX_SUBMINOR_VERSION < 5))) +int orte_rmaps_rank_file_lex_destroy (void) +{ + if (NULL != YY_CURRENT_BUFFER) { + yy_delete_buffer(YY_CURRENT_BUFFER); +#if defined(YY_CURRENT_BUFFER_LVALUE) + YY_CURRENT_BUFFER_LVALUE = NULL; +#else + YY_CURRENT_BUFFER = NULL; +#endif /* YY_CURRENT_BUFFER_LVALUE */ + } + return YY_NULL; +} +#endif + int orte_rmaps_rank_file_wrap(void) { orte_rmaps_rank_file_done = true;