Skip to content

Fix SWIG stdout/err redirection bug

Description

The SWIG stdout/err redirection code (!1827 (merged)) is currently not reentrant, i.e. it's not safe when a SWIG wrapper function ends up calling another SWIG wrapper function. This behaviour can however occur e.g. with destructor functions calling other destructor functions.

This MR fixes the bug by adding a flag to indicate whether stdout/err redirection is already in force (i.e. in the outermost SWIG wrapper function) so that any nested SWIG wrapper function calls do not attempt to re-redirect stdout/err.

This MR also streamlines the stdout/err redirection code by only using low-level file descriptors and the system open(), close(), etc. file functions. (Realised too late that this was using Linux-specific features.)

This MR reverts the workaround in !1960 (merged) for lalpulsar/python/lalpulsar/PulsarParametersWrapper.py as it is no longer needed.

API Changes and Justification

Backwards Compatible Changes

  • This change does not modify any class/function/struct/type definitions in a public C header file or any Python class/function definitions
  • This change adds new classes/functions/structs/types to a public C header file or Python module

Backwards Incompatible Changes

  • This change modifies an existing class/function/struct/type definition in a public C header file or Python module
  • This change removes an existing class/function/struct/type from a public C header file or Python module

Review Status

This MR needs !1960 (merged) to be merged first.

cc @adam-mercer @matthew-pitkin

Edited by Karl Wette

Merge request reports

Loading