Stefan Behnel schrieb am 05.09.2015 um 16:01:
Jeroen Demeyer schrieb am 05.09.2015 um 12:17:
I noticed that now unsigned constants like
DEF foo = 1
become 1U in the C source code.
This change (i.e. commit ea6414cd293ba2134c3df5b37b158d8e3db79083) broke Sage. I haven't managed yet to actually isolate why this change broke something.
Was this change of 1 to 1U intentional? Why was it done?
Pretty much intentional, yes. I changed it in response to this bug report:
http://thread.gmane.org/gmane.comp.python.cython.devel/15774
The problem with DEF constants is that they are Python values that use Python semantics in expressions before they eventually get converted back into literals and inserted into the AST. Specifically, they loose any literals semantics that they initially had in the source code, including any information about literal C integer types that contributed to their value, as in this case. Thus, there isn't really a 'correct' way to write them out as literals and C might be happy with what we output, or not.
I guess it might be better to undo this part of the change. Unsigned literals are usually not the right way to do it in C, definitely not for everything. We could then maybe apply the usual 32/64 bits heuristic to add at least L/LL suffixes at need.
Does this look better? https://github.com/cython/cython/commit/2ac9ffbab1e868137bf33bf025eb7a5c7e47... It now appends the 'U' suffix only to literals that are used in an unsigned context (e.g. assignment to unsigned variable), and additionally appends L/LL suffixes for integers that might exceed the int/long limits. That's just guessing, but it should generally improve the current handling of literals and DEF expressions. Stefan