Skip to content

Commit

Permalink
Make chpl_library_finalize re-entrant
Browse files Browse the repository at this point in the history
We were encountering a problem when chpl_library_finalize was getting called
multiple times - exiting the Python program would result in:

```
Assertion failed: (data && data->bundle), function chpl_task_getInfoChapel, file chpl-tasks-impl-fns.h, line 140.
```

because our generated `__init__.py` file added an `atexit` call to clean up the
runtime, but code could invoke an explicit cleanup call as well.

I need to take a look if we explicitly state you need to make that cleanup call,
but this may also help in cases where multiple Chapel libraries are used in a
Python program.

----
Signed-off-by: Lydia Duncan <[email protected]>
  • Loading branch information
lydia-duncan committed Nov 12, 2024
1 parent a06d6f4 commit 2dbff81
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions runtime/src/chpl-init.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,23 @@ void chpl_library_init(int argc, char* argv[]) {
// we may have initialized
extern void chpl_deinitModules(void);

bool lib_deinited = false;

//
// A wrapper around chplexit.c:chpl_finalize(...), sole purpose is
// to provide a "chpl_library_*" interface for the Chapel "library-user".
void chpl_library_finalize(void) {
if (!lib_inited) {
return;
}

if (lib_deinited) {
// Nothing to do, we've already been cleaned up
return;
} else {
lib_deinited = true;
}

chpl_libraryModuleLevelCleanup();
chpl_deinitModules();
chpl_finalize(0, 1);
Expand Down

0 comments on commit 2dbff81

Please sign in to comment.