You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a Segmentation Fault in the attached example (simplified from actually failing production code).
Requirement for failure:
Usage of Walrus Operator in an if statement.
First If Statement does not fully evaluate
Second If Statement uses same variable name in assignment operator.
Segmentation fault occurs because Variable gets dereferenced in the second If-condition without having a value assigned.
The assignment doesn't happen because first If-condition doesn't get fully evaluated.
Thanks - in the short term I suspect the better solution is to treat assignment expressions as "maybe assignments" rather than "definite assignments". There's quite a few variations of cases like this where it isn't clear if they're actually run and which our flow control doesn't currently cover so working it out comprehensively is likely hard.
That'll de-optimize assignment expressions slightly but I think that's OK.
da-woods
added a commit
to da-woods/cython
that referenced
this issue
Apr 1, 2024
Some expressions are partly conditionally evaluated, and so
bits of them may be skipped. This has implications if they
contain an assignment expression since the variable may not
actually be assigned.
The tests for various comprehensions aren't actually needed
since they already worked, but are added for completeness.
Fixescython#6094
walrus define variable after or operate, make gunicorn crash: [ERROR] Worker (pid:9467) was sent code 139!
deffunc(cell: dict):
if (flag :=True) or ((text := cell.get("text")) and text.isdigit()):
returnTrue
text = cell.get("text") or cell.get("value")
return text
Describe the bug
There is a Segmentation Fault in the attached example (simplified from actually failing production code).
Requirement for failure:
Segmentation fault occurs because Variable gets dereferenced in the second If-condition without having a value assigned.
The assignment doesn't happen because first If-condition doesn't get fully evaluated.
Code to reproduce the behaviour:
Expected behaviour
No Segmentation Fault in Cythonized code
OS
Linux
Python version
3.11.8
Cython version
latest master
Additional context
No response
The text was updated successfully, but these errors were encountered: