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 errors when compiling Argos with the latest Cython #494

Merged
merged 1 commit into from
Apr 29, 2024

Conversation

bdutro
Copy link
Contributor

@bdutro bdutro commented Apr 24, 2024

Fixes NameError: name 'extract_value' is not defined error and a segfault when trying to start Argos.

Fixes #465, #490, #492

    - Fixes `NameError: name 'extract_value' is not defined` error
    - Fixes segfault when trying to start Argos

Fixes #465, #490, #492
@bdutro bdutro requested review from furuame and klingaard April 24, 2024 19:45
Comment on lines +203 to +205
# Color expression namespace
EXPR_NAMESPACE = {'re':re, 'colorsys':colorsys, 'math':math, 'extract':extract_value}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just needed to move this after extract_value was defined - I have no idea why this ever worked to begin with.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was my temporal fix as well!

Comment on lines 408 to 411
def setFontFromDC(self, dc):
self.c_font = getFont(dc.GetFont())[0]
py_font = dc.GetFont()
self.c_font = getFont(py_font)[0]
self.c_bold_font = wxFont(self.c_font)
Copy link
Contributor Author

@bdutro bdutro Apr 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quick explainer of what's happening here:

  • dc.GetFont() returns a Python wx.Font object
  • We call getFont to unwrap it and grab a pointer to the C++ wxFont object underneath it
  • We dereference that pointer and store a copy of the object in this class

The latest version of Cython decided it was a good idea to garbage collect the Python object returned from dc.GetFont() right before it dereferences the C++ pointer and tries to copy the C++ object, which means we end up trying to make a copy of a freed object and we get a segfault.

By storing the result of dc.GetFont() in a temporary variable, we can ensure it lives long enough for the copy to succeed.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow that’s Python internals 🐍

The latest version of Cython decided it was a good idea to garbage collect the Python object returned from dc.GetFont() right before it dereferences the C++ pointer

Dunno why it’s a good idea ... isn’t that usual to collect dynamic object at the end of the function? From what you describe, it’s immdiately collected right after dc.GetFont() ...

Copy link
Member

@furuame furuame left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I’m excited to use this patch!

@klingaard klingaard merged commit 102a119 into master Apr 29, 2024
8 checks passed
@klingaard klingaard deleted the dev/bdutro/cython-argos-fix branch April 29, 2024 20:21
@furuame
Copy link
Member

furuame commented Apr 30, 2024

@bdutro @klingaard Just verified it, It works pretty fine!!! Thank you!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: pipeViewer Issue is related to the Helios Pipeline Viewer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

run helios issue NameError: name 'extract_value' is not defined
3 participants