Skip to content

Commit

Permalink
remove useless warnings and fix save-temps with object targets
Browse files Browse the repository at this point in the history
* 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)
  • Loading branch information
lefessan committed Nov 29, 2023
1 parent c0d64ad commit d8e7e15
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 4 deletions.
8 changes: 8 additions & 0 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@

2023-11-29 Fabrice Le Fessant <[email protected]>

* 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 <[email protected]>

* typeck.c (search_set_keys): improving SEARCH ALL syntax checks
Expand Down
6 changes: 5 additions & 1 deletion cobc/cobc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
42 changes: 42 additions & 0 deletions cobc/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -10969,6 +11009,8 @@ procedure_division:
statements
_dot_or_else_area_a
_procedure_list
{
}
;

_procedure_using_chaining:
Expand Down
9 changes: 9 additions & 0 deletions libcob/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@

2023-11-29 Fabrice Le Fessant <[email protected]>

* 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 <[email protected]>

* screenio.c, common.c: replace use of NCURSES_MOUSE_VERSION by
Expand Down
9 changes: 8 additions & 1 deletion libcob/coblocal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions libcob/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ cob_get_source_line ()
}

/* reentrant version of strerror */
static char *
char *
cob_get_strerror (void)
{
size_t size;
Expand Down Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions libcob/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions libcob/intrinsic.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 2 additions & 0 deletions libcob/mlio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions libcob/move.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions libcob/screenio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions libcob/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d8e7e15

Please sign in to comment.