Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cob_call_with_exception_check (test 771) #129

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions libcob/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@

2023-12-14 David Declerck <[email protected]>

* common.c (cob_terminate_routines, cob_call_with_exception_check):
add a mechanism to postpone unloading of modules when using longjmp,
as this is not safe on Windows (its implementation of longjmp
performs stack-unwinding)

2023-07-28 Simon Sobisch <[email protected]>

* screenio.c, common.c: replace use of NCURSES_MOUSE_VERSION by
Expand Down
30 changes: 27 additions & 3 deletions libcob/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@ struct cob_external {
int esize; /* Item size */
};

/* How should modules be unloaded */

enum cob_module_unload {
COB_IMMEDIATE = 0, /* Module unloading must be performed immediately */
COB_POSTPONE = 1, /* Module unloading must be postponed */
COB_REQUESTED = 2 /* Module unloaded has been requested after being postponed */
};

#define COB_ERRBUF_SIZE 1024

/* Local variables */
Expand All @@ -297,6 +305,8 @@ static const char *cob_last_progid = NULL;
static cob_global *cobglobptr = NULL;
static cob_settings *cobsetptr = NULL;

static enum cob_module_unload module_unload = COB_IMMEDIATE;

static int last_exception_code; /* Last exception: code */
static int active_error_handler = 0;

Expand Down Expand Up @@ -877,8 +887,13 @@ cob_terminate_routines (void)
cob_exit_numeric ();

cob_exit_common_modules ();
cob_exit_call ();
cob_exit_common ();
if (module_unload == COB_IMMEDIATE) {
cob_exit_call ();
cob_exit_common ();
/* If module unloading has been postponed, "remember" unloading has indeed been requested */
} else if (module_unload == COB_POSTPONE) {
module_unload = COB_REQUESTED;
}
}

static void
Expand Down Expand Up @@ -10014,17 +10029,26 @@ cob_common_init (void *setptr)
errors (-1), hard errors (-2) or signals (-3) */
int
cob_call_with_exception_check (const char *name, const int argc, void **argv)
{
{
#ifndef COB_WITHOUT_JMP
int ret;
return_jmp_buffer_set = 1;
ret = setjmp (return_jmp_buf);
if (ret) {
return_jmp_buffer_set = 0;
/* Module unloading has been requested (after being postponed): perform it */
if (module_unload == COB_REQUESTED) {
cob_exit_call ();
cob_exit_common ();
}
module_unload = COB_IMMEDIATE;
return ret;
}
/* Set module unloading to be postponed (until longjmp is performed) */
module_unload = COB_POSTPONE;
#endif
exit_code = cob_call (name, argc, argv);
module_unload = COB_IMMEDIATE;
return 0;
}

Expand Down
Loading