-
Notifications
You must be signed in to change notification settings - Fork 59
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
Conversation
# Color expression namespace | ||
EXPR_NAMESPACE = {'re':re, 'colorsys':colorsys, 'math':math, 'extract':extract_value} | ||
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
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) |
There was a problem hiding this comment.
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 Pythonwx.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.
There was a problem hiding this comment.
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() ...
There was a problem hiding this 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!
@bdutro @klingaard Just verified it, It works pretty fine!!! Thank you!!! |
Fixes
NameError: name 'extract_value' is not defined
error and a segfault when trying to start Argos.Fixes #465, #490, #492