From d8e7e1504f1a10f3cccd4bb702e8a332def6cd1a Mon Sep 17 00:00:00 2001 From: Fabrice Le Fessant Date: Tue, 28 Nov 2023 23:43:48 +0100 Subject: [PATCH] remove useless warnings and fix save-temps with object targets * Make function declarations (cob_min_int, cob_max_int) in coblocal.h only included if the corresponding macros are defined (COB_NEEDS_MIN_INT, COB_NEEDS_MAX_INT). Avoids useless gcc warnings. * Add a few commented functions in parser.y that might be useful in the future * Do not move object files if they were specified as an explicit target on the command line (typically cobc -c --save-temps=DIR -o foo.o foo.cob should keep foo.o in the current directory) --- cobc/ChangeLog | 8 ++++++++ cobc/cobc.c | 6 +++++- cobc/parser.y | 42 ++++++++++++++++++++++++++++++++++++++++++ libcob/ChangeLog | 9 +++++++++ libcob/coblocal.h | 9 ++++++++- libcob/common.c | 4 ++-- libcob/common.h | 1 + libcob/intrinsic.c | 1 + libcob/mlio.c | 2 ++ libcob/move.c | 2 ++ libcob/screenio.c | 1 + libcob/strings.c | 1 + 12 files changed, 82 insertions(+), 4 deletions(-) diff --git a/cobc/ChangeLog b/cobc/ChangeLog index 0c5659e71..50f5d7658 100644 --- a/cobc/ChangeLog +++ b/cobc/ChangeLog @@ -1,4 +1,12 @@ +2023-11-29 Fabrice Le Fessant + + * cobc.c (cobc_clean_up): do not move object files if they were + specified as an explicit target on the command line + * parser.y: add "emit_statement_before", "drop_last_statement" + and "replace_last_statement" function for later eventual use. + They are commented using a macro. + 2023-07-26 Simon Sobisch * typeck.c (search_set_keys): improving SEARCH ALL syntax checks diff --git a/cobc/cobc.c b/cobc/cobc.c index b3a52303c..6326b30e4 100644 --- a/cobc/cobc.c +++ b/cobc/cobc.c @@ -2287,7 +2287,11 @@ cobc_clean_up (const int status) if (fn->need_assemble && (status || cb_compile_level > CB_LEVEL_ASSEMBLE - || (cb_compile_level == CB_LEVEL_ASSEMBLE && save_temps))) { + || (cb_compile_level == CB_LEVEL_ASSEMBLE + && save_temps + /* do not move object if a name was + * specified on the command line */ + && !output_name))) { cobc_check_action (fn->object); } clean_up_intermediates (fn, status); diff --git a/cobc/parser.y b/cobc/parser.y index b77193c93..3b79f8e70 100644 --- a/cobc/parser.y +++ b/cobc/parser.y @@ -407,6 +407,46 @@ emit_statement (cb_tree x) } } +#if 0 +/* Uncomment one of these functions if needed. */ + +/* Insert a statement before the current statement. */ +static COB_INLINE COB_A_INLINE void +emit_statement_before (cb_tree x) +{ + if (!skip_statements){ + emit_statement(x); + struct cb_list * l1 = CB_LIST (current_program->exec_list); + struct cb_list * l2 = CB_LIST (l1->chain); + if (l2){ + l1->chain = l2->chain; + l2->chain = CB_TREE(l1); + current_program->exec_list = CB_TREE (l2); + } + } +} + +/* Drop the current statement. */ +static COB_INLINE COB_A_INLINE void +drop_last_statement (void) +{ + if (!skip_statements){ + if (current_program->exec_list){ + struct cb_list * l1 = CB_LIST (current_program->exec_list); + current_program->exec_list = l1->chain; + } + } +} + +/* Insert a statement to replace the current statement. */ +static COB_INLINE COB_A_INLINE void +replace_last_statement (cb_tree x) +{ + drop_last_statement (); + emit_statement (x); +} +#endif + static void begin_statement_internal (enum cob_statement statement, const unsigned int term, const char *file, const int line) @@ -10969,6 +11009,8 @@ procedure_division: statements _dot_or_else_area_a _procedure_list + { + } ; _procedure_using_chaining: diff --git a/libcob/ChangeLog b/libcob/ChangeLog index c47fc3186..633157fcd 100644 --- a/libcob/ChangeLog +++ b/libcob/ChangeLog @@ -1,4 +1,13 @@ +2023-11-29 Fabrice Le Fessant + + * common.h: export "cob_get_strerror" as a public function + * common.c: (cob_expand_env_string): use "getpid" instead + of "cob_sys_getpid" to use the correct PID in case of "fork" + * coblocal.h: remove unused warnings about inline functions by + adding macro flags "COB_NEEDS_MAX_INT" and "COB_NEEDS_MIN_INT" + that must be declared to use "cob_max_int" and "cob_min_int" + 2023-07-28 Simon Sobisch * screenio.c, common.c: replace use of NCURSES_MOUSE_VERSION by diff --git a/libcob/coblocal.h b/libcob/coblocal.h index 835f972fe..97b539309 100644 --- a/libcob/coblocal.h +++ b/libcob/coblocal.h @@ -503,7 +503,6 @@ COB_HIDDEN int cob_field_to_string (const cob_field *, void *, COB_HIDDEN cob_settings *cob_get_settings_ptr (void); COB_HIDDEN char *cob_strndup (const char *, const size_t); - enum cob_datetime_res { DTR_DATE, DTR_TIME_NO_NANO, @@ -555,19 +554,27 @@ DECLNORET COB_HIDDEN void cob_hard_failure (void) COB_A_NORETURN; /* static inline of smaller helpers */ +/* The following functions are only defined on-demand using flags + COB_NEEDS_*. Otherwise, we get either defined-but-not-used + warnings, or not-always-inlined warnings. */ + +#ifdef COB_NEEDS_MIN_INT static COB_INLINE COB_A_INLINE int cob_min_int (const int x, const int y) { if (x < y) return x; return y; } +#endif +#ifdef COB_NEEDS_MAX_INT static COB_INLINE COB_A_INLINE int cob_max_int (const int x, const int y) { if (x > y) return x; return y; } +#endif #undef COB_HIDDEN diff --git a/libcob/common.c b/libcob/common.c index eef27ffc1..555635925 100644 --- a/libcob/common.c +++ b/libcob/common.c @@ -907,7 +907,7 @@ cob_get_source_line () } /* reentrant version of strerror */ -static char * +char * cob_get_strerror (void) { size_t size; @@ -7801,7 +7801,7 @@ cob_expand_env_string (char *strval) k--; } else if (strval[k] == '$' && strval[k+1] == '$') { /* Replace $$ with process-id */ - j += sprintf (&env[j], "%d", cob_sys_getpid()); + j += sprintf (&env[j], "%d", getpid()); k++; /* CHECME: possibly add $f /$b as basename of executable [or, when passed to cob_init the first name] along with $d date as yyyymmdd and $t as hhmmss */ diff --git a/libcob/common.h b/libcob/common.h index c01965eff..77b03d04e 100644 --- a/libcob/common.h +++ b/libcob/common.h @@ -1645,6 +1645,7 @@ COB_EXPIMP int cob_last_exception_is (const int); COB_EXPIMP int cob_last_exit_code (void); COB_EXPIMP const char* cob_last_runtime_error (void); +COB_EXPIMP char* cob_get_strerror (void); COB_EXPIMP void cob_runtime_hint (const char *, ...) COB_A_FORMAT12; COB_EXPIMP void cob_runtime_error (const char *, ...) COB_A_FORMAT12; diff --git a/libcob/intrinsic.c b/libcob/intrinsic.c index 7ca4a9648..2ff1cd167 100644 --- a/libcob/intrinsic.c +++ b/libcob/intrinsic.c @@ -45,6 +45,7 @@ /* include internal and external libcob definitions, forcing exports */ #define COB_LIB_EXPIMP +#define COB_NEEDS_MIN_INT #include "coblocal.h" /* Note we include the Cygwin version of windows.h here */ diff --git a/libcob/mlio.c b/libcob/mlio.c index f6a657b46..5330a2761 100644 --- a/libcob/mlio.c +++ b/libcob/mlio.c @@ -28,6 +28,8 @@ /* include internal and external libcob definitions, forcing exports */ #define COB_LIB_EXPIMP +#define COB_NEEDS_MAX_INT +#define COB_NEEDS_MIN_INT #include "coblocal.h" #if defined (WITH_XML2) diff --git a/libcob/move.c b/libcob/move.c index c8216ba68..f0e81f39f 100644 --- a/libcob/move.c +++ b/libcob/move.c @@ -37,6 +37,8 @@ /* include internal and external libcob definitions, forcing exports */ #define COB_LIB_EXPIMP +#define COB_NEEDS_MAX_INT +#define COB_NEEDS_MIN_INT #include "coblocal.h" static cob_global *cobglobptr; diff --git a/libcob/screenio.c b/libcob/screenio.c index 3197019a2..14f603d00 100644 --- a/libcob/screenio.c +++ b/libcob/screenio.c @@ -99,6 +99,7 @@ /* include internal and external libcob definitions, forcing exports */ #define COB_LIB_EXPIMP +#define COB_NEEDS_MIN_INT #include "coblocal.h" #ifdef HAVE_CURSES_FREEALL diff --git a/libcob/strings.c b/libcob/strings.c index 674df8cfc..4d113f9a6 100644 --- a/libcob/strings.c +++ b/libcob/strings.c @@ -31,6 +31,7 @@ /* include internal and external libcob definitions, forcing exports */ #define COB_LIB_EXPIMP +#define COB_NEEDS_MIN_INT #include "coblocal.h" enum inspect_type {