Skip to content

Prevent interpreter crashes when displaying uninitialized Janus objects - #1

Open
Montana wants to merge 1 commit into
Boeing:mainfrom
Montana:fix-empty-janus-repr
Open

Montana wants to merge 1 commit into
Boeing:mainfrom
Montana:fix-empty-janus-repr

Conversation

@Montana

@Montana Montana commented Sep 18, 2026

Copy link
Copy Markdown

Hey all,

The problem is as follows:

Janus.__repr__ obtains the instance address through getVariableDef().front().getJanusInstance(). A default-constructed Janus has no variables, so accessing the first element invokes undefined behavior.

This causes a segmentation fault when evaluating:

import pyJanus

repr(pyJanus.Janus())

The failure was reproduced on Linux with Python 3.12.14: the subprocess terminated with SIGSEGV (return code -11). Ordinary object inspection in a REPL, notebook, debugger, or assertion diagnostic can therefore terminate the interpreter.

Both __repr__ and __str__ also omit the closing quote around
xml_filename.

Changes

  • Use the current Janus object's address directly in __repr__, removing
    the dependency on a populated variable collection.
  • Accept a const Janus & in the representation callback.
  • Restore the closing filename quote in both representation methods.
  • Add regression tests covering empty-object representation,
    empty-object string formatting, and loaded-model representation
    and instance identity.

The crash regression runs in a subprocess so a future native crash is
reported as a test failure without terminating the entire test suite.

Validation

Built the native bindings using GCC 13.3, CMake 3.31.10, Python 3.12.14, and the repository's pinned submodules.

Check Result
New regression tests against unchanged code 3 failed, including the reproduced segmentation fault
New regression tests after the fix 3 passed
Existing suite against unchanged code 7 passed, 7 failed
Full suite after the fix 10 passed, 7 failed

The seven existing failures all occur in test_set_var_def_example.py while loading SetVarDefExample.xml. The gt_function05 table reports 5 entries against 25 breakpoints. These failures were reproduced on the unmodified baseline; this PR does not change the example or its parsing behavior.

Cheers,
Michael

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant