Skip to content

Commit

Permalink
Revert changes: remove allocated states and use full static states fo…
Browse files Browse the repository at this point in the history
…r strings
  • Loading branch information
engboris committed Jul 22, 2024
1 parent ed1c853 commit f5601ef
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 336 deletions.
4 changes: 0 additions & 4 deletions cobc/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@
2024-02-26 Boris Eng <[email protected]>

FR #488: thread-safety for string handling using state vars
* tree.h (cb_program): new attributes
* codegen.c (output_strings_states, codegen_internal, output_data):
added structures for the data used by strings functions as local variables
in the C generated code. Handle CB_TAG_DIRECT in output_data function
* parser.y (examine_format_variant, inspect_region), typeck.c:
function calls of strings functions have been replaced by calls to
thread-safe versions
Expand Down
36 changes: 0 additions & 36 deletions cobc/codegen.c
Original file line number Diff line number Diff line change
Expand Up @@ -2509,28 +2509,6 @@ output_nonlocal_field_cache (void)
output_storage ("\n/* End of fields */\n\n");
}

/* Strings states */

static void
output_strings_states (struct cb_program *prog)
{
unsigned int strings_defined =
prog->inspect_st ||
prog->string_st||
prog->unstring_st;

if (strings_defined)
output_local ("/* States of string statements */\n");
if (prog->inspect_st)
output_local ("static cob_inspect_state *inspect_st = NULL;\n");
if (prog->string_st)
output_local ("static cob_string_state\t*string_st = NULL;\n");
if (prog->unstring_st)
output_local ("static cob_unstring_state *unstring_st = NULL;\n");
if (strings_defined)
output_newline ();
}

/* Literals, figurative constants and user-defined constants */

static void
Expand Down Expand Up @@ -12873,19 +12851,6 @@ output_internal_function (struct cb_program *prog, cb_tree parameter_list)
output_line ("\tcob_fatal_error (COB_FERROR_CANCEL);");
output_newline ();

if (prog->inspect_st) {
output_line ("if (inspect_st != NULL)");
output_line ("\tcob_inspect_free (inspect_st);");
}
if (prog->string_st) {
output_line ("if (string_st != NULL)");
output_line ("\tcob_string_free (string_st);");
}
if (prog->unstring_st) {
output_line ("if (unstring_st != NULL)");
output_line ("\tcob_unstring_free (unstring_st);");
}

if (prog->flag_main) {
goto cancel_end;
}
Expand Down Expand Up @@ -14092,7 +14057,6 @@ codegen_internal (struct cb_program *prog, const int subsequent_call)
output_call_parameter_stack_pointers (prog);
output_frame_stack (prog);
output_dynamic_field_function_id_pointers ();
output_strings_states (prog);

if (prog->report_storage) {
output_target = prog->local_include->local_fp;
Expand Down
40 changes: 5 additions & 35 deletions cobc/parser.y
Original file line number Diff line number Diff line change
Expand Up @@ -14877,8 +14877,6 @@ inquire_body:
inspect_statement:
INSPECT
{
if (!current_program->inspect_st)
current_program->inspect_st = cb_build_direct ("inspect_st", 0);
begin_statement (STMT_INSPECT, 0);
inspect_keyword = INSPECT_REP_DEFAULT;
}
Expand Down Expand Up @@ -14917,8 +14915,6 @@ inspect_format_variant:
examine_statement:
EXAMINE
{
if (!current_program->inspect_st)
current_program->inspect_st = cb_build_direct ("inspect_st", 0);
begin_statement (STMT_EXAMINE, 0);
}
send_identifier
Expand Down Expand Up @@ -14948,11 +14944,7 @@ examine_format_variant:
t = cb_build_tallying_value (x, r);
break;
case EXAMINE_TAL_UNTIL_FIRST:
r = cb_list_add (r, CB_BUILD_FUNCALL_2 (
"cob_inspect_before_r",
current_program->inspect_st,
x
));
r = cb_list_add (r, CB_BUILD_FUNCALL_1 ("cob_inspect_before", x));
t = cb_build_tallying_characters (r);
break;
/* LCOV_EXCL_START */
Expand All @@ -14973,11 +14965,7 @@ examine_format_variant:
t = cb_build_replacing_leading (x, replacing_to, r);
break;
case EXAMINE_TAL_UNTIL_FIRST:
r = cb_list_add (r, CB_BUILD_FUNCALL_2 (
"cob_inspect_before_r",
current_program->inspect_st,
x
));
r = cb_list_add (r, CB_BUILD_FUNCALL_1 ("cob_inspect_before", x));
t = cb_build_replacing_characters (replacing_to, r);
break;
}
Expand All @@ -15000,11 +14988,7 @@ examine_format_variant:
t = cb_build_replacing_first (from, to, r);
break;
case EXAMINE_REP_UNTIL_FIRST:
r = cb_list_add (r, CB_BUILD_FUNCALL_2 (
"cob_inspect_before_r",
current_program->inspect_st,
from
));
r = cb_list_add (r, CB_BUILD_FUNCALL_1 ("cob_inspect_before", from));
t = cb_build_replacing_characters (to, r);
break;
/* LCOV_EXCL_START */
Expand Down Expand Up @@ -15218,22 +15202,14 @@ inspect_region:
inspect_before:
BEFORE _initial x
{
$$ = CB_BUILD_FUNCALL_2 (
"cob_inspect_before_r",
current_program->inspect_st,
$3
);
$$ = CB_BUILD_FUNCALL_1 ("cob_inspect_before", $3);
}
;

inspect_after:
AFTER _initial x
{
$$ = CB_BUILD_FUNCALL_2 (
"cob_inspect_after_r",
current_program->inspect_st,
$3
);
$$ = CB_BUILD_FUNCALL_1 ("cob_inspect_after", $3);
}
;

Expand Down Expand Up @@ -16910,8 +16886,6 @@ stop_literal:
string_statement:
STRING
{
if (!current_program->string_st)
current_program->string_st = cb_build_direct ("string_st", 0);
begin_statement (STMT_STRING, TERM_STRING);
}
string_body
Expand Down Expand Up @@ -17080,8 +17054,6 @@ terminate_body:
transform_statement:
TRANSFORM
{
if (!current_program->inspect_st)
current_program->inspect_st = cb_build_direct ("inspect_st", 0);
begin_statement (STMT_TRANSFORM, 0);
}
transform_body
Expand Down Expand Up @@ -17125,8 +17097,6 @@ unlock_body:
unstring_statement:
UNSTRING
{
if (!current_program->unstring_st)
current_program->unstring_st = cb_build_direct ("unstring_st", 0);
begin_statement (STMT_UNSTRING, TERM_UNSTRING);
}
unstring_body
Expand Down
3 changes: 0 additions & 3 deletions cobc/tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1899,9 +1899,6 @@ struct cb_program {
const char *extfh; /* CALLFH for this program */

int last_source_line; /* Line of (implicit) END PROGRAM/FUNCTION */
cb_tree inspect_st;
cb_tree string_st;
cb_tree unstring_st;

/* Internal variables */
int loop_counter; /* Loop counters */
Expand Down
Loading

0 comments on commit f5601ef

Please sign in to comment.